Skip to content
Open
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
21 changes: 18 additions & 3 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/codehaus/mojo/exec/ExecMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions src/test/projects/project22/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.cb.maven.plugins.exec</groupId>
<artifactId>project1</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>Maven Exec Plugin</name>
<inceptionYear>2005</inceptionYear>
<licenses>
<license>
<name>Apache License 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<name>Ivo Limmen</name>
<id>ivolimmen</id>
<email>ivo@limmen.org</email>
<roles>
<role>Java Developer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>

<build>
<!-- for manual tests. Can't be automated in the unit tests as the plugin's not installed. What about integration tests? -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<argumentsFile>true</argumentsFile>
<arguments>
<argument>-Dproject.env1=value1</argument>
<argument>-classpath</argument>
<classpath/>
<argument>org.codehaus.mojo.exec.test1.Test</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.codehaus.mojo.exec.test1;

public class Test
{
public static void main( String[] args ) throws Exception {
}
}