Repository: maven Updated Branches: refs/heads/master 2d34e67ee -> dd5eb31a0
Fold back into MavenRepositorySystem and work from there to clean up all references to the legacy system and Settings. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/dd5eb31a Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/dd5eb31a Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/dd5eb31a Branch: refs/heads/master Commit: dd5eb31a08ae84f560c36ad1145d835ffd90b1ee Parents: 2d34e67 Author: Jason van Zyl <ja...@tesla.io> Authored: Mon Feb 9 01:44:32 2015 -0500 Committer: Jason van Zyl <ja...@tesla.io> Committed: Mon Feb 9 01:44:32 2015 -0500 ---------------------------------------------------------------------- .../maven/bridge/MavenRepositorySystem.java | 410 ++++++++++-------- .../org/apache/maven/bridge/MirrorSelector.java | 197 --------- .../DefaultMavenExecutionRequestPopulator.java | 420 +------------------ .../maven/project/DefaultProjectBuilder.java | 5 + ...faultMavenExecutionRequestPopulatorTest.java | 12 +- 5 files changed, 271 insertions(+), 773 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/dd5eb31a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java index e01ffc3..060713f 100644 --- a/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java +++ b/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java @@ -20,13 +20,14 @@ package org.apache.maven.bridge; */ import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; @@ -44,24 +45,18 @@ import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.model.Dependency; import org.apache.maven.model.Exclusion; import org.apache.maven.model.Plugin; import org.apache.maven.repository.Proxy; +import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Mirror; -import org.apache.maven.settings.Server; -import org.apache.maven.settings.building.SettingsProblem; -import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; import org.apache.maven.settings.crypto.SettingsDecrypter; -import org.apache.maven.settings.crypto.SettingsDecryptionRequest; -import org.apache.maven.settings.crypto.SettingsDecryptionResult; -import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.impl.ArtifactResolver; import org.eclipse.aether.repository.AuthenticationContext; import org.eclipse.aether.repository.AuthenticationSelector; import org.eclipse.aether.repository.ProxySelector; @@ -73,23 +68,13 @@ import org.eclipse.aether.repository.RemoteRepository; @Component( role = MavenRepositorySystem.class, hint = "default" ) public class MavenRepositorySystem { - - @Requirement - private Logger logger; - @Requirement private ArtifactHandlerManager artifactHandlerManager; - @Requirement - private ArtifactResolver artifactResolver; - @Requirement( role = ArtifactRepositoryLayout.class ) private Map<String, ArtifactRepositoryLayout> layouts; @Requirement - private PlexusContainer plexus; - - @Requirement private SettingsDecrypter settingsDecrypter; // DefaultProjectBuilder @@ -189,99 +174,6 @@ public class MavenRepositorySystem return XcreatePluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); } - public List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories ) - { - if ( repositories == null ) - { - return null; - } - - Map<String, List<ArtifactRepository>> reposByKey = new LinkedHashMap<String, List<ArtifactRepository>>(); - - for ( ArtifactRepository repository : repositories ) - { - String key = repository.getId(); - - List<ArtifactRepository> aliasedRepos = reposByKey.get( key ); - - if ( aliasedRepos == null ) - { - aliasedRepos = new ArrayList<ArtifactRepository>(); - reposByKey.put( key, aliasedRepos ); - } - - aliasedRepos.add( repository ); - } - - List<ArtifactRepository> effectiveRepositories = new ArrayList<ArtifactRepository>(); - - for ( List<ArtifactRepository> aliasedRepos : reposByKey.values() ) - { - List<ArtifactRepository> mirroredRepos = new ArrayList<ArtifactRepository>(); - - List<ArtifactRepositoryPolicy> releasePolicies = - new ArrayList<ArtifactRepositoryPolicy>( aliasedRepos.size() ); - - for ( ArtifactRepository aliasedRepo : aliasedRepos ) - { - releasePolicies.add( aliasedRepo.getReleases() ); - mirroredRepos.addAll( aliasedRepo.getMirroredRepositories() ); - } - - ArtifactRepositoryPolicy releasePolicy = getEffectivePolicy( releasePolicies ); - - List<ArtifactRepositoryPolicy> snapshotPolicies = - new ArrayList<ArtifactRepositoryPolicy>( aliasedRepos.size() ); - - for ( ArtifactRepository aliasedRepo : aliasedRepos ) - { - snapshotPolicies.add( aliasedRepo.getSnapshots() ); - } - - ArtifactRepositoryPolicy snapshotPolicy = getEffectivePolicy( snapshotPolicies ); - - ArtifactRepository aliasedRepo = aliasedRepos.get( 0 ); - - ArtifactRepository effectiveRepository = - createArtifactRepository( aliasedRepo.getId(), aliasedRepo.getUrl(), aliasedRepo.getLayout(), - snapshotPolicy, releasePolicy ); - - effectiveRepository.setAuthentication( aliasedRepo.getAuthentication() ); - - effectiveRepository.setProxy( aliasedRepo.getProxy() ); - - effectiveRepository.setMirroredRepositories( mirroredRepos ); - - effectiveRepositories.add( effectiveRepository ); - } - - return effectiveRepositories; - } - - private ArtifactRepositoryPolicy getEffectivePolicy( Collection<ArtifactRepositoryPolicy> policies ) - { - ArtifactRepositoryPolicy effectivePolicy = null; - - for ( ArtifactRepositoryPolicy policy : policies ) - { - if ( effectivePolicy == null ) - { - effectivePolicy = new ArtifactRepositoryPolicy( policy ); - } - else - { - effectivePolicy.merge( policy ); - } - } - - return effectivePolicy; - } - - public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors ) - { - return MirrorSelector.getMirror( repository, mirrors ); - } - public void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors ) { if ( repositories != null && mirrors != null ) @@ -347,55 +239,6 @@ public class MavenRepositorySystem } } - public void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers ) - { - if ( repositories != null ) - { - Map<String, Server> serversById = new HashMap<String, Server>(); - - 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 ) - { - SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest( server ); - SettingsDecryptionResult result = settingsDecrypter.decrypt( request ); - server = result.getServer(); - - if ( logger.isDebugEnabled() ) - { - for ( SettingsProblem problem : result.getProblems() ) - { - logger.debug( problem.getMessage(), problem.getException() ); - } - } - - Authentication authentication = new Authentication( server.getUsername(), server.getPassword() ); - authentication.setPrivateKey( server.getPrivateKey() ); - authentication.setPassphrase( server.getPassphrase() ); - - repository.setAuthentication( authentication ); - } - else - { - repository.setAuthentication( null ); - } - } - } - } - private Authentication getAuthentication( RepositorySystemSession session, ArtifactRepository repository ) { if ( session != null ) @@ -512,7 +355,7 @@ public class MavenRepositorySystem return modelRepositoryPolicy; } - public static ArtifactRepository buildArtifactRepository( org.apache.maven.settings.Repository repo ) + public ArtifactRepository buildArtifactRepository( org.apache.maven.settings.Repository repo ) throws InvalidRepositoryException { return buildArtifactRepository( fromSettingsRepository( repo ) ); @@ -574,8 +417,30 @@ public class MavenRepositorySystem } return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); + } + + public ArtifactRepository createArtifactRepository( String id, String url, String layoutId, + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ) + throws Exception + { + ArtifactRepositoryLayout layout = layouts.get( layoutId ); + + checkLayout( id, layoutId, layout ); + + return createArtifactRepository( id, url, layout, snapshots, releases ); } + private void checkLayout( String repositoryId, String layoutId, ArtifactRepositoryLayout layout ) + throws Exception + { + if ( layout == null ) + { + throw new Exception( String.format( "Cannot find ArtifactRepositoryLayout instance for: %s %s", layoutId, + repositoryId ) ); + } + } + public static ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, @@ -700,4 +565,221 @@ public class MavenRepositorySystem return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler, optional ); } + + // + // Code taken from LegacyRepositorySystem + // + + public ArtifactRepository createDefaultRemoteRepository( MavenExecutionRequest request ) + throws Exception + { + return createRepository( RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID, + true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, false, + ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + } + + public ArtifactRepository createRepository( String url, String repositoryId, boolean releases, + String releaseUpdates, boolean snapshots, String snapshotUpdates, + String checksumPolicy ) throws Exception + { + ArtifactRepositoryPolicy snapshotsPolicy = + new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy ); + + ArtifactRepositoryPolicy releasesPolicy = + new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy ); + + return createArtifactRepository( repositoryId, url, "default", snapshotsPolicy, releasesPolicy ); + } + + public Set<String> getRepoIds( List<ArtifactRepository> repositories ) + { + Set<String> repoIds = new HashSet<String>(); + + if ( repositories != null ) + { + for ( ArtifactRepository repository : repositories ) + { + repoIds.add( repository.getId() ); + } + } + + return repoIds; + } + + + public ArtifactRepository createLocalRepository( MavenExecutionRequest request, File localRepository ) + throws Exception + { + return createRepository( "file://" + localRepository.toURI().getRawPath(), + RepositorySystem.DEFAULT_LOCAL_REPO_ID, true, + ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, + ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + private static final String WILDCARD = "*"; + + private static final String EXTERNAL_WILDCARD = "external:*"; + + public static Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors ) + { + String repoId = repository.getId(); + + if ( repoId != null && mirrors != null ) + { + for ( Mirror mirror : mirrors ) + { + if ( repoId.equals( mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) + { + return mirror; + } + } + + for ( Mirror mirror : mirrors ) + { + if ( matchPattern( repository, mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) + { + return mirror; + } + } + } + + return null; + } + + /** + * This method checks if the pattern matches the originalRepository. Valid patterns: * = everything external:* = + * everything not on the localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1 + * + * @param originalRepository to compare for a match. + * @param pattern used for match. Currently only '*' is supported. + * @return true if the repository is a match to this pattern. + */ + static boolean matchPattern( ArtifactRepository originalRepository, String pattern ) + { + boolean result = false; + String originalId = originalRepository.getId(); + + // simple checks first to short circuit processing below. + if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) ) + { + result = true; + } + else + { + // process the list + String[] repos = pattern.split( "," ); + for ( String repo : repos ) + { + // see if this is a negative match + if ( repo.length() > 1 && repo.startsWith( "!" ) ) + { + if ( repo.substring( 1 ).equals( originalId ) ) + { + // explicitly exclude. Set result and stop processing. + result = false; + break; + } + } + // check for exact match + else if ( repo.equals( originalId ) ) + { + result = true; + break; + } + // check for external:* + else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository ) ) + { + result = true; + // don't stop processing in case a future segment explicitly excludes this repo + } + else if ( WILDCARD.equals( repo ) ) + { + result = true; + // don't stop processing in case a future segment explicitly excludes this repo + } + } + } + return result; + } + + /** + * Checks the URL to see if this repository refers to an external repository + * + * @param originalRepository + * @return true if external. + */ + static boolean isExternalRepo( ArtifactRepository originalRepository ) + { + try + { + URL url = new URL( originalRepository.getUrl() ); + return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) || url.getProtocol().equals( "file" ) ); + } + catch ( MalformedURLException e ) + { + // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it + return false; + } + } + + static boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) + { + return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() ); + } + + /** + * Checks whether the layouts configured for a mirror match with the layout of the repository. + * + * @param repoLayout The layout of the repository, may be {@code null}. + * @param mirrorLayout The layouts supported by the mirror, may be {@code null}. + * @return {@code true} if the layouts associated with the mirror match the layout of the original repository, + * {@code false} otherwise. + */ + static boolean matchesLayout( String repoLayout, String mirrorLayout ) + { + boolean result = false; + + // simple checks first to short circuit processing below. + if ( StringUtils.isEmpty( mirrorLayout ) || WILDCARD.equals( mirrorLayout ) ) + { + result = true; + } + else if ( mirrorLayout.equals( repoLayout ) ) + { + result = true; + } + else + { + // process the list + String[] layouts = mirrorLayout.split( "," ); + for ( String layout : layouts ) + { + // see if this is a negative match + if ( layout.length() > 1 && layout.startsWith( "!" ) ) + { + if ( layout.substring( 1 ).equals( repoLayout ) ) + { + // explicitly exclude. Set result and stop processing. + result = false; + break; + } + } + // check for exact match + else if ( layout.equals( repoLayout ) ) + { + result = true; + break; + } + else if ( WILDCARD.equals( layout ) ) + { + result = true; + // don't stop processing in case a future segment explicitly excludes this repo + } + } + } + + return result; + } } http://git-wip-us.apache.org/repos/asf/maven/blob/dd5eb31a/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java b/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java deleted file mode 100644 index c0dd935..0000000 --- a/maven-core/src/main/java/org/apache/maven/bridge/MirrorSelector.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.apache.maven.bridge; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.settings.Mirror; -import org.codehaus.plexus.util.StringUtils; - -public class MirrorSelector -{ - private static final String WILDCARD = "*"; - - private static final String EXTERNAL_WILDCARD = "external:*"; - - public static Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors ) - { - String repoId = repository.getId(); - - if ( repoId != null && mirrors != null ) - { - for ( Mirror mirror : mirrors ) - { - if ( repoId.equals( mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) - { - return mirror; - } - } - - for ( Mirror mirror : mirrors ) - { - if ( matchPattern( repository, mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) - { - return mirror; - } - } - } - - return null; - } - - /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = everything external:* = - * everything not on the localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1 - * - * @param originalRepository to compare for a match. - * @param pattern used for match. Currently only '*' is supported. - * @return true if the repository is a match to this pattern. - */ - static boolean matchPattern( ArtifactRepository originalRepository, String pattern ) - { - boolean result = false; - String originalId = originalRepository.getId(); - - // simple checks first to short circuit processing below. - if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) ) - { - result = true; - } - else - { - // process the list - String[] repos = pattern.split( "," ); - for ( String repo : repos ) - { - // see if this is a negative match - if ( repo.length() > 1 && repo.startsWith( "!" ) ) - { - if ( repo.substring( 1 ).equals( originalId ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( repo.equals( originalId ) ) - { - result = true; - break; - } - // check for external:* - else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - else if ( WILDCARD.equals( repo ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - return result; - } - - /** - * Checks the URL to see if this repository refers to an external repository - * - * @param originalRepository - * @return true if external. - */ - static boolean isExternalRepo( ArtifactRepository originalRepository ) - { - try - { - URL url = new URL( originalRepository.getUrl() ); - return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) || url.getProtocol().equals( "file" ) ); - } - catch ( MalformedURLException e ) - { - // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it - return false; - } - } - - static boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) - { - return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() ); - } - - /** - * Checks whether the layouts configured for a mirror match with the layout of the repository. - * - * @param repoLayout The layout of the repository, may be {@code null}. - * @param mirrorLayout The layouts supported by the mirror, may be {@code null}. - * @return {@code true} if the layouts associated with the mirror match the layout of the original repository, - * {@code false} otherwise. - */ - static boolean matchesLayout( String repoLayout, String mirrorLayout ) - { - boolean result = false; - - // simple checks first to short circuit processing below. - if ( StringUtils.isEmpty( mirrorLayout ) || WILDCARD.equals( mirrorLayout ) ) - { - result = true; - } - else if ( mirrorLayout.equals( repoLayout ) ) - { - result = true; - } - else - { - // process the list - String[] layouts = mirrorLayout.split( "," ); - for ( String layout : layouts ) - { - // see if this is a negative match - if ( layout.length() > 1 && layout.startsWith( "!" ) ) - { - if ( layout.substring( 1 ).equals( repoLayout ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( layout.equals( repoLayout ) ) - { - result = true; - break; - } - else if ( WILDCARD.equals( layout ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/maven/blob/dd5eb31a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index dc2521c..fac1eb9 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -20,12 +20,8 @@ package org.apache.maven.execution; */ import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -33,15 +29,8 @@ import java.util.Set; import javax.inject.Inject; import javax.inject.Named; -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.MavenArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2; import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.repository.RepositorySystem; // @@ -64,17 +53,13 @@ import org.codehaus.plexus.util.StringUtils; public class DefaultMavenExecutionRequestPopulator implements MavenExecutionRequestPopulator { - - private static final String WILDCARD = "*"; - - private static final String EXTERNAL_WILDCARD = "external:*"; - - private final Map<String, ArtifactRepositoryLayout> layouts; - + + private final MavenRepositorySystem repositorySystem; + @Inject - public DefaultMavenExecutionRequestPopulator( RepositorySystem repositorySystem, Map<String, ArtifactRepositoryLayout> layouts ) + public DefaultMavenExecutionRequestPopulator( MavenRepositorySystem repositorySystem ) { - this.layouts = layouts; + this.repositorySystem = repositorySystem; } @Override @@ -153,7 +138,7 @@ public class DefaultMavenExecutionRequestPopulator { try { - request.addRemoteRepository( MavenRepositorySystem.buildArtifactRepository( remoteRepository ) ); + request.addRemoteRepository( repositorySystem.buildArtifactRepository( remoteRepository ) ); } catch ( InvalidRepositoryException e ) { @@ -166,7 +151,7 @@ public class DefaultMavenExecutionRequestPopulator { try { - request.addPluginArtifactRepository( MavenRepositorySystem.buildArtifactRepository( pluginRepository ) ); + request.addPluginArtifactRepository( repositorySystem.buildArtifactRepository( pluginRepository ) ); } catch ( InvalidRepositoryException e ) { @@ -234,13 +219,13 @@ public class DefaultMavenExecutionRequestPopulator private void injectDefaultRepositories( MavenExecutionRequest request ) throws MavenExecutionRequestPopulationException { - Set<String> definedRepositories = getRepoIds( request.getRemoteRepositories() ); + Set<String> definedRepositories = repositorySystem.getRepoIds( request.getRemoteRepositories() ); if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) { try { - request.addRemoteRepository( createDefaultRemoteRepository( request ) ); + request.addRemoteRepository( repositorySystem.createDefaultRemoteRepository( request ) ); } catch ( Exception e ) { @@ -252,13 +237,13 @@ public class DefaultMavenExecutionRequestPopulator private void injectDefaultPluginRepositories( MavenExecutionRequest request ) throws MavenExecutionRequestPopulationException { - Set<String> definedRepositories = getRepoIds( request.getPluginArtifactRepositories() ); + Set<String> definedRepositories = repositorySystem.getRepoIds( request.getPluginArtifactRepositories() ); if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) { try { - request.addPluginArtifactRepository( createDefaultRemoteRepository( request ) ); + request.addPluginArtifactRepository( repositorySystem.createDefaultRemoteRepository( request ) ); } catch ( Exception e ) { @@ -267,43 +252,6 @@ public class DefaultMavenExecutionRequestPopulator } } - private ArtifactRepository createDefaultRemoteRepository( MavenExecutionRequest request ) - throws Exception - { - return createRepository( request, RepositorySystem.DEFAULT_REMOTE_REPO_URL, RepositorySystem.DEFAULT_REMOTE_REPO_ID, - true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, false, - ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, - ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); - } - - private ArtifactRepository createRepository( MavenExecutionRequest request, String url, String repositoryId, boolean releases, - String releaseUpdates, boolean snapshots, String snapshotUpdates, - String checksumPolicy ) throws Exception - { - ArtifactRepositoryPolicy snapshotsPolicy = - new ArtifactRepositoryPolicy( snapshots, snapshotUpdates, checksumPolicy ); - - ArtifactRepositoryPolicy releasesPolicy = - new ArtifactRepositoryPolicy( releases, releaseUpdates, checksumPolicy ); - - return createArtifactRepository( repositoryId, url, "default", snapshotsPolicy, releasesPolicy, request ); - } - - private Set<String> getRepoIds( List<ArtifactRepository> repositories ) - { - Set<String> repoIds = new HashSet<String>(); - - if ( repositories != null ) - { - for ( ArtifactRepository repository : repositories ) - { - repoIds.add( repository.getId() ); - } - } - - return repoIds; - } - private void processRepositoriesInSettings( MavenExecutionRequest request ) throws MavenExecutionRequestPopulationException { @@ -347,8 +295,8 @@ public class DefaultMavenExecutionRequestPopulator // // Not sure why the DefaultMirrorSelector doesn't do this... // - injectMirror( request, request.getRemoteRepositories(), request.getMirrors() ); - injectMirror( request, request.getPluginArtifactRepositories(), request.getMirrors() ); + repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() ); + repositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() ); } private void localRepository( MavenExecutionRequest request ) @@ -394,7 +342,7 @@ public class DefaultMavenExecutionRequestPopulator try { - return createLocalRepository( request, new File( localRepositoryPath ) ); + return repositorySystem.createLocalRepository( request, new File( localRepositoryPath ) ); } catch ( Exception e ) { @@ -408,345 +356,5 @@ public class DefaultMavenExecutionRequestPopulator { request.setBaseDirectory( request.getPom().getAbsoluteFile().getParentFile() ); } - } - - // - // Code taken from LegacyRepositorySystem - // - - private ArtifactRepository createLocalRepository( MavenExecutionRequest request, File localRepository ) - throws Exception - { - return createRepository( request, "file://" + localRepository.toURI().getRawPath(), - RepositorySystem.DEFAULT_LOCAL_REPO_ID, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, true, - ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, - ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); - } - - private void injectMirror( MavenExecutionRequest request, List<ArtifactRepository> repositories, List<Mirror> mirrors ) - { - if ( repositories != null && mirrors != null ) - { - for ( ArtifactRepository repository : repositories ) - { - Mirror mirror = getMirror( repository, mirrors ); - injectMirror( request, repository, mirror ); - } - } } - - private void injectMirror( MavenExecutionRequest request, ArtifactRepository repository, Mirror mirror ) - { - if ( mirror != null ) - { - ArtifactRepository original = - createArtifactRepository( repository.getId(), repository.getUrl(), repository.getLayout(), - repository.getSnapshots(), repository.getReleases(), request ); - - repository.setMirroredRepositories( Collections.singletonList( original ) ); - - repository.setId( mirror.getId() ); - repository.setUrl( mirror.getUrl() ); - - if ( StringUtils.isNotEmpty( mirror.getLayout() ) ) - { - repository.setLayout( getLayout( mirror.getLayout() ) ); - } - } - } - - private ArtifactRepositoryLayout getLayout( String id ) - { - ArtifactRepositoryLayout layout = layouts.get( id ); - - if ( layout == null ) - { - layout = new UnknownRepositoryLayout( id, layouts.get( "default" ) ); - } - - return layout; - } - - /** - * In the future, the legacy system might encounter repository types for which no layout components exists because - * the actual communication with the repository happens via a repository connector. As a minimum, the legacy system - * needs to retain the id of this layout so that the content type of the remote repository can still be accurately - * described. - */ - private static class UnknownRepositoryLayout - implements ArtifactRepositoryLayout - { - - private final String id; - - private final ArtifactRepositoryLayout fallback; - - public UnknownRepositoryLayout( String id, ArtifactRepositoryLayout fallback ) - { - this.id = id; - this.fallback = fallback; - } - - @Override - public String getId() - { - return id; - } - - @Override - public String pathOf( Artifact artifact ) - { - return fallback.pathOf( artifact ); - } - - @Override - public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) - { - return fallback.pathOfLocalRepositoryMetadata( metadata, repository ); - } - - @Override - public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) - { - return fallback.pathOfRemoteRepositoryMetadata( metadata ); - } - - @Override - public String toString() - { - return getId(); - } - } - - // - // ArtifactRepositoryFactory - // - private ArtifactRepository createArtifactRepository( String id, String url, String layoutId, - ArtifactRepositoryPolicy snapshots, - ArtifactRepositoryPolicy releases, - MavenExecutionRequest request ) - throws Exception - { - ArtifactRepositoryLayout layout = layouts.get( layoutId ); - - checkLayout( id, layoutId, layout ); - - return createArtifactRepository( id, url, layout, snapshots, releases, request ); - } - - private ArtifactRepository createArtifactRepository( String id, String url, - ArtifactRepositoryLayout repositoryLayout, - ArtifactRepositoryPolicy snapshots, - ArtifactRepositoryPolicy releases, - MavenExecutionRequest request ) - { - String globalChecksumPolicy = request.getGlobalChecksumPolicy(); - - if ( snapshots == null ) - { - snapshots = new ArtifactRepositoryPolicy(); - } - - if ( releases == null ) - { - releases = new ArtifactRepositoryPolicy(); - } - - if ( globalChecksumPolicy != null ) - { - snapshots.setChecksumPolicy( globalChecksumPolicy ); - releases.setChecksumPolicy( globalChecksumPolicy ); - } - - ArtifactRepository repository; - if ( repositoryLayout instanceof ArtifactRepositoryLayout2 ) - { - repository = - ( (ArtifactRepositoryLayout2) repositoryLayout ).newMavenArtifactRepository( id, url, snapshots, - releases ); - } - else - { - repository = new MavenArtifactRepository( id, url, repositoryLayout, snapshots, releases ); - } - - return repository; - } - - private void checkLayout( String repositoryId, String layoutId, ArtifactRepositoryLayout layout ) - throws Exception - { - if ( layout == null ) - { - throw new Exception( String.format( "Cannot find ArtifactRepositoryLayout instance for: %s %s", layoutId, repositoryId ) ); - } - } - - // - // MirrorSelector - // - private Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors ) - { - String repoId = repository.getId(); - - if ( repoId != null && mirrors != null ) - { - for ( Mirror mirror : mirrors ) - { - if ( repoId.equals( mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) - { - return mirror; - } - } - - for ( Mirror mirror : mirrors ) - { - if ( matchPattern( repository, mirror.getMirrorOf() ) && matchesLayout( repository, mirror ) ) - { - return mirror; - } - } - } - - return null; - } - - /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = - * everything external:* = everything not on the localhost and not file based. repo,repo1 = repo - * or repo1 *,!repo1 = everything except repo1 - * - * @param originalRepository to compare for a match. - * @param pattern used for match. Currently only '*' is supported. - * @return true if the repository is a match to this pattern. - */ - private boolean matchPattern( ArtifactRepository originalRepository, String pattern ) - { - boolean result = false; - String originalId = originalRepository.getId(); - - // simple checks first to short circuit processing below. - if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) ) - { - result = true; - } - else - { - // process the list - String[] repos = pattern.split( "," ); - for ( String repo : repos ) - { - repo = repo.trim(); - // see if this is a negative match - if ( repo.length() > 1 && repo.startsWith( "!" ) ) - { - if ( repo.substring( 1 ).equals( originalId ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( repo.equals( originalId ) ) - { - result = true; - break; - } - // check for external:* - else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( originalRepository ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - else if ( WILDCARD.equals( repo ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - return result; - } - - /** - * Checks the URL to see if this repository refers to an external repository - * - * @param originalRepository - * @return true if external. - */ - private boolean isExternalRepo( ArtifactRepository originalRepository ) - { - try - { - URL url = new URL( originalRepository.getUrl() ); - return !( url.getHost().equals( "localhost" ) || url.getHost().equals( "127.0.0.1" ) - || url.getProtocol().equals( "file" ) ); - } - catch ( MalformedURLException e ) - { - // bad url just skip it here. It should have been validated already, but the wagon lookup will deal with it - return false; - } - } - - private boolean matchesLayout( ArtifactRepository repository, Mirror mirror ) - { - return matchesLayout( RepositoryUtils.getLayout( repository ), mirror.getMirrorOfLayouts() ); - } - - /** - * Checks whether the layouts configured for a mirror match with the layout of the repository. - * - * @param repoLayout The layout of the repository, may be {@code null}. - * @param mirrorLayout The layouts supported by the mirror, may be {@code null}. - * @return {@code true} if the layouts associated with the mirror match the layout of the original repository, - * {@code false} otherwise. - */ - private boolean matchesLayout( String repoLayout, String mirrorLayout ) - { - boolean result = false; - - // simple checks first to short circuit processing below. - if ( StringUtils.isEmpty( mirrorLayout ) || WILDCARD.equals( mirrorLayout ) ) - { - result = true; - } - else if ( mirrorLayout.equals( repoLayout ) ) - { - result = true; - } - else - { - // process the list - String[] layouts = mirrorLayout.split( "," ); - for ( String layout : layouts ) - { - // see if this is a negative match - if ( layout.length() > 1 && layout.startsWith( "!" ) ) - { - if ( layout.substring( 1 ).equals( repoLayout ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( layout.equals( repoLayout ) ) - { - result = true; - break; - } - else if ( WILDCARD.equals( layout ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - - return result; - } } http://git-wip-us.apache.org/repos/asf/maven/blob/dd5eb31a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java ---------------------------------------------------------------------- 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 5365756..871d6e5 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 @@ -112,12 +112,14 @@ public class DefaultProjectBuilder // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- + @Override public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest request ) throws ProjectBuildingException { return build( pomFile, new FileModelSource( pomFile ), new InternalConfig( request, null ) ); } + @Override public ProjectBuildingResult build( ModelSource modelSource, ProjectBuildingRequest request ) throws ProjectBuildingException { @@ -278,12 +280,14 @@ public class DefaultProjectBuilder return request; } + @Override public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) throws ProjectBuildingException { return build( artifact, false, request ); } + @Override public ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, ProjectBuildingRequest request ) throws ProjectBuildingException { @@ -380,6 +384,7 @@ public class DefaultProjectBuilder return new StringModelSource( buffer, artifact.getId() ); } + @Override public List<ProjectBuildingResult> build( List<File> pomFiles, boolean recursive, ProjectBuildingRequest request ) throws ProjectBuildingException { http://git-wip-us.apache.org/repos/asf/maven/blob/dd5eb31a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java ---------------------------------------------------------------------- diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java index 67f4dee..15a7a7b 100644 --- a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java @@ -2,13 +2,13 @@ package org.apache.maven.execution; import java.util.List; -import junit.framework.TestCase; +import javax.inject.Inject; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.repository.TestRepositorySystem; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Repository; import org.apache.maven.settings.Settings; +import org.eclipse.sisu.launch.InjectedTestCase; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -30,11 +30,11 @@ import org.apache.maven.settings.Settings; */ public class DefaultMavenExecutionRequestPopulatorTest - extends TestCase + extends InjectedTestCase { - DefaultMavenExecutionRequestPopulator testee = - new DefaultMavenExecutionRequestPopulator( new TestRepositorySystem(), null ); - + @Inject + MavenExecutionRequestPopulator testee; + public void testPluginRepositoryInjection() throws Exception {