diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
index ed8dfbdac9..3f2c336203 100755
--- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
+++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
@@ -17,9 +17,9 @@ package org.apache.maven.artifact.ant;
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -100,7 +100,7 @@ public class DependenciesTask
Set artifacts;
try
{
- artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
+ artifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null );
}
catch ( InvalidVersionSpecificationException e )
{
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
index 561ec2feba..5b0179f2b7 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
@@ -30,7 +30,7 @@ import java.util.Set;
public class ResolutionNode
{
- private Artifact artifact;
+ private final Artifact artifact;
private List children;
@@ -132,11 +132,6 @@ public class ResolutionNode
return depth;
}
- public void setArtifact( Artifact artifact )
- {
- this.artifact = artifact;
- }
-
public List getRemoteRepositories()
{
return remoteRepositories;
diff --git a/maven-core-it/it0042/expected-results.txt b/maven-core-it/it0042/expected-results.txt
index 2e02d60148..ee6dd9841f 100644
--- a/maven-core-it/it0042/expected-results.txt
+++ b/maven-core-it/it0042/expected-results.txt
@@ -1,3 +1,5 @@
test-component-a/target/test-component-a-0.1.jar
-test-component-b/target/test-component-b-0.1.war
-test-component-b/target/test-component-b-0.1.war!/WEB-INF/lib/test-component-a-0.1.jar
+test-component-b/target/test-component-b-0.1.jar
+test-component-c/target/test-component-c-0.1.war
+test-component-c/target/test-component-c-0.1.war!/WEB-INF/lib/test-component-a-0.1.jar
+test-component-c/target/test-component-c-0.1.war!/WEB-INF/lib/test-component-b-0.1.jar
diff --git a/maven-core-it/it0042/pom.xml b/maven-core-it/it0042/pom.xml
index 725ef78be1..cb0f012490 100644
--- a/maven-core-it/it0042/pom.xml
+++ b/maven-core-it/it0042/pom.xml
@@ -7,7 +7,8 @@
pom
- test-component-a
+ test-component-c
test-component-b
+ test-component-a
diff --git a/maven-core-it/it0042/test-component-b/pom.xml b/maven-core-it/it0042/test-component-b/pom.xml
index d08fc00af8..64745ad784 100644
--- a/maven-core-it/it0042/test-component-b/pom.xml
+++ b/maven-core-it/it0042/test-component-b/pom.xml
@@ -10,7 +10,7 @@
test-component-b
0.1
Test Component B
- war
+ jar
diff --git a/maven-core-it/it0042/test-component-c/pom.xml b/maven-core-it/it0042/test-component-c/pom.xml
new file mode 100644
index 0000000000..9dfa703d73
--- /dev/null
+++ b/maven-core-it/it0042/test-component-c/pom.xml
@@ -0,0 +1,22 @@
+
+ 4.0.0
+
+ test-components
+ test
+ 0.1
+
+
+ test
+ test-component-c
+ 0.1
+ Test Component C
+ war
+
+
+
+ test
+ test-component-b
+ 0.1
+
+
+
diff --git a/maven-core-it/it0042/test-component-c/src/main/java/C.java b/maven-core-it/it0042/test-component-c/src/main/java/C.java
new file mode 100644
index 0000000000..f7546a58a7
--- /dev/null
+++ b/maven-core-it/it0042/test-component-c/src/main/java/C.java
@@ -0,0 +1,5 @@
+public class C
+ extends A
+{
+}
+
diff --git a/maven-core-it/it0042/test-component-b/src/main/webapp/WEB-INF/web.xml b/maven-core-it/it0042/test-component-c/src/main/webapp/WEB-INF/web.xml
similarity index 100%
rename from maven-core-it/it0042/test-component-b/src/main/webapp/WEB-INF/web.xml
rename to maven-core-it/it0042/test-component-c/src/main/webapp/WEB-INF/web.xml
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
index 000f043db9..96cf7ab216 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
@@ -1051,7 +1051,7 @@ public class DefaultPluginManager
// check this with yourkit as a hot spot.
try
{
- project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
+ project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidVersionSpecificationException e )
{
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 89dd16f897..56e813cc66 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
@@ -115,6 +115,8 @@ public class DefaultMavenProjectBuilder
public static final String MAVEN_MODEL_VERSION = "4.0.0";
+ private Map projectCache = new HashMap();
+
public void initialize()
{
modelReader = new MavenXpp3Reader();
@@ -154,7 +156,7 @@ public class DefaultMavenProjectBuilder
try
{
- project.setDependencyArtifacts( project.createArtifacts( artifactFactory ) );
+ project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidVersionSpecificationException e )
{
@@ -261,6 +263,13 @@ public class DefaultMavenProjectBuilder
ArtifactRepository localRepository )
throws ProjectBuildingException
{
+ String cacheKey = createCacheKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
+ MavenProject project = (MavenProject) projectCache.get( cacheKey );
+ if ( project != null )
+ {
+ return project;
+ }
+
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories,
@@ -416,6 +425,8 @@ public class DefaultMavenProjectBuilder
throw new ProjectBuildingException( "Error building project from \'" + pomLocation + "\': " + model.getId(),
e );
}
+ projectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ),
+ project );
return project;
}
@@ -770,11 +781,11 @@ public class DefaultMavenProjectBuilder
version = p.getVersion();
}
- Artifact artifact = null;
+ Artifact artifact;
try
{
- artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), VersionRange
- .createFromVersionSpec( version ) );
+ artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(),
+ VersionRange.createFromVersionSpec( version ) );
}
catch ( InvalidVersionSpecificationException e )
{
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 abc3f6de14..1b742c71da 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
@@ -21,6 +21,7 @@ import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
@@ -53,12 +54,12 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-import java.util.HashSet;
/**
* The concern of the project is provide runtime values based on the model.
@@ -1230,32 +1231,11 @@ public class MavenProject
/**
* @todo the lazy initialisation of this makes me uneasy.
*/
- public Set createArtifacts( ArtifactFactory artifactFactory )
+ public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedScope,
+ ArtifactFilter dependencyFilter )
throws InvalidVersionSpecificationException
{
- Set artifacts = new HashSet( getDependencies().size() );
-
- List list = new ArrayList( getDependencies().size() );
- for ( Iterator i = getDependencies().iterator(); i.hasNext(); )
- {
- Dependency dependency = (Dependency) i.next();
- String refId = getProjectReferenceId( dependency.getGroupId(), dependency.getArtifactId() );
- MavenProject project = (MavenProject) projectReferences.get( refId );
- if ( project != null && project.getArtifact() != null )
- {
- // TODO: actually these need to be funnelled through the same process and the artifacts cloned somehow
- project.getArtifact().setScope( dependency.getScope() );
- artifacts.add( project.getArtifact() );
- }
- else
- {
- list.add( dependency );
- }
- }
-
- artifacts.addAll( MavenMetadataSource.createArtifacts( artifactFactory, list, null, null ) );
-
- return artifacts;
+ return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), null, null, projectReferences );
}
public void addProjectReference( MavenProject project )
diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
new file mode 100644
index 0000000000..de9c50c226
--- /dev/null
+++ b/maven-project/src/main/java/org/apache/maven/project/artifact/ActiveProjectArtifact.java
@@ -0,0 +1,223 @@
+package org.apache.maven.project.artifact;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Wraps an active project instance to be able to receive updates from its artifact without affecting the original
+ * attributes of this artifact.
+ *
+ * @todo I think this exposes a design flaw in that the immutable and mutable parts of an artifact are in one class and
+ * should be split. ie scope, file, etc depend on the context of use, whereas everything else is immutable.
+ *
+ * @author Brett Porter
+ * @version $Id$
+ */
+public class ActiveProjectArtifact
+ implements Artifact
+{
+ private final Artifact artifact;
+
+ private final MavenProject project;
+
+ public ActiveProjectArtifact( MavenProject project, Artifact artifact )
+ {
+ this.artifact = artifact;
+ this.project = project;
+ }
+
+ public File getFile()
+ {
+ // we need to get the latest file for the project, not the artifact that was created at one point in time
+ return project.getArtifact().getFile();
+ }
+
+ public String getGroupId()
+ {
+ return artifact.getGroupId();
+ }
+
+ public String getArtifactId()
+ {
+ return artifact.getArtifactId();
+ }
+
+ public String getVersion()
+ {
+ return artifact.getVersion();
+ }
+
+ public void setVersion( String version )
+ {
+ artifact.setVersion( version );
+ }
+
+ public String getScope()
+ {
+ return artifact.getScope();
+ }
+
+ public String getType()
+ {
+ return artifact.getType();
+ }
+
+ public String getClassifier()
+ {
+ return artifact.getClassifier();
+ }
+
+ public boolean hasClassifier()
+ {
+ return artifact.hasClassifier();
+ }
+
+ public void setFile( File destination )
+ {
+ artifact.setFile( destination );
+ }
+
+ public String getBaseVersion()
+ {
+ return artifact.getBaseVersion();
+ }
+
+ public void setBaseVersion( String baseVersion )
+ {
+ artifact.setBaseVersion( baseVersion );
+ }
+
+ public String getId()
+ {
+ return artifact.getId();
+ }
+
+ public String getDependencyConflictId()
+ {
+ return artifact.getDependencyConflictId();
+ }
+
+ public void addMetadata( ArtifactMetadata metadata )
+ {
+ artifact.addMetadata( metadata );
+ }
+
+ public List getMetadataList()
+ {
+ return artifact.getMetadataList();
+ }
+
+ public void setRepository( ArtifactRepository remoteRepository )
+ {
+ artifact.setRepository( remoteRepository );
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return artifact.getRepository();
+ }
+
+ public void updateVersion( String version, ArtifactRepository localRepository )
+ {
+ artifact.updateVersion( version, localRepository );
+ }
+
+ public String getDownloadUrl()
+ {
+ return artifact.getDownloadUrl();
+ }
+
+ public void setDownloadUrl( String downloadUrl )
+ {
+ artifact.setDownloadUrl( downloadUrl );
+ }
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ return artifact.getDependencyFilter();
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+ artifact.setDependencyFilter( artifactFilter );
+ }
+
+ public ArtifactHandler getArtifactHandler()
+ {
+ return artifact.getArtifactHandler();
+ }
+
+ public List getDependencyTrail()
+ {
+ return artifact.getDependencyTrail();
+ }
+
+ public void setDependencyTrail( List dependencyTrail )
+ {
+ artifact.setDependencyTrail( dependencyTrail );
+ }
+
+ public void setScope( String scope )
+ {
+ artifact.setScope( scope );
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return artifact.getVersionRange();
+ }
+
+ public void setVersionRange( VersionRange newRange )
+ {
+ artifact.setVersionRange( newRange );
+ }
+
+ public void selectVersion( String version )
+ {
+ artifact.selectVersion( version );
+ }
+
+ public void setGroupId( String groupId )
+ {
+ artifact.setGroupId( groupId );
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ artifact.setArtifactId( artifactId );
+ }
+
+ public boolean isSnapshot()
+ {
+ return artifact.isSnapshot();
+ }
+
+ public int compareTo( Object o )
+ {
+ return artifact.compareTo( o );
+ }
+}
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 cbaf3fb606..77124c8656 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
@@ -41,6 +41,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.Map;
/**
* @author Jason van Zyl
@@ -65,7 +66,7 @@ public class MavenMetadataSource
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
- MavenProject p;
+ MavenProject project;
Artifact pomArtifact;
boolean done = false;
@@ -77,7 +78,7 @@ public class MavenMetadataSource
try
{
- p = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
+ project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
}
catch ( ProjectBuildingException e )
{
@@ -86,7 +87,7 @@ public class MavenMetadataSource
Relocation relocation = null;
- DistributionManagement distMgmt = p.getDistributionManagement();
+ DistributionManagement distMgmt = project.getDistributionManagement();
if ( distMgmt != null )
{
relocation = distMgmt.getRelocation();
@@ -128,12 +129,12 @@ public class MavenMetadataSource
try
{
- // TODO: we could possibly use p.getDependencyArtifacts instead, but they haven't been filtered or used the
- // scope (should that be passed to the buildFromRepository method above?
- Set artifacts = createArtifacts( artifactFactory, p.getDependencies(), artifact.getScope(),
- artifact.getDependencyFilter() );
+ // TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered
+ // or used the inherited scope (should that be passed to the buildFromRepository method above?)
+ Set artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
+ artifact.getDependencyFilter() );
- return new ResolutionGroup( pomArtifact, artifacts, p.getRemoteArtifactRepositories() );
+ return new ResolutionGroup( pomArtifact, artifacts, project.getRemoteArtifactRepositories() );
}
catch ( InvalidVersionSpecificationException e )
{
@@ -142,10 +143,10 @@ public class MavenMetadataSource
}
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
- ArtifactFilter dependencyFilter )
+ ArtifactFilter dependencyFilter, Map projectReferences )
throws InvalidVersionSpecificationException
{
- Set projectArtifacts = new HashSet();
+ Set projectArtifacts = new HashSet( dependencies.size() );
for ( Iterator i = dependencies.iterator(); i.hasNext(); )
{
@@ -184,6 +185,17 @@ public class MavenMetadataSource
artifact.setDependencyFilter( dependencyFilter );
+ if ( projectReferences != null )
+ {
+ // TODO: use MavenProject getProjectReferenceId
+ String refId = d.getGroupId() + ":" + d.getArtifactId();
+ MavenProject project = (MavenProject) projectReferences.get( refId );
+ if ( project != null && project.getArtifact() != null )
+ {
+ artifact = new ActiveProjectArtifact( project, artifact );
+ }
+ }
+
projectArtifacts.add( artifact );
}
}