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 2006/02/26 19:09:28 UTC

svn commit: r381132 - in /maven/components/branches/maven-embedder-refactor: maven-core/src/main/java/org/apache/maven/ maven-core/src/main/java/org/apache/maven/cli/ maven-core/src/main/resources/META-INF/plexus/ maven-settings/src/main/java/org/apach...

Author: jvanzyl
Date: Sun Feb 26 10:09:26 2006
New Revision: 381132

URL: http://svn.apache.org/viewcvs?rev=381132&view=rev
Log:
o all the ITs are fine now, need to create some JIRA issues and discuss the merge into the trunk

Modified:
    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/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
    maven/components/branches/maven-embedder-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml
    maven/components/branches/maven-embedder-refactor/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java

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=381132&r1=381131&r2=381132&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 Sun Feb 26 10:09:26 2006
@@ -1,7 +1,7 @@
 package org.apache.maven;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.apache.maven.settings.Settings;
 
 import java.io.File;
 
@@ -10,8 +10,17 @@
  */
 public interface CommonMavenObjectFactory
 {
-     ArtifactRepository createLocalRepository( File localRepositoryPath,
-                                               boolean offline,
-                                               boolean updateSnapshots,
-                                               String globalChecksumPolicy );
+    static String ROLE = CommonMavenObjectFactory.class.getName();
+
+    ArtifactRepository createLocalRepository( File localRepositoryPath,
+                                              boolean offline,
+                                              boolean updateSnapshots,
+                                              String globalChecksumPolicy );
+
+    public Settings buildSettings( String userSettingsPath,
+                                   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=381132&r1=381131&r2=381132&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 Sun Feb 26 10:09:26 2006
@@ -5,14 +5,19 @@
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.RuntimeInfo;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
+import java.io.IOException;
 
 /**
  * A small utility that provides a common place for creating object instances that are used frequently in Maven:
  * ArtifactRepositories, Artifacts .... A facade for all factories we have lying around. This could very well
  * belong somewhere else but is here for the maven-embedder-refactor.
- * 
+ *
  * @author Jason van Zyl
  */
 public class DefaultCommonMavenObjectFactory
@@ -22,6 +27,8 @@
 
     private ArtifactRepositoryFactory artifactRepositoryFactory;
 
+    private MavenSettingsBuilder settingsBuilder;
+
     public ArtifactRepository createLocalRepository( File localRepositoryPath,
                                                      boolean offline,
                                                      boolean updateSnapshots,
@@ -51,5 +58,66 @@
         artifactRepositoryFactory.setGlobalChecksumPolicy( globalChecksumPolicy );
 
         return localRepository;
+    }
+
+    public Settings buildSettings( String userSettingsPath,
+                                   boolean interactive,
+                                   boolean offline,
+                                   boolean usePluginRegistry,
+                                   Boolean pluginUpdateOverride )
+        throws SettingsConfigurationException
+    {
+        Settings settings = null;
+
+        try
+        {
+            if ( userSettingsPath != null )
+            {
+                File userSettingsFile = new File( userSettingsPath );
+
+                if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() )
+                {
+                    settings = settingsBuilder.buildSettings( userSettingsFile );
+
+                    System.out.println( "settings local repository = " + settings.getLocalRepository() );
+                }
+                else
+                {
+                    System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
+                        " is invalid. Using default path." );
+                }
+            }
+
+            if ( settings == null )
+            {
+                settings = settingsBuilder.buildSettings();
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new SettingsConfigurationException( "Error reading settings file", e );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new SettingsConfigurationException( e.getMessage(), e.getDetail(), e.getLineNumber(),
+                                                      e.getColumnNumber() );
+        }
+
+        if ( offline )
+        {
+            settings.setOffline( true );
+        }
+
+        settings.setInteractiveMode( interactive );
+
+        settings.setUsePluginRegistry( usePluginRegistry );
+
+        RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
+
+        runtimeInfo.setPluginUpdateOverride( pluginUpdateOverride );
+
+        settings.setRuntimeInfo( runtimeInfo );
+
+        return settings;
     }
 }

Modified: maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java?rev=381132&r1=381131&r2=381132&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/branches/maven-embedder-refactor/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java Sun Feb 26 10:09:26 2006
@@ -18,6 +18,7 @@
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.ParseException;
+import org.apache.maven.CommonMavenObjectFactory;
 import org.apache.maven.Maven;
 import org.apache.maven.SettingsConfigurationException;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@@ -25,15 +26,12 @@
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.ReactorManager;
 import org.apache.maven.reactor.MavenExecutionException;
-import org.apache.maven.settings.MavenSettingsBuilder;
-import org.apache.maven.settings.RuntimeInfo;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.wagon.events.TransferListener;
 import org.codehaus.classworlds.ClassWorld;
 import org.codehaus.plexus.PlexusContainerException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.embed.Embedder;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
@@ -48,14 +46,9 @@
  * @author jason van zyl
  * @version $Id$
  * @noinspection UseOfSystemOutOrSystemErr,ACCESS_STATIC_VIA_INSTANCE
- * @todo clear strategy for creating local repository
- * @todo clear strategy
- * @todo clearn strategy for using settings, they are really an artifact of the CLI but people want integration with existing installations
  */
 public class MavenCli
 {
-    private static Embedder embedder;
-
     /**
      * @noinspection ConfusingMainMethod
      */
@@ -124,7 +117,7 @@
         // bring the maven component to life for use.
         // ----------------------------------------------------------------------
 
-        embedder = new Embedder();
+        Embedder embedder = new Embedder();
 
         try
         {
@@ -329,16 +322,12 @@
 
             Properties executionProperties = getExecutionProperties( commandLine );
 
-            Settings settings = buildSettings( userSettingsPath, interactive, offline, usePluginRegistry, pluginUpdateOverride );
-
             // the local repository should just be a path and we should look here:
             // in the system property
             // user specified settings.xml
             // default ~/.m2/settings.xml
             // and with that maven internals should contruct the ArtifactRepository object
 
-            String localRepositoryPath = settings.getLocalRepository();
-
             int loggingLevel;
 
             if ( debug )
@@ -352,6 +341,12 @@
 
             Maven maven = (Maven) embedder.lookup( Maven.ROLE );
 
+            CommonMavenObjectFactory mavenObjectFactory = (CommonMavenObjectFactory) embedder.lookup( CommonMavenObjectFactory.ROLE );
+
+            Settings settings = mavenObjectFactory.buildSettings( userSettingsPath, interactive, offline, usePluginRegistry, pluginUpdateOverride );
+
+            String localRepositoryPath = settings.getLocalRepository();
+
             // @todo we either make Settings the official configuration mechanism or allow the indiviaul setting in the request
             // for each of the things in the settings object. Seems redundant to configure some things via settings and
             // some via the request. The Settings object is used in about 16 different places in the core so something
@@ -510,74 +505,5 @@
         // ----------------------------------------------------------------------
 
         System.setProperty( name, value );
-    }
-
-    // ----------------------------------------------------------------------
-    // Command line manager
-    // ----------------------------------------------------------------------
-
-    private static Settings buildSettings( String userSettingsPath,
-                                           boolean interactive,
-                                           boolean offline,
-                                           boolean usePluginRegistry,
-                                           Boolean pluginUpdateOverride )
-        throws ComponentLookupException, SettingsConfigurationException
-    {
-        Settings settings = null;
-
-        MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) embedder.lookup( MavenSettingsBuilder.ROLE );
-
-        if ( offline )
-        {
-            settings.setOffline( true );
-        }
-
-        try
-        {
-            if ( userSettingsPath != null )
-            {
-                File userSettingsFile = new File( userSettingsPath );
-
-                if ( userSettingsFile.exists() && !userSettingsFile.isDirectory() )
-                {
-                    settings = settingsBuilder.buildSettings( userSettingsFile );
-
-                    System.out.println( "settings local repository = " + settings.getLocalRepository() );
-                }
-                else
-                {
-                    System.out.println( "WARNING: Alternate user settings file: " + userSettingsPath +
-                        " is invalid. Using default path." );
-                }
-            }
-
-            System.out.println( "settings = " + settings );
-
-            if ( settings == null )
-            {
-                settings = settingsBuilder.buildSettings();
-            }
-        }
-        catch ( IOException e )
-        {
-            throw new SettingsConfigurationException( "Error reading settings file", e );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new SettingsConfigurationException( e.getMessage(), e.getDetail(), e.getLineNumber(),
-                                                      e.getColumnNumber() );
-        }
-
-        settings.setInteractiveMode( interactive );
-
-        settings.setUsePluginRegistry( usePluginRegistry );
-
-        RuntimeInfo runtimeInfo = new RuntimeInfo( settings );
-
-        runtimeInfo.setPluginUpdateOverride( pluginUpdateOverride );
-
-        settings.setRuntimeInfo( runtimeInfo );
-
-        return settings;
     }
 }

Modified: maven/components/branches/maven-embedder-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=381132&r1=381131&r2=381132&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/branches/maven-embedder-refactor/maven-core/src/main/resources/META-INF/plexus/components.xml Sun Feb 26 10:09:26 2006
@@ -79,6 +79,9 @@
         <requirement>
           <role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
         </requirement>
+        <requirement>
+          <role>org.apache.maven.settings.MavenSettingsBuilder</role>
+        </requirement>
       </requirements>
     </component>
 

Modified: maven/components/branches/maven-embedder-refactor/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-embedder-refactor/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java?rev=381132&r1=381131&r2=381132&view=diff
==============================================================================
--- maven/components/branches/maven-embedder-refactor/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java (original)
+++ maven/components/branches/maven-embedder-refactor/maven-settings/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java Sun Feb 26 10:09:26 2006
@@ -189,11 +189,7 @@
     private void setLocalRepository( Settings userSettings )
     {
         // try using the local repository specified on the command line...
-        //String localRepository = System.getProperty( MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION );
-
-        String localRepository = null;
-
-        System.out.println( "from the system localRepository = " + localRepository );
+        String localRepository = System.getProperty( MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION );
 
         // otherwise, use the one in settings.xml
         if ( localRepository == null || localRepository.length() < 1 )