Skip to content

Commit

Permalink
Unit test code
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosanchez committed Sep 4, 2024
1 parent 2798688 commit cdfcfa2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,7 @@ protected List<String> getBuildArgs() throws MojoExecutionException {
}

if (buildArgs != null && !buildArgs.isEmpty()) {
for (String buildArg : buildArgs) {
if(buildArg.startsWith("\\Q") || buildArg.startsWith("-H")) {
cliArgs.add(buildArg);
continue;
}
cliArgs.addAll(Arrays.asList(buildArg.split("\\s+", 2)));
}
cliArgs.addAll(processBuildArgs(buildArgs));
}

List<String> actualCliArgs;
Expand All @@ -266,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"
]
}
}

0 comments on commit cdfcfa2

Please sign in to comment.