• 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

72.13
/plugins/jreleaser/src/main/java/org/jreleaser/cli/AbstractCommand.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.cli;
19

20
import org.jreleaser.cli.internal.Colorizer;
21
import org.jreleaser.model.JReleaserException;
22
import picocli.CommandLine;
23

24
import java.util.Comparator;
25
import java.util.List;
26
import java.util.Map;
27
import java.util.Objects;
28
import java.util.Set;
29
import java.util.TreeSet;
30
import java.util.concurrent.Callable;
31
import java.util.stream.Collectors;
32

33
/**
34
 * @author Andres Almiray
35
 * @since 0.1.0
36
 */
37
@CommandLine.Command
38
public abstract class AbstractCommand<C extends IO> extends BaseCommand implements Callable<Integer> {
1✔
39
    @CommandLine.ParentCommand
40
    private C parent;
41

42
    protected C parent() {
43
        return parent;
1✔
44
    }
45

46
    @Override
47
    public Integer call() {
48
        setup();
1✔
49
        checkArgsForDeprecations();
1✔
50

51
        try {
52
            execute();
1✔
53
        } catch (HaltExecutionException e) {
×
54
            return 1;
×
55
        } catch (JReleaserException e) {
1✔
56
            Colorizer colorizer = new Colorizer(parent().getOut());
1✔
57
            String message = e.getMessage();
1✔
58
            colorizer.println(message);
1✔
59
            printDetails(e.getCause(), message, colorizer);
1✔
60
            return 1;
1✔
61
        } catch (Exception e) {
×
62
            e.printStackTrace(new Colorizer(parent().getOut()));
×
63
            return 1;
×
64
        }
1✔
65

66
        return 0;
1✔
67
    }
68

69
    protected void setup() {
70
        Banner.display(parent().getErr());
1✔
71

72
        System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "error");
1✔
73
    }
1✔
74

75
    protected void checkArgsForDeprecations() {
76
        Set<DeprecatedArg> candidates = new TreeSet<>();
1✔
77
        collectCandidateDeprecatedArgs(candidates);
1✔
78
        Map<String, DeprecatedArg> groupedCandidates = candidates.stream()
1✔
79
            .collect(Collectors.toMap(DeprecatedArg::getDeprecated, e -> e));
1✔
80

81
        Set<DeprecatedArg> args = new TreeSet<>();
1✔
82

83
        CommandLine.ParseResult pr = spec.commandLine().getParseResult();
1✔
84
        List<CommandLine.Model.OptionSpec> options = spec.options();
1✔
85
        for (CommandLine.Model.OptionSpec opt : options) {
1✔
86
            String optName = opt.shortestName();
1✔
87
            if (groupedCandidates.containsKey(optName) &&
1✔
88
                pr.expandedArgs().contains(optName) &&
1✔
UNCOV
89
                pr.hasMatchedOption(optName)) {
×
UNCOV
90
                args.add(groupedCandidates.get(optName));
×
91
            }
92
        }
1✔
93

94
        for (DeprecatedArg arg : args) {
1✔
UNCOV
95
            parent().getErr().println($("deprecated.arg", arg.deprecated, arg.since, arg.replacement));
×
UNCOV
96
        }
×
97
    }
1✔
98

99
    protected void collectCandidateDeprecatedArgs(Set<DeprecatedArg> args) {
100
        // noop
101
    }
1✔
102

103
    protected void printDetails(Throwable throwable, String message, Colorizer colorizer) {
104
        if (null == throwable) return;
1✔
105
        String myMessage = throwable.getMessage();
1✔
106
        if (!message.equals(myMessage)) {
1✔
107
            colorizer.println(myMessage);
1✔
108
        } else {
109
            printDetails(throwable.getCause(), message, colorizer);
×
110
        }
111
    }
1✔
112

113
    protected abstract void execute();
114

115
    public static final class DeprecatedArg implements Comparable<DeprecatedArg> {
116
        private final String deprecated;
117
        private final String replacement;
118
        private final String since;
119

120
        public DeprecatedArg(String deprecated, String replacement, String since) {
1✔
121
            this.deprecated = deprecated;
1✔
122
            this.replacement = replacement;
1✔
123
            this.since = since;
1✔
124
        }
1✔
125

126
        public String getDeprecated() {
127
            return deprecated;
1✔
128
        }
129

130
        public String getReplacement() {
131
            return replacement;
×
132
        }
133

134
        public String getSince() {
135
            return since;
×
136
        }
137

138
        @Override
139
        public boolean equals(Object o) {
140
            if (this == o) return true;
×
141
            if (o == null || getClass() != o.getClass()) return false;
×
142
            DeprecatedArg that = (DeprecatedArg) o;
×
143
            return deprecated.equals(that.deprecated) && replacement.equals(that.replacement) && since.equals(that.since);
×
144
        }
145

146
        @Override
147
        public int hashCode() {
148
            return Objects.hash(deprecated, replacement, since);
×
149
        }
150

151
        @Override
152
        public int compareTo(DeprecatedArg o) {
153
            return Comparator.comparing(DeprecatedArg::getDeprecated)
1✔
154
                .compare(this, o);
1✔
155
        }
156
    }
157
}
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