diff --git a/src/it/projects/exec_special-args/invoker.properties b/src/it/projects/exec_special-args/invoker.properties new file mode 100644 index 00000000..f448afa3 --- /dev/null +++ b/src/it/projects/exec_special-args/invoker.properties @@ -0,0 +1 @@ +invoker.goals.1 = exec:exec diff --git a/src/it/projects/exec_special-args/pom.xml b/src/it/projects/exec_special-args/pom.xml new file mode 100644 index 00000000..6ad61956 --- /dev/null +++ b/src/it/projects/exec_special-args/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + + org.codehaus.mojo.exec.it + parent + 0.1 + + + special-args + 0.0.1-SNAPSHOT + + + + + org.codehaus.mojo + exec-maven-plugin + @project.version@ + + + + -p + nomodulepath + -cp + noclasspath + + + + + + + + + windows + + + windows + + + + + + org.codehaus.mojo + exec-maven-plugin + + echo.cmd + + + + + + + non-indows + + + !windows + + + + + + org.codehaus.mojo + exec-maven-plugin + + echo + + + + + + + diff --git a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java index ead705a5..557392e6 100644 --- a/src/main/java/org/codehaus/mojo/exec/ExecMojo.java +++ b/src/main/java/org/codehaus/mojo/exec/ExecMojo.java @@ -470,57 +470,70 @@ else if ( args[i].contains( CLASSPATH_TOKEN ) ) private void handleArguments( List commandArguments ) throws MojoExecutionException, IOException { + String specialArg = null; + for ( int i = 0; i < arguments.size(); i++ ) { Object argument = arguments.get( i ); - String arg; - if ( argument instanceof String && isLongClassPathArgument( (String) argument ) ) - { - // it is assumed that starting from -cp or -classpath the arguments - // are: -classpath/-cp %classpath mainClass - // the arguments are replaced with: -jar $TMP/maven-exec.jar - // NOTE: the jar will contain the classpath and the main class - commandArguments.add( "-jar" ); - File tmpFile = createJar( computePath( (Classpath) arguments.get( i + 1 ) ), - (String) arguments.get( i + 2 ) ); - commandArguments.add( tmpFile.getAbsolutePath() ); - i += 2; - } - else if ( argument instanceof String && isLongModulePathArgument( (String) argument ) ) - { - String filePath = new File( buildDirectory, "modulepath" ).getAbsolutePath(); - commandArguments.add( '@' + filePath ); + if ( specialArg != null ) + { + if ( isLongClassPathArgument( specialArg ) && argument instanceof Classpath ) + { + // it is assumed that starting from -cp or -classpath the arguments + // are: -classpath/-cp %classpath mainClass + // the arguments are replaced with: -jar $TMP/maven-exec.jar + // NOTE: the jar will contain the classpath and the main class + commandArguments.add( "-jar" ); + + File tmpFile = createJar( computePath( (Classpath) argument ), + (String) arguments.get( ++i ) ); + commandArguments.add( tmpFile.getAbsolutePath() ); + } + else if ( isLongModulePathArgument( specialArg ) && argument instanceof Modulepath ) + { + String filePath = new File( buildDirectory, "modulepath" ).getAbsolutePath(); - StringBuilder modulePath = new StringBuilder(); - modulePath.append( '"' ); + StringBuilder modulePath = new StringBuilder(); + modulePath.append( '"' ); - for ( Iterator it = computePath( (Modulepath) arguments.get( ++i ) ).iterator(); it.hasNext(); ) - { - modulePath.append( it.next().replace( "\\", "\\\\" ) ); - if ( it.hasNext() ) + for ( Iterator it = computePath( (Modulepath) argument ).iterator(); it.hasNext(); ) { - modulePath.append( File.pathSeparatorChar ); + modulePath.append( it.next().replace( "\\", "\\\\" ) ); + if ( it.hasNext() ) + { + modulePath.append( File.pathSeparatorChar ); + } } + + modulePath.append( '"' ); + + createArgFile( filePath, Arrays.asList( "-p", modulePath.toString() ) ); + commandArguments.add( '@' + filePath ); + } + else + { + commandArguments.add( specialArg ); } - modulePath.append( '"' ); + specialArg = null; - createArgFile( filePath, Arrays.asList( "-p", modulePath.toString() ) ); + continue; } - else if ( argument instanceof Classpath ) + + if ( argument instanceof Classpath ) { Classpath specifiedClasspath = (Classpath) argument; - - arg = computeClasspathString( specifiedClasspath ); - commandArguments.add( arg ); + commandArguments.add( computeClasspathString( specifiedClasspath ) ); } else if ( argument instanceof Modulepath ) { Modulepath specifiedModulepath = (Modulepath) argument; - - arg = computeClasspathString( specifiedModulepath ); - commandArguments.add( arg ); + commandArguments.add( computeClasspathString( specifiedModulepath ) ); + } + else if ( isLongModulePathArgument( specialArg ) || isLongClassPathArgument( specialArg ) ) + { + specialArg = (String) argument; } else {