From cdfcfa20574139d6bbf7f2ab7f7a2e0047d0c23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20S=C3=A1nchez-Mariscal?= Date: Wed, 4 Sep 2024 11:59:51 +0200 Subject: [PATCH] Unit test code --- .../maven/AbstractNativeImageMojo.java | 20 ++++++++----- .../maven/AbstractNativeImageMojoTest.groovy | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 native-maven-plugin/src/test/groovy/org/graalvm/buildtools/maven/AbstractNativeImageMojoTest.groovy 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 339ae4a3a..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,13 +242,7 @@ protected List 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 actualCliArgs; @@ -266,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" + ] + } +}