Skip to content

Commit 9412cb2

Browse files
authored
1.7.1 (#32)
* Fixed to throw an error when cannot download image * Fixed allowing multiple values in buildOption
1 parent 2c93b74 commit 9412cb2

6 files changed

Lines changed: 104 additions & 11 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'com.formkiq.gradle'
13-
version '1.7.0'
13+
version '1.7.1'
1414

1515
spotless {
1616
java {
@@ -56,7 +56,7 @@ spotbugsMain {
5656

5757
spotless {
5858
java {
59-
eclipse().configFile project.rootProject.file("spotless.eclipseformat.xml")
59+
eclipse().configFile rootProject.file("spotless.eclipseformat.xml")
6060
}
6161
}
6262

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/Downloader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package com.formkiq.gradle.internal;
1616

17+
import java.io.FileNotFoundException;
1718
import java.io.FileOutputStream;
1819
import java.io.IOException;
1920
import java.io.InputStream;
@@ -42,11 +43,13 @@ public class Downloader {
4243
*/
4344
public void download(final Collection<String> urls, final Path toFile) throws IOException {
4445

46+
boolean found = false;
4547
if (!toFile.toFile().exists()) {
4648

4749
for (final String url : urls) {
4850

4951
if (urlExists(url)) {
52+
found = true;
5053
LOGGER.log(Level.INFO, "Downloading " + url + " to " + toFile);
5154
Path parent = toFile.getParent();
5255
if (parent != null) {
@@ -71,6 +74,10 @@ public void download(final Collection<String> urls, final Path toFile) throws IO
7174
} else {
7275
LOGGER.log(Level.INFO, "Downloaded file {0} already exists", toFile);
7376
}
77+
78+
if (!found) {
79+
throw new FileNotFoundException("Failed to download file from urls " + urls);
80+
}
7481
}
7582

7683
/**

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)