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

jreleaser / jreleaser / #556

22 Nov 2025 04:17PM UTC coverage: 46.213% (-2.0%) from 48.203%
#556

push

github

aalmiray
feat(jdks): Allow filtering by platform

Closes #2000

Co-authored-by: Ixchel Ruiz <ixchelruiz@yahoo.com>

0 of 42 new or added lines in 5 files covered. (0.0%)

1116 existing lines in 107 files now uncovered.

24939 of 53965 relevant lines covered (46.21%)

0.46 hits per line

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

62.22
/plugins/jreleaser-maven-plugin/src/main/java/org/jreleaser/maven/plugin/AbstractJReleaserMojo.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.maven.plugin;
19

20
import org.apache.maven.execution.MavenSession;
21
import org.apache.maven.plugin.AbstractMojo;
22
import org.apache.maven.plugin.MojoExecutionException;
23
import org.apache.maven.plugin.MojoFailureException;
24
import org.apache.maven.plugins.annotations.Parameter;
25
import org.apache.maven.project.MavenProject;
26
import org.jreleaser.engine.context.ContextCreator;
27
import org.jreleaser.logging.JReleaserLogger;
28
import org.jreleaser.maven.plugin.internal.JReleaserLoggerAdapter;
29
import org.jreleaser.maven.plugin.internal.JReleaserModelConfigurer;
30
import org.jreleaser.model.JReleaserException;
31
import org.jreleaser.model.JReleaserVersion;
32
import org.jreleaser.model.api.JReleaserCommand;
33
import org.jreleaser.model.api.JReleaserContext.Mode;
34
import org.jreleaser.model.internal.JReleaserContext;
35
import org.jreleaser.model.internal.JReleaserModel;
36
import org.jreleaser.util.Env;
37
import org.jreleaser.util.PlatformUtils;
38
import org.jreleaser.util.StringUtils;
39

40
import java.io.File;
41
import java.io.FileOutputStream;
42
import java.io.IOException;
43
import java.io.PrintWriter;
44
import java.nio.file.Path;
45
import java.nio.file.Paths;
46
import java.util.ArrayList;
47
import java.util.Arrays;
48
import java.util.Collections;
49
import java.util.List;
50
import java.util.Locale;
51

52
import static java.util.stream.Collectors.toList;
53
import static org.jreleaser.model.JReleaserOutput.JRELEASER_QUIET;
54
import static org.jreleaser.util.IoUtils.newPrintWriter;
55
import static org.jreleaser.util.StringUtils.isBlank;
56
import static org.jreleaser.util.StringUtils.isNotBlank;
57

58
/**
59
 * @author Andres Almiray
60
 * @since 0.1.0
61
 */
62
abstract class AbstractJReleaserMojo extends AbstractMojo {
1✔
63
    /**
64
     * The project whose model will be checked.
65
     */
66
    @Parameter(defaultValue = "${project}", readonly = true, required = true)
67
    protected MavenProject project;
68

69
    @Parameter
70
    protected JReleaserModel jreleaser;
71

72
    @Parameter(property = "jreleaser.output.directory", defaultValue = "${project.build.directory}/jreleaser")
73
    protected File outputDirectory;
74

75
    @Parameter(property = "jreleaser.config.file")
76
    protected File configFile;
77

78
    @Parameter(property = "jreleaser.settings.file")
79
    protected File settingsFile;
80

81
    /**
82
     * Skips non-configured operations.
83
     */
84
    @Parameter(property = "jreleaser.yolo")
85
    protected Boolean yolo;
86

87
    /**
88
     * Skips remote operations.
89
     */
90
    @Parameter(property = "jreleaser.dry.run")
91
    protected Boolean dryrun;
92

93
    /**
94
     * Searches for the Git root.
95
     */
96
    @Parameter(property = "jreleaser.git.root.search")
97
    protected Boolean gitRootSearch;
98

99
    /**
100
     * Enable strict mode.
101
     */
102
    @Parameter(property = "jreleaser.strict")
103
    protected Boolean strict;
104

105
    @Parameter(defaultValue = "${session}", required = true)
106
    private MavenSession session;
107

108
    @Parameter(defaultValue = "${maven.multiModuleProjectDirectory}")
109
    private String multiModuleProjectDirectory;
110

111
    @Override
112
    public void execute() throws MojoExecutionException, MojoFailureException {
113
        Banner.display(project, getLog());
1✔
UNCOV
114
        if (isSkip()) {
×
115
            getLog().info("Execution has been explicitly skipped.");
×
116
            return;
×
117
        }
118

UNCOV
119
        doExecute();
×
UNCOV
120
    }
×
121

122
    protected abstract boolean isSkip();
123

124
    protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
125

126
    protected boolean isQuiet() {
127
        return getLog().isErrorEnabled() &&
1✔
128
            !getLog().isWarnEnabled() &&
1✔
129
            !getLog().isInfoEnabled() &&
×
130
            !getLog().isDebugEnabled();
1✔
131
    }
132

133
    protected JReleaserLogger getLogger() throws MojoExecutionException {
134
        return new JReleaserLoggerAdapter(createTracer(), getLog());
1✔
135
    }
136

137
    protected PrintWriter createTracer() throws MojoExecutionException {
138
        try {
139
            java.nio.file.Files.createDirectories(outputDirectory.toPath());
1✔
140
            return newPrintWriter(new FileOutputStream(
1✔
141
                outputDirectory.toPath().resolve("trace.log").toFile()));
1✔
142
        } catch (IOException e) {
×
143
            throw new MojoExecutionException("Could not initialize trace file", e);
×
144
        }
145
    }
146

147
    protected JReleaserModel convertModel() {
148
        JReleaserModel jreleaserModel = null != jreleaser ? jreleaser : new JReleaserModel();
×
149
        return JReleaserModelConfigurer.configure(jreleaserModel, project, session);
×
150
    }
151

152
    protected JReleaserModel readModel(JReleaserLogger logger) {
153
        JReleaserModel jreleaserModel = ContextCreator.resolveModel(logger, configFile.toPath());
1✔
154
        return JReleaserModelConfigurer.configure(jreleaserModel, project, session);
1✔
155
    }
156

157
    protected JReleaserContext createContext() throws MojoExecutionException {
158
        try {
159
            if (isQuiet()) {
1✔
160
                System.setProperty(JRELEASER_QUIET, "true");
×
161
            }
162

163
            JReleaserLogger logger = getLogger();
1✔
164
            PlatformUtils.resolveCurrentPlatform(logger);
1✔
165
            Path basedir = resolveBasedir();
1✔
166

167
            logger.info("JReleaser {}", JReleaserVersion.getPlainVersion());
1✔
168
            JReleaserVersion.banner(logger.getTracer());
1✔
169
            if (null != configFile) {
1✔
170
                logger.info("Configuring with {}", configFile.getAbsolutePath());
1✔
171
            }
172
            logger.increaseIndent();
1✔
173
            logger.info("- basedir set to {}", basedir.toAbsolutePath());
1✔
174
            Path settings = resolveSettings();
1✔
175
            if (null != settings) {
1✔
176
                logger.info("- settings set to {}", settings.toAbsolutePath());
×
177
            }
178
            logger.info("- outputdir set to {}", outputDirectory.toPath().toAbsolutePath());
1✔
179
            logger.decreaseIndent();
1✔
180

181
            return ContextCreator.create(
1✔
182
                logger,
183
                resolveConfigurer(configFile),
1✔
184
                getMode(),
1✔
185
                getCommand(),
1✔
186
                null == configFile ? convertModel() : readModel(logger),
1✔
187
                basedir,
188
                settings,
189
                outputDirectory.toPath(),
1✔
190
                resolveBoolean(org.jreleaser.model.api.JReleaserContext.YOLO, yolo),
1✔
191
                resolveBoolean(org.jreleaser.model.api.JReleaserContext.DRY_RUN, dryrun),
1✔
192
                resolveBoolean(org.jreleaser.model.api.JReleaserContext.GIT_ROOT_SEARCH, gitRootSearch),
1✔
193
                resolveBoolean(org.jreleaser.model.api.JReleaserContext.STRICT, strict),
1✔
194
                collectSelectedPlatforms(),
1✔
195
                collectRejectedPlatforms());
1✔
196
        } catch (JReleaserException e) {
×
197
            throw new MojoExecutionException("JReleaser for project " + project.getArtifactId() + " has not been properly configured.", e);
×
198
        }
199
    }
200

201
    protected boolean resolveBoolean(String key, Boolean value) {
202
        if (null != value) return value;
1✔
203
        String resolvedValue = Env.resolve(key, "");
1✔
204
        return isNotBlank(resolvedValue) && Boolean.parseBoolean(resolvedValue);
1✔
205
    }
206

207
    protected List<String> resolveCollection(String key, List<String> values) {
208
        if (!values.isEmpty()) return values;
1✔
209
        String resolvedValue = Env.resolve(key, "");
1✔
210
        if (isBlank(resolvedValue)) return Collections.emptyList();
1✔
211
        return Arrays.stream(resolvedValue.trim().split(","))
×
212
            .map(String::trim)
×
213
            .filter(StringUtils::isNotBlank)
×
214
            .collect(toList());
×
215
    }
216

217
    protected JReleaserContext.Configurer resolveConfigurer(File configFile) {
218
        if (null == configFile) return JReleaserContext.Configurer.MAVEN;
1✔
219

220
        switch (StringUtils.getFilenameExtension(configFile.getName())) {
1✔
221
            case "yml":
222
            case "yaml":
223
                return JReleaserContext.Configurer.CLI_YAML;
1✔
224
            case "toml":
225
                return JReleaserContext.Configurer.CLI_TOML;
×
226
            case "json":
227
                return JReleaserContext.Configurer.CLI_JSON;
×
228
            default:
229
                // should not happen!
230
                throw new IllegalArgumentException("Invalid configuration format: " + configFile.getName());
×
231
        }
232
    }
233

234
    protected Mode getMode() {
UNCOV
235
        return Mode.FULL;
×
236
    }
237

238
    protected abstract JReleaserCommand getCommand();
239

240
    private Path resolveBasedir() {
241
        String resolvedBasedir = Env.resolve(org.jreleaser.model.api.JReleaserContext.BASEDIR, "");
1✔
242
        if (isNotBlank(resolvedBasedir)) {
1✔
243
            return Paths.get(resolvedBasedir.trim());
×
244
        } else if (isNotBlank(multiModuleProjectDirectory)) {
1✔
245
            return Paths.get(multiModuleProjectDirectory.trim());
1✔
246
        } else if (isNotBlank(session.getExecutionRootDirectory())) {
×
247
            return Paths.get(session.getExecutionRootDirectory().trim());
×
248
        }
249
        return project.getBasedir().toPath();
×
250
    }
251

252
    private Path resolveSettings() {
253
        if (null != settingsFile) {
1✔
254
            return resolveBasedir().resolve(settingsFile.toPath()).normalize();
×
255
        }
256

257
        return null;
1✔
258
    }
259

260
    protected List<String> collectSelectedPlatforms() {
UNCOV
261
        return Collections.emptyList();
×
262
    }
263

264
    protected List<String> collectRejectedPlatforms() {
UNCOV
265
        return Collections.emptyList();
×
266
    }
267

268
    protected List<String> collectEntries(String[] input) {
269
        return collectEntries(input, false);
1✔
270
    }
271

272
    protected List<String> collectEntries(String[] input, boolean lowerCase) {
273
        List<String> list = new ArrayList<>();
1✔
274
        if (null != input && input.length > 0) {
1✔
UNCOV
275
            for (String s : input) {
×
UNCOV
276
                if (isNotBlank(s)) {
×
UNCOV
277
                    if (!s.contains("-") && lowerCase) {
×
UNCOV
278
                        s = StringUtils.getHyphenatedName(s);
×
279
                    }
UNCOV
280
                    list.add(lowerCase ? s.toLowerCase(Locale.ENGLISH) : s);
×
281
                }
282
            }
283
        }
284
        return list;
1✔
285
    }
286
}
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