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

jreleaser / jreleaser / #537

25 Sep 2025 02:50PM UTC coverage: 48.299% (-0.7%) from 48.959%
#537

push

github

web-flow
fix: check snapshot version for '-SNAPSHOT' tag

Fixe #1971

2 of 2 new or added lines in 1 file covered. (100.0%)

362 existing lines in 31 files now uncovered.

25821 of 53461 relevant lines covered (48.3%)

0.48 hits per line

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

49.14
/core/jreleaser-engine/src/main/java/org/jreleaser/engine/distribution/Distributions.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.engine.distribution;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.extensions.api.workflow.WorkflowListenerException;
22
import org.jreleaser.model.JReleaserException;
23
import org.jreleaser.model.api.JReleaserCommand;
24
import org.jreleaser.model.api.hooks.ExecutionEvent;
25
import org.jreleaser.model.internal.JReleaserContext;
26
import org.jreleaser.model.internal.distributions.Distribution;
27
import org.jreleaser.model.internal.packagers.Packager;
28
import org.jreleaser.model.spi.packagers.PackagerProcessingException;
29

30
import java.util.List;
31
import java.util.Locale;
32

33
import static org.jreleaser.model.internal.JReleaserSupport.supportedPackagers;
34

35
/**
36
 * @author Andres Almiray
37
 * @since 0.1.0
38
 */
39
public final class Distributions {
40
    private Distributions() {
41
        // noop
42
    }
43

44
    public static void process(JReleaserContext context, DistributionProcessor.PackagingAction action) {
45
        List<Distribution> activeDistributions = context.getModel().getActiveDistributions();
1✔
46

47
        if (activeDistributions.isEmpty()) {
1✔
48
            context.getLogger().debug(RB.$("distributions.not.enabled"), action.getText().toLowerCase(Locale.ENGLISH));
×
49
            return;
×
50
        }
51

52
        if (!context.getIncludedDistributions().isEmpty()) {
1✔
53
            for (String distributionName : context.getIncludedDistributions()) {
×
54
                Distribution distribution = activeDistributions.stream()
×
55
                    .filter(d -> distributionName.equals(d.getName()))
×
56
                    .findFirst().orElse(null);
×
57

58
                if (null == distribution) {
×
59
                    context.getLogger().error(RB.$("distributions.no.match"), distributionName);
×
60
                    return;
×
61
                }
62

63
                if (!context.getIncludedPackagers().isEmpty()) {
×
64
                    for (String packagerName : context.getIncludedPackagers()) {
×
65
                        if (!supportedPackagers().contains(packagerName)) {
×
66
                            context.getLogger().warn(RB.$("ERROR_unsupported_packager", packagerName));
×
67
                            continue;
×
68
                        }
69

70
                        context.getLogger().info(RB.$("distributions.apply.action"), action.getText());
×
71

72
                        processDistribution(context, distribution, packagerName, action);
×
73
                    }
×
74
                } else {
75
                    processDistribution(context, distribution, action);
×
76
                }
77
            }
×
78
        } else if (!context.getIncludedPackagers().isEmpty()) {
1✔
79
            for (String packagerName : context.getIncludedPackagers()) {
×
80
                if (!supportedPackagers().contains(packagerName)) {
×
81
                    context.getLogger().warn(RB.$("ERROR_unsupported_packager", packagerName));
×
82
                    continue;
×
83
                }
84

85
                context.getLogger().info(RB.$("distributions.apply.action"), action.getText());
×
86
                for (Distribution distribution : activeDistributions) {
×
87
                    processDistribution(context, distribution, packagerName, action);
×
88
                }
×
89
            }
×
90
        } else {
91
            // process all
92
            context.getLogger().info(RB.$("distributions.apply.action"), action.getText());
1✔
93
            for (Distribution distribution : activeDistributions) {
1✔
94
                if (context.getExcludedDistributions().contains(distribution.getName())) {
1✔
95
                    context.getLogger().info(RB.$("distributions.distribution.excluded"), distribution.getName());
×
96
                    continue;
×
97
                }
98

99
                processDistribution(context, distribution, action);
1✔
100
            }
1✔
101
        }
102
    }
1✔
103

104
    private static void processDistribution(JReleaserContext context, Distribution distribution, DistributionProcessor.PackagingAction action) {
105
        context.getLogger().increaseIndent();
1✔
106
        context.getLogger().info(RB.$("distributions.apply.action.to"), action.getText(), distribution.getName());
1✔
107

108
        fireDistributionStartEvent(context, distribution);
1✔
109

110
        for (String packagerName : supportedPackagers()) {
1✔
111
            if (context.getExcludedPackagers().contains(packagerName)) {
1✔
112
                context.getLogger().info(RB.$("packagers.packager.excluded"), packagerName);
1✔
113
                continue;
1✔
114
            }
115
            processPackager(context, distribution, packagerName, action);
1✔
116
        }
1✔
117

118
        fireDistributionEndEvent(context, distribution);
1✔
119

120
        context.getLogger().decreaseIndent();
1✔
121
    }
1✔
122

123
    private static void processDistribution(JReleaserContext context, Distribution distribution, String packagerName, DistributionProcessor.PackagingAction action) {
124
        context.getLogger().increaseIndent();
×
125
        context.getLogger().info(RB.$("distributions.apply.action.to"), action.getText(), distribution.getName());
×
126

127
        processPackager(context, distribution, packagerName, action);
×
128

129
        context.getLogger().decreaseIndent();
×
130
    }
×
131

132
    private static void processPackager(JReleaserContext context, Distribution distribution, String packagerName, DistributionProcessor.PackagingAction action) {
133
        Packager<?> packager = distribution.findPackager(packagerName);
1✔
134

135
        try {
136
            context.getLogger().increaseIndent();
1✔
137
            context.getLogger().setPrefix(packagerName);
1✔
138
            firePackagerEvent(ExecutionEvent.before(actionToStep(action.getType())), context, distribution, action.getType(), packager);
1✔
139

140
            DistributionProcessor processor = createDistributionProcessor(context,
1✔
141
                distribution,
142
                packagerName);
143

144
            action.getFunction().consume(processor);
1✔
145

146
            firePackagerEvent(ExecutionEvent.success(actionToStep(action.getType())), context, distribution, action.getType(), packager);
1✔
UNCOV
147
        } catch (PackagerProcessingException e) {
×
UNCOV
148
            firePackagerEvent(ExecutionEvent.failure(actionToStep(action.getType()), e), context, distribution, action.getType(), packager);
×
UNCOV
149
            throw new JReleaserException(RB.$("ERROR_unexpected_error"), e);
×
150
        } finally {
151
            context.getLogger().restorePrefix();
1✔
152
            context.getLogger().decreaseIndent();
1✔
153
        }
154
    }
1✔
155

156
    private static String actionToStep(DistributionProcessor.PackagingAction.Type type) {
157
        switch (type) {
1✔
158
            case PACKAGE:
159
                return JReleaserCommand.PACKAGE.toStep();
1✔
160
            case PUBLISH:
161
                return JReleaserCommand.PUBLISH.toStep();
1✔
162
            default:
163
                // noop
164
                break;
165
        }
166
        return JReleaserCommand.PREPARE.toStep();
1✔
167
    }
168

169
    private static DistributionProcessor createDistributionProcessor(JReleaserContext context,
170
                                                                     Distribution distribution,
171
                                                                     String packagerName) {
172
        return DistributionProcessor.builder()
1✔
173
            .context(context)
1✔
174
            .distributionName(distribution.getName())
1✔
175
            .packagerName(packagerName)
1✔
176
            .build();
1✔
177
    }
178

179
    private static void fireDistributionStartEvent(JReleaserContext context, Distribution distribution) {
180
        try {
181
            context.fireDistributionStartEvent(distribution.asImmutable());
1✔
182
        } catch (WorkflowListenerException e) {
×
183
            context.getLogger().error(RB.$("listener.failure", e.getListener().getClass().getName()));
×
184
            context.getLogger().trace(e);
×
185
            if (!e.getListener().isContinueOnError()) {
×
186
                if (e.getCause() instanceof RuntimeException) {
×
187
                    throw (RuntimeException) e.getCause();
×
188
                } else {
189
                    throw new JReleaserException(RB.$("ERROR_unexpected_error"), e.getCause());
×
190
                }
191
            }
192
        }
1✔
193
    }
1✔
194

195
    private static void fireDistributionEndEvent(JReleaserContext context, Distribution distribution) {
196
        if (!distribution.isEnabled()) return;
1✔
197

198
        try {
199
            context.fireDistributionEndEvent(distribution.asImmutable());
1✔
200
        } catch (WorkflowListenerException e) {
×
201
            context.getLogger().error(RB.$("listener.failure", e.getListener().getClass().getName()));
×
202
            context.getLogger().trace(e);
×
203
            if (!e.getListener().isContinueOnError()) {
×
204
                if (e.getCause() instanceof RuntimeException) {
×
205
                    throw (RuntimeException) e.getCause();
×
206
                } else {
207
                    throw new JReleaserException(RB.$("ERROR_unexpected_error"), e.getCause());
×
208
                }
209
            }
210
        }
1✔
211
    }
1✔
212

213
    private static void firePackagerEvent(ExecutionEvent event, JReleaserContext context, Distribution distribution, DistributionProcessor.PackagingAction.Type type, Packager<?> packager) {
214
        if (!packager.isEnabled()) return;
1✔
215

216
        try {
217
            switch (type) {
1✔
218
                case PREPARE:
219
                    context.firePackagerPrepareEvent(event, distribution.asImmutable(), packager.asImmutable());
1✔
220
                    break;
1✔
221
                case PACKAGE:
222
                    context.firePackagerPackageEvent(event, distribution.asImmutable(), packager.asImmutable());
1✔
223
                    break;
1✔
224
                case PUBLISH:
225
                    context.firePackagerPublishEvent(event, distribution.asImmutable(), packager.asImmutable());
1✔
226
                    break;
227
            }
228
        } catch (WorkflowListenerException e) {
×
229
            context.getLogger().error(RB.$("listener.failure", e.getListener().getClass().getName()));
×
230
            context.getLogger().trace(e);
×
231
            if (event.getType() != ExecutionEvent.Type.FAILURE && !e.getListener().isContinueOnError()) {
×
232
                if (e.getCause() instanceof RuntimeException) {
×
233
                    throw (RuntimeException) e.getCause();
×
234
                } else {
235
                    throw new JReleaserException(RB.$("ERROR_unexpected_error"), e.getCause());
×
236
                }
237
            }
238
        }
1✔
239
    }
1✔
240
}
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