• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jreleaser / jreleaser / #513

27 Jul 2025 10:36PM UTC coverage: 44.82% (-0.3%) from 45.153%
#513

push

github

aalmiray
feat(hooks): Add named groups to command and script hooks

Closes #1947

55 of 478 new or added lines in 14 files covered. (11.51%)

18 existing lines in 6 files now uncovered.

23664 of 52798 relevant lines covered (44.82%)

0.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.06
/core/jreleaser-model-impl/src/main/java/org/jreleaser/model/internal/hooks/ScriptHooks.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * Copyright 2020-2025 The JReleaser authors.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.jreleaser.model.internal.hooks;
19

20
import com.fasterxml.jackson.annotation.JsonIgnore;
21
import org.jreleaser.model.Active;
22
import org.jreleaser.model.internal.common.AbstractActivatable;
23
import org.jreleaser.model.internal.common.Domain;
24
import org.jreleaser.model.internal.common.Matrix;
25

26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.LinkedHashMap;
29
import java.util.List;
30
import java.util.Map;
31

32
import static java.util.Collections.unmodifiableMap;
33
import static java.util.function.UnaryOperator.identity;
34
import static java.util.stream.Collectors.toList;
35
import static java.util.stream.Collectors.toMap;
36

37
/**
38
 * @author Andres Almiray
39
 * @since 1.6.0
40
 */
41
public final class ScriptHooks extends AbstractActivatable<ScriptHooks> implements Domain {
42
    private static final long serialVersionUID = 1187801964887441750L;
43

44
    private final Map<String, NamedScriptHooks> groups = new LinkedHashMap<>();
1✔
45
    private final List<ScriptHook> before = new ArrayList<>();
1✔
46
    private final List<ScriptHook> success = new ArrayList<>();
1✔
47
    private final List<ScriptHook> failure = new ArrayList<>();
1✔
48
    private final Map<String, String> environment = new LinkedHashMap<>();
1✔
49
    private final Matrix matrix = new Matrix();
1✔
50

51
    private String condition;
52
    private Boolean applyDefaultMatrix;
53

54
    @JsonIgnore
1✔
55
    private final org.jreleaser.model.api.hooks.ScriptHooks immutable = new org.jreleaser.model.api.hooks.ScriptHooks() {
1✔
56
        private static final long serialVersionUID = -1023913545346878510L;
57

58
        private Map<String, ? extends org.jreleaser.model.api.hooks.NamedScriptHooks> groups;
59
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> before;
60
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> success;
61
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> failure;
62

63
        @Override
64
        public String getCondition() {
65
            return ScriptHooks.this.getCondition();
×
66
        }
67

68
        @Override
69
        public Map<String, ? extends org.jreleaser.model.api.hooks.NamedScriptHooks> getGroups() {
NEW
70
            if (null == groups) {
×
NEW
71
                groups = ScriptHooks.this.groups.values().stream()
×
NEW
72
                    .map(NamedScriptHooks::asImmutable)
×
NEW
73
                    .collect(toMap(org.jreleaser.model.api.hooks.NamedScriptHooks::getName, identity()));
×
74
            }
NEW
75
            return groups;
×
76
        }
77

78
        @Override
79
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getBefore() {
80
            if (null == before) {
×
81
                before = ScriptHooks.this.before.stream()
×
82
                    .map(ScriptHook::asImmutable)
×
83
                    .collect(toList());
×
84
            }
85
            return before;
×
86
        }
87

88
        @Override
89
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getSuccess() {
90
            if (null == success) {
×
91
                success = ScriptHooks.this.success.stream()
×
92
                    .map(ScriptHook::asImmutable)
×
93
                    .collect(toList());
×
94
            }
95
            return success;
×
96
        }
97

98
        @Override
99
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getFailure() {
100
            if (null == failure) {
×
101
                failure = ScriptHooks.this.failure.stream()
×
102
                    .map(ScriptHook::asImmutable)
×
103
                    .collect(toList());
×
104
            }
105
            return failure;
×
106
        }
107

108
        @Override
109
        public Map<String, String> getEnvironment() {
110
            return unmodifiableMap(ScriptHooks.this.getEnvironment());
×
111
        }
112

113
        @Override
114
        public boolean isApplyDefaultMatrix() {
115
            return ScriptHooks.this.isApplyDefaultMatrix();
×
116
        }
117

118
        @Override
119
        public org.jreleaser.model.api.common.Matrix getMatrix() {
120
            return matrix.asImmutable();
×
121
        }
122

123
        @Override
124
        public Active getActive() {
125
            return ScriptHooks.this.getActive();
×
126
        }
127

128
        @Override
129
        public boolean isEnabled() {
130
            return ScriptHooks.this.isEnabled();
×
131
        }
132

133
        @Override
134
        public Map<String, Object> asMap(boolean full) {
135
            return Collections.unmodifiableMap(ScriptHooks.this.asMap(full));
×
136
        }
137
    };
138

139
    public ScriptHooks() {
1✔
140
        enabledSet(true);
1✔
141
    }
1✔
142

143
    public org.jreleaser.model.api.hooks.ScriptHooks asImmutable() {
144
        return immutable;
×
145
    }
146

147
    @Override
148
    public void merge(ScriptHooks source) {
149
        super.merge(source);
1✔
150
        this.condition = merge(this.condition, source.condition);
1✔
151
        setGroups(mergeModel(this.groups, source.groups));
1✔
152
        setBefore(merge(this.before, source.before));
1✔
153
        setSuccess(merge(this.success, source.success));
1✔
154
        setFailure(merge(this.failure, source.failure));
1✔
155
        setEnvironment(merge(this.environment, source.getEnvironment()));
1✔
156
        setMatrix(source.matrix);
1✔
157
    }
1✔
158

159
    @Override
160
    public boolean isSet() {
161
        return super.isSet() ||
×
162
            !before.isEmpty() ||
×
163
            !success.isEmpty() ||
×
164
            !failure.isEmpty();
×
165
    }
166

167
    public String getCondition() {
168
        return condition;
1✔
169
    }
170

171
    public void setCondition(String condition) {
172
        this.condition = condition;
×
173
    }
×
174

175
    public Map<String, NamedScriptHooks> getGroups() {
176
        return groups;
1✔
177
    }
178

179
    public void setGroups(Map<String, NamedScriptHooks> groups) {
180
        this.groups.clear();
1✔
181
        this.groups.putAll(groups);
1✔
182
    }
1✔
183

184
    public void addGroup(NamedScriptHooks hook) {
NEW
185
        this.groups.put(hook.getName(), hook);
×
NEW
186
    }
×
187

188
    public List<ScriptHook> getBefore() {
189
        return before;
1✔
190
    }
191

192
    public void setBefore(List<ScriptHook> before) {
193
        this.before.clear();
1✔
194
        this.before.addAll(before);
1✔
195
    }
1✔
196

197
    public List<ScriptHook> getSuccess() {
198
        return success;
1✔
199
    }
200

201
    public void setSuccess(List<ScriptHook> success) {
202
        this.success.clear();
1✔
203
        this.success.addAll(success);
1✔
204
    }
1✔
205

206
    public List<ScriptHook> getFailure() {
207
        return failure;
1✔
208
    }
209

210
    public void setFailure(List<ScriptHook> failure) {
211
        this.failure.clear();
1✔
212
        this.failure.addAll(failure);
1✔
213
    }
1✔
214

215
    public void addBefore(ScriptHook hook) {
216
        if (null != hook) {
×
217
            this.before.add(hook);
×
218
        }
219
    }
×
220

221
    public void addSuccess(ScriptHook hook) {
222
        if (null != hook) {
×
223
            this.success.add(hook);
×
224
        }
225
    }
×
226

227
    public void addFailure(ScriptHook hook) {
228
        if (null != hook) {
×
229
            this.failure.add(hook);
×
230
        }
231
    }
×
232

233
    public Map<String, String> getEnvironment() {
234
        return environment;
1✔
235
    }
236

237
    public void setEnvironment(Map<String, String> environment) {
238
        this.environment.clear();
1✔
239
        this.environment.putAll(environment);
1✔
240
    }
1✔
241

242
    public boolean isApplyDefaultMatrixSet() {
243
        return null != applyDefaultMatrix;
×
244
    }
245

246
    public boolean isApplyDefaultMatrix() {
247
        return null != applyDefaultMatrix && applyDefaultMatrix;
1✔
248
    }
249

250
    public void setApplyDefaultMatrix(Boolean applyDefaultMatrix) {
251
        this.applyDefaultMatrix = applyDefaultMatrix;
×
252
    }
×
253

254
    public Matrix getMatrix() {
255
        return matrix;
1✔
256
    }
257

258
    public void setMatrix(Matrix matrix) {
259
        this.matrix.merge(matrix);
1✔
260
    }
1✔
261

262
    @Override
263
    public Map<String, Object> asMap(boolean full) {
264
        Map<String, Object> map = new LinkedHashMap<>();
1✔
265
        map.put("enabled", isEnabled());
1✔
266
        map.put("active", getActive());
1✔
267
        map.put("condition", condition);
1✔
268
        map.put("environment", environment);
1✔
269
        matrix.asMap(map);
1✔
270

271
        Map<String, Map<String, Object>> m = new LinkedHashMap<>();
1✔
272
        int i = 0;
1✔
273
        for (ScriptHook hook : getBefore()) {
1✔
274
            m.put("hook " + (i++), hook.asMap(full));
1✔
275
        }
1✔
276
        map.put("before", m);
1✔
277

278
        m = new LinkedHashMap<>();
1✔
279
        i = 0;
1✔
280
        for (ScriptHook hook : getSuccess()) {
1✔
281
            m.put("hook " + (i++), hook.asMap(full));
×
282
        }
×
283
        map.put("success", m);
1✔
284

285
        m = new LinkedHashMap<>();
1✔
286
        i = 0;
1✔
287
        for (ScriptHook hook : getFailure()) {
1✔
288
            m.put("hook " + (i++), hook.asMap(full));
×
289
        }
×
290
        map.put("failure", m);
1✔
291

292
        List<Map<String, Object>> groups = this.groups.values()
1✔
293
            .stream()
1✔
294
            .filter(d -> full || d.isEnabled())
1✔
295
            .map(d -> d.asMap(full))
1✔
296
            .collect(toList());
1✔
297
        if (!groups.isEmpty()) map.put("groups", groups);
1✔
298

299
        return map;
1✔
300
    }
301
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc