• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jreleaser / jreleaser / #477

04 Apr 2025 05:53PM UTC coverage: 35.124% (-5.1%) from 40.183%
#477

push

github

aalmiray
fix(deploy): Add missing Forgejo messages

Related to #1842

18210 of 51845 relevant lines covered (35.12%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/sdks/jreleaser-tool-java-sdk/src/main/java/org/jreleaser/sdk/tool/AbstractTool.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.sdk.tool;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.model.api.JReleaserContext;
22
import org.jreleaser.sdk.command.Command;
23
import org.jreleaser.sdk.command.CommandException;
24
import org.jreleaser.sdk.command.CommandExecutor;
25
import org.jreleaser.util.PlatformUtils;
26

27
import java.nio.file.Path;
28
import java.util.List;
29

30
import static org.jreleaser.util.StringUtils.requireNonBlank;
31

32
/**
33
 * @author Andres Almiray
34
 * @since 1.0.0
35
 */
36
public class AbstractTool {
37
    protected final JReleaserContext context;
38
    protected final DownloadableTool tool;
39
    protected final String name;
40
    protected final String version;
41
    protected final boolean verifyErrorOutput;
42

43
    public AbstractTool(JReleaserContext context, String name, String version) {
44
        this(context, name, version, false);
1✔
45
    }
1✔
46

47
    public AbstractTool(JReleaserContext context, String name, String version, boolean verifyErrorOutput) {
1✔
48
        this.version = requireNonBlank(version, "'version' must not be blank");
1✔
49
        this.name = requireNonBlank(name, "'name' must not be blank");
1✔
50
        this.context = context;
1✔
51
        this.verifyErrorOutput = verifyErrorOutput;
1✔
52
        this.tool = new DownloadableTool(context.getLogger(), name, version, PlatformUtils.getCurrentFull(), true);
1✔
53
    }
1✔
54

55
    public String getName() {
56
        return name;
×
57
    }
58

59
    public String getVersion() {
60
        return version;
×
61
    }
62

63
    public boolean setup() throws ToolException {
64
        if (!tool.verify()) {
1✔
65
            if (tool.isEnabled()) {
1✔
66
                try {
67
                    tool.download();
1✔
68
                } catch (Exception e) {
×
69
                    throw new ToolException(RB.$("ERROR_unexpected_error"), e);
×
70
                }
1✔
71
                if (tool.verify()) return true;
1✔
72
            }
73

74
            context.getLogger().warn(RB.$("tool_verify_error", name, tool.getVersion()));
1✔
75
            return false;
1✔
76
        }
77

78
        return true;
×
79
    }
80

81
    public void invoke(Path parent, List<String> args) throws CommandException {
82
        Command command = tool.asCommand().args(args);
×
83
        Command.Result result = executeCommand(() -> new CommandExecutor(context.getLogger())
×
84
            .executeCommand(parent, command));
×
85
        if (result.getExitValue() != 0) {
×
86
            throw new CommandException(RB.$("ERROR_command_execution_exit_value", result.getExitValue()));
×
87
        }
88
    }
×
89

90
    protected Command.Result executeCommand(CommandExecution execution) throws CommandException {
91
        return execution.execute();
×
92
    }
93

94
    interface CommandExecution {
95
        Command.Result execute() throws CommandException;
96
    }
97
}
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