o large patch to rework the chained local repository implementations necessary for efficient reactor and IDE workspace resolution

Submitted by: Igor Fedorenko

I've asked Igor to fill out and send in a CLA and I will put him on the Sonatype CCLA



git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@777298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-21 22:35:29 +00:00
parent 503cc60cc5
commit b54a1b781b
9 changed files with 176 additions and 120 deletions

View File

@ -42,6 +42,7 @@ import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -68,9 +69,6 @@ public class DefaultMaven
@Requirement
protected RuntimeInformation runtimeInformation;
@Requirement
List<LocalArtifactRepository> localArtifactRepositories;
public List<String> getLifecyclePhases()
{
return lifecycleExecutor.getLifecyclePhases();
@ -89,12 +87,6 @@ public class DefaultMaven
MavenExecutionResult result = new DefaultMavenExecutionResult();
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository = new DelegatingLocalArtifactRepository( request.getLocalRepository() );
delegatingLocalArtifactRepository.addToEndOfSearchOrder( new UserLocalArtifactRepository( request.getLocalRepository() ) );
if ( localArtifactRepositories != null && localArtifactRepositories.size() > 0 )
{
delegatingLocalArtifactRepository.addToBeginningOfSearchOrder( localArtifactRepositories.get( 0 ) );
}
request.setLocalRepository( delegatingLocalArtifactRepository );
@ -148,7 +140,7 @@ public class DefaultMaven
// Workspace
// User Local Repository
delegatingLocalArtifactRepository.addToBeginningOfSearchOrder( new ReactorArtifactRepository( projects ) );
delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( projects ) );
if ( result.hasExceptions() )
{

View File

@ -1,99 +0,0 @@
package org.apache.maven;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public class DelegatingLocalArtifactRepository
extends DefaultArtifactRepository
{
private List<LocalArtifactRepository> localRepositories;
private ArtifactRepository userLocalArtifactRepository;
public DelegatingLocalArtifactRepository( ArtifactRepository artifactRepository )
{
this.userLocalArtifactRepository = artifactRepository;
}
public void addToEndOfSearchOrder( LocalArtifactRepository localRepository )
{
if ( localRepositories == null )
{
localRepositories = new ArrayList<LocalArtifactRepository>();
}
localRepositories.add( localRepository );
}
public void addToBeginningOfSearchOrder( LocalArtifactRepository localRepository )
{
if ( localRepositories == null )
{
localRepositories = new ArrayList<LocalArtifactRepository>();
}
localRepositories.add( 0, localRepository );
}
@Override
public Artifact find( Artifact artifact )
{
for( LocalArtifactRepository repository : localRepositories )
{
artifact = repository.find( artifact );
if ( artifact.isResolved() )
{
return artifact;
}
}
return artifact;
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
for( LocalArtifactRepository localRepository : localRepositories )
{
if ( localRepository.hasLocalMetadata() )
{
return localRepository.pathOfLocalRepositoryMetadata( metadata, localRepository );
}
}
return null;
}
// This ID is necessary of the metadata lookup doesn't work correctly.
public String getId()
{
return "delegating";
}
@Override
public String pathOf( Artifact artifact )
{
for( LocalArtifactRepository localRepository : localRepositories )
{
if( localRepository.hasLocalMetadata() )
{
String path = localRepository.pathOf( artifact );
return path;
}
}
return null;
}
@Override
public String getBasedir()
{
return userLocalArtifactRepository.getBasedir();
}
}

View File

@ -7,6 +7,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.LocalArtifactRepository;
/**
* An implementation of a repository that knows how to search the Maven reactor for artifacts.

View File

@ -216,4 +216,32 @@ public class DefaultMavenSettingsBuilder
throw new IOException( "Failed to validate Settings file at " + location + "\n" + validationResult.render( "\n" ) );
}
}
public SettingsValidationResult validateSettings( File settingsFile )
{
SettingsValidationResult result = new SettingsValidationResult();
if ( settingsFile != null && !settingsFile.canRead() )
{
try
{
Settings settings = readSettings( settingsFile );
return validator.validate( settings );
}
catch ( IOException e )
{
result.addMessage( e.getMessage() );
}
catch ( XmlPullParserException e )
{
result.addMessage( e.getMessage() );
}
}
else
{
// TODO do we have anything to say?
}
return result;
}
}

View File

@ -19,9 +19,11 @@ package org.apache.maven.settings;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.settings.validation.SettingsValidationResult;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@ -34,4 +36,6 @@ public interface MavenSettingsBuilder
Settings buildSettings( MavenExecutionRequest request )
throws IOException, XmlPullParserException;
SettingsValidationResult validateSettings( File settingsFile );
}

View File

@ -0,0 +1,84 @@
package org.apache.maven.repository;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
/**
* Delegating local artifact repository chains the reactor, IDE workspace
* and user local repository.
*/
public class DelegatingLocalArtifactRepository
extends DefaultArtifactRepository
{
private LocalArtifactRepository buildReactor;
private LocalArtifactRepository ideWorkspace;
private ArtifactRepository userLocalArtifactRepository;
public DelegatingLocalArtifactRepository( ArtifactRepository artifactRepository )
{
this.userLocalArtifactRepository = artifactRepository;
}
public void setBuildReactor( LocalArtifactRepository localRepository )
{
this.buildReactor = localRepository;
}
public void setIdeWorkspace( LocalArtifactRepository localRepository )
{
this.ideWorkspace = localRepository;
}
public LocalArtifactRepository getIdeWorspace()
{
return ideWorkspace;
}
@Override
public Artifact find( Artifact artifact )
{
if ( !artifact.isRelease() && buildReactor != null )
{
artifact = buildReactor.find( artifact );
}
if ( !artifact.isResolved() && ideWorkspace != null )
{
artifact = ideWorkspace.find( artifact );
}
if ( !artifact.isResolved() )
{
artifact = userLocalArtifactRepository.find( artifact );
}
return artifact;
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return userLocalArtifactRepository.pathOfLocalRepositoryMetadata( metadata, userLocalArtifactRepository );
}
// This ID is necessary of the metadata lookup doesn't work correctly.
public String getId()
{
return "delegating";
}
@Override
public String pathOf( Artifact artifact )
{
return userLocalArtifactRepository.pathOf( artifact );
}
@Override
public String getBasedir()
{
return userLocalArtifactRepository.getBasedir();
}
}

View File

@ -17,10 +17,7 @@ package org.apache.maven.repository;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
@ -41,12 +38,11 @@ import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.events.TransferListener;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* @author Jason van Zyl
@ -73,6 +69,9 @@ public class LegacyRepositorySystem
@Requirement
private WagonManager wagonManager;
@Requirement
private PlexusContainer plexus;
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
{
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
@ -265,6 +264,52 @@ public class LegacyRepositorySystem
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
{
/*
* Probably is not worth it, but here I make sure I restore request
* to its original state.
*/
try
{
LocalArtifactRepository ideWorkspace = plexus.lookup( LocalArtifactRepository.class, LocalArtifactRepository.IDE_WORKSPACE );
if ( request.getLocalRepository() instanceof DelegatingLocalArtifactRepository )
{
DelegatingLocalArtifactRepository delegatingLocalRepository = (DelegatingLocalArtifactRepository) request.getLocalRepository();
LocalArtifactRepository orig = delegatingLocalRepository.getIdeWorspace();
delegatingLocalRepository.setIdeWorkspace( ideWorkspace );
try
{
return artifactResolver.resolve( request );
}
finally
{
delegatingLocalRepository.setIdeWorkspace( orig );
}
}
else
{
ArtifactRepository localRepository = request.getLocalRepository();
DelegatingLocalArtifactRepository delegatingLocalRepository = new DelegatingLocalArtifactRepository( localRepository );
delegatingLocalRepository.setIdeWorkspace( ideWorkspace );
request.setLocalRepository( delegatingLocalRepository );
try
{
return artifactResolver.resolve( request );
}
finally
{
request.setLocalRepository( localRepository );
}
}
}
catch ( ComponentLookupException e )
{
// no ide workspace artifact resolution
}
return artifactResolver.resolve( request );
}

View File

@ -1,4 +1,4 @@
package org.apache.maven;
package org.apache.maven.repository;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
@ -6,6 +6,8 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public abstract class LocalArtifactRepository
extends DefaultArtifactRepository
{
public static final String IDE_WORKSPACE = "ide-workspace";
public abstract Artifact find( Artifact artifact );
/**

View File

@ -1,11 +1,10 @@
package org.apache.maven;
package org.apache.maven.repository;
import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
public class UserLocalArtifactRepository
extends LocalArtifactRepository