|
19 | 19 |
|
20 | 20 | import javax.inject.Inject; |
21 | 21 | import java.io.ByteArrayOutputStream; |
22 | | -import java.util.ArrayList; |
23 | 22 | import java.util.List; |
24 | 23 |
|
25 | 24 | public abstract class JlinkTask extends DefaultTask { |
@@ -63,49 +62,35 @@ public JlinkTask(ProjectLayout layout, JavaToolchainService javaToolchain) { |
63 | 62 | public void createJre() { |
64 | 63 | var installationPath = getJavaCompiler().get().getMetadata().getInstallationPath(); |
65 | 64 |
|
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(); |
68 | 67 |
|
69 | 68 | var jlinkOutput = getOutputDirectory().dir("jre").get().getAsFile(); |
70 | 69 | getFs().delete(deleteSpec -> deleteSpec.delete(jlinkOutput)); |
71 | 70 |
|
72 | 71 | var stdout = new ByteArrayOutputStream(); |
73 | | - var stderr = new ByteArrayOutputStream(); |
74 | 72 |
|
75 | 73 | var result = getExec().exec(execSpec -> { |
76 | 74 | execSpec.setIgnoreExitValue(true); |
77 | 75 |
|
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 | + |
81 | 79 | if (getIncludeModulePath().get()) { |
82 | | - commandLine.add("--module-path"); |
83 | | - commandLine.add(jmods.toString()); |
| 80 | + execSpec.args("--module-path", jmods.getAbsolutePath()); |
84 | 81 | } |
85 | | - commandLine.add("--add-modules"); |
86 | | - commandLine.add(String.join(",", getModules().get())); |
87 | | - commandLine.add("--output"); |
88 | | - commandLine.add(jlinkOutput.toString()); |
89 | 82 |
|
90 | | - execSpec.setCommandLine(commandLine); |
| 83 | + execSpec.args("--add-modules", String.join(",", getModules().get())); |
| 84 | + execSpec.args("--output", jlinkOutput.getAbsolutePath()); |
91 | 85 |
|
92 | 86 | execSpec.setStandardOutput(stdout); |
93 | | - execSpec.setErrorOutput(stderr); |
| 87 | + execSpec.setErrorOutput(stdout); |
94 | 88 | }); |
95 | 89 |
|
96 | 90 | var stdoutStr = stdout.toString(); |
97 | | - var stderrStr = stderr.toString(); |
98 | | - |
99 | 91 | if (!stdoutStr.isEmpty()) { |
100 | | - getLogger().info(stdoutStr); |
101 | | - } |
102 | | - |
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 | | - } |
| 92 | + var level = result.getExitValue() == 0 ? LogLevel.INFO : LogLevel.ERROR; |
| 93 | + getLogger().log(level, stdoutStr); |
109 | 94 | } |
110 | 95 |
|
111 | 96 | result.assertNormalExitValue(); |
|
0 commit comments