continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r572778 - /maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java
Date Tue, 04 Sep 2007 19:23:03 GMT
Author: evenisse
Date: Tue Sep  4 12:23:03 2007
New Revision: 572778

URL: http://svn.apache.org/viewvc?rev=572778&view=rev
Log:
Read settings.xml if it exists to find the local repository path

Modified:
    maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java

Modified: maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java?rev=572778&r1=572777&r2=572778&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java
(original)
+++ maven/continuum/trunk/continuum-data-management/data-management-cli/src/main/java/org/apache/maven/continuum/management/DataManagementCli.java
Tue Sep  4 12:23:03 2007
@@ -37,15 +37,17 @@
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.DefaultPlexusContainer;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.PlexusContainerException;
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
@@ -232,7 +234,7 @@
 
     private static Collection<Artifact> downloadArtifact( PlexusContainer container,
String groupId, String artifactId,
                                                           String version )
-        throws ComponentLookupException, MalformedURLException, ArtifactNotFoundException,
ArtifactResolutionException
+        throws ComponentLookupException, ArtifactNotFoundException, ArtifactResolutionException,
IOException
     {
         ArtifactRepositoryFactory factory =
             (ArtifactRepositoryFactory) container.lookup( ArtifactRepositoryFactory.ROLE
);
@@ -240,12 +242,12 @@
         DefaultRepositoryLayout layout =
             (DefaultRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, "default"
);
 
-        File file = new File( System.getProperty( "user.home" ), "/.m2/repository" );
         ArtifactRepository localRepository =
-            factory.createArtifactRepository( "local", file.toURL().toString(), layout, null,
null );
+            factory.createArtifactRepository( "local", getLocalRepositoryURL( container ),
layout, null, null );
 
         List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
-        remoteRepositories.add( factory.createArtifactRepository( "central", "http://repo1.maven.org/maven2",
layout, null, null ) );
+        remoteRepositories.add(
+            factory.createArtifactRepository( "central", "http://repo1.maven.org/maven2",
layout, null, null ) );
 
         ArtifactFactory artifactFactory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE
);
         Artifact artifact =
@@ -253,8 +255,10 @@
         Artifact dummyArtifact = artifactFactory.createProjectArtifact( "dummy", "dummy",
"1.0" );
 
         if ( artifact.isSnapshot() )
-	{
-	    remoteRepositories.add( factory.createArtifactRepository( "apache.snapshots", "http://people.apache.org/repo/m2-snapshot-repository",
layout, null, null ) );
+        {
+            remoteRepositories.add( factory.createArtifactRepository( "apache.snapshots",
+                                                                      "http://people.apache.org/repo/m2-snapshot-repository",
+                                                                      layout, null, null
) );
         }
 
         ArtifactResolver resolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE
);
@@ -277,11 +281,43 @@
         return result.getArtifacts();
     }
 
+    private static String getLocalRepositoryURL( PlexusContainer container )
+        throws ComponentLookupException, IOException
+    {
+        File settingsFile = new File( System.getProperty( "user.home" ), "/.m2/settings.xml"
);
+        if ( !settingsFile.exists() )
+        {
+            return new File( System.getProperty( "user.home" ), "/.m2/repository" ).toURL().toString();
+        }
+        else
+        {
+            Settings settings = getSettings( container );
+            return new File( settings.getLocalRepository() ).toURL().toString();
+        }
+    }
+
+    private static Settings getSettings( PlexusContainer container )
+        throws ComponentLookupException, IOException
+    {
+        MavenSettingsBuilder mavenSettingsBuilder =
+            (MavenSettingsBuilder) container.lookup( MavenSettingsBuilder.class.getName()
);
+        try
+        {
+            return mavenSettingsBuilder.buildSettings( false );
+        }
+        catch ( XmlPullParserException e )
+        {
+            e.printStackTrace();
+            throw new IOException( "Can't read settings.xml. " + e.getMessage() );
+        }
+    }
+
     private static String getVersion()
         throws IOException
     {
         Properties properties = new Properties();
-        properties.load( DataManagementCli.class.getResourceAsStream( "/META-INF/maven/org.apache.maven.continuum/data-management-api/pom.properties"
) );
+        properties.load( DataManagementCli.class.getResourceAsStream(
+            "/META-INF/maven/org.apache.maven.continuum/data-management-api/pom.properties"
) );
         return properties.getProperty( "version" );
     }
 



Mime
View raw message