diff --git a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy index 2b8aa6280..88b943bf2 100644 --- a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy +++ b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationFunctionalTest.groovy @@ -131,4 +131,16 @@ class JavaApplicationFunctionalTest extends AbstractGraalVMMavenFunctionalTest { file("target/").listFiles().findAll(x->x.name.contains("native-image") && x.name.endsWith(".args")).size() == 1 } + def "can handle spaces when writing the args file"() { + withSpacesInProjectDir() + withSample("java-application") + + when: + mvn '-DquickBuild', '-Pnative', 'native:write-args-file' + + then: + buildSucceeded + outputContains "Args file written to: target" + File.separator + "native-image" + } + } diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java index fa5e563bd..35a09382b 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java @@ -242,9 +242,7 @@ protected List getBuildArgs() throws MojoExecutionException { } if (buildArgs != null && !buildArgs.isEmpty()) { - for (String buildArg : buildArgs) { - cliArgs.addAll(Arrays.asList(buildArg.split("\\s+"))); - } + cliArgs.addAll(processBuildArgs(buildArgs)); } List actualCliArgs; @@ -262,6 +260,18 @@ protected List getBuildArgs() throws MojoExecutionException { return Collections.unmodifiableList(actualCliArgs); } + static List processBuildArgs(List buildArgs) { + var result = new ArrayList(); + for (String buildArg : buildArgs) { + if(buildArg.startsWith("\\Q") || buildArg.startsWith("-H:ConfigurationFileDirectories")) { + result.add(buildArg); + } else { + result.addAll(Arrays.asList(buildArg.split("\\s+", 2))); + } + } + return result; + } + protected Path processSupportedArtifacts(Artifact artifact) throws MojoExecutionException { return processArtifact(artifact, "jar", "test-jar", "war"); } diff --git a/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy new file mode 100644 index 000000000..dc2df79ce --- /dev/null +++ b/native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy @@ -0,0 +1,30 @@ +package org.graalvm.buildtools.maven + +import spock.lang.Specification + +class AbstractNativeImageMojoTest extends Specification { + + void "it can process build args"() { + given: + def buildArgs = [ + "--exclude-config", + "\\QC:\\Users\\Lahoucine EL ADDALI\\.m2\\repository\\io\\netty\\netty-transport\\4.1.108.Final\\netty-transport-4.1.108.Final.jar\\E", + "^/META-INF/native-image/", + "-cp C:\\Users\\Lahoucine EL ADDALI\\Desktop\\outdir\\target/java-application-with-custom-packaging-0.1.jar", + "-H:ConfigurationFileDirectories=C:\\Users\\Lahoucine EL ADDALI\\Downloads\\4.5.0.0_kubernetes_kubernetes-demo-java-maven\\api\\target\\native\\generated\\generateResourceConfig" + ] + + when: + def processedArgs = AbstractNativeImageMojo.processBuildArgs(buildArgs) + + then: + processedArgs == [ + "--exclude-config", + "\\QC:\\Users\\Lahoucine EL ADDALI\\.m2\\repository\\io\\netty\\netty-transport\\4.1.108.Final\\netty-transport-4.1.108.Final.jar\\E", + "^/META-INF/native-image/", + "-cp", + "C:\\Users\\Lahoucine EL ADDALI\\Desktop\\outdir\\target/java-application-with-custom-packaging-0.1.jar", + "-H:ConfigurationFileDirectories=C:\\Users\\Lahoucine EL ADDALI\\Downloads\\4.5.0.0_kubernetes_kubernetes-demo-java-maven\\api\\target\\native\\generated\\generateResourceConfig" + ] + } +} diff --git a/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/AbstractGraalVMMavenFunctionalTest.groovy b/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/AbstractGraalVMMavenFunctionalTest.groovy index 00c593bc6..a02de1d93 100644 --- a/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/AbstractGraalVMMavenFunctionalTest.groovy +++ b/native-maven-plugin/src/testFixtures/groovy/org/graalvm/buildtools/maven/AbstractGraalVMMavenFunctionalTest.groovy @@ -43,7 +43,6 @@ package org.graalvm.buildtools.maven import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.ServerConnector -import org.eclipse.jetty.server.SymlinkAllowedResourceAliasChecker import org.eclipse.jetty.server.handler.ContextHandler import org.eclipse.jetty.server.handler.ResourceHandler import spock.lang.Specification @@ -57,7 +56,7 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification { @TempDir Path testDirectory - Path testOrigin; + Path testOrigin private IsolatedMavenExecutor executor @@ -66,9 +65,9 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification { Server server ServerConnector connector - boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows"); - boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux"); - boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac"); + boolean IS_WINDOWS = System.getProperty("os.name", "unknown").contains("Windows") + boolean IS_LINUX = System.getProperty("os.name", "unknown").contains("Linux") + boolean IS_MAC = System.getProperty("os.name", "unknown").contains("Mac") def setup() { executor = new IsolatedMavenExecutor( @@ -154,12 +153,13 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification { } void mvn(List args, Map systemProperties) { - System.out.println("Running copy of maven project `" + testOrigin + "` with " + args); + println("Running copy of maven project ${testOrigin} in ${testDirectory} with $args") var resultingSystemProperties = [ "common.repo.uri": System.getProperty("common.repo.uri"), "seed.repo.uri": System.getProperty("seed.repo.uri"), "maven.repo.local": testDirectory.resolve("local-repo").toFile().absolutePath ] + println "Using local repo: ${resultingSystemProperties['maven.repo.local']}" resultingSystemProperties.putAll(systemProperties) result = executor.execute( @@ -169,7 +169,7 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification { *args], new File(System.getProperty("maven.settings")) ) - System.out.println("Exit code is ${result.exitCode}") + println "Exit code is ${result.exitCode}" }