You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2007/02/28 02:18:02 UTC

svn commit: r512542 - in /maven/components/trunk/maven-cli/src: main/java/org/apache/maven/cli/MavenCli.java test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java

Author: jvanzyl
Date: Tue Feb 27 17:18:01 2007
New Revision: 512542

URL: http://svn.apache.org/viewvc?view=rev&rev=512542
Log:
o adding a way to set the local repository using a -D option 
o make the cli handle things that are CLI specific like:
  - the $m2_home/conf/settings.xml file and the standard ~/.m2/settings.xml file, i am still falling back
    to this as people using the embedder have become used to this. but this has the effect of greatly 
    simplifying settings handling because it is up to the client code to define where settings are
    and how they should be processed
o use an embedder configuration for things like settings and the local repository which generally remain constant, another
  push toward a single source for session and request configuration information

Modified:
    maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java
    maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
    maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java

Modified: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java?view=diff&rev=512542&r1=512541&r2=512542
==============================================================================
--- maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java Tue Feb 27 17:18:01 2007
@@ -21,10 +21,11 @@
 import org.apache.maven.MavenTransferListener;
 import org.apache.maven.embedder.MavenEmbedder;
 import org.apache.maven.embedder.MavenEmbedderException;
+import org.apache.maven.embedder.configuration.Configuration;
+import org.apache.maven.embedder.configuration.DefaultConfiguration;
 import org.apache.maven.execution.DefaultMavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionResult;
-import org.apache.maven.settings.SettingsBuilderAdvice;
 import org.codehaus.plexus.classworlds.ClassWorld;
 
 import java.io.File;
@@ -42,6 +43,11 @@
  */
 public class MavenCli
 {
+    public static final File DEFAULT_GLOBAL_SETTINGS_FILE = new File( System
+        .getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );
+
+    public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
+
     public static void main( String[] args )
     {
         ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
@@ -90,6 +96,7 @@
         }
 
         boolean debug = commandLine.hasOption( CLIManager.DEBUG );
+
         boolean quiet = !debug && commandLine.hasOption( CLIManager.QUIET );
 
         boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS );
@@ -125,21 +132,6 @@
         // bring the maven component to life for use.
         // ----------------------------------------------------------------------
 
-        //** use CLI option values directly in request where possible
-
-        MavenEmbedder mavenEmbedder;
-
-        try
-        {
-            mavenEmbedder = new MavenEmbedder( classWorld );            
-        }
-        catch ( MavenEmbedderException e )
-        {
-            showFatalError( "Unable to start the embedded plexus container", e, showErrors );
-
-            return 1;
-        }
-
         boolean interactive = true;
 
         if ( commandLine.hasOption( CLIManager.BATCH_MODE ) )
@@ -315,11 +307,6 @@
             }
 
             Properties executionProperties = getExecutionProperties( commandLine );
-            
-            SettingsBuilderAdvice settingsAdvice = new SettingsBuilderAdvice();
-            
-            settingsAdvice.setDefaultGlobalLocationEnabled( true );
-            settingsAdvice.setDefaultUserLocationEnabled( true );
 
             MavenExecutionRequest request = new DefaultMavenExecutionRequest()
                 .setBaseDirectory( baseDirectory )
@@ -330,22 +317,54 @@
                 .setUseReactor( useReactor ) // default: false
                 .setPomFile( alternatePomFile ) // optional
                 .setShowErrors( showErrors ) // default: false
-                    // Settings
-                .setSettingsFile( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) )
-                .setSettingsBuilderAdvice( settingsAdvice )
-                    //.setLocalRepositoryPath( localRepositoryPath ) // default: ~/.m2/repository
                 .setInteractiveMode( interactive ) // default: false
                 .setUsePluginRegistry( usePluginRegistry )
                 .setOffline( offline ) // default: false
                 .setUsePluginUpdateOverride( pluginUpdateOverride )
                 .addActiveProfiles( activeProfiles ) // optional
                 .addInactiveProfiles( inactiveProfiles ) // optional
-                    //
                 .setLoggingLevel( loggingLevel ) // default: info
                 .setTransferListener( transferListener ) // default: batch mode which goes along with interactive
                 .setUpdateSnapshots( updateSnapshots ) // default: false
                 .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
                 .setGlobalChecksumPolicy( globalChecksumPolicy ); // default: warn
+
+        File userSettingsFile;
+
+        if ( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) != null )
+        {
+            userSettingsFile = new File( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
+        }
+        else
+        {
+            userSettingsFile = MavenEmbedder.DEFAULT_USER_SETTINGS_FILE;
+        }
+
+        Configuration configuration = new DefaultConfiguration()
+            .setUserSettingsFile( userSettingsFile )
+            .setGlobalSettingsFile( DEFAULT_GLOBAL_SETTINGS_FILE )
+            .setClassWorld( classWorld );
+
+        String localRepoProperty = executionProperties.getProperty( LOCAL_REPO_PROPERTY );
+
+        if ( localRepoProperty != null )
+        {
+            configuration.setLocalRepository( new File( localRepoProperty ) );
+        }
+
+        MavenEmbedder mavenEmbedder;
+
+        try
+        {
+            mavenEmbedder = new MavenEmbedder( configuration );
+        }
+        catch ( MavenEmbedderException e )
+        {
+            showFatalError( "Unable to start the embedded plexus container", e, showErrors );
+
+            return 1;
+        }
+
 
         MavenExecutionResult result = mavenEmbedder.execute( request );
 

Modified: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java?view=diff&rev=512542&r1=512541&r2=512542
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java (original)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/BatchModeDownloadMonitorTest.java Tue Feb 27 17:18:01 2007
@@ -25,11 +25,11 @@
 public class BatchModeDownloadMonitorTest
     extends AbstractConsoleDownloadMonitorTest
 {
-
     protected void setUp()
         throws Exception
     {
         super.setMonitor( new BatchModeDownloadMonitor() );
+
         super.setUp();
     }
 }

Modified: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java?view=diff&rev=512542&r1=512541&r2=512542
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java (original)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/ConsoleDownloadMonitorTest.java Tue Feb 27 17:18:01 2007
@@ -30,6 +30,7 @@
         throws Exception
     {
         super.setMonitor( new ConsoleDownloadMonitor() );
+
         super.setUp();
     }
 }