diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java index 9efbafa76e..c5160ea7e5 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -38,12 +38,14 @@ public interface ArtifactRepository String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ); String getUrl(); + void setUrl( String url ); String getBasedir(); String getProtocol(); String getId(); + void setId( String id ); ArtifactRepositoryPolicy getSnapshots(); void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java index 0a313ad39e..ad8daa17c0 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/plan/DefaultBuildPlanner.java @@ -194,11 +194,7 @@ public class DefaultBuildPlanner final boolean allowUnbindableMojos ) throws LifecyclePlannerException, LifecycleSpecificationException, LifecycleLoaderException { - PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, - plan, - project, - session, - allowUnbindableMojos ); + PluginDescriptor pluginDescriptor = loadPluginDescriptor( mojoBinding, plan, project, session, allowUnbindableMojos ); if ( pluginDescriptor == null ) { @@ -314,14 +310,11 @@ public class DefaultBuildPlanner } } - private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding, - final BuildPlan plan, - final MavenProject project, - final MavenSession session, - final boolean allowUnbindableMojos ) + private PluginDescriptor loadPluginDescriptor( final MojoBinding mojoBinding, final BuildPlan plan, final MavenProject project, final MavenSession session, final boolean allowUnbindableMojos ) throws LifecyclePlannerException { PluginDescriptor pluginDescriptor = null; + try { pluginDescriptor = pluginLoader.loadPlugin( mojoBinding, project, session ); @@ -330,9 +323,7 @@ public class DefaultBuildPlanner { if ( allowUnbindableMojos ) { - String message = "Failed to load plugin: " - + MojoBindingUtils.createPluginKey( mojoBinding ) - + ". Adding to late-bound plugins list.\nReason: " + e.getMessage(); + String message = "Failed to load plugin: " + MojoBindingUtils.createPluginKey( mojoBinding ) + ". Adding to late-bound plugins list.\nReason: " + e.getMessage(); if ( logger.isDebugEnabled() ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginLoader.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginLoader.java index 659ae318f3..6f4b34abb6 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginLoader.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginLoader.java @@ -64,7 +64,7 @@ public class DefaultPluginLoader */ public PluginDescriptor loadPlugin( Plugin plugin, MavenProject project, MavenSession session ) throws PluginLoaderException - { + { if ( plugin.getGroupId() == null ) { plugin.setGroupId( PluginDescriptor.getDefaultPluginGroupId() ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java index ff3899ab0d..ff071607fe 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java @@ -83,12 +83,12 @@ public class DefaultPluginManagerSupport MavenProject pluginProject = buildPluginProject( plugin, localRepository, project.getRemoteArtifactRepositories() ); + Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); + checkRequiredMavenVersion( plugin, pluginProject, localRepository, project.getRemoteArtifactRepositories() ); checkPluginDependencySpec( plugin, pluginProject ); - Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); - pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact ); ArtifactResolutionRequest request = new ArtifactResolutionRequest( pluginArtifact, localRepository, project.getRemoteArtifactRepositories() ); @@ -100,13 +100,15 @@ public class DefaultPluginManagerSupport return pluginArtifact; } - public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) + public MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) throws InvalidPluginException { Artifact artifact = repositorySystem.createProjectArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); try { - return mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository ); + MavenProject p = mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository ); + + return p; } catch ( ProjectBuildingException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerSupport.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerSupport.java index 7316fc4662..b29bce3ea7 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerSupport.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManagerSupport.java @@ -17,7 +17,7 @@ public interface PluginManagerSupport Artifact resolvePluginArtifact( Plugin plugin, MavenProject project, MavenSession session ) throws PluginManagerException, InvalidPluginException, PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException; - MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) + MavenProject buildPluginProject( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) throws InvalidPluginException; /** 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 412a42c1b0..93dd2f41c8 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 @@ -274,19 +274,20 @@ public class DefaultMavenExecutionRequestPopulator for ( Server server : settings.getServers() ) { - String pass; - String phrase; + String password; + String passPhrase; + try { - pass = securityDispatcher.decrypt( server.getPassword() ); - phrase = securityDispatcher.decrypt( server.getPassphrase() ); + password = securityDispatcher.decrypt( server.getPassword() ); + passPhrase = securityDispatcher.decrypt( server.getPassphrase() ); } catch ( SecDispatcherException e ) { throw new MavenEmbedderException( "Error decrypting server password/passphrase.", e ); } - repositorySystem.addAuthenticationInfo( server.getId(), server.getUsername(), pass, server.getPrivateKey(), phrase ); + repositorySystem.addAuthenticationInfo( server.getId(), server.getUsername(), password, server.getPrivateKey(), passPhrase ); repositorySystem.addPermissionInfo( server.getId(), server.getFilePermissions(), server.getDirectoryPermissions() ); } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 19bc014b02..674c34f4d0 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -217,21 +217,12 @@ public class DefaultMavenProjectBuilder { return project; } - - List artifactRepositories = new ArrayList( remoteRepositories ); - try - { - artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( getSuperModel().getRepositories() ) ); - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( "Cannot create repositories from super model.", e.getMessage() ); - } - + File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); - try - { - repositorySystem.findModelFromRepository( artifact, artifactRepositories, localRepository ); + + try + { + repositorySystem.findModelFromRepository( artifact, remoteRepositories, localRepository ); } catch ( ArtifactResolutionException e ) { @@ -250,7 +241,8 @@ public class DefaultMavenProjectBuilder .setLocalRepository( localRepository ) .setRemoteRepositories( remoteRepositories ); - project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), artifactRepositories, config ); + project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), remoteRepositories + , config ); project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() ); artifact.setFile( f ); project.setVersion( artifact.getVersion() ); diff --git a/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java b/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java index 8567fa3465..77f62532e6 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java @@ -91,36 +91,23 @@ public class DefaultMirrorBuilder public List getMirrors( List remoteRepositories ) { - Set remoteRepositoriesWithMirrors = new LinkedHashSet(); - if ( remoteRepositories != null ) { for ( ArtifactRepository repository : remoteRepositories) { // Check to see if we have a valid mirror for this repository ArtifactRepository mirror = getMirror( repository ); - - if ( mirror != null ) - { - // Make sure that we take the the properties of the repository we are mirroring we want to direct - // all requests for this mirror at the mirror, but the mirror specification does not allow for - // any of the regular settings. - mirror.setLayout( repository.getLayout() ); - mirror.setSnapshotUpdatePolicy( repository.getSnapshots() ); - mirror.setReleaseUpdatePolicy( repository.getReleases() ); - // If there is a valid mirror for this repository then we'll enter the mirror as a replacement for this repository. - remoteRepositoriesWithMirrors.add( mirror ); - } - else - { - // If we have no valid mirrors for this repository we will keep this repository in the list. - remoteRepositoriesWithMirrors.add( repository ); + if ( mirror != null ) + { + // We basically just want to take the URL + repository.setUrl( mirror.getUrl() ); + repository.setId( repository.getId() + "-" + mirror.getId() ); } } } - return new ArrayList( remoteRepositoriesWithMirrors ); + return remoteRepositories; } // Make these available to tests diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java index 66a03ebdad..b66a8a9bfa 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java @@ -448,19 +448,14 @@ public class LegacyMavenRepositorySystem public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException - { - + { if ( cache.containsKey( artifact.getId() ) ) { artifact.setFile( cache.get( artifact.getId() ).getFile() ); } - - String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); - remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId ); - - Artifact projectArtifact; - + // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. + /* if ( "pom".equals( artifact.getType() ) ) { projectArtifact = artifact; @@ -472,55 +467,15 @@ public class LegacyMavenRepositorySystem projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); } - - ArtifactResolutionRequest request = - new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ); + */ + + ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories ); ArtifactResolutionResult result = resolve( request ); resolutionErrorHandler.throwErrors( request, result ); - - File file = projectArtifact.getFile(); - artifact.setFile( file ); + cache.put( artifact.getId(), artifact ); } - private List normalizeToArtifactRepositories( List remoteArtifactRepositories, String projectId ) - throws InvalidRepositoryException - { - List normalized = new ArrayList( remoteArtifactRepositories.size() ); - - boolean normalizationNeeded = false; - for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) - { - Object item = it.next(); - - if ( item instanceof ArtifactRepository ) - { - normalized.add( item ); - } - else if ( item instanceof Repository ) - { - Repository repo = (Repository) item; - item = buildArtifactRepository( repo ); - - normalized.add( item ); - normalizationNeeded = true; - } - else - { - throw new InvalidRepositoryException( projectId, "Error building artifact repository from non-repository information item: " + item ); - } - } - - if ( normalizationNeeded ) - { - return normalized; - } - else - { - return remoteArtifactRepositories; - } - } - private String safeVersionlessKey( String groupId, String artifactId ) { String gid = groupId; diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MirrorBuilder.java b/maven-repository/src/main/java/org/apache/maven/repository/MirrorBuilder.java index a37d3e5bf9..d1a0ec6f02 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MirrorBuilder.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MirrorBuilder.java @@ -1,8 +1,6 @@ package org.apache.maven.repository; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import org.apache.maven.artifact.repository.ArtifactRepository;