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

jreleaser / jreleaser / #512

27 Jul 2025 05:51PM UTC coverage: 45.153% (-0.7%) from 45.803%
#512

push

github

aalmiray
feat(core): Add a --deploy flag to config

Closes #1946

3 of 11 new or added lines in 4 files covered. (27.27%)

845 existing lines in 34 files now uncovered.

23625 of 52322 relevant lines covered (45.15%)

0.45 hits per line

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

75.0
/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✔
114
        if (isSkip()) {
1✔
UNCOV
115
            getLog().info("Execution has been explicitly skipped.");
×
UNCOV
116
            return;
×
117
        }
118

119
        doExecute();
1✔
120
    }
1✔
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✔
UNCOV
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✔
UNCOV
142
        } catch (IOException e) {
×
UNCOV
143
            throw new MojoExecutionException("Could not initialize trace file", e);
×
144
        }
145
    }
146

147
    protected JReleaserModel convertModel() {
UNCOV
148
        JReleaserModel jreleaserModel = null != jreleaser ? jreleaser : new JReleaserModel();
×
UNCOV
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✔
UNCOV
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
            logger.info("- outputdir set to {}", outputDirectory.toPath().toAbsolutePath());
1✔
175
            logger.decreaseIndent();
1✔
176

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

197
    protected boolean resolveBoolean(String key, Boolean value) {
198
        if (null != value) return value;
1✔
199
        String resolvedValue = Env.resolve(key, "");
1✔
200
        return isNotBlank(resolvedValue) && Boolean.parseBoolean(resolvedValue);
1✔
201
    }
202

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

213
    protected JReleaserContext.Configurer resolveConfigurer(File configFile) {
214
        if (null == configFile) return JReleaserContext.Configurer.MAVEN;
1✔
215

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

230
    protected Mode getMode() {
231
        return Mode.FULL;
1✔
232
    }
233

234
    protected abstract JReleaserCommand getCommand();
235

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

248
    private Path resolveSettings() {
249
        if (null != settingsFile) {
1✔
UNCOV
250
            return resolveBasedir().resolve(settingsFile.toPath()).normalize();
×
251
        }
252

253
        return null;
1✔
254
    }
255

256
    protected List<String> collectSelectedPlatforms() {
257
        return Collections.emptyList();
1✔
258
    }
259

260
    protected List<String> collectRejectedPlatforms() {
261
        return Collections.emptyList();
1✔
262
    }
263

264
    protected List<String> collectEntries(String[] input) {
265
        return collectEntries(input, false);
1✔
266
    }
267

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