• 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

75.86
/core/jreleaser-engine/src/main/java/org/jreleaser/engine/init/Init.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.init;
19

20
import org.apache.commons.io.IOUtils;
21
import org.jreleaser.config.JReleaserConfigParser;
22
import org.jreleaser.logging.JReleaserLogger;
23
import org.jreleaser.model.JReleaserException;
24
import org.jreleaser.templates.TemplateResource;
25
import org.jreleaser.templates.TemplateUtils;
26
import org.jreleaser.templates.VersionDecoratingWriter;
27

28
import java.io.BufferedWriter;
29
import java.io.IOException;
30
import java.io.Writer;
31
import java.nio.file.FileAlreadyExistsException;
32
import java.nio.file.Files;
33
import java.nio.file.Path;
34
import java.time.LocalDate;
35
import java.util.LinkedHashSet;
36
import java.util.ServiceLoader;
37
import java.util.Set;
38

39
import static java.nio.file.StandardOpenOption.CREATE;
40
import static java.nio.file.StandardOpenOption.CREATE_NEW;
41
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
42
import static java.nio.file.StandardOpenOption.WRITE;
43
import static org.jreleaser.bundle.RB.$;
44
import static org.jreleaser.util.StringUtils.isBlank;
45

46
/**
47
 * @author Andres Almiray
48
 * @since 1.4.0
49
 */
50
public final class Init {
51
    private Init() {
52
        // noop
53
    }
54

55
    public static void execute(JReleaserLogger logger, String format, boolean overwrite, Path outputDirectory) {
56
        try {
57
            if (isBlank(format)) format = "yml";
1✔
58

59
            if (!getSupportedConfigFormats().contains(format)) {
1✔
60
                throw new IllegalArgumentException($("jreleaser.init.ERROR_invalid_format",
×
61
                    String.join("|", getSupportedConfigFormats())));
×
62
            }
63

64
            Path outputFile = outputDirectory.resolve("jreleaser." + format);
1✔
65

66
            TemplateResource template = TemplateUtils.resolveTemplate(logger, "init/jreleaser." + format + ".tpl");
1✔
67

68
            String content = IOUtils.toString(template.getReader());
1✔
69
            LocalDate now = LocalDate.now();
1✔
70
            content = content.replace("@year@", now.getYear() + "");
1✔
71

72
            logger.info($("jreleaser.init.TEXT_writing_file"), outputFile.toAbsolutePath());
1✔
73

74
            try (Writer fileWriter = Files.newBufferedWriter(outputFile, overwrite ? CREATE : CREATE_NEW, WRITE, TRUNCATE_EXISTING);
1✔
75
                 BufferedWriter decoratedWriter = new VersionDecoratingWriter(fileWriter)) {
1✔
76
                decoratedWriter.write(content);
1✔
UNCOV
77
            } catch (FileAlreadyExistsException e) {
×
UNCOV
78
                logger.error($("jreleaser.ERROR_file_exists"), outputFile.toAbsolutePath());
×
UNCOV
79
                return;
×
80
            }
1✔
81

82
            logger.info($("jreleaser.init.TEXT_success"), outputDirectory.toAbsolutePath());
1✔
83
        } catch (IllegalStateException | IOException e) {
×
84
            throw new JReleaserException($("ERROR_unexpected_error"), e);
×
85
        } finally {
86
            if (null != logger) logger.close();
1✔
87
        }
88
    }
1✔
89

90
    private static Set<String> getSupportedConfigFormats() {
91
        Set<String> extensions = new LinkedHashSet<>();
1✔
92

93
        ServiceLoader<JReleaserConfigParser> parsers = ServiceLoader.load(JReleaserConfigParser.class,
1✔
94
            JReleaserConfigParser.class.getClassLoader());
1✔
95

96
        for (JReleaserConfigParser parser : parsers) {
1✔
97
            extensions.add(parser.getPreferredFileExtension());
1✔
98
        }
1✔
99

100
        return extensions;
1✔
101
    }
102
}
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