• 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

0.0
/plugins/jreleaser-ant-tasks/src/main/java/org/jreleaser/ant/tasks/AbstractJReleaserTask.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.ant.tasks;
19

20
import org.apache.tools.ant.BuildException;
21
import org.apache.tools.ant.Task;
22
import org.jreleaser.ant.tasks.internal.JReleaserLoggerAdapter;
23
import org.jreleaser.config.JReleaserConfigParser;
24
import org.jreleaser.engine.context.ContextCreator;
25
import org.jreleaser.logging.JReleaserLogger;
26
import org.jreleaser.model.JReleaserVersion;
27
import org.jreleaser.model.api.JReleaserCommand;
28
import org.jreleaser.model.api.JReleaserContext.Mode;
29
import org.jreleaser.model.internal.JReleaserContext;
30
import org.jreleaser.util.Env;
31
import org.jreleaser.util.PlatformUtils;
32
import org.jreleaser.util.StringUtils;
33

34
import java.io.File;
35
import java.io.FileOutputStream;
36
import java.io.IOException;
37
import java.io.PrintWriter;
38
import java.nio.file.Files;
39
import java.nio.file.Path;
40
import java.nio.file.Paths;
41
import java.util.ArrayList;
42
import java.util.Arrays;
43
import java.util.Collection;
44
import java.util.Collections;
45
import java.util.LinkedHashSet;
46
import java.util.List;
47
import java.util.Locale;
48
import java.util.ServiceLoader;
49
import java.util.Set;
50

51
import static java.util.stream.Collectors.toList;
52
import static org.jreleaser.util.FileUtils.resolveOutputDirectory;
53
import static org.jreleaser.util.IoUtils.newPrintWriter;
54
import static org.jreleaser.util.StringUtils.isBlank;
55
import static org.jreleaser.util.StringUtils.isNotBlank;
56

57
/**
58
 * @author Andres Almiray
59
 * @since 0.1.0
60
 */
UNCOV
61
abstract class AbstractJReleaserTask extends Task {
×
62
    protected File basedir;
63
    protected File settingsFile;
64
    protected File configFile;
65
    protected Boolean yolo;
66
    protected Boolean dryrun;
67
    protected Boolean gitRootSearch;
68
    protected Boolean strict;
69
    protected boolean skip;
70
    protected Path outputDir;
71

72
    protected JReleaserLogger logger;
73
    protected Path actualConfigFile;
74
    protected Path actualBasedir;
75

76
    public void setBasedir(File basedir) {
UNCOV
77
        this.basedir = basedir;
×
UNCOV
78
    }
×
79

80
    public void setSettingsFile(File settingsFile) {
UNCOV
81
        this.settingsFile = settingsFile;
×
UNCOV
82
    }
×
83

84
    public void setConfigFile(File configFile) {
85
        this.configFile = configFile;
×
UNCOV
86
    }
×
87

88
    public void setYolo(Boolean yolo) {
UNCOV
89
        this.yolo = yolo;
×
UNCOV
90
    }
×
91

92
    public void setDryrun(Boolean dryrun) {
UNCOV
93
        this.dryrun = dryrun;
×
UNCOV
94
    }
×
95

96
    public void setGitRootSearch(Boolean gitRootSearch) {
UNCOV
97
        this.gitRootSearch = gitRootSearch;
×
UNCOV
98
    }
×
99

100
    public void setStrict(Boolean strict) {
UNCOV
101
        this.strict = strict;
×
UNCOV
102
    }
×
103

104
    public void setSkip(boolean skip) {
UNCOV
105
        this.skip = skip;
×
UNCOV
106
    }
×
107

108
    public void setOutputDir(Path outputDir) {
UNCOV
109
        this.outputDir = outputDir;
×
UNCOV
110
    }
×
111

112
    @Override
113
    public void execute() throws BuildException {
UNCOV
114
        Banner.display(newPrintWriter(System.err));
×
UNCOV
115
        if (skip) return;
×
116

UNCOV
117
        resolveConfigFile();
×
UNCOV
118
        resolveBasedir();
×
UNCOV
119
        initLogger();
×
UNCOV
120
        PlatformUtils.resolveCurrentPlatform(logger);
×
UNCOV
121
        logger.info("JReleaser {}", JReleaserVersion.getPlainVersion());
×
UNCOV
122
        JReleaserVersion.banner(logger.getTracer());
×
UNCOV
123
        logger.info("Configuring with {}", actualConfigFile);
×
UNCOV
124
        logger.info(" - basedir set to {}", actualBasedir.toAbsolutePath());
×
UNCOV
125
        logger.info(" - outputdir set to {}", getOutputDirectory().toAbsolutePath());
×
UNCOV
126
        doExecute(createContext());
×
UNCOV
127
    }
×
128

129
    private void resolveConfigFile() {
UNCOV
130
        if (null != configFile) {
×
131
            actualConfigFile = configFile.toPath();
×
132
        } else {
133
            ServiceLoader<JReleaserConfigParser> parsers = ServiceLoader.load(JReleaserConfigParser.class,
×
134
                JReleaserConfigParser.class.getClassLoader());
×
135

136
            for (JReleaserConfigParser parser : parsers) {
×
UNCOV
137
                Path file = Paths.get(".").normalize()
×
138
                    .resolve("jreleaser." + parser.getPreferredFileExtension());
×
UNCOV
139
                if (Files.exists(file)) {
×
UNCOV
140
                    actualConfigFile = file;
×
UNCOV
141
                    break;
×
142
                }
UNCOV
143
            }
×
144
        }
145

UNCOV
146
        if (null == actualConfigFile || !Files.exists(actualConfigFile)) {
×
UNCOV
147
            throw new BuildException("Missing required option 'configFile' " +
×
148
                "or local file named jreleaser[" +
UNCOV
149
                String.join("|", getSupportedConfigFormats()) + "]");
×
150
        }
UNCOV
151
    }
×
152

153
    private void resolveBasedir() {
UNCOV
154
        String resolvedBasedir = Env.resolve(org.jreleaser.model.api.JReleaserContext.BASEDIR, null != basedir ? basedir.getPath() : "");
×
UNCOV
155
        actualBasedir = (isNotBlank(resolvedBasedir) ? Paths.get(resolvedBasedir) : actualConfigFile.toAbsolutePath().getParent()).normalize();
×
UNCOV
156
    }
×
157

158
    private Path resolveSettings() {
UNCOV
159
        if (null != settingsFile) {
×
UNCOV
160
            return actualBasedir.resolve(settingsFile.toPath()).normalize();
×
161
        }
162

UNCOV
163
        return null;
×
164
    }
165

166
    protected abstract void doExecute(JReleaserContext context);
167

168
    protected JReleaserLogger initLogger() {
UNCOV
169
        if (null == logger) {
×
UNCOV
170
            logger = new JReleaserLoggerAdapter(createTracer(), getProject());
×
171
        }
UNCOV
172
        return logger;
×
173
    }
174

175
    protected PrintWriter createTracer() {
176
        try {
UNCOV
177
            Files.createDirectories(getOutputDirectory());
×
UNCOV
178
            return newPrintWriter(new FileOutputStream(
×
UNCOV
179
                getOutputDirectory().resolve("trace.log").toFile()));
×
UNCOV
180
        } catch (IOException e) {
×
UNCOV
181
            throw new IllegalStateException("Could not initialize trace file", e);
×
182
        }
183
    }
184

185
    protected Path getOutputDirectory() {
UNCOV
186
        return resolveOutputDirectory(actualBasedir, outputDir, "build");
×
187
    }
188

189
    protected JReleaserContext createContext() {
UNCOV
190
        return ContextCreator.create(
×
191
            logger,
UNCOV
192
            resolveConfigurer(actualConfigFile),
×
UNCOV
193
            getMode(),
×
UNCOV
194
            getCommand(),
×
195
            actualConfigFile,
196
            actualBasedir,
UNCOV
197
            resolveSettings(),
×
UNCOV
198
            getOutputDirectory(),
×
UNCOV
199
            resolveBoolean(org.jreleaser.model.api.JReleaserContext.YOLO, yolo),
×
UNCOV
200
            resolveBoolean(org.jreleaser.model.api.JReleaserContext.DRY_RUN, dryrun),
×
UNCOV
201
            resolveBoolean(org.jreleaser.model.api.JReleaserContext.GIT_ROOT_SEARCH, gitRootSearch),
×
UNCOV
202
            resolveBoolean(org.jreleaser.model.api.JReleaserContext.STRICT, strict),
×
203
            collectSelectedPlatforms(),
×
204
            collectRejectedPlatforms());
×
205
    }
206

207
    protected boolean resolveBoolean(String key, Boolean value) {
UNCOV
208
        if (null != value) return value;
×
UNCOV
209
        String resolvedValue = Env.resolve(key, "");
×
UNCOV
210
        return isNotBlank(resolvedValue) && Boolean.parseBoolean(resolvedValue);
×
211
    }
212

213
    protected List<String> resolveCollection(String key, List<String> values) {
UNCOV
214
        if (!values.isEmpty()) return values;
×
215
        String resolvedValue = Env.resolve(key, "");
×
UNCOV
216
        if (isBlank(resolvedValue)) return Collections.emptyList();
×
217
        return Arrays.stream(resolvedValue.trim().split(","))
×
UNCOV
218
            .map(String::trim)
×
UNCOV
219
            .filter(StringUtils::isNotBlank)
×
220
            .collect(toList());
×
221
    }
222

223
    protected JReleaserContext.Configurer resolveConfigurer(Path configFile) {
UNCOV
224
        switch (StringUtils.getFilenameExtension(configFile.getFileName().toString())) {
×
225
            case "yml":
226
            case "yaml":
227
                return JReleaserContext.Configurer.CLI_YAML;
×
228
            case "toml":
UNCOV
229
                return JReleaserContext.Configurer.CLI_TOML;
×
230
            case "json":
231
                return JReleaserContext.Configurer.CLI_JSON;
×
232
            default:
233
                // should not happen!
234
                throw new IllegalArgumentException("Invalid configuration format: " + configFile.getFileName());
×
235
        }
236
    }
237

238
    private Set<String> getSupportedConfigFormats() {
UNCOV
239
        Set<String> extensions = new LinkedHashSet<>();
×
240

UNCOV
241
        ServiceLoader<JReleaserConfigParser> parsers = ServiceLoader.load(JReleaserConfigParser.class,
×
UNCOV
242
            JReleaserConfigParser.class.getClassLoader());
×
243

UNCOV
244
        for (JReleaserConfigParser parser : parsers) {
×
UNCOV
245
            extensions.add("." + parser.getPreferredFileExtension());
×
UNCOV
246
        }
×
247

UNCOV
248
        return extensions;
×
249
    }
250

251
    protected Mode getMode() {
UNCOV
252
        return Mode.FULL;
×
253
    }
254

255
    protected abstract JReleaserCommand getCommand();
256

257
    protected List<String> collectSelectedPlatforms() {
UNCOV
258
        return Collections.emptyList();
×
259
    }
260

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

265
    protected List<String> collectEntries(List<String> input) {
UNCOV
266
        return collectEntries(input, false);
×
267
    }
268

269
    protected List<String> collectEntries(List<String> input, boolean lowerCase) {
UNCOV
270
        List<String> list = new ArrayList<>();
×
UNCOV
271
        if (null != input && !input.isEmpty()) {
×
UNCOV
272
            for (String s : input) {
×
UNCOV
273
                if (isNotBlank(s)) {
×
274
                    if (!s.contains("-") && lowerCase) {
×
275
                        s = StringUtils.getHyphenatedName(s);
×
276
                    }
277
                    list.add(lowerCase ? s.toLowerCase(Locale.ENGLISH) : s);
×
278
                }
UNCOV
279
            }
×
280
        }
UNCOV
281
        return list;
×
282
    }
283

284
    protected Collection<String> expandAndCollect(String input) {
UNCOV
285
        if (isBlank(input)) return Collections.emptyList();
×
286

UNCOV
287
        if (input.contains(",")) {
×
UNCOV
288
            return Arrays.stream(input.split(","))
×
UNCOV
289
                .map(String::trim)
×
UNCOV
290
                .filter(StringUtils::isNotBlank)
×
UNCOV
291
                .collect(toList());
×
292
        }
293

UNCOV
294
        return Collections.singletonList(input.trim());
×
295
    }
296
}
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