• 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

79.63
/core/jreleaser-engine/src/main/java/org/jreleaser/engine/environment/Environment.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.environment;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.config.JReleaserConfigLoader;
22
import org.jreleaser.config.JReleaserConfigParser;
23
import org.jreleaser.logging.JReleaserLogger;
24

25
import java.io.File;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.nio.file.Files;
29
import java.nio.file.Path;
30
import java.nio.file.Paths;
31
import java.util.Optional;
32
import java.util.Properties;
33
import java.util.ServiceLoader;
34
import java.util.Set;
35
import java.util.TreeSet;
36

37
import static java.nio.file.Files.newInputStream;
38
import static org.jreleaser.model.Constants.DEFAULT_GIT_REMOTE;
39
import static org.jreleaser.model.Constants.JRELEASER_USER_HOME;
40
import static org.jreleaser.model.Constants.XDG_CONFIG_HOME;
41
import static org.jreleaser.util.Env.JRELEASER_ENV_PREFIX;
42
import static org.jreleaser.util.Env.envKey;
43
import static org.jreleaser.util.StringUtils.isBlank;
44
import static org.jreleaser.util.StringUtils.isNotBlank;
45

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

55
    public static void display(JReleaserLogger logger, Path basedir, Path settings) {
56
        if (null != settings) {
1✔
UNCOV
57
            loadVariables(logger, settings);
×
58
        } else {
59
            Path configDirectory = null;
1✔
60

61
            String home = System.getenv(XDG_CONFIG_HOME);
1✔
62
            if (isNotBlank(home) && Files.exists(Paths.get(home).resolve("jreleaser"))) {
1✔
UNCOV
63
                configDirectory = Paths.get(home).resolve("jreleaser");
×
64
            }
65

66
            if (null == configDirectory) {
1✔
67
                home = System.getenv(JRELEASER_USER_HOME);
1✔
68
                if (isBlank(home)) {
1✔
UNCOV
69
                    home = System.getProperty("user.home") + File.separator + ".jreleaser";
×
70
                }
71
                configDirectory = Paths.get(home);
1✔
72
            }
73

74
            loadVariables(logger, resolveConfigFileAt(configDirectory)
1✔
75
                .orElse(configDirectory.resolve("config.properties")));
1✔
76
        }
77

78
        Path envFilePath = basedir.resolve(".env");
1✔
79
        if (Files.exists(envFilePath)) {
1✔
UNCOV
80
            loadVariables(logger, envFilePath);
×
81
        }
82

83
        Set<String> vars = new TreeSet<>();
1✔
84
        System.getenv().forEach((k, v) -> {
1✔
85
            if (k.startsWith(JRELEASER_ENV_PREFIX) && isNotBlank(v)) vars.add(k);
1✔
86
        });
1✔
87
        if (System.getenv().containsKey(envKey(DEFAULT_GIT_REMOTE))) {
1✔
UNCOV
88
            vars.add(envKey(DEFAULT_GIT_REMOTE));
×
89
        }
90

91
        if (!vars.isEmpty()) {
1✔
92
            logger.info(RB.$("environment.variables.env"));
1✔
93
            vars.forEach(message -> logger.info("  " + message));
1✔
94
        }
95
    }
1✔
96

97
    private static void loadVariables(JReleaserLogger logger, Path file) {
98
        Set<String> vars = new TreeSet<>();
1✔
99

100
        Properties p = new Properties();
1✔
101
        logger.info(RB.$("environment.load.variables"), file.toAbsolutePath());
1✔
102
        if (Files.exists(file)) {
1✔
103
            try {
104
                if (file.getFileName().toString().endsWith(".properties") ||
1✔
105
                    file.getFileName().toString().equals(".env")) {
1✔
UNCOV
106
                    try (InputStream in = newInputStream(file)) {
×
UNCOV
107
                        p.load(in);
×
108
                    }
109
                } else {
110
                    p.putAll(JReleaserConfigLoader.loadProperties(file));
1✔
111
                }
112
            } catch (IOException e) {
×
UNCOV
113
                logger.debug(RB.$("environment.variables.load.error"), file.toAbsolutePath(), e);
×
114
            }
1✔
115
        } else {
UNCOV
116
            logger.warn(RB.$("environment.variables.source.missing"), file.toAbsolutePath());
×
117
        }
118

119
        p.stringPropertyNames().stream()
1✔
120
            .filter(k -> k.startsWith(JRELEASER_ENV_PREFIX)).
1✔
121
            forEach(vars::add);
1✔
122

123
        if (!vars.isEmpty()) {
1✔
124
            logger.info(RB.$("environment.variables.file", file.getFileName().toString()));
1✔
125
            vars.forEach(message -> logger.info("  " + message));
1✔
126
        }
127
    }
1✔
128

129
    private static Optional<Path> resolveConfigFileAt(Path directory) {
130
        ServiceLoader<JReleaserConfigParser> parsers = ServiceLoader.load(JReleaserConfigParser.class,
1✔
131
            JReleaserConfigParser.class.getClassLoader());
1✔
132

133
        for (JReleaserConfigParser parser : parsers) {
1✔
134
            Path file = directory.resolve("config." + parser.getPreferredFileExtension());
1✔
135
            if (Files.exists(file)) {
1✔
136
                return Optional.of(file);
1✔
137
            }
138
        }
1✔
139

UNCOV
140
        return Optional.empty();
×
141
    }
142
}
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