• 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

91.36
/core/jreleaser-engine/src/main/java/org/jreleaser/engine/distribution/DistributionProcessor.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.model.Constants;
22
import org.jreleaser.model.internal.JReleaserContext;
23
import org.jreleaser.model.internal.distributions.Distribution;
24
import org.jreleaser.model.internal.packagers.Packager;
25
import org.jreleaser.model.spi.packagers.PackagerProcessingException;
26
import org.jreleaser.model.spi.packagers.PackagerProcessor;
27
import org.jreleaser.mustache.TemplateContext;
28

29
import static java.util.Objects.requireNonNull;
30
import static org.jreleaser.util.StringUtils.requireNonBlank;
31

32
/**
33
 * @author Andres Almiray
34
 * @since 0.1.0
35
 */
36
public class DistributionProcessor {
37
    private final JReleaserContext context;
38
    private final String distributionName;
39
    private final String packagerName;
40

41
    private DistributionProcessor(JReleaserContext context,
42
                                  String distributionName,
43
                                  String packagerName) {
1✔
44
        this.context = context;
1✔
45
        this.distributionName = distributionName;
1✔
46
        this.packagerName = packagerName;
1✔
47
    }
1✔
48

49
    public String getDistributionName() {
50
        return distributionName;
×
51
    }
52

53
    public String getPackagerName() {
54
        return packagerName;
×
55
    }
56

57
    public void prepareDistribution() throws PackagerProcessingException {
58
        Distribution distribution = context.getModel().findDistribution(distributionName);
1✔
59
        Packager<?> packager = distribution.findPackager(packagerName);
1✔
60
        executeProcessor(distribution, packager, false, RB.$("distributions.action.preparing"),
1✔
61
            packagerProcessor -> packagerProcessor.prepareDistribution(distribution, initProps()));
1✔
62
    }
1✔
63

64
    public void packageDistribution() throws PackagerProcessingException {
65
        Distribution distribution = context.getModel().findDistribution(distributionName);
1✔
66
        Packager<?> packager = distribution.findPackager(packagerName);
1✔
67
        executeProcessor(distribution, packager, true, RB.$("distributions.action.packaging"),
1✔
68
            packagerProcessor -> packagerProcessor.packageDistribution(distribution, initProps()));
1✔
69
    }
1✔
70

71
    public void publishDistribution() throws PackagerProcessingException {
72
        Distribution distribution = context.getModel().findDistribution(distributionName);
1✔
73
        Packager<?> packager = distribution.findPackager(packagerName);
1✔
74
        executeProcessor(distribution, packager, true, RB.$("distributions.action.publishing"),
1✔
75
            packagerProcessor -> packagerProcessor.publishDistribution(distribution, initProps()));
1✔
76
    }
1✔
77

78
    private void executeProcessor(Distribution distribution, Packager<?> packager, boolean checkFailed, String action, ProcessorFunction function) throws PackagerProcessingException {
79
        if (!packager.isEnabled()) {
1✔
80
            context.getLogger().debug(RB.$("distributions.skip.distribution"), distributionName);
1✔
81
            return;
1✔
82
        }
83

84
        if (checkFailed && packager.isFailed()) {
1✔
85
            context.getLogger().warn(RB.$("distributions.previous.failure"));
×
86
            return;
×
87
        }
88

89
        PackagerProcessor<Packager<?>> packagerProcessor = PackagerProcessors.findProcessor(context, packager);
1✔
90
        if (!packagerProcessor.supportsDistribution(distribution)) {
1✔
91
            context.getLogger().info(RB.$("distributions.not.supported.distribution"), distributionName, distribution.getType());
×
92
            return;
×
93
        }
94

95
        context.getLogger().info(RB.$("distributions.apply.action.distribution"), action, distributionName);
1✔
96

97
        try {
98
            function.process(packagerProcessor);
1✔
99
        } catch (PackagerProcessingException ppe) {
1✔
100
            if (packager.isContinueOnError()) {
1✔
101
                packager.fail();
1✔
102
                context.getLogger().warn(RB.$("distributions.failure"), ppe.getMessage());
1✔
103
                context.getLogger().trace(ppe);
1✔
104
            } else {
UNCOV
105
                throw ppe;
×
106
            }
107
        }
1✔
108
    }
1✔
109

110
    private TemplateContext initProps() {
111
        TemplateContext props = context.props();
1✔
112
        props.set(Constants.KEY_PREPARE_DIRECTORY, context.getPrepareDirectory());
1✔
113
        props.set(Constants.KEY_PACKAGE_DIRECTORY, context.getPackageDirectory());
1✔
114
        props.set(Constants.KEY_PUBLISH_DIRECTORY, context.getPublishDirectory());
1✔
115
        props.set(Constants.KEY_DISTRIBUTION_PREPARE_DIRECTORY, context.getPrepareDirectory()
1✔
116
            .resolve(distributionName)
1✔
117
            .resolve(packagerName));
1✔
118
        props.set(Constants.KEY_DISTRIBUTION_PACKAGE_DIRECTORY, context.getPackageDirectory()
1✔
119
            .resolve(distributionName)
1✔
120
            .resolve(packagerName));
1✔
121
        props.set(Constants.KEY_DISTRIBUTION_PUBLISH_DIRECTORY, context.getPublishDirectory()
1✔
122
            .resolve(distributionName)
1✔
123
            .resolve(packagerName));
1✔
124
        return props;
1✔
125
    }
126

127
    public static DistributionProcessorBuilder builder() {
128
        return new DistributionProcessorBuilder();
1✔
129
    }
130

131
    interface ProcessorFunction {
132
        void process(PackagerProcessor<Packager<?>> packagerProcessor) throws PackagerProcessingException;
133
    }
134

135
    public static class PackagingAction {
136
        private final String text;
137
        private final Type type;
138
        private final PackagerProcessingFunction function;
139

140
        private PackagingAction(String text, Type type, PackagerProcessingFunction function) {
1✔
141
            this.text = text;
1✔
142
            this.type = type;
1✔
143
            this.function = function;
1✔
144
        }
1✔
145

146
        public String getText() {
147
            return text;
1✔
148
        }
149

150
        public Type getType() {
151
            return type;
1✔
152
        }
153

154
        public PackagerProcessingFunction getFunction() {
155
            return function;
1✔
156
        }
157

158
        public static PackagingAction of(String text, Type type, PackagerProcessingFunction function) {
159
            return new PackagingAction(text, type, function);
1✔
160
        }
161

162
        public enum Type {
1✔
163
            PREPARE,
1✔
164
            PACKAGE,
1✔
165
            PUBLISH
1✔
166
        }
167
    }
168

169
    public static class DistributionProcessorBuilder {
1✔
170
        private JReleaserContext context;
171
        private String distributionName;
172
        private String packagerName;
173

174
        public DistributionProcessorBuilder context(JReleaserContext context) {
175
            this.context = requireNonNull(context, "'context' must not be null");
1✔
176
            return this;
1✔
177
        }
178

179
        public DistributionProcessorBuilder distributionName(String distributionName) {
180
            this.distributionName = requireNonBlank(distributionName, "'distributionName' must not be blank");
1✔
181
            return this;
1✔
182
        }
183

184
        public DistributionProcessorBuilder packagerName(String packagerName) {
185
            this.packagerName = requireNonBlank(packagerName, "'packagerName' must not be blank");
1✔
186
            return this;
1✔
187
        }
188

189
        public DistributionProcessor build() {
190
            requireNonNull(context, "'context' must not be null");
1✔
191
            requireNonBlank(distributionName, "'distributionName' must not be blank");
1✔
192
            requireNonBlank(packagerName, "'packagerName' must not be blank");
1✔
193
            return new DistributionProcessor(context, distributionName, packagerName);
1✔
194
        }
195
    }
196
}
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