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

jreleaser / jreleaser / #503

20 Jul 2025 10:20AM UTC coverage: 49.347% (-0.02%) from 49.362%
#503

push

github

aalmiray
fix: Configure mising resources in native-image

Fixes #1918

25724 of 52129 relevant lines covered (49.35%)

0.49 hits per line

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

82.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
@org.jreleaser.infra.nativeimage.annotations.NativeImage
37
public class AbstractTool {
38
    protected final JReleaserContext context;
39
    protected final DownloadableTool tool;
40
    protected final String name;
41
    protected final String version;
42
    protected final boolean verifyErrorOutput;
43

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

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

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

60
    public String getVersion() {
61
        return version;
1✔
62
    }
63

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

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

79
        return true;
×
80
    }
81

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

91
    protected Command.Result executeCommand(CommandExecution execution) throws CommandException {
92
        return execution.execute();
1✔
93
    }
94

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