From ed12e0a541096523449996195663d0762fff2e05 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Wed, 23 Feb 2011 20:25:29 +0000 Subject: [PATCH] [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 --- .../deployer/DefaultArtifactDeployer.java | 8 ++--- .../installer/DefaultArtifactInstaller.java | 8 ++--- .../resolver/DefaultArtifactResolver.java | 18 +--------- .../LegacyLocalRepositoryManager.java | 36 +++++++++++++++---- .../maven/project/DefaultProjectBuilder.java | 5 ++- 5 files changed, 40 insertions(+), 35 deletions(-) rename {maven-compat => maven-core}/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java (90%) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 24907575f3..97aeff9e04 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -38,13 +38,12 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.sonatype.aether.RepositorySystem; +import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.deployment.DeployRequest; import org.sonatype.aether.deployment.DeployResult; import org.sonatype.aether.deployment.DeploymentException; import org.sonatype.aether.metadata.MergeableMetadata; -import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.artifact.SubArtifact; @Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" ) @@ -79,9 +78,8 @@ public class DefaultArtifactDeployer ArtifactRepository localRepository ) throws ArtifactDeploymentException { - DefaultRepositorySystemSession session = - new DefaultRepositorySystemSession( legacySupport.getRepositorySession() ); - session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) ); + RepositorySystemSession session = + LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem ); DeployRequest request = new DeployRequest(); diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java index c1658a269e..c82770b960 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/installer/DefaultArtifactInstaller.java @@ -37,10 +37,9 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.sonatype.aether.RepositorySystem; +import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.installation.InstallRequest; 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; /** @@ -72,9 +71,8 @@ public class DefaultArtifactInstaller public void install( File source, Artifact artifact, ArtifactRepository localRepository ) throws ArtifactInstallationException { - DefaultRepositorySystemSession session = - new DefaultRepositorySystemSession( legacySupport.getRepositorySession() ); - session.setLocalRepositoryManager( LegacyLocalRepositoryManager.wrap( localRepository, repoSystem ) ); + RepositorySystemSession session = + LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem ); InstallRequest request = new InstallRequest(); diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index c8cf19bf78..9c8364d461 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -58,11 +58,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti import org.codehaus.plexus.logging.Logger; import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactResult; -import org.sonatype.aether.util.DefaultRepositorySystemSession; /** * @author Jason van Zyl @@ -129,21 +127,7 @@ public class DefaultArtifactResolver private RepositorySystemSession getSession( ArtifactRepository localRepository ) { - MavenSession mavenSession = legacySupport.getSession(); - 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; + return LegacyLocalRepositoryManager.overlay( localRepository, legacySupport.getRepositorySession(), repoSystem ); } private void injectSession1( RepositoryRequest request, MavenSession session ) diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java similarity index 90% rename from maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java rename to maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java index 0c3dca9116..7c09aae1fd 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/LegacyLocalRepositoryManager.java @@ -26,7 +26,6 @@ import java.util.List; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.metadata.ArtifactMetadata; 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.repository.Proxy; 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.LocalRepositoryManager; import org.sonatype.aether.repository.RemoteRepository; +import org.sonatype.aether.util.DefaultRepositorySystemSession; +import org.sonatype.aether.util.FilterRepositorySystemSession; /** * Warning: 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; - public static LocalRepositoryManager wrap( ArtifactRepository repository, RepositorySystem system ) + public static RepositorySystemSession overlay( ArtifactRepository repository, RepositorySystemSession session, + RepositorySystem system ) { - ArtifactRepositoryLayout layout = repository.getLayout(); - if ( layout != null && layout.getClass().equals( DefaultRepositoryLayout.class ) ) + if ( repository == null || repository.getBasedir() == null ) { - // map the default layout to the default impl of the repo system - return system.newLocalRepositoryManager( new LocalRepository( repository.getBasedir() ) ); + return session; } - 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 ) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 6ef729c5da..b78a131ab7 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.LegacyLocalRepositoryManager; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; @@ -654,7 +655,9 @@ public class DefaultProjectBuilder this.request = request; this.modelPool = modelPool; this.modelCache = modelCache; - session = request.getRepositorySession(); + session = + LegacyLocalRepositoryManager.overlay( request.getLocalRepository(), request.getRepositorySession(), + repoSystem ); repositories = RepositoryUtils.toRepos( request.getRemoteRepositories() ); }