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

jreleaser / jreleaser / #475

03 Apr 2025 10:50AM UTC coverage: 40.322% (-8.9%) from 49.193%
#475

push

github

aalmiray
feat(release): Support Forgejo as releaser

Closes #1842

Closes #1843

182 of 1099 new or added lines in 45 files covered. (16.56%)

4239 existing lines in 333 files now uncovered.

20797 of 51577 relevant lines covered (40.32%)

0.4 hits per line

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

0.0
/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,
UNCOV
43
                                  String packagerName) {
×
UNCOV
44
        this.context = context;
×
UNCOV
45
        this.distributionName = distributionName;
×
UNCOV
46
        this.packagerName = packagerName;
×
UNCOV
47
    }
×
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 {
UNCOV
58
        Distribution distribution = context.getModel().findDistribution(distributionName);
×
UNCOV
59
        Packager<?> packager = distribution.findPackager(packagerName);
×
UNCOV
60
        executeProcessor(distribution, packager, false, RB.$("distributions.action.preparing"),
×
UNCOV
61
            packagerProcessor -> packagerProcessor.prepareDistribution(distribution, initProps()));
×
UNCOV
62
    }
×
63

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

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

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

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

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

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

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

110
    private TemplateContext initProps() {
UNCOV
111
        TemplateContext props = context.props();
×
UNCOV
112
        props.set(Constants.KEY_PREPARE_DIRECTORY, context.getPrepareDirectory());
×
UNCOV
113
        props.set(Constants.KEY_PACKAGE_DIRECTORY, context.getPackageDirectory());
×
UNCOV
114
        props.set(Constants.KEY_DISTRIBUTION_PREPARE_DIRECTORY, context.getPrepareDirectory()
×
UNCOV
115
            .resolve(distributionName)
×
UNCOV
116
            .resolve(packagerName));
×
UNCOV
117
        props.set(Constants.KEY_DISTRIBUTION_PACKAGE_DIRECTORY, context.getPackageDirectory()
×
UNCOV
118
            .resolve(distributionName)
×
UNCOV
119
            .resolve(packagerName));
×
UNCOV
120
        return props;
×
121
    }
122

123
    public static DistributionProcessorBuilder builder() {
UNCOV
124
        return new DistributionProcessorBuilder();
×
125
    }
126

127
    interface ProcessorFunction {
128
        void process(PackagerProcessor<Packager<?>> packagerProcessor) throws PackagerProcessingException;
129
    }
130

131
    public static class PackagingAction {
132
        private final String text;
133
        private final Type type;
134
        private final PackagerProcessingFunction function;
135

UNCOV
136
        private PackagingAction(String text, Type type, PackagerProcessingFunction function) {
×
UNCOV
137
            this.text = text;
×
UNCOV
138
            this.type = type;
×
UNCOV
139
            this.function = function;
×
UNCOV
140
        }
×
141

142
        public String getText() {
UNCOV
143
            return text;
×
144
        }
145

146
        public Type getType() {
UNCOV
147
            return type;
×
148
        }
149

150
        public PackagerProcessingFunction getFunction() {
UNCOV
151
            return function;
×
152
        }
153

154
        public static PackagingAction of(String text, Type type, PackagerProcessingFunction function) {
UNCOV
155
            return new PackagingAction(text, type, function);
×
156
        }
157

UNCOV
158
        public enum Type {
×
UNCOV
159
            PREPARE,
×
UNCOV
160
            PACKAGE,
×
UNCOV
161
            PUBLISH
×
162
        }
163
    }
164

UNCOV
165
    public static class DistributionProcessorBuilder {
×
166
        private JReleaserContext context;
167
        private String distributionName;
168
        private String packagerName;
169

170
        public DistributionProcessorBuilder context(JReleaserContext context) {
UNCOV
171
            this.context = requireNonNull(context, "'context' must not be null");
×
UNCOV
172
            return this;
×
173
        }
174

175
        public DistributionProcessorBuilder distributionName(String distributionName) {
UNCOV
176
            this.distributionName = requireNonBlank(distributionName, "'distributionName' must not be blank");
×
UNCOV
177
            return this;
×
178
        }
179

180
        public DistributionProcessorBuilder packagerName(String packagerName) {
UNCOV
181
            this.packagerName = requireNonBlank(packagerName, "'packagerName' must not be blank");
×
UNCOV
182
            return this;
×
183
        }
184

185
        public DistributionProcessor build() {
UNCOV
186
            requireNonNull(context, "'context' must not be null");
×
UNCOV
187
            requireNonBlank(distributionName, "'distributionName' must not be blank");
×
UNCOV
188
            requireNonBlank(packagerName, "'packagerName' must not be blank");
×
UNCOV
189
            return new DistributionProcessor(context, distributionName, packagerName);
×
190
        }
191
    }
192
}
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