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
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
Copy link
Contributor

@dnestoro dnestoro Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you have removed @TempDir annotation and then proceeded with deleting files manually in the cleanup function?

Copy link
Member Author

@houcine7 houcine7 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my local when I work with Tempdir all tests are passing, because windows avoids tempDir path whitespace with a certain encoding (C:\Users\Lahoucine~\AppData\Temp) so no parsing errors will result if I have withespaces in my path.

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