diff --git a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java index fb2ba3a3..523b8903 100644 --- a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java +++ b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java @@ -336,6 +336,12 @@ public class ExecMojo extends AbstractExecMojo { @Parameter(property = "exec.async", defaultValue = "false") private boolean async; + /** + * If set to true all arguments will be written to file and then used as arguments file using a '@' when using the exec variant. + */ + @Parameter(property = "exec.argumentsFile", defaultValue = "false") + private boolean argumentsFile; + /** * If set to true, the asynchronous child process is destroyed upon JVM shutdown. If set to false, asynchronous * child process continues execution after JVM shutdown. Applies only to asynchronous processes; ignored for @@ -410,9 +416,14 @@ public void execute() throws MojoExecutionException { CommandLine commandLine = getExecutablePath(enviro, workingDirectory); - String[] args = commandArguments.toArray(new String[commandArguments.size()]); - - commandLine.addArguments(args, false); + if (argumentsFile) { + Path commandLineArguments = Paths.get("target", "commandLineArguments"); + Files.write(commandLineArguments, commandArguments); + commandLine.addArguments(new String[] {"@" + commandLineArguments.toString()}, false); + } else { + String[] args = commandArguments.toArray(new String[0]); + commandLine.addArguments(args, false); + } Executor exec = new ExtendedExecutor(inheritIo); if (this.timeout > 0) { @@ -924,6 +935,10 @@ public void onProcessComplete(int exitValue) { // methods used for tests purposes - allow mocking and simulate automatic setters // + void setArgumentsFile(boolean argumentsFile) { + this.argumentsFile = argumentsFile; + } + void setExecutable(String executable) { this.executable = executable; } diff --git a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java index b056dd81..af88d1cb 100644 --- a/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java +++ b/src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java @@ -338,6 +338,29 @@ void exec_receives_all_parameters(ExecMojo execMojo) throws Exception { assertTrue(Paths.get("target", "dist", "mails").toFile().exists(), "dir should have been created"); } + @Test + @InjectMojo(goal = "exec", pom = "src/test/projects/project22/pom.xml") + void exec_uses_arguments_as_file(ExecMojo execMojo) throws Exception { + // given + String testJavaPath; + + testJavaPath = "/path/to/java/home"; + when(toolchainManager.getToolchainFromBuildContext(any(), eq(session))) + .thenReturn(new DummyJdkToolchain(testJavaPath + "/bin/java")); + + // when + try { + execMojo.execute(); + } catch (Exception e) { + // ignore + } + + // then + assertTrue( + Paths.get("target", "commandLineArguments").toFile().exists(), + "commandline arugments file should have been created"); + } + @Test @InjectMojo(goal = "exec", pom = "src/test/projects/project20/pom.xml") @DisabledOnOs(OS.WINDOWS) diff --git a/src/test/projects/project22/pom.xml b/src/test/projects/project22/pom.xml new file mode 100644 index 00000000..8f045b79 --- /dev/null +++ b/src/test/projects/project22/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + org.cb.maven.plugins.exec + project1 + 0.1 + jar + Maven Exec Plugin + 2005 + + + Apache License 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + + Ivo Limmen + ivolimmen + ivo@limmen.org + + Java Developer + + +1 + + + + + + + + org.codehaus.mojo + exec-maven-plugin + + + test + + exec + + + + + java + true + + -Dproject.env1=value1 + -classpath + + org.codehaus.mojo.exec.test1.Test + + + + + + + diff --git a/src/test/projects/project22/src/main/java/org/codehaus/mojo/exec/test1/Test.java b/src/test/projects/project22/src/main/java/org/codehaus/mojo/exec/test1/Test.java new file mode 100644 index 00000000..53acbad0 --- /dev/null +++ b/src/test/projects/project22/src/main/java/org/codehaus/mojo/exec/test1/Test.java @@ -0,0 +1,7 @@ +package org.codehaus.mojo.exec.test1; + +public class Test +{ + public static void main( String[] args ) throws Exception { + } +}