Skip to content

Commit c0594c5

Browse files
Improve jlink task, and change how the output is logged
1 parent c415768 commit c0594c5

File tree

1 file changed

+15
-26
lines changed
  • buildSrc/src/main/java/com/github/stickerifier/stickerify

1 file changed

+15
-26
lines changed

buildSrc/src/main/java/com/github/stickerifier/stickerify/JlinkTask.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import javax.inject.Inject;
2121
import java.io.ByteArrayOutputStream;
22-
import java.util.ArrayList;
2322
import java.util.List;
2423

2524
public abstract class JlinkTask extends DefaultTask {
@@ -63,49 +62,39 @@ public JlinkTask(ProjectLayout layout, JavaToolchainService javaToolchain) {
6362
public void createJre() {
6463
var installationPath = getJavaCompiler().get().getMetadata().getInstallationPath();
6564

66-
var jlink = installationPath.file("bin/jlink");
67-
var jmods = installationPath.dir("jmods");
65+
var jlink = installationPath.file("bin/jlink").getAsFile();
66+
var jmods = installationPath.dir("jmods").getAsFile();
6867

6968
var jlinkOutput = getOutputDirectory().dir("jre").get().getAsFile();
7069
getFs().delete(deleteSpec -> deleteSpec.delete(jlinkOutput));
7170

7271
var stdout = new ByteArrayOutputStream();
73-
var stderr = new ByteArrayOutputStream();
7472

7573
var result = getExec().exec(execSpec -> {
7674
execSpec.setIgnoreExitValue(true);
7775

78-
var commandLine = new ArrayList<String>();
79-
commandLine.add(jlink.toString());
80-
commandLine.addAll(getOptions().get());
76+
execSpec.setCommandLine(jlink.getAbsolutePath());
77+
execSpec.args(getOptions().get());
78+
8179
if (getIncludeModulePath().get()) {
82-
commandLine.add("--module-path");
83-
commandLine.add(jmods.toString());
80+
execSpec.args("--module-path", jmods.getAbsolutePath());
8481
}
85-
commandLine.add("--add-modules");
86-
commandLine.add(String.join(",", getModules().get()));
87-
commandLine.add("--output");
88-
commandLine.add(jlinkOutput.toString());
8982

90-
execSpec.setCommandLine(commandLine);
83+
execSpec.args("--add-modules", String.join(",", getModules().get()));
84+
execSpec.args("--output", jlinkOutput.getAbsolutePath());
9185

9286
execSpec.setStandardOutput(stdout);
93-
execSpec.setErrorOutput(stderr);
87+
execSpec.setErrorOutput(stdout);
9488
});
9589

96-
var stdoutStr = stdout.toString();
97-
var stderrStr = stderr.toString();
98-
99-
if (!stdoutStr.isEmpty()) {
100-
getLogger().info(stdoutStr);
90+
if (result.getExitValue() != 0) {
91+
getLogger().log(LogLevel.ERROR, "jlink failed with exit code: {}", result.getExitValue());
10192
}
10293

103-
if (result.getExitValue() != 0) {
104-
if (stderrStr.isEmpty()) {
105-
getLogger().log(LogLevel.ERROR, "jlink failed with exit code: {}", result.getExitValue());
106-
} else {
107-
getLogger().log(LogLevel.ERROR, stderrStr);
108-
}
94+
var stdoutStr = stdout.toString();
95+
if (!stdoutStr.isEmpty()) {
96+
var level = result.getExitValue() == 0 ? LogLevel.INFO : LogLevel.ERROR;
97+
getLogger().log(level, stdoutStr);
10998
}
11099

111100
result.assertNormalExitValue();

0 commit comments

Comments
 (0)