[MNG-4990] RepositorySystem#resolve(request) uses two different local repositories

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1073928 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-02-23 20:25:29 +00:00
parent c4f0aa5209
commit ed12e0a541
5 changed files with 40 additions and 35 deletions

View File

@ -38,13 +38,12 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.deployment.DeployRequest; import org.sonatype.aether.deployment.DeployRequest;
import org.sonatype.aether.deployment.DeployResult; import org.sonatype.aether.deployment.DeployResult;
import org.sonatype.aether.deployment.DeploymentException; import org.sonatype.aether.deployment.DeploymentException;
import org.sonatype.aether.metadata.MergeableMetadata; import org.sonatype.aether.metadata.MergeableMetadata;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
@Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" ) @Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" )
@ -79,9 +78,8 @@ public class DefaultArtifactDeployer
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ArtifactDeploymentException throws ArtifactDeploymentException
{ {
DefaultRepositorySystemSession session = RepositorySystemSession session =
new DefaultRepositorySystemSession( legacySupport.getRepositorySession() ); LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem );
session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) );
DeployRequest request = new DeployRequest(); DeployRequest request = new DeployRequest();

View File

@ -37,10 +37,9 @@ import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.installation.InstallRequest; import org.sonatype.aether.installation.InstallRequest;
import org.sonatype.aether.installation.InstallationException; import org.sonatype.aether.installation.InstallationException;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.artifact.SubArtifact;
/** /**
@ -72,9 +71,8 @@ public class DefaultArtifactInstaller
public void install( File source, Artifact artifact, ArtifactRepository localRepository ) public void install( File source, Artifact artifact, ArtifactRepository localRepository )
throws ArtifactInstallationException throws ArtifactInstallationException
{ {
DefaultRepositorySystemSession session = RepositorySystemSession session =
new DefaultRepositorySystemSession( legacySupport.getRepositorySession() ); LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem );
session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) );
InstallRequest request = new InstallRequest(); InstallRequest request = new InstallRequest();

View File

@ -58,11 +58,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.repository.LocalRepositoryManager;
import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResult; import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
/** /**
* @author Jason van Zyl * @author Jason van Zyl
@ -129,21 +127,7 @@ public class DefaultArtifactResolver
private RepositorySystemSession getSession( ArtifactRepository localRepository ) private RepositorySystemSession getSession( ArtifactRepository localRepository )
{ {
MavenSession mavenSession = legacySupport.getSession(); return LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem );
DefaultRepositorySystemSession session;
if ( mavenSession != null )
{
session = new DefaultRepositorySystemSession( mavenSession.getRepositorySession() );
}
else
{
session = new DefaultRepositorySystemSession();
}
if ( localRepository != null && localRepository.getBasedir() != null )
{
session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) );
}
return session;
} }
private void injectSession1( RepositoryRequest request, MavenSession session ) private void injectSession1( RepositoryRequest request, MavenSession session )

View File

@ -26,7 +26,6 @@ import java.util.List;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
import org.apache.maven.repository.Proxy; import org.apache.maven.repository.Proxy;
import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystem;
@ -42,6 +41,8 @@ import org.sonatype.aether.repository.LocalMetadataResult;
import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.repository.LocalRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository; import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
import org.sonatype.aether.util.FilterRepositorySystemSession;
/** /**
* <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part * <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
@ -57,16 +58,37 @@ public class LegacyLocalRepositoryManager
private final LocalRepository repo; private final LocalRepository repo;
public static LocalRepositoryManager wrap( ArtifactRepository repository, RepositorySystem system ) public static RepositorySystemSession overlay( ArtifactRepository repository, RepositorySystemSession session,
RepositorySystem system )
{ {
ArtifactRepositoryLayout layout = repository.getLayout(); if ( repository == null || repository.getBasedir() == null )
if ( layout != null && layout.getClass().equals( DefaultRepositoryLayout.class ) )
{ {
// map the default layout to the default impl of the repo system return session;
return system.newLocalRepositoryManager( new LocalRepository( repository.getBasedir() ) );
} }
return new LegacyLocalRepositoryManager( repository ); if ( session != null )
{
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
if ( lrm != null && lrm.getRepository().getBasedir().equals( new File( repository.getBasedir() ) ) )
{
return session;
}
}
else
{
session = new DefaultRepositorySystemSession();
}
final LocalRepositoryManager llrm = new LegacyLocalRepositoryManager( repository );
return new FilterRepositorySystemSession( session )
{
@Override
public LocalRepositoryManager getLocalRepositoryManager()
{
return llrm;
}
};
} }
private LegacyLocalRepositoryManager( ArtifactRepository delegate ) private LegacyLocalRepositoryManager( ArtifactRepository delegate )

View File

@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Profile; import org.apache.maven.model.Profile;
@ -654,7 +655,9 @@ public class DefaultProjectBuilder
this.request = request; this.request = request;
this.modelPool = modelPool; this.modelPool = modelPool;
this.modelCache = modelCache; this.modelCache = modelCache;
session = request.getRepositorySession(); session =
LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(),
repoSystem );
repositories = RepositoryUtils.toRepos( request.getRemoteRepositories() ); repositories = RepositoryUtils.toRepos( request.getRemoteRepositories() );
} }