mirror of https://github.com/apache/maven.git
PR: MNG-249
also recognise transitive projects git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e26eecde45
commit
5d82fcb8a6
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>test-component-a</module>
|
||||
<module>test-component-c</module>
|
||||
<module>test-component-b</module>
|
||||
<module>test-component-a</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<artifactId>test-component-b</artifactId>
|
||||
<version>0.1</version>
|
||||
<name>Test Component B</name>
|
||||
<packaging>war</packaging>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>test-components</artifactId>
|
||||
<groupId>test</groupId>
|
||||
<version>0.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>test</groupId>
|
||||
<artifactId>test-component-c</artifactId>
|
||||
<version>0.1</version>
|
||||
<name>Test Component C</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>test-component-b</artifactId>
|
||||
<version>0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,5 @@
|
|||
public class C
|
||||
extends A
|
||||
{
|
||||
}
|
||||
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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. <p/>
|
||||
|
@ -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 )
|
||||
|
|
|
@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @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 );
|
||||
}
|
||||
}
|
|
@ -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 <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue