Author: jvanzyl
Date: Fri Mar 31 08:07:02 2006
New Revision: 390450

URL: http://svn.apache.org/viewcvs?rev=390450&view=rev
Log:
o merging in changes that were made to handled quoted args on the CLI, it0098 
was failing on the branch

Modified:
    maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2
    maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2.bat
    maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn
    maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn.bat
    
maven/components/branches/maven-embedder-refactor/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java
    
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/CommonMavenObjectFactory.java
    
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/DefaultCommonMavenObjectFactory.java
    maven/components/branches/maven-embedder-refactor/pom.xml

Modified: maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2 
(original)
+++ maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2 Fri 
Mar 31 08:07:02 2006
@@ -22,4 +22,5 @@
 echo THE m2 COMMMAND IS DEPRECATED - PLEASE RUN mvn INSTEAD
 echo ""
 
-exec "`dirname "$0"`/mvn" $@
+. `dirname "$0"`/mvn
+exec "`dirname "$0"`/mvn" $QUOTED_ARGS

Modified: 
maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2.bat
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2.bat?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2.bat 
(original)
+++ maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/m2.bat 
Fri Mar 31 08:07:02 2006
@@ -20,5 +20,5 @@
 echo THE m2 COMMMAND IS DEPRECATED - PLEASE RUN mvn INSTEAD
 echo.
 
-%~dps0\mvn %*
+"%~dp0\mvn" %*
 

Modified: 
maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn 
(original)
+++ maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn Fri 
Mar 31 08:07:02 2006
@@ -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 @@
   -classpath "${M2_HOME}"/core/boot/classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
   "-Dmaven.home=${M2_HOME}"  \
-  ${CLASSWORLDS_LAUNCHER} $@
+  ${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS
 

Modified: 
maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn.bat
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn.bat?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn.bat 
(original)
+++ maven/components/branches/maven-embedder-refactor/maven-cli/src/bin/mvn.bat 
Fri Mar 31 08:07:02 2006
@@ -38,11 +38,11 @@
 @REM Execute a user defined script before this one
 if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
 
+set ERROR_CODE=0
+
 @REM set local scope for the variables with windows NT shell
 if "%OS%"=="Windows_NT" @setlocal
 
-set ERROR_CODE=0
-
 @REM ==== START VALIDATION ====
 if not "%JAVA_HOME%" == "" goto OkJHome
 
@@ -67,7 +67,7 @@
 :chkMHome
 if not "%M2_HOME%"=="" goto valMHome
 
-if "%OS%"=="Windows_NT" SET M2_HOME=%~dps0\..
+if "%OS%"=="Windows_NT" SET M2_HOME=%~dp0\..
 if not "%M2_HOME%"=="" goto valMHome
 
 echo.

Modified: 
maven/components/branches/maven-embedder-refactor/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- 
maven/components/branches/maven-embedder-refactor/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java
 (original)
+++ 
maven/components/branches/maven-embedder-refactor/maven-cli/src/main/java/org/apache/maven/cli/CLIManager.java
 Fri Mar 31 08:07:02 2006
@@ -11,6 +11,9 @@
 import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.HelpFormatter;
 
+import java.util.List;
+import java.util.ArrayList;
+
 /**
  * @author Jason van Zyl
  * @version $Revision: 381114 $
@@ -131,15 +134,135 @@
     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()
     {
         System.out.println();
 
         HelpFormatter formatter = new HelpFormatter();
+
         formatter.printHelp( "mvn [options] [<goal(s)>] [<phase(s)>]", 
"\nOptions:", options, "\n" );
     }
 }

Modified: 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/CommonMavenObjectFactory.java
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/CommonMavenObjectFactory.java?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/CommonMavenObjectFactory.java
 (original)
+++ 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/CommonMavenObjectFactory.java
 Fri Mar 31 08:07:02 2006
@@ -17,11 +17,18 @@
                                               boolean updateSnapshots,
                                               String globalChecksumPolicy );
 
-    public Settings buildSettings( File userSettingsPath,
-                                   File globalSettingsPath,
-                                   boolean interactive,
-                                   boolean offline,
-                                   boolean usePluginRegistry,
-                                   Boolean pluginUpdateOverride )
+    ArtifactRepository createRepository( String repositoryId,
+                                         String repositoryUrl,
+                                         boolean offline,
+                                         boolean updateSnapshots,
+                                         String globalChecksumPolicy );
+
+
+    Settings buildSettings( File userSettingsPath,
+                            File globalSettingsPath,
+                            boolean interactive,
+                            boolean offline,
+                            boolean usePluginRegistry,
+                            Boolean pluginUpdateOverride )
         throws SettingsConfigurationException;
 }

Modified: 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/DefaultCommonMavenObjectFactory.java
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/DefaultCommonMavenObjectFactory.java?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/DefaultCommonMavenObjectFactory.java
 (original)
+++ 
maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/DefaultCommonMavenObjectFactory.java
 Fri Mar 31 08:07:02 2006
@@ -35,7 +35,8 @@
  * @author Jason van Zyl
  */
 public class DefaultCommonMavenObjectFactory
-    implements CommonMavenObjectFactory, Contextualizable
+    implements CommonMavenObjectFactory,
+    Contextualizable
 {
     private ArtifactRepositoryLayout repositoryLayout;
 
@@ -61,16 +62,18 @@
             localRepositoryUrl = "file://" + localRepositoryUrl;
         }
 
-        return createRepository( "local", localRepositoryUrl, false, true, 
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
+        return createRepository( "local", localRepositoryUrl, false, true,
+                                 ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN 
);
     }
 
-    protected ArtifactRepository createRepository( String repositoryId,
-                                                   String repositoryUrl,
-                                                   boolean offline,
-                                                   boolean updateSnapshots,
-                                                   String globalChecksumPolicy 
)
+    public ArtifactRepository createRepository( String repositoryId,
+                                                String repositoryUrl,
+                                                boolean offline,
+                                                boolean updateSnapshots,
+                                                String globalChecksumPolicy )
     {
-        ArtifactRepository localRepository = new DefaultArtifactRepository( 
repositoryId, repositoryUrl, repositoryLayout );
+        ArtifactRepository localRepository =
+            new DefaultArtifactRepository( repositoryId, repositoryUrl, 
repositoryLayout );
 
         boolean snapshotPolicySet = false;
 
@@ -84,12 +87,11 @@
             artifactRepositoryFactory.setGlobalUpdatePolicy( 
ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
         }
 
-        artifactRepositoryFactory.setGlobalChecksumPolicy( 
globalChecksumPolicy  );
+        artifactRepositoryFactory.setGlobalChecksumPolicy( 
globalChecksumPolicy );
 
         return localRepository;
     }
 
-
     // 
----------------------------------------------------------------------------
     // Settings
     // 
----------------------------------------------------------------------------
@@ -106,7 +108,7 @@
 
         try
         {
-                settings = settingsBuilder.buildSettings( userSettingsPath, 
globalSettingsPath );
+            settings = settingsBuilder.buildSettings( userSettingsPath, 
globalSettingsPath );
         }
         catch ( IOException e )
         {
@@ -151,8 +153,7 @@
         {
             Repository mavenRepo = (Repository) i.next();
 
-            ArtifactRepository artifactRepo =
-                buildArtifactRepository( mavenRepo );
+            ArtifactRepository artifactRepo = buildArtifactRepository( 
mavenRepo );
 
             if ( !repos.contains( artifactRepo ) )
             {

Modified: maven/components/branches/maven-embedder-refactor/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/pom.xml?rev=390450&r1=390449&r2=390450&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/pom.xml (original)
+++ maven/components/branches/maven-embedder-refactor/pom.xml Fri Mar 31 
08:07:02 2006
@@ -101,7 +101,8 @@
     <module>maven-repository-metadata</module>
     <module>maven-script</module>
     <module>maven-settings</module>
-    <module>maven-cli</module>    
+    <module>maven-cli</module>
+    <module>maven-embedder</module>
   </modules>
   <dependencies>
     <dependency>


Reply via email to