Skip to content

Commit

Permalink
#75 java.lang.String cannot be cast to org.codehaus.mojo.exec.Modulepath
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte authored Mar 5, 2019
2 parents 4c864cb + 137189b commit 3296fc8
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/it/projects/exec_special-args/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals.1 = exec:exec
74 changes: 74 additions & 0 deletions src/it/projects/exec_special-args/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<artifactId>special-args</artifactId>
<version>0.0.1-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<!-- executable is echo.cmd or echo, depending on OS, see profiles -->
<arguments>
<argument>-p</argument>
<argument>nomodulepath</argument>
<argument>-cp</argument>
<argument>noclasspath</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>echo.cmd</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>non-indows</id>
<activation>
<os>
<family>!windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>echo</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
79 changes: 46 additions & 33 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,57 +470,70 @@ else if ( args[i].contains( CLASSPATH_TOKEN ) )
private void handleArguments( List<String> 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<String> it = computePath( (Modulepath) arguments.get( ++i ) ).iterator(); it.hasNext(); )
{
modulePath.append( it.next().replace( "\\", "\\\\" ) );
if ( it.hasNext() )
for ( Iterator<String> 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
{
Expand Down

0 comments on commit 3296fc8

Please sign in to comment.