• 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

0.0
/core/jreleaser-model-impl/src/main/java/org/jreleaser/model/internal/hooks/NamedScriptHooks.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.stream.Collectors.toList;
34

35
/**
36
 * @author Andres Almiray
37
 * @since 1.6.0
38
 */
39
public final class NamedScriptHooks extends AbstractActivatable<NamedScriptHooks> implements Domain {
40
    private static final long serialVersionUID = -6502126145832381920L;
41

NEW
42
    private final List<ScriptHook> before = new ArrayList<>();
×
NEW
43
    private final List<ScriptHook> success = new ArrayList<>();
×
NEW
44
    private final List<ScriptHook> failure = new ArrayList<>();
×
NEW
45
    private final Map<String, String> environment = new LinkedHashMap<>();
×
NEW
46
    private final Matrix matrix = new Matrix();
×
47

48
    private String name;
49
    private String condition;
50
    private Boolean applyDefaultMatrix;
51

NEW
52
    @JsonIgnore
×
NEW
53
    private final org.jreleaser.model.api.hooks.NamedScriptHooks immutable = new org.jreleaser.model.api.hooks.NamedScriptHooks() {
×
54
        private static final long serialVersionUID = 6452589570225991883L;
55

56
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> before;
57
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> success;
58
        private List<? extends org.jreleaser.model.api.hooks.ScriptHook> failure;
59

60
        @Override
61
        public String getName() {
NEW
62
            return NamedScriptHooks.this.getName();
×
63
        }
64

65
        @Override
66
        public String getCondition() {
NEW
67
            return NamedScriptHooks.this.getCondition();
×
68
        }
69

70
        @Override
71
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getBefore() {
NEW
72
            if (null == before) {
×
NEW
73
                before = NamedScriptHooks.this.before.stream()
×
NEW
74
                    .map(ScriptHook::asImmutable)
×
NEW
75
                    .collect(toList());
×
76
            }
NEW
77
            return before;
×
78
        }
79

80
        @Override
81
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getSuccess() {
NEW
82
            if (null == success) {
×
NEW
83
                success = NamedScriptHooks.this.success.stream()
×
NEW
84
                    .map(ScriptHook::asImmutable)
×
NEW
85
                    .collect(toList());
×
86
            }
NEW
87
            return success;
×
88
        }
89

90
        @Override
91
        public List<? extends org.jreleaser.model.api.hooks.ScriptHook> getFailure() {
NEW
92
            if (null == failure) {
×
NEW
93
                failure = NamedScriptHooks.this.failure.stream()
×
NEW
94
                    .map(ScriptHook::asImmutable)
×
NEW
95
                    .collect(toList());
×
96
            }
NEW
97
            return failure;
×
98
        }
99

100
        @Override
101
        public Map<String, String> getEnvironment() {
NEW
102
            return unmodifiableMap(NamedScriptHooks.this.getEnvironment());
×
103
        }
104

105
        @Override
106
        public boolean isApplyDefaultMatrix() {
NEW
107
            return NamedScriptHooks.this.isApplyDefaultMatrix();
×
108
        }
109

110
        @Override
111
        public org.jreleaser.model.api.common.Matrix getMatrix() {
NEW
112
            return matrix.asImmutable();
×
113
        }
114

115
        @Override
116
        public Active getActive() {
NEW
117
            return NamedScriptHooks.this.getActive();
×
118
        }
119

120
        @Override
121
        public boolean isEnabled() {
NEW
122
            return NamedScriptHooks.this.isEnabled();
×
123
        }
124

125
        @Override
126
        public Map<String, Object> asMap(boolean full) {
NEW
127
            return Collections.unmodifiableMap(NamedScriptHooks.this.asMap(full));
×
128
        }
129
    };
130

NEW
131
    public NamedScriptHooks() {
×
NEW
132
        enabledSet(true);
×
NEW
133
    }
×
134

135
    public org.jreleaser.model.api.hooks.NamedScriptHooks asImmutable() {
NEW
136
        return immutable;
×
137
    }
138

139
    @Override
140
    public void merge(NamedScriptHooks source) {
NEW
141
        super.merge(source);
×
NEW
142
        this.name = merge(this.name, source.name);
×
NEW
143
        this.condition = merge(this.condition, source.condition);
×
NEW
144
        setBefore(merge(this.before, source.before));
×
NEW
145
        setSuccess(merge(this.success, source.success));
×
NEW
146
        setFailure(merge(this.failure, source.failure));
×
NEW
147
        setEnvironment(merge(this.environment, source.getEnvironment()));
×
NEW
148
        setMatrix(source.matrix);
×
NEW
149
    }
×
150

151
    @Override
152
    public boolean isSet() {
NEW
153
        return super.isSet() ||
×
NEW
154
            !before.isEmpty() ||
×
NEW
155
            !success.isEmpty() ||
×
NEW
156
            !failure.isEmpty();
×
157
    }
158

159
    public String getName() {
NEW
160
        return name;
×
161
    }
162

163
    public void setName(String name) {
NEW
164
        this.name = name;
×
NEW
165
    }
×
166

167
    public String getCondition() {
NEW
168
        return condition;
×
169
    }
170

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

175
    public List<ScriptHook> getBefore() {
NEW
176
        return before;
×
177
    }
178

179
    public void setBefore(List<ScriptHook> before) {
NEW
180
        this.before.clear();
×
NEW
181
        this.before.addAll(before);
×
NEW
182
    }
×
183

184
    public List<ScriptHook> getSuccess() {
NEW
185
        return success;
×
186
    }
187

188
    public void setSuccess(List<ScriptHook> success) {
NEW
189
        this.success.clear();
×
NEW
190
        this.success.addAll(success);
×
NEW
191
    }
×
192

193
    public List<ScriptHook> getFailure() {
NEW
194
        return failure;
×
195
    }
196

197
    public void setFailure(List<ScriptHook> failure) {
NEW
198
        this.failure.clear();
×
NEW
199
        this.failure.addAll(failure);
×
NEW
200
    }
×
201

202
    public void addBefore(ScriptHook hook) {
NEW
203
        if (null != hook) {
×
NEW
204
            this.before.add(hook);
×
205
        }
NEW
206
    }
×
207

208
    public void addSuccess(ScriptHook hook) {
NEW
209
        if (null != hook) {
×
NEW
210
            this.success.add(hook);
×
211
        }
NEW
212
    }
×
213

214
    public void addFailure(ScriptHook hook) {
NEW
215
        if (null != hook) {
×
NEW
216
            this.failure.add(hook);
×
217
        }
NEW
218
    }
×
219

220
    public Map<String, String> getEnvironment() {
NEW
221
        return environment;
×
222
    }
223

224
    public void setEnvironment(Map<String, String> environment) {
NEW
225
        this.environment.clear();
×
NEW
226
        this.environment.putAll(environment);
×
NEW
227
    }
×
228

229
    public boolean isApplyDefaultMatrixSet() {
NEW
230
        return null != applyDefaultMatrix;
×
231
    }
232

233
    public boolean isApplyDefaultMatrix() {
NEW
234
        return null != applyDefaultMatrix && applyDefaultMatrix;
×
235
    }
236

237
    public void setApplyDefaultMatrix(Boolean applyDefaultMatrix) {
NEW
238
        this.applyDefaultMatrix = applyDefaultMatrix;
×
NEW
239
    }
×
240

241
    public Matrix getMatrix() {
NEW
242
        return matrix;
×
243
    }
244

245
    public void setMatrix(Matrix matrix) {
NEW
246
        this.matrix.merge(matrix);
×
NEW
247
    }
×
248

249
    @Override
250
    public Map<String, Object> asMap(boolean full) {
NEW
251
        Map<String, Object> map = new LinkedHashMap<>();
×
NEW
252
        map.put("enabled", isEnabled());
×
NEW
253
        map.put("active", getActive());
×
NEW
254
        map.put("name", name);
×
NEW
255
        map.put("condition", condition);
×
NEW
256
        map.put("environment", environment);
×
NEW
257
        matrix.asMap(map);
×
258

NEW
259
        Map<String, Map<String, Object>> m = new LinkedHashMap<>();
×
NEW
260
        int i = 0;
×
NEW
261
        for (ScriptHook hook : getBefore()) {
×
NEW
262
            m.put("hook " + (i++), hook.asMap(full));
×
NEW
263
        }
×
NEW
264
        map.put("before", m);
×
265

NEW
266
        m = new LinkedHashMap<>();
×
NEW
267
        i = 0;
×
NEW
268
        for (ScriptHook hook : getSuccess()) {
×
NEW
269
            m.put("hook " + (i++), hook.asMap(full));
×
NEW
270
        }
×
NEW
271
        map.put("success", m);
×
272

NEW
273
        m = new LinkedHashMap<>();
×
NEW
274
        i = 0;
×
NEW
275
        for (ScriptHook hook : getFailure()) {
×
NEW
276
            m.put("hook " + (i++), hook.asMap(full));
×
NEW
277
        }
×
NEW
278
        map.put("failure", m);
×
279

NEW
280
        return map;
×
281
    }
282
}
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