You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by bm...@apache.org on 2023/07/27 13:56:49 UTC
[maven-jlink-plugin] branch master updated: [MJLINK-64] add quoting on forking (#166)
This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 8ba25c0 [MJLINK-64] add quoting on forking (#166)
8ba25c0 is described below
commit 8ba25c08dd9748697b1e81c7bc38089c8aac2028
Author: Benjamin Marwell <bm...@apache.org>
AuthorDate: Thu Jul 27 15:56:44 2023 +0200
[MJLINK-64] add quoting on forking (#166)
---
.../projects/cli-options/add-options/verify.groovy | 5 ++--
.../jlink/AbstractJLinkToolchainExecutor.java | 2 +-
.../org/apache/maven/plugins/jlink/JLinkMojo.java | 4 +--
.../apache/maven/plugins/jlink/JLinkMojoTest.java} | 33 ++++++++++++++--------
4 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/src/it/projects/cli-options/add-options/verify.groovy b/src/it/projects/cli-options/add-options/verify.groovy
index 8bd9385..2281a99 100644
--- a/src/it/projects/cli-options/add-options/verify.groovy
+++ b/src/it/projects/cli-options/add-options/verify.groovy
@@ -24,12 +24,11 @@ import java.util.jar.*
import org.codehaus.plexus.util.*
String buildlog = new File( basedir, "build.log").text
-assert buildlog.contains( "--add-options" )
-assert buildlog.contains( "\"-Xmx128m --enable-preview -Dvar=value\"" )
+assert buildlog.contains( "--add-options, \"-Xmx128m --enable-preview -Dvar=value\"" )
+assert buildlog.contains( "addOptions = [-Xmx128m, --enable-preview, -Dvar=value]" )
File target = new File( basedir, "target" )
assert target.isDirectory()
File artifact = new File( target, "maven-jlink-plugin-cli-options-add-options-101.0.zip" )
assert artifact.isFile()
-
diff --git a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java
index 086492c..15fd7db 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java
@@ -102,7 +102,7 @@ abstract class AbstractJLinkToolchainExecutor extends AbstractJLinkExecutor {
private Commandline createJLinkCommandLine(List<String> jlinkArgs) {
Commandline cmd = new Commandline();
- jlinkArgs.forEach(arg -> cmd.createArg().setValue(arg));
+ jlinkArgs.forEach(arg -> cmd.createArg().setValue("\"" + arg + "\""));
return cmd;
}
diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index a5f203d..34487a3 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -577,7 +577,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
}
}
- private List<String> createJlinkArgs(Collection<String> pathsOfModules, Collection<String> modulesToAdd) {
+ protected List<String> createJlinkArgs(Collection<String> pathsOfModules, Collection<String> modulesToAdd) {
List<String> jlinkArgs = new ArrayList<>();
if (stripDebug) {
@@ -612,7 +612,7 @@ public class JLinkMojo extends AbstractJLinkMojo {
jlinkArgs.add("--disable-plugin");
jlinkArgs.add(disablePlugin);
}
- if (pathsOfModules != null) {
+ if (pathsOfModules != null && !pathsOfModules.isEmpty()) {
// @formatter:off
jlinkArgs.add("--module-path");
jlinkArgs.add(getPlatformDependSeparateList(pathsOfModules).replace("\\", "\\\\"));
diff --git a/src/it/projects/cli-options/add-options/verify.groovy b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
similarity index 54%
copy from src/it/projects/cli-options/add-options/verify.groovy
copy to src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
index 8bd9385..77d670f 100644
--- a/src/it/projects/cli-options/add-options/verify.groovy
+++ b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,19 +16,29 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.jlink;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
-import java.io.*
-import java.util.*
-import java.util.jar.*
-import org.codehaus.plexus.util.*
+import static org.assertj.core.api.Assertions.assertThat;
-String buildlog = new File( basedir, "build.log").text
-assert buildlog.contains( "--add-options" )
-assert buildlog.contains( "\"-Xmx128m --enable-preview -Dvar=value\"" )
+public class JLinkMojoTest {
-File target = new File( basedir, "target" )
-assert target.isDirectory()
+ @Test
+ void quote_every_argument() throws Exception {
+ // given
+ JLinkMojo mojo = new JLinkMojo();
+ Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
+ stripDebug.setAccessible(true);
+ stripDebug.set(mojo, Boolean.TRUE);
-File artifact = new File( target, "maven-jlink-plugin-cli-options-add-options-101.0.zip" )
-assert artifact.isFile()
+ // when
+ List<String> jlinkArgs = mojo.createJlinkArgs(List.of(), List.of());
+ // then
+ assertThat(jlinkArgs).noneMatch(arg -> arg.trim().isBlank());
+ }
+}