Skip to content

Commit 76eb62d

Browse files
committed
Fixed allowing multiple values in buildOption
1 parent 84eda4a commit 76eb62d

4 files changed

Lines changed: 95 additions & 9 deletions

File tree

src/main/java/com/formkiq/gradle/GraalvmParameterToStrings.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ public List<String> apply(final GraalvmNativeExtension extension) {
1414
List<String> args = new ArrayList<>();
1515

1616
if (extension.getBuildOptions() != null) {
17-
args.add(extension.getBuildOptions());
17+
String[] split = extension.getBuildOptions().split("-");
18+
for (String s : split) {
19+
if (!s.isEmpty()) {
20+
args.add("-" + s.trim());
21+
}
22+
}
1823
}
1924

2025
addBooleanArgument(args, extension.isEnableFallback(), "--no-fallback");

src/main/java/com/formkiq/gradle/internal/NativeImageExecutor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ public void buildGraalvmJavaMain(final Project project, final Path buildDir) {
8484
new RuntimeDependenciesDecompress(project).apply(buildDir);
8585
}
8686

87-
private List<String> getBuildGraalvmImageArguments(final Project project, final Path buildDir) {
87+
List<String> getBuildGraalvmImageArguments(final Project project, final Path buildDir) {
8888

89-
List<String> args = new ArrayList<>();
90-
args.add("--report-unsupported-elements-at-runtime");
91-
args.add("--no-server");
89+
List<String> args = new ArrayList<>(new GraalvmParameterToStrings().apply(this.extension));
9290

93-
args.addAll(new GraalvmParameterToStrings().apply(this.extension));
91+
String executableName = this.extension.getOutputFileName();
9492

95-
args.add("-H:Name=" + getExecutableName(project));
93+
if (executableName != null) {
94+
args.add("-H:Name=" + getExecutableName(project));
95+
}
9696

9797
args.addAll(new GraalvmClasspathArguments(buildDir).apply(this.extension));
9898

@@ -123,7 +123,7 @@ public void runGuInstallation(final ExecOperations execOperations, final Path gr
123123
throws IOException {
124124

125125
String guExecutable = OperatingSystem.current().isWindows() ? "gu.cmd" : "gu";
126-
Path gu = graalvmBaseDir.resolve(guExecutable);
126+
Path gu = getGraalBin(graalvmBaseDir.toFile()).resolve(guExecutable);
127127

128128
if (gu.toFile().exists()) {
129129
execOperations.exec(arg0 -> {

src/test/java/com/formkiq/gradle/GraalvmParameterToStringsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void testAllParametersSet() {
8181
// apply(...)
8282
List<String> expected = List.of(
8383
// 1. buildOptions
84-
"myBuildOptions",
84+
"-myBuildOptions",
8585
// 2. boolean flags in declaration order
8686
"--no-fallback", "--allow-incomplete-classpath", "--install-exit-handlers",
8787
// disabled HTTP/HTTPS → do not appear
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.formkiq.gradle.internal;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import com.formkiq.gradle.GraalvmNativeExtension;
6+
import java.nio.file.Path;
7+
import java.util.List;
8+
import org.gradle.api.Project;
9+
import org.gradle.testfixtures.ProjectBuilder;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
class NativeImageExecutorNoMockTest {
14+
15+
private Project project;
16+
private Path fakeBuildDir;
17+
18+
@BeforeEach
19+
void setUp() {
20+
project = ProjectBuilder.builder().build();
21+
fakeBuildDir = Path.of("build", "dummy");
22+
}
23+
24+
/** With output filename set. */
25+
@Test
26+
void testGetBuildGraalvmImageArguments01() {
27+
// given
28+
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
29+
extension.setOutputFileName("my-app");
30+
extension.setMainClassName("com.example.Main");
31+
32+
NativeImageExecutor executor = new NativeImageExecutor(extension);
33+
34+
// when
35+
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);
36+
37+
// then
38+
assertTrue(args.stream().anyMatch(a -> a.equals("-H:Name=my-app")),
39+
() -> "Expected '-H:Name=my-app' in " + args);
40+
assertEquals("com.example.Main", args.get(args.size() - 1));
41+
}
42+
43+
/** Without output filename set. */
44+
@Test
45+
void testGetBuildGraalvmImageArguments02() {
46+
// given
47+
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
48+
extension.setMainClassName("com.example.Main");
49+
NativeImageExecutor executor = new NativeImageExecutor(extension);
50+
51+
// when
52+
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);
53+
54+
// then
55+
assertTrue(args.stream().noneMatch(a -> a.startsWith("-H:Name=")),
56+
() -> "Did not expect any '-H:Name=' flag in " + args);
57+
assertEquals("com.example.Main", args.get(args.size() - 1));
58+
}
59+
60+
/** With multiple build options. */
61+
@Test
62+
void testGetBuildGraalvmImageArguments03() {
63+
// given
64+
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
65+
extension.setBuildOptions("-Os -o fk");
66+
extension.setMainClassName("com.example.Main");
67+
NativeImageExecutor executor = new NativeImageExecutor(extension);
68+
69+
// when
70+
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);
71+
72+
// then
73+
final int expected = 7;
74+
int i = 0;
75+
assertEquals(expected, args.size());
76+
assertEquals("-Os", args.get(i++));
77+
assertEquals("-o fk", args.get(i++));
78+
assertEquals("--enable-http", args.get(i++));
79+
assertEquals("--enable-https", args.get(i));
80+
}
81+
}

0 commit comments

Comments
 (0)