(merged from 382460.) [MNG-1415] Added quoted-argument reconstruction to MavenCLI, and quote preservation to the shell scripts. Both are necessary to fix this issue. Test is it0098.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@382461 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-03-02 18:18:06 +00:00
parent 9d515afa31
commit d201131b59
13 changed files with 229 additions and 3 deletions

View File

@ -263,6 +263,8 @@ it0096: Test that plugin executions from >1 step of inheritance don't run multip
it0097: Test that the implied relative path for the parent POM works, even two
levels deep.
it0098: Test that quoted system properties are processed correctly. [MNG-1415]
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,4 @@
it0098
it0097
it0096
it0095

View File

@ -0,0 +1 @@
-DgroupId=org.someproject "-DartifactId=test project"

View File

@ -0,0 +1 @@
test project/pom.xml

View File

@ -0,0 +1 @@
archetype:create

View File

@ -0,0 +1,22 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.it0098</groupId>
<artifactId>it0098-archetype-orchestration-test</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>test project</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,18 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.someproject</groupId>
<artifactId>test project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package org.someproject;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@ -0,0 +1,38 @@
package org.someproject;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

View File

@ -0,0 +1 @@
failOnErrorOutput=false

View File

@ -22,4 +22,5 @@ echo ""
echo THE m2 COMMMAND IS DEPRECATED - PLEASE RUN mvn INSTEAD
echo ""
exec "`dirname "$0"`/mvn" $@
. `dirname "$0"`/mvn
exec "`dirname "$0"`/mvn" $QUOTED_ARGS

View File

@ -18,6 +18,14 @@
# Copyright (c) 2001-2002 The Apache Software Foundation. All rights
# reserved.
QUOTED_ARGS=""
while [ "$1" != "" ] ; do
QUOTED_ARGS="$QUOTED_ARGS \"$1\""
shift
done
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
@ -134,5 +142,5 @@ exec "$JAVACMD" \
-classpath "${M2_HOME}"/core/boot/classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
"-Dmaven.home=${M2_HOME}" \
${CLASSWORLDS_LAUNCHER} $@
${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS

View File

@ -56,6 +56,8 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
@ -703,8 +705,125 @@ public class MavenCli
public CommandLine parse( String[] args )
throws ParseException
{
// We need to eat any quotes surrounding arguments...
String[] cleanArgs = cleanArgs( args );
CommandLineParser parser = new GnuParser();
return parser.parse( options, args );
return parser.parse( options, cleanArgs );
}
private String[] cleanArgs( String[] args )
{
List cleaned = new ArrayList();
StringBuffer currentArg = null;
for ( int i = 0; i < args.length; i++ )
{
String arg = args[i];
// System.out.println( "Processing raw arg: " + arg );
boolean addedToBuffer = false;
if ( arg.startsWith( "\"" ) )
{
// if we're in the process of building up another arg, push it and start over.
// this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
if ( currentArg != null )
{
// System.out.println( "Flushing last arg buffer: \'" + currentArg + "\' to cleaned list." );
cleaned.add( currentArg.toString() );
}
// start building an argument here.
currentArg = new StringBuffer( arg.substring( 1 ) );
addedToBuffer = true;
}
// this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
if ( arg.endsWith( "\"" ) )
{
String cleanArgPart = arg.substring( 0, arg.length() - 1 );
// if we're building an argument, keep doing so.
if ( currentArg != null )
{
// if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
if ( addedToBuffer )
{
// System.out.println( "Adjusting argument already appended to the arg buffer." );
currentArg.setLength( currentArg.length() - 1 );
}
// otherwise, we trim the trailing " and append to the buffer.
else
{
// System.out.println( "Appending arg part: \'" + cleanArgPart + "\' with preceding space to arg buffer." );
// TODO: introducing a space here...not sure what else to do but collapse whitespace
currentArg.append( ' ' ).append( cleanArgPart );
}
// System.out.println( "Flushing completed arg buffer: \'" + currentArg + "\' to cleaned list." );
// we're done with this argument, so add it.
cleaned.add( currentArg.toString() );
}
else
{
// System.out.println( "appending cleaned arg: \'" + cleanArgPart + "\' directly to cleaned list." );
// this is a simple argument...just add it.
cleaned.add( cleanArgPart );
}
// System.out.println( "Clearing arg buffer." );
// the currentArg MUST be finished when this completes.
currentArg = null;
continue;
}
// if we haven't added this arg to the buffer, and we ARE building an argument
// buffer, then append it with a preceding space...again, not sure what else to
// do other than collapse whitespace.
// NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
if ( !addedToBuffer )
{
// append to the argument we're building, collapsing whitespace to a single space.
if ( currentArg != null )
{
// System.out.println( "Append unquoted arg part: \'" + arg + "\' to arg buffer." );
currentArg.append( ' ' ).append( arg );
}
// this is a loner, just add it directly.
else
{
// System.out.println( "Append unquoted arg part: \'" + arg + "\' directly to cleaned list." );
cleaned.add( arg );
}
}
}
// clean up.
if ( currentArg != null )
{
// System.out.println( "Adding unterminated arg buffer: \'" + currentArg + "\' to cleaned list." );
cleaned.add( currentArg.toString() );
}
int cleanedSz = cleaned.size();
String[] cleanArgs = null;
if ( cleanedSz == 0 )
{
// if we didn't have any arguments to clean, simply pass the original array through
cleanArgs = args;
}
else
{
// System.out.println( "Cleaned argument list:\n" + cleaned );
cleanArgs = (String[]) cleaned.toArray( new String[cleanedSz] );
}
return cleanArgs;
}
public void displayHelp()