Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group 'com.formkiq.gradle'
version '1.7.0'
version '1.7.1'

spotless {
java {
Expand Down Expand Up @@ -56,7 +56,7 @@ spotbugsMain {

spotless {
java {
eclipse().configFile project.rootProject.file("spotless.eclipseformat.xml")
eclipse().configFile rootProject.file("spotless.eclipseformat.xml")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public List<String> apply(final GraalvmNativeExtension extension) {
List<String> args = new ArrayList<>();

if (extension.getBuildOptions() != null) {
args.add(extension.getBuildOptions());
String[] split = extension.getBuildOptions().split("-");
for (String s : split) {
if (!s.isEmpty()) {
args.add("-" + s.trim());
}
}
}

addBooleanArgument(args, extension.isEnableFallback(), "--no-fallback");
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/formkiq/gradle/internal/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.formkiq.gradle.internal;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -42,11 +43,13 @@ public class Downloader {
*/
public void download(final Collection<String> urls, final Path toFile) throws IOException {

boolean found = false;
if (!toFile.toFile().exists()) {

for (final String url : urls) {

if (urlExists(url)) {
found = true;
LOGGER.log(Level.INFO, "Downloading " + url + " to " + toFile);
Path parent = toFile.getParent();
if (parent != null) {
Expand All @@ -71,6 +74,10 @@ public void download(final Collection<String> urls, final Path toFile) throws IO
} else {
LOGGER.log(Level.INFO, "Downloaded file {0} already exists", toFile);
}

if (!found) {
throw new FileNotFoundException("Failed to download file from urls " + urls);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ public void buildGraalvmJavaMain(final Project project, final Path buildDir) {
new RuntimeDependenciesDecompress(project).apply(buildDir);
}

private List<String> getBuildGraalvmImageArguments(final Project project, final Path buildDir) {
List<String> getBuildGraalvmImageArguments(final Project project, final Path buildDir) {

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

args.addAll(new GraalvmParameterToStrings().apply(this.extension));
String executableName = this.extension.getOutputFileName();

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

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

Expand Down Expand Up @@ -123,7 +123,7 @@ public void runGuInstallation(final ExecOperations execOperations, final Path gr
throws IOException {

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

if (gu.toFile().exists()) {
execOperations.exec(arg0 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void testAllParametersSet() {
// apply(...)
List<String> expected = List.of(
// 1. buildOptions
"myBuildOptions",
"-myBuildOptions",
// 2. boolean flags in declaration order
"--no-fallback", "--allow-incomplete-classpath", "--install-exit-handlers",
// disabled HTTP/HTTPS → do not appear
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.formkiq.gradle.internal;

import static org.junit.jupiter.api.Assertions.*;

import com.formkiq.gradle.GraalvmNativeExtension;
import java.nio.file.Path;
import java.util.List;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class NativeImageExecutorNoMockTest {

private Project project;
private Path fakeBuildDir;

@BeforeEach
void setUp() {
project = ProjectBuilder.builder().build();
fakeBuildDir = Path.of("build", "dummy");
}

/** With output filename set. */
@Test
void testGetBuildGraalvmImageArguments01() {
// given
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
extension.setOutputFileName("my-app");
extension.setMainClassName("com.example.Main");

NativeImageExecutor executor = new NativeImageExecutor(extension);

// when
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);

// then
assertTrue(args.stream().anyMatch(a -> a.equals("-H:Name=my-app")),
() -> "Expected '-H:Name=my-app' in " + args);
assertEquals("com.example.Main", args.get(args.size() - 1));
}

/** Without output filename set. */
@Test
void testGetBuildGraalvmImageArguments02() {
// given
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
extension.setMainClassName("com.example.Main");
NativeImageExecutor executor = new NativeImageExecutor(extension);

// when
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);

// then
assertTrue(args.stream().noneMatch(a -> a.startsWith("-H:Name=")),
() -> "Did not expect any '-H:Name=' flag in " + args);
assertEquals("com.example.Main", args.get(args.size() - 1));
}

/** With multiple build options. */
@Test
void testGetBuildGraalvmImageArguments03() {
// given
GraalvmNativeExtension extension = new GraalvmNativeExtension(project.getObjects());
extension.setBuildOptions("-Os -o fk");
extension.setMainClassName("com.example.Main");
NativeImageExecutor executor = new NativeImageExecutor(extension);

// when
List<String> args = executor.getBuildGraalvmImageArguments(project, fakeBuildDir);

// then
final int expected = 7;
int i = 0;
assertEquals(expected, args.size());
assertEquals("-Os", args.get(i++));
assertEquals("-o fk", args.get(i++));
assertEquals("--enable-http", args.get(i++));
assertEquals("--enable-https", args.get(i));
}
}