mirror of https://github.com/apache/maven.git
PR: MNG-440
read settings.xml for the local repository git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189484 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6a38bf445c
commit
e2e1a3830c
|
@ -23,6 +23,11 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-settings</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
|
|
|
@ -19,13 +19,21 @@ package org.apache.maven.artifact.ant;
|
|||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.codehaus.plexus.PlexusContainerException;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
import org.codehaus.plexus.embed.Embedder;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Base class for artifact tasks.
|
||||
|
@ -38,7 +46,9 @@ public abstract class AbstractArtifactTask
|
|||
{
|
||||
private Embedder embedder;
|
||||
|
||||
protected ArtifactRepository createArtifactRepository( LocalRepository repository )
|
||||
private Settings settings;
|
||||
|
||||
protected ArtifactRepository createLocalArtifactRepository( LocalRepository repository )
|
||||
{
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||
repository.getLayout() );
|
||||
|
@ -49,7 +59,7 @@ public abstract class AbstractArtifactTask
|
|||
return new ArtifactRepository( "local", "file://" + repository.getLocation(), repositoryLayout );
|
||||
}
|
||||
|
||||
protected ArtifactRepository createArtifactRepository( RemoteRepository repository )
|
||||
protected ArtifactRepository createRemoteArtifactRepository( RemoteRepository repository )
|
||||
{
|
||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
|
||||
repository.getLayout() );
|
||||
|
@ -114,8 +124,57 @@ public abstract class AbstractArtifactTask
|
|||
|
||||
protected LocalRepository getDefaultLocalRepository()
|
||||
{
|
||||
Settings settings = getSettings();
|
||||
LocalRepository localRepository = new LocalRepository();
|
||||
localRepository.setLocation( new File( System.getProperty( "user.home" ), ".m2/repository" ) );
|
||||
localRepository.setLocation( new File( settings.getLocalRepository() ) );
|
||||
return localRepository;
|
||||
}
|
||||
|
||||
protected synchronized Settings getSettings()
|
||||
{
|
||||
if ( settings == null )
|
||||
{
|
||||
settings = new Settings();
|
||||
|
||||
File settingsFile = new File( System.getProperty( "user.home" ), ".ant/settings.xml" );
|
||||
if ( !settingsFile.exists() )
|
||||
{
|
||||
settingsFile = new File( System.getProperty( "user.home" ), ".m2/settings.xml" );
|
||||
}
|
||||
|
||||
if ( settingsFile.exists() )
|
||||
{
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( settingsFile );
|
||||
|
||||
SettingsXpp3Reader modelReader = new SettingsXpp3Reader();
|
||||
|
||||
settings = modelReader.read( reader );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
log( "Error reading settings file '" + settingsFile + "' - ignoring. Error was: " + e.getMessage(),
|
||||
Project.MSG_WARN );
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
log( "Error parsing settings file '" + settingsFile + "' - ignoring. Error was: " + e.getMessage(),
|
||||
Project.MSG_WARN );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
if ( StringUtils.isEmpty( settings.getLocalRepository() ) )
|
||||
{
|
||||
String location = new File( System.getProperty( "user.home" ), ".m2/repository" ).getAbsolutePath();
|
||||
settings.setLocalRepository( location );
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class DependenciesTask
|
|||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepo = createArtifactRepository( localRepository );
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
|
||||
ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
|
||||
MavenProjectBuilder projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
|
@ -157,7 +157,7 @@ public class DependenciesTask
|
|||
List list = new ArrayList();
|
||||
for ( Iterator i = getRemoteRepositories().iterator(); i.hasNext(); )
|
||||
{
|
||||
list.add( createArtifactRepository( (RemoteRepository) i.next() ) );
|
||||
list.add( createRemoteArtifactRepository( (RemoteRepository) i.next() ) );
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -52,10 +52,10 @@ public class DeployTask
|
|||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepo = createArtifactRepository( localRepository );
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
pom.initialise( (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ), localRepo );
|
||||
|
||||
ArtifactRepository deploymentRepository = createArtifactRepository( remoteRepository );
|
||||
ArtifactRepository deploymentRepository = createRemoteArtifactRepository( remoteRepository );
|
||||
|
||||
// Deploy the POM
|
||||
Artifact artifact = new DefaultArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
|
||||
|
|
|
@ -51,7 +51,7 @@ public class InstallTask
|
|||
localRepository = getDefaultLocalRepository();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepo = createArtifactRepository( localRepository );
|
||||
ArtifactRepository localRepo = createLocalArtifactRepository( localRepository );
|
||||
pom.initialise( (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ), localRepo );
|
||||
|
||||
Artifact artifact = new DefaultArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(),
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
<role>org.apache.maven.artifact.transform.ArtifactTransformation</role>
|
||||
<field-name>artifactTransformations</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
|
||||
|
|
Loading…
Reference in New Issue