Skip to content

Commit

Permalink
Merge pull request #609 from houcine7/fix-path-whitespaces-args
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosanchez authored Sep 4, 2024
2 parents 2c8c2a7 + cdfcfa2 commit 8536ecd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
}

if (buildArgs != null && !buildArgs.isEmpty()) {
for (String buildArg : buildArgs) {
cliArgs.addAll(Arrays.asList(buildArg.split("\\s+")));
}
cliArgs.addAll(processBuildArgs(buildArgs));
}

List<String> actualCliArgs;
Expand All @@ -262,6 +260,18 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
return Collections.unmodifiableList(actualCliArgs);
}

static List<String> processBuildArgs(List<String> buildArgs) {
var result = new ArrayList<String>();
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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,7 +56,7 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
@TempDir
Path testDirectory

Path testOrigin;
Path testOrigin

private IsolatedMavenExecutor executor

Expand All @@ -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(
Expand Down Expand Up @@ -154,12 +153,13 @@ abstract class AbstractGraalVMMavenFunctionalTest extends Specification {
}

void mvn(List<String> args, Map<String, String> 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(
Expand All @@ -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}"

}

Expand Down

0 comments on commit 8536ecd

Please sign in to comment.