From 3c34aa8c1427f1bb85a10828920aeb8c1c976c3c Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Tue, 1 Sep 2009 22:49:05 +0000 Subject: [PATCH] [MNG-4334] maven core caches settings.xml o First pass: auth & mirror moved out of the components into the requests git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@810296 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 2 +- maven-compat/pom.xml | 1 + .../apache/maven/project/ProjectUtils.java | 17 ++- .../repository/DefaultMirrorBuilder.java | 4 +- .../repository/LegacyRepositorySystem.java | 121 ++++++++++++------ .../maven/repository/RepositorySystem.java | 31 ++++- .../src/main/mdo/settings.mdo | 0 .../legacy/LegacyRepositorySystemTest.java | 18 +-- maven-core/pom.xml | 1 - .../DefaultMavenExecutionRequest.java | 2 + .../project/DefaultMavenProjectBuilder.java | 4 +- .../project/DefaultModelBuildingListener.java | 6 +- .../maven/project/DefaultProjectBuilder.java | 8 +- .../project/DefaultProjectBuildingHelper.java | 7 +- .../DefaultProjectBuildingRequest.java | 46 +++++++ .../apache/maven/project/MavenProject.java | 11 +- .../maven/project/ProjectBuildingHelper.java | 5 +- .../maven/project/ProjectBuildingRequest.java | 10 ++ .../project/RepositoryModelResolver.java | 31 +++-- .../project/EmptyProjectBuildingHelper.java | 3 +- ...DefaultMavenExecutionRequestPopulator.java | 28 ++-- 21 files changed, 253 insertions(+), 103 deletions(-) rename {maven-core => maven-compat}/src/main/mdo/settings.mdo (100%) diff --git a/build.xml b/build.xml index 398b867a24..e2c3c0471a 100644 --- a/build.xml +++ b/build.xml @@ -181,7 +181,7 @@ END SNIPPET: ant-bootstrap --> - + diff --git a/maven-compat/pom.xml b/maven-compat/pom.xml index 7c3ba07bb8..9adbcfefa7 100644 --- a/maven-compat/pom.xml +++ b/maven-compat/pom.xml @@ -79,6 +79,7 @@ src/main/mdo/metadata.mdo src/main/mdo/profiles.mdo src/main/mdo/paramdoc.mdo + src/main/mdo/settings.mdo diff --git a/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java b/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java index 226f657d6d..9c1baab4e8 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java +++ b/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java @@ -34,9 +34,9 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti // This class needs to stick around because it was exposed the the remote resources plugin started using it instead of // getting the repositories from the project. +@Deprecated public final class ProjectUtils { - static RepositorySystem rs; private ProjectUtils() { @@ -53,7 +53,10 @@ public final class ProjectUtils remoteRepositories.add( buildArtifactRepository( r, artifactRepositoryFactory, c ) ); } - remoteRepositories = rs( c ).getMirrors( remoteRepositories ); + /* + * FIXME: The bad dependency relation between maven-core and maven-compat prevents access to LegacySupport here + * which is required to get the mirror&authentication settings from the session/request. + */ return remoteRepositories; } @@ -61,6 +64,10 @@ public final class ProjectUtils public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c ) throws InvalidRepositoryException { + /* + * FIXME: The bad dependency relation between maven-core and maven-compat prevents access to LegacySupport here + * which is required to get the authentication settings from the session/request. + */ return rs( c ).buildArtifactRepository( repo ); } @@ -74,12 +81,12 @@ public final class ProjectUtils { try { - rs = c.lookup( RepositorySystem.class ); + return c.lookup( RepositorySystem.class ); } catch ( ComponentLookupException e ) { + throw new IllegalStateException( e ); } - - return rs; } + } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java index 43fb2306b0..9c504e25fb 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java @@ -163,7 +163,7 @@ public class DefaultMirrorBuilder * @param pattern used for match. Currently only '*' is supported. * @return true if the repository is a match to this pattern. */ - boolean matchPattern( ArtifactRepository originalRepository, String pattern ) + static boolean matchPattern( ArtifactRepository originalRepository, String pattern ) { boolean result = false; String originalId = originalRepository.getId(); @@ -218,7 +218,7 @@ public class DefaultMirrorBuilder * @param originalRepository * @return true if external. */ - boolean isExternalRepo( ArtifactRepository originalRepository ) + static boolean isExternalRepo( ArtifactRepository originalRepository ) { try { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index 48ad0bfff6..9884cd52e8 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -47,9 +47,10 @@ import org.apache.maven.repository.DelegatingLocalArtifactRepository; import org.apache.maven.repository.LocalArtifactRepository; import org.apache.maven.repository.MetadataResolutionRequest; import org.apache.maven.repository.MetadataResolutionResult; -import org.apache.maven.repository.MirrorBuilder; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.repository.legacy.WagonManager; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.events.TransferListener; @@ -77,9 +78,6 @@ public class LegacyRepositorySystem @Requirement( role = ArtifactRepositoryLayout.class ) private Map layouts; - - @Requirement - private MirrorBuilder mirrorBuilder; @Requirement private WagonManager wagonManager; @@ -87,10 +85,9 @@ public class LegacyRepositorySystem @Requirement private PlexusContainer plexus; - private Map authentications = new HashMap(); - + // TODO: move this out, the component needs to be stateless for safe reuse private Map proxies = new HashMap(); - + public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) { return artifactFactory.createArtifact( groupId, artifactId, version, scope, type ); @@ -329,18 +326,6 @@ public class LegacyRepositorySystem } */ - // Mirror - public void addMirror( String id, String mirrorOf, String url ) - { - Authentication auth = id != null ? authentications.get( id ) : null; - mirrorBuilder.addMirror( id, mirrorOf, url, auth ); - } - - public List getMirrors( List repositories ) - { - return mirrorBuilder.getMirrors( repositories ); - } - public List getEffectiveRepositories( List repositories ) { if ( repositories == null ) @@ -392,6 +377,8 @@ public class LegacyRepositorySystem ArtifactRepository effectiveRepository = createArtifactRepository( aliasedRepo.getId(), aliasedRepo.getUrl(), aliasedRepo.getLayout(), snapshotPolicy, releasePolicy ); + effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() ); + effectiveRepositories.add( effectiveRepository ); } @@ -466,6 +453,84 @@ public class LegacyRepositorySystem } } + private Mirror getMirror( ArtifactRepository repository, List mirrors ) + { + String repoId = repository.getId(); + + if ( repoId != null ) + { + for ( Mirror mirror : mirrors ) + { + if ( repoId.equals( mirror.getMirrorOf() ) ) + { + return mirror; + } + } + + for ( Mirror mirror : mirrors ) + { + if ( DefaultMirrorBuilder.matchPattern( repository, mirror.getMirrorOf() ) ) + { + return mirror; + } + } + } + + return null; + } + + public void injectMirror( List repositories, List mirrors ) + { + if ( repositories != null && mirrors != null ) + { + for ( ArtifactRepository repository : repositories ) + { + Mirror mirror = getMirror( repository, mirrors ); + + if ( mirror != null ) + { + repository.setId( mirror.getId() ); + repository.setUrl( mirror.getUrl() ); + } + } + } + } + + public void injectAuthentication( List repositories, List servers ) + { + if ( repositories != null ) + { + Map serversById = new HashMap(); + + if ( servers != null ) + { + for ( Server server : servers ) + { + if ( !serversById.containsKey( server.getId() ) ) + { + serversById.put( server.getId(), server ); + } + } + } + + for ( ArtifactRepository repository : repositories ) + { + Server server = serversById.get( repository.getId() ); + + if ( server != null ) + { + Authentication authentication = new Authentication( server.getUsername(), server.getPassword() ); + + repository.setAuthentication( authentication ); + } + else + { + repository.setAuthentication( null ); + } + } + } + } + public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ) { @@ -495,15 +560,6 @@ public class LegacyRepositorySystem wagonManager.putRemoteFile( repository, source, remotePath, downloadMonitor ); } - // - // serverId = repository id - // - public void addAuthenticationForArtifactRepository( String repositoryId, String username, String password ) - { - Authentication authentication = new Authentication( username, password ); - authentications.put( repositoryId, authentication ); - } - // // Artifact Repository Creation // @@ -556,14 +612,7 @@ public class LegacyRepositorySystem ArtifactRepository artifactRepository = artifactRepositoryFactory.createArtifactRepository( repositoryId, url, repositoryLayout, snapshots, releases ); - Authentication authentication = authentications.get( repositoryId ); - - if ( authentication != null ) - { - artifactRepository.setAuthentication( authentication ); - } - - Proxy proxy = proxies.get( artifactRepository.getProtocol() ); + Proxy proxy = proxies.get( artifactRepository.getProtocol() ); if ( proxy != null ) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java index 5a507cc044..b34b4360fe 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -32,6 +32,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.model.Repository; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.events.TransferListener; @@ -90,14 +92,31 @@ public interface RepositorySystem */ List getEffectiveRepositories( List repositories ); + /** + * Injects the mirroring information into the specified repositories. For each repository that is matched by a + * mirror, its URL and ID will be updated to match the values from the mirror specification. Repositories without a + * matching mirror will pass through unchanged. Note: This method must be called before + * {@link #injectAuthentication(List, List)} or the repositories will end up with the wrong credentials. + * + * @param repositories The repositories into which to inject the mirror information, may be {@code null}. + * @param mirrors The available mirrors, may be {@code null}. + */ + void injectMirror( List repositories, List mirrors ); + + /** + * Injects the authentication information into the specified repositories. For each repository that is matched by a + * server, its credentials will be updated to match the values from the server specification. Repositories without a + * matching server will have their credentials cleared. Note: This method must be called before + * {@link #injectAuthentication(List, List)} or the repositories will end up with the wrong credentials. + * + * @param repositories The repositories into which to inject the authentication information, may be {@code null}. + * @param servers The available servers, may be {@code null}. + */ + void injectAuthentication( List repositories, List servers ); + ArtifactResolutionResult resolve( ArtifactResolutionRequest request ); MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ); - - //TODO: remove the request should already be processed to select the mirror for the request instead of the processing happen internally. - // Mirrors - void addMirror( String id, String mirrorOf, String url ); - List getMirrors( List repositories ); // Install @@ -113,8 +132,6 @@ public interface RepositorySystem void retrieve( ArtifactRepository repository, File destination, String remotePath, TransferListener downloadMonitor ) throws TransferFailedException, ResourceDoesNotExistException; - - void addAuthenticationForArtifactRepository( String repositoryId, String username, String password ); void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); } diff --git a/maven-core/src/main/mdo/settings.mdo b/maven-compat/src/main/mdo/settings.mdo similarity index 100% rename from maven-core/src/main/mdo/settings.mdo rename to maven-compat/src/main/mdo/settings.mdo diff --git a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java index b3e83dfdd8..ff1e557421 100644 --- a/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java +++ b/maven-compat/src/test/java/org/apache/maven/repository/legacy/LegacyRepositorySystemTest.java @@ -16,18 +16,13 @@ package org.apache.maven.repository.legacy; */ import java.io.File; -import java.lang.reflect.Array; import java.util.Arrays; -import java.util.Collections; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.Authentication; -import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; -import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.model.Dependency; import org.apache.maven.repository.LegacyRepositorySystem; import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.settings.Server; import org.codehaus.plexus.PlexusTestCase; /** @@ -67,11 +62,18 @@ public class LegacyRepositorySystemTest public void testAuthenticationHandling() throws Exception { - repositorySystem.addAuthenticationForArtifactRepository( "repository", "jason", "abc123" ); - ArtifactRepository repository = repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null ); + Server server = new Server(); + server.setId( "repository" ); + server.setUsername( "jason" ); + server.setPassword( "abc123" ); + + ArtifactRepository repository = + repositorySystem.createArtifactRepository( "repository", "http://foo", null, null, null ); + repositorySystem.injectAuthentication( Arrays.asList( repository ), Arrays.asList( server ) ); Authentication authentication = repository.getAuthentication(); assertNotNull( authentication ); assertEquals( "jason", authentication.getUsername() ); assertEquals( "abc123", authentication.getPassword() ); } + } diff --git a/maven-core/pom.xml b/maven-core/pom.xml index 2f22ea1d95..1c8552c6e8 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -103,7 +103,6 @@ 1.0.0 - src/main/mdo/settings.mdo src/main/mdo/toolchains.mdo diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index b03c7b173c..dda29ce142 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -965,6 +965,8 @@ public class DefaultMavenExecutionRequest projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() ); projectBuildingRequest.setRepositoryCache( getRepositoryCache() ); projectBuildingRequest.setOffline( isOffline() ); + projectBuildingRequest.setServers( getServers() ); + projectBuildingRequest.setMirrors( getMirrors() ); projectBuildingRequest.setActiveProfileIds( getActiveProfiles() ); projectBuildingRequest.setInactiveProfileIds( getInactiveProfiles() ); projectBuildingRequest.setProfiles( getProfiles() ); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index a4adaa35d5..93622e9ebe 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -85,7 +85,9 @@ public class DefaultMavenProjectBuilder try { ArtifactRepository repo = repositorySystem.buildArtifactRepository( (Repository) repository ); - repos.addAll( repositorySystem.getMirrors( Arrays.asList( repo ) ) ); + repositorySystem.injectMirror( Arrays.asList( repo ), configuration.getMirrors() ); + repositorySystem.injectAuthentication( Arrays.asList( repo ), configuration.getServers() ); + repos.add( repo ); } catch ( InvalidRepositoryException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java index 60fda4b309..8fc3503400 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultModelBuildingListener.java @@ -114,7 +114,8 @@ class DefaultModelBuildingListener try { remoteRepositories = - projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories ); + projectBuildingHelper.createArtifactRepositories( model.getRepositories(), remoteRepositories, + projectBuildingRequest ); } catch ( Exception e ) { @@ -124,7 +125,8 @@ class DefaultModelBuildingListener try { pluginRepositories = - projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories ); + projectBuildingHelper.createArtifactRepositories( model.getPluginRepositories(), pluginRepositories, + projectBuildingRequest ); } catch ( Exception e ) { 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 f4527f7620..42d94b8300 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 @@ -199,14 +199,8 @@ public class DefaultProjectBuilder private ModelBuildingRequest getModelBuildingRequest( ProjectBuildingRequest configuration, ReactorModelPool reactorModelPool ) { - RepositoryRequest repositoryRequest = new DefaultRepositoryRequest(); - repositoryRequest.setCache( configuration.getRepositoryCache() ); - repositoryRequest.setLocalRepository( configuration.getLocalRepository() ); - repositoryRequest.setOffline( configuration.isOffline() ); - ModelResolver resolver = - new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, repositoryRequest, - configuration.getRemoteRepositories(), reactorModelPool ); + new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, configuration, reactorModelPool ); ModelBuildingRequest request = new DefaultModelBuildingRequest(); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java index f629af02be..b1f7f74ef0 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java @@ -87,7 +87,8 @@ public class DefaultProjectBuildingHelper private PluginVersionResolver pluginVersionResolver; public List createArtifactRepositories( List pomRepositories, - List externalRepositories ) + List externalRepositories, + ProjectBuildingRequest request ) throws InvalidRepositoryException { List artifactRepositories = new ArrayList(); @@ -97,7 +98,9 @@ public class DefaultProjectBuildingHelper artifactRepositories.add( repositorySystem.buildArtifactRepository( repository ) ); } - artifactRepositories = repositorySystem.getMirrors( artifactRepositories ); + repositorySystem.injectMirror( artifactRepositories, request.getMirrors() ); + + repositorySystem.injectAuthentication( artifactRepositories, request.getServers() ); if ( externalRepositories != null ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java index dce4548880..bf33132f0f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingRequest.java @@ -29,6 +29,8 @@ import org.apache.maven.artifact.repository.RepositoryCache; import org.apache.maven.model.Profile; import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.model.building.ModelEventListener; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; public class DefaultProjectBuildingRequest implements ProjectBuildingRequest @@ -44,6 +46,10 @@ public class DefaultProjectBuildingRequest private List pluginArtifactRepositories; + private List servers; + + private List mirrors; + private List listeners; private MavenProject project; @@ -79,6 +85,8 @@ public class DefaultProjectBuildingRequest userProperties = new Properties(); remoteRepositories = new ArrayList(); pluginArtifactRepositories = new ArrayList(); + servers = new ArrayList(); + mirrors = new ArrayList(); } public MavenProject getProject() @@ -164,6 +172,44 @@ public class DefaultProjectBuildingRequest return this; } + public ProjectBuildingRequest setServers( List servers ) + { + if ( servers != null ) + { + this.servers = new ArrayList( servers ); + } + else + { + this.servers.clear(); + } + + return this; + } + + public List getServers() + { + return servers; + } + + public ProjectBuildingRequest setMirrors( List mirrors ) + { + if ( mirrors != null ) + { + this.mirrors = new ArrayList( mirrors ); + } + else + { + this.mirrors.clear(); + } + + return this; + } + + public List getMirrors() + { + return mirrors; + } + public Properties getSystemProperties() { return systemProperties; diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index be342dc0aa..76f9bc3fdb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -1738,7 +1739,10 @@ public class MavenProject { try { - setReleaseArtifactRepository( repositorySystem.buildArtifactRepository( getDistributionManagement().getRepository() ) ); + ArtifactRepository repo = + repositorySystem.buildArtifactRepository( getDistributionManagement().getRepository() ); + repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuilderConfiguration.getServers() ); + setReleaseArtifactRepository( repo ); } catch ( InvalidRepositoryException e ) { @@ -1754,7 +1758,10 @@ public class MavenProject { try { - setSnapshotArtifactRepository( repositorySystem.buildArtifactRepository( getDistributionManagement().getSnapshotRepository() ) ); + ArtifactRepository repo = + repositorySystem.buildArtifactRepository( getDistributionManagement().getSnapshotRepository() ); + repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuilderConfiguration.getServers() ); + setSnapshotArtifactRepository( repo ); } catch ( InvalidRepositoryException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java index f879d279ba..dd87581ef4 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingHelper.java @@ -46,11 +46,14 @@ public interface ProjectBuildingHelper * @param pomRepositories The POM repositories to create the artifact repositories from, must not be {@code null}. * @param externalRepositories The external (and already mirrored) repositories to merge into the result list, may * be {@code null}. + * @param request The project building request holding further settings like repository settings, must not be + * {@code null}. * @return The effective artifact repositories, never {@code null}. * @throws InvalidRepositoryException */ List createArtifactRepositories( List pomRepositories, - List externalRepositories ) + List externalRepositories, + ProjectBuildingRequest request ) throws InvalidRepositoryException; /** diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java index 3f6986c7de..be54bdbde5 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectBuildingRequest.java @@ -27,6 +27,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.RepositoryCache; import org.apache.maven.model.Profile; import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Server; public interface ProjectBuildingRequest { @@ -51,6 +53,14 @@ public interface ProjectBuildingRequest List getPluginArtifactRepositories(); + ProjectBuildingRequest setServers( List servers ); + + List getServers(); + + ProjectBuildingRequest setMirrors( List mirrors ); + + List getMirrors(); + /** * Sets the system properties to use for interpolation and profile activation. The system properties are collected * from the runtime environment like {@link System#getProperties()} and environment variables. diff --git a/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java index 66c8c3689b..bc9b563a7e 100644 --- a/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/RepositoryModelResolver.java @@ -26,7 +26,6 @@ import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.RepositoryRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; @@ -52,15 +51,14 @@ class RepositoryModelResolver private ResolutionErrorHandler resolutionErrorHandler; - private RepositoryRequest repositoryRequest; + private ProjectBuildingRequest projectBuildingRequest; private List remoteRepositories; private ReactorModelPool reactorModelPool; public RepositoryModelResolver( RepositorySystem repositorySystem, ResolutionErrorHandler resolutionErrorHandler, - RepositoryRequest repositoryRequest, List remoteRepositories, - ReactorModelPool reactorModelPool ) + ProjectBuildingRequest projectBuildingRequest, ReactorModelPool reactorModelPool ) { if ( repositorySystem == null ) { @@ -74,25 +72,25 @@ class RepositoryModelResolver } this.resolutionErrorHandler = resolutionErrorHandler; - if ( repositoryRequest == null ) + if ( projectBuildingRequest == null ) { - throw new IllegalArgumentException( "no repository request specified" ); + throw new IllegalArgumentException( "no project building request specified" ); } - this.repositoryRequest = repositoryRequest; + this.projectBuildingRequest = projectBuildingRequest; - if ( remoteRepositories == null ) + if ( projectBuildingRequest.getRemoteRepositories() == null ) { throw new IllegalArgumentException( "no remote repositories specified" ); } - this.remoteRepositories = new ArrayList( remoteRepositories ); + this.remoteRepositories = new ArrayList( projectBuildingRequest.getRemoteRepositories() ); this.reactorModelPool = reactorModelPool; } public ModelResolver newCopy() { - return new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, repositoryRequest, - remoteRepositories, reactorModelPool ); + return new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, projectBuildingRequest, + reactorModelPool ); } public void addRepository( Repository repository ) @@ -102,9 +100,11 @@ class RepositoryModelResolver { ArtifactRepository repo = repositorySystem.buildArtifactRepository( repository ); - List mirrors = repositorySystem.getMirrors( Arrays.asList( repo ) ); + repositorySystem.injectMirror( Arrays.asList( repo ), projectBuildingRequest.getMirrors() ); - remoteRepositories.addAll( 0, mirrors ); + repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuildingRequest.getServers() ); + + remoteRepositories.add( 0, repo ); remoteRepositories = repositorySystem.getEffectiveRepositories( remoteRepositories ); } @@ -128,9 +128,12 @@ class RepositoryModelResolver { Artifact artifactParent = repositorySystem.createProjectArtifact( groupId, artifactId, version ); - ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest ); + ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact( artifactParent ); request.setRemoteRepositories( remoteRepositories ); + request.setLocalRepository( projectBuildingRequest.getLocalRepository() ); + request.setOffline( projectBuildingRequest.isOffline() ); + request.setCache( projectBuildingRequest.getRepositoryCache() ); // FIXME setTransferListener ArtifactResolutionResult result = repositorySystem.resolve( request ); diff --git a/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java b/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java index 6646899506..095e6fd13c 100644 --- a/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java +++ b/maven-core/src/test/java/org/apache/maven/project/EmptyProjectBuildingHelper.java @@ -42,7 +42,8 @@ public class EmptyProjectBuildingHelper { public List createArtifactRepositories( List pomRepositories, - List externalRepositories ) + List externalRepositories, + ProjectBuildingRequest request ) throws InvalidRepositoryException { if ( externalRepositories != null ) diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index b5c4d62fc6..be58d550c6 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -229,17 +229,6 @@ public class DefaultMavenExecutionRequestPopulator server.setPassword( password ); request.addServer( server ); - - repositorySystem.addAuthenticationForArtifactRepository( server.getId(), server.getUsername(), password ); - } - - for ( Mirror mirror : settings.getMirrors() ) - { - mirror = mirror.clone(); - - request.addMirror( mirror ); - - repositorySystem.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() ); } // @@ -250,9 +239,22 @@ public class DefaultMavenExecutionRequestPopulator // // - request.setRemoteRepositories( repositorySystem.getMirrors( request.getRemoteRepositories() ) ); + for ( Mirror mirror : settings.getMirrors() ) + { + mirror = mirror.clone(); - request.setPluginArtifactRepositories( repositorySystem.getMirrors( request.getPluginArtifactRepositories() ) ); + request.addMirror( mirror ); + } + + repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() ); + repositorySystem.injectAuthentication( request.getRemoteRepositories(), request.getServers() ); + + request.setRemoteRepositories( repositorySystem.getEffectiveRepositories( request.getRemoteRepositories() ) ); + + repositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() ); + repositorySystem.injectAuthentication( request.getPluginArtifactRepositories(), request.getServers() ); + + request.setPluginArtifactRepositories( repositorySystem.getEffectiveRepositories( request.getPluginArtifactRepositories() ) ); } private String decrypt( String encrypted, String source )