diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 195c25e01c..df75a6a138 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -68,6 +68,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.artifact.ActiveProjectArtifact; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.artifact.MavenMetadataSource; +import org.apache.maven.repository.MavenRepositoryWrapper; import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -87,7 +88,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; * */ public class MavenProject - implements Cloneable + implements Cloneable, MavenRepositoryWrapper { public static final String EMPTY_PROJECT_GROUP_ID = "unknown"; @@ -1705,6 +1706,11 @@ public class MavenProject { return getBuild() != null ? getBuild().getDefaultGoal() : null; } + + public Artifact find( Artifact artifact ) + { + return replaceWithActiveArtifact( artifact ); + } public Artifact replaceWithActiveArtifact( Artifact pluginArtifact ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 8c68719e29..c56e87739c 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -55,6 +55,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.validation.ModelValidationResult; +import org.apache.maven.repository.MavenRepositoryWrapper; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -461,7 +462,7 @@ public class MavenMetadataSource List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, - MavenProject project ) + MavenRepositoryWrapper reactor ) throws InvalidDependencyVersionException { Set projectArtifacts = new LinkedHashSet( dependencies.size() ); @@ -486,7 +487,7 @@ public class MavenMetadataSource } catch ( InvalidVersionSpecificationException e ) { - throw new InvalidDependencyVersionException( project.getId(), d, project.getFile(), e ); + throw new InvalidDependencyVersionException( reactor.getId(), d, reactor.getFile(), e ); } Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), @@ -527,9 +528,9 @@ public class MavenMetadataSource artifact.setDependencyFilter( artifactFilter ); - if ( project != null ) + if ( reactor != null ) { - artifact = project.replaceWithActiveArtifact( artifact ); + artifact = reactor.find( artifact ); } projectArtifacts.add( artifact ); diff --git a/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java index 86d7f7a8a8..39206f4395 100644 --- a/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java +++ b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java @@ -181,7 +181,7 @@ public class LegacyMavenRepositorySystem return artifactFactory.createPluginArtifact( groupId, artifactId, versionRange ); } - public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project ) + public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper project ) throws InvalidDependencyVersionException { return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, project ); diff --git a/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java index 1d35b4a95f..b76129705a 100644 --- a/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java +++ b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java @@ -63,7 +63,7 @@ public interface MavenRepositorySystem Artifact createDependencyArtifact( String groupId, String artifactId, String version, String type, String classifier, String scope, String inheritedScope ); - Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project ) + Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) throws InvalidDependencyVersionException; // Repository creation diff --git a/maven-project/src/main/java/org/apache/maven/repository/MavenRepositoryWrapper.java b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositoryWrapper.java new file mode 100644 index 0000000000..590b082dd9 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositoryWrapper.java @@ -0,0 +1,53 @@ +/* +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. +*/ + +package org.apache.maven.repository; + +import java.io.File; + +import org.apache.maven.artifact.Artifact; + +/** + * small repository implementation used to find artifact in a local source + * instead of going out to the real repo. Used to search reactor for matches + * + * @author Oleg Gusakov + * @version $Id$ + * + */ +public interface MavenRepositoryWrapper +{ + /** + * finds supplied artifact, if any, in the wrapped source + * + * @param artifact + * @return + */ + Artifact find( Artifact artifact ); + + /** + * @return + */ + String getId(); + + /** + * @return + */ + File getFile(); +}