• 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

36.78
/core/jreleaser-engine/src/main/java/org/jreleaser/engine/context/ModelConfigurer.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.context;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.logging.JReleaserLogger;
22
import org.jreleaser.model.JReleaserException;
23
import org.jreleaser.model.api.JReleaserCommand;
24
import org.jreleaser.model.api.JReleaserModel;
25
import org.jreleaser.model.internal.JReleaserContext;
26
import org.jreleaser.model.internal.release.BaseReleaser;
27
import org.jreleaser.model.internal.release.CodebergReleaser;
28
import org.jreleaser.model.internal.release.GithubReleaser;
29
import org.jreleaser.model.internal.release.GitlabReleaser;
30
import org.jreleaser.model.spi.release.Commit;
31
import org.jreleaser.model.spi.release.Repository;
32
import org.jreleaser.sdk.git.GitSdk;
33
import org.jreleaser.util.Env;
34

35
import static org.jreleaser.model.api.release.Releaser.BRANCH;
36
import static org.jreleaser.util.StringUtils.isBlank;
37

38
/**
39
 * @author Andres Almiray
40
 * @since 0.2.0
41
 */
42
public final class ModelConfigurer {
43
    private ModelConfigurer() {
44
        // noop
45
    }
46

47
    public static void configure(JReleaserContext context) {
48
        try {
49
            Commit head = GitSdk.of(context).head();
1✔
50
            context.getModel().setCommit(new JReleaserModel.Commit(head.getShortHash(),
1✔
51
                head.getFullHash(),
1✔
52
                head.getRefName(),
1✔
53
                head.getCommitTime(),
1✔
54
                head.getTimestamp()));
1✔
55
        } catch (Exception e) {
×
56
            if (!requiresGit(context)) return;
×
57
            context.getLogger().trace(e);
×
58
            throw new JReleaserException(RB.$("ERROR_context_configurer_fail_git_head"), e);
×
59
        }
1✔
60

61
        Repository repository = null;
1✔
62
        try {
63
            repository = GitSdk.of(context).getRemote();
1✔
64
        } catch (Exception e) {
×
65
            if (!requiresGit(context)) return;
×
66
            context.getLogger().trace(e);
×
67
            throw new JReleaserException(RB.$("ERROR_context_configurer_fail_git_remote"), e);
×
68
        }
1✔
69

70
        if (isBlank(context.getModel().getProject().getResolvedName())) {
1✔
UNCOV
71
            context.getModel().getProject().setName(repository.getName());
×
72
        }
73

74
        switch (repository.getKind()) {
1✔
75
            case GITHUB:
76
                autoConfigureGithub(context, repository);
1✔
77
                break;
1✔
78
            case GITLAB:
79
                autoConfigureGitlab(context, repository);
×
80
                break;
×
81
            case CODEBERG:
82
                autoConfigureCodeberg(context, repository);
×
83
                break;
×
84
            default:
85
                autoConfigureOther(context, repository);
×
86
        }
87
    }
1✔
88

89
    private static boolean requiresGit(JReleaserContext context) {
90
        if (context.getCommand() == JReleaserCommand.CONFIG) {
×
91
            switch (context.getMode()) {
×
92
                case DOWNLOAD:
93
                case ASSEMBLE:
94
                case CHANGELOG:
95
                case ANNOUNCE:
96
                    return false;
×
97
                default:
98
                    return true;
×
99
            }
100
        }
101
        return context.getCommand().requiresGit();
×
102
    }
103

104
    private static void autoConfigureGithub(JReleaserContext context, Repository repository) {
105
        BaseReleaser<?, ?> service = context.getModel().getRelease().getReleaser();
1✔
106

107
        if (null != service) {
1✔
108
            if (!(service instanceof GithubReleaser)) {
1✔
109
                context.getModel().getRelease().getReleaser().setMatch(false);
×
110
                context.getModel().getRelease().getReleaser().setSkipTag(true);
×
111
                context.getLogger().warn(RB.$("ERROR_context_configurer_detected_git"), "github", service.getServiceName());
×
112
            }
113
        } else {
114
            context.getModel().getRelease().setGithub(new GithubReleaser());
×
115
        }
116

117
        fillGitProperties(context.getLogger(), context.getModel().getRelease().getReleaser(),
1✔
118
            repository, context.getModel().getCommit());
1✔
119
    }
1✔
120

121
    private static void autoConfigureGitlab(JReleaserContext context, Repository repository) {
122
        BaseReleaser<?, ?> service = context.getModel().getRelease().getReleaser();
×
123

124
        if (null != service) {
×
125
            if (!(service instanceof GitlabReleaser)) {
×
126
                context.getModel().getRelease().getReleaser().setMatch(false);
×
127
                context.getModel().getRelease().getReleaser().setSkipTag(true);
×
128
                context.getLogger().warn(RB.$("ERROR_context_configurer_detected_git"), "gitlab", service.getServiceName());
×
129
            }
130
        } else {
131
            context.getModel().getRelease().setGitlab(new GitlabReleaser());
×
132
        }
133

134
        fillGitProperties(context.getLogger(), context.getModel().getRelease().getReleaser(),
×
135
            repository, context.getModel().getCommit());
×
136
    }
×
137

138
    private static void autoConfigureCodeberg(JReleaserContext context, Repository repository) {
139
        BaseReleaser<?, ?> service = context.getModel().getRelease().getReleaser();
×
140

141
        if (null != service) {
×
142
            if (!(service instanceof CodebergReleaser)) {
×
143
                context.getModel().getRelease().getReleaser().setMatch(false);
×
144
                context.getModel().getRelease().getReleaser().setSkipTag(true);
×
145
                context.getLogger().warn(RB.$("ERROR_context_configurer_detected_git"), "codeberg", service.getServiceName());
×
146
            }
147
        } else {
148
            context.getModel().getRelease().setCodeberg(new CodebergReleaser());
×
149
        }
150

151
        fillGitProperties(context.getLogger(), context.getModel().getRelease().getReleaser(),
×
152
            repository, context.getModel().getCommit());
×
153
    }
×
154

155
    private static void autoConfigureOther(JReleaserContext context, Repository repository) {
156
        BaseReleaser<?, ?> service = context.getModel().getRelease().getReleaser();
×
157

158
        if (null != service) {
×
159
            fillGitProperties(context.getLogger(), service, repository, context.getModel().getCommit());
×
160
        }
161
    }
×
162

163
    private static void fillGitProperties(JReleaserLogger logger, BaseReleaser<?, ?> service, Repository repository, JReleaserModel.Commit head) {
164
        if (isBlank(service.getOwner())) {
1✔
165
            service.setOwner(repository.getOwner());
1✔
166
        }
167
        if (!service.getOwner().equals(repository.getOwner())) {
1✔
168
            service.setMatch(false);
×
169
            service.setSkipTag(true);
×
170
            logger.warn(RB.$("ERROR_context_configurer_detected_git_owner"), repository.getOwner(), service.getOwner());
×
171
        }
172

173
        if (isBlank(service.getName())) {
1✔
174
            service.setName(repository.getName());
1✔
175
        }
176
        if (!service.getName().equals(repository.getName())) {
1✔
177
            service.setMatch(false);
×
178
            service.setSkipTag(true);
×
179
            logger.warn(RB.$("ERROR_context_configurer_detected_git_name"), repository.getName(), service.getName());
×
180
        }
181

182
        service.setBranch(Env.env(BRANCH, service.getBranch()));
1✔
183
        if (isBlank(service.getBranch())) {
1✔
184
            service.setBranch(head.getRefName());
1✔
185
        }
186
        if (!service.getBranch().equals(head.getRefName())) {
1✔
187
            service.setMatch(false);
×
188
            logger.warn(RB.$("ERROR_context_configurer_detected_git_branch"), head.getRefName(), service.getBranch());
×
189
        }
190
    }
1✔
191
}
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