Author: jdcasey
Date: Tue Jul 8 19:23:29 2008
New Revision: 675087
URL: http://svn.apache.org/viewvc?rev=675087&view=rev
Log:
[MNG-3380] Process relocations before child-nodes are discovered during
artifact collection.
Modified:
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
Modified:
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java
Tue Jul 8 19:23:29 2008
@@ -130,6 +130,14 @@
{
throw new UnsupportedOperationException( "Cannot get available
versions in this test case" );
}
+
+ public Artifact retrieveRelocatedArtifact( Artifact artifact,
+ ArtifactRepository
localRepository,
+ List remoteRepositories
)
+ throws ArtifactMetadataRetrievalException
+ {
+ return artifact;
+ }
};
ArtifactResolutionResult result =
artifactResolver.resolveTransitively( Collections.singleton( g ),
@@ -186,6 +194,14 @@
{
throw new UnsupportedOperationException( "Cannot get available
versions in this test case" );
}
+
+ public Artifact retrieveRelocatedArtifact( Artifact artifact,
+ ArtifactRepository
localRepository,
+ List remoteRepositories
)
+ throws ArtifactMetadataRetrievalException
+ {
+ return artifact;
+ }
};
ArtifactResolutionResult result =
artifactResolver.resolveTransitively( Collections.singleton( i ),
Modified:
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java
Tue Jul 8 19:23:29 2008
@@ -28,7 +28,7 @@
/**
* Provides some metadata operations, like querying the remote repository for
a list of versions available for an
* artifact.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl </a>
* @version $Id$
*/
@@ -40,10 +40,16 @@
throws ArtifactMetadataRetrievalException;
/**
+ * Resolve all relocations in the POM for this artifact, and return the
new artifact coordinate.
+ */
+ Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository
localRepository, List remoteRepositories )
+ throws ArtifactMetadataRetrievalException;
+
+ /**
* Get a list of available versions for an artifact in the remote
repository
- *
+ *
* @param artifact artifact we are interested in. Only
<code>groupid</code> and <code>artifactId</code>
- * are needed, for instance the following code will work
+ * are needed, for instance the following code will work
* <code>artifactFactory.createProjectArtifact(
"org.apache.maven", "maven", "" )</code>
* @param localRepository local repository
* @param remoteRepositories remote repositories, [EMAIL PROTECTED] List}
$lt; [EMAIL PROTECTED] ArtifactRepository} >
Modified:
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
Tue Jul 8 19:23:29 2008
@@ -296,88 +296,101 @@
List childRemoteRepositories =
child.getRemoteRepositories();
try
{
- Object childKey = child.getKey();
- if ( managedVersions.containsKey( childKey ) )
+ Object childKey;
+ do
{
- // If this child node is a managed dependency,
ensure
- // we are using the dependency management version
- // of this child if applicable b/c we want to use
the
- // managed version's POM, *not* any other
version's POM.
- // We retrieve the POM below in the retrieval step.
- manageArtifact( child, managedVersions, listeners
);
-
- // Also, we need to ensure that any exclusions it
presents are
- // added to the artifact before we retrieve the
metadata
- // for the artifact; otherwise we may end up with
unwanted
- // dependencies.
- Artifact ma = (Artifact) managedVersions.get(
childKey );
- ArtifactFilter managedExclusionFilter =
ma.getDependencyFilter();
- if ( null != managedExclusionFilter )
+ childKey = child.getKey();
+
+ if ( managedVersions.containsKey( childKey ) )
{
- if ( null != artifact.getDependencyFilter() )
- {
- AndArtifactFilter aaf = new
AndArtifactFilter();
- aaf.add( artifact.getDependencyFilter() );
- aaf.add( managedExclusionFilter );
- artifact.setDependencyFilter( aaf );
- }
- else
+ // If this child node is a managed dependency,
ensure
+ // we are using the dependency management
version
+ // of this child if applicable b/c we want to
use the
+ // managed version's POM, *not* any other
version's POM.
+ // We retrieve the POM below in the retrieval
step.
+ manageArtifact( child, managedVersions,
listeners );
+
+ // Also, we need to ensure that any exclusions
it presents are
+ // added to the artifact before we retrieve
the metadata
+ // for the artifact; otherwise we may end up
with unwanted
+ // dependencies.
+ Artifact ma = (Artifact) managedVersions.get(
childKey );
+ ArtifactFilter managedExclusionFilter =
ma.getDependencyFilter();
+ if ( null != managedExclusionFilter )
{
- artifact.setDependencyFilter(
managedExclusionFilter );
+ if ( null !=
artifact.getDependencyFilter() )
+ {
+ AndArtifactFilter aaf = new
AndArtifactFilter();
+ aaf.add(
artifact.getDependencyFilter() );
+ aaf.add( managedExclusionFilter );
+ artifact.setDependencyFilter( aaf );
+ }
+ else
+ {
+ artifact.setDependencyFilter(
managedExclusionFilter );
+ }
}
}
- }
- if ( artifact.getVersion() == null )
- {
- // set the recommended version
- // TODO: maybe its better to just pass the range
through to retrieval and use a transformation?
- ArtifactVersion version;
- if ( artifact.isSelectedVersionKnown() )
- {
- version = artifact.getSelectedVersion();
- }
- else
+ if ( artifact.getVersion() == null )
{
- //go find the version
- List versions =
artifact.getAvailableVersions();
- if ( versions == null )
+ // set the recommended version
+ // TODO: maybe its better to just pass the
range through to retrieval and use a transformation?
+ ArtifactVersion version;
+ if ( artifact.isSelectedVersionKnown() )
{
- versions =
source.retrieveAvailableVersions( artifact, localRepository,
-
childRemoteRepositories );
- artifact.setAvailableVersions( versions );
+ version = artifact.getSelectedVersion();
}
+ else
+ {
+ //go find the version
+ List versions =
artifact.getAvailableVersions();
+ if ( versions == null )
+ {
+ versions =
source.retrieveAvailableVersions( artifact, localRepository,
+
childRemoteRepositories );
+ artifact.setAvailableVersions(
versions );
+ }
- Collections.sort( versions );
-
- VersionRange versionRange =
artifact.getVersionRange();
+ Collections.sort( versions );
- version = versionRange.matchVersion( versions
);
+ VersionRange versionRange =
artifact.getVersionRange();
- if ( version == null )
- {
- // Getting the dependency trail so it can
be logged in the exception
- artifact.setDependencyTrail(
node.getDependencyTrail() );
+ version = versionRange.matchVersion(
versions );
- if ( versions.isEmpty() )
+ if ( version == null )
{
- throw new
OverConstrainedVersionException(
- "No versions are present in the
repository for the artifact with a range " +
- versionRange, artifact,
childRemoteRepositories );
- }
+ // Getting the dependency trail so it
can be logged in the exception
+ artifact.setDependencyTrail(
node.getDependencyTrail() );
- throw new OverConstrainedVersionException(
"Couldn't find a version in " +
- versions + " to match range " +
versionRange, artifact,
- childRemoteRepositories );
+ if ( versions.isEmpty() )
+ {
+ throw new
OverConstrainedVersionException(
+ "No versions are present in
the repository for the artifact with a range " +
+ versionRange, artifact,
childRemoteRepositories );
+ }
+
+ throw new
OverConstrainedVersionException( "Couldn't find a version in " +
+ versions + " to match range " +
versionRange, artifact,
+ childRemoteRepositories );
+ }
}
+
+ //this is dangerous because
artifact.getSelectedVersion() can
+ //return null. However it is ok here because
we first check if the
+ //selected version is known. As currently
coded we can't get a null here.
+ artifact.selectVersion( version.toString() );
+ fireEvent(
ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
}
- //this is dangerous because
artifact.getSelectedVersion() can
- //return null. However it is ok here because we
first check if the
- //selected version is known. As currently coded we
can't get a null here.
- artifact.selectVersion( version.toString() );
- fireEvent(
ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
+ Artifact relocated =
source.retrieveRelocatedArtifact( artifact, localRepository,
childRemoteRepositories );
+ if ( !artifact.equals( relocated ) )
+ {
+ artifact = relocated;
+ child.setArtifact( artifact );
+ }
}
+ while( !childKey.equals( child.getKey() ) );
artifact.setDependencyTrail( node.getDependencyTrail()
);
ResolutionGroup rGroup = source.retrieve( artifact,
localRepository, childRemoteRepositories );
Modified:
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
Tue Jul 8 19:23:29 2008
@@ -19,6 +19,11 @@
* under the License.
*/
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -26,14 +31,9 @@
import java.util.List;
import java.util.Set;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
-
public class ResolutionNode
{
- private final Artifact artifact;
+ private Artifact artifact;
private List children;
@@ -53,22 +53,27 @@
{
this.artifact = artifact;
this.remoteRepositories = remoteRepositories;
- this.depth = 0;
- this.parents = Collections.EMPTY_LIST;
- this.parent = null;
+ depth = 0;
+ parents = Collections.EMPTY_LIST;
+ parent = null;
}
public ResolutionNode( Artifact artifact, List remoteRepositories,
ResolutionNode parent )
{
this.artifact = artifact;
this.remoteRepositories = remoteRepositories;
- this.depth = parent.depth + 1;
- this.parents = new ArrayList();
- this.parents.addAll( parent.parents );
- this.parents.add( parent.getKey() );
+ depth = parent.depth + 1;
+ parents = new ArrayList();
+ parents.addAll( parent.parents );
+ parents.add( parent.getKey() );
this.parent = parent;
}
+ public void setArtifact( Artifact artifact )
+ {
+ this.artifact = artifact;
+ }
+
public Artifact getArtifact()
{
return artifact;
@@ -142,13 +147,13 @@
//MNG-2123: null is a valid response to
getSelectedVersion, don't
//assume it won't ever be.
if (selected != null)
- {
+ {
artifact.selectVersion( selected.toString() );
}
else
{
throw new OverConstrainedVersionException("Unable to
get a selected Version for "+ artifact.getArtifactId(),artifact);
- }
+ }
}
ids.add( 0, artifact );
@@ -191,7 +196,7 @@
public void enable()
{
- this.active = true;
+ active = true;
// TODO: if it was null, we really need to go find them now... or is
this taken care of by the ordering?
if ( children != null )
{
@@ -205,7 +210,7 @@
public void disable()
{
- this.active = false;
+ active = false;
if ( children != null )
{
for ( Iterator i = children.iterator(); i.hasNext(); )
Modified:
maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Tue Jul 8 19:23:29 2008
@@ -1061,5 +1061,13 @@
artifactVersions.add( new DefaultArtifactVersion(
spec.artifact.getVersion() ) );
}
}
+
+ public Artifact retrieveRelocatedArtifact( Artifact artifact,
+ ArtifactRepository
localRepository,
+ List remoteRepositories )
+ throws ArtifactMetadataRetrievalException
+ {
+ return artifact;
+ }
}
}
Modified:
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Tue Jul 8 19:23:29 2008
@@ -78,11 +78,52 @@
private MavenProject superProject;
/**
- * Retrieve the metadata for the project from the repository.
- * Uses the ProjectBuilder, to enable post-processing and inheritance
calculation before retrieving the
- * associated artifacts.
+ * Resolve all relocations in the POM for this artifact, and return the
new artifact coordinate.
*/
- public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository
localRepository, List remoteRepositories )
+ public Artifact retrieveRelocatedArtifact( Artifact artifact,
ArtifactRepository localRepository, List remoteRepositories )
+ throws ArtifactMetadataRetrievalException
+ {
+ if ( artifact instanceof ActiveProjectArtifact )
+ {
+ return artifact;
+ }
+
+ MavenProject project = retrieveRelocatedProject( artifact,
localRepository, remoteRepositories );
+
+ if ( project == null || getRelocationKey( artifact ).equals(
getRelocationKey( project.getArtifact() ) ) )
+ {
+ return artifact;
+ }
+
+ Artifact result = null;
+ if ( artifact.getClassifier() != null )
+ {
+ result = artifactFactory.createArtifactWithClassifier(
project.getGroupId(), project.getArtifactId(), project.getVersion(),
artifact.getType(), artifact.getClassifier() );
+ }
+ else
+ {
+ result = artifactFactory.createArtifact( project.getGroupId(),
project.getArtifactId(), project.getVersion(), artifact.getScope(),
artifact.getType() );
+ }
+
+ result.setResolved( artifact.isResolved() );
+ result.setFile( artifact.getFile() );
+
+ result.setScope( artifact.getScope() );
+ result.setArtifactHandler( artifact.getArtifactHandler() );
+ result.setDependencyFilter( artifact.getDependencyFilter() );
+ result.setDependencyTrail( artifact.getDependencyTrail() );
+ result.setOptional( artifact.isOptional() );
+ result.setRelease( artifact.isRelease() );
+
+ return result;
+ }
+
+ private String getRelocationKey( Artifact artifact )
+ {
+ return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
artifact.getVersion();
+ }
+
+ private MavenProject retrieveRelocatedProject( Artifact artifact,
ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException
{
MavenProject project = null;
@@ -154,15 +195,18 @@
if ( relocation.getGroupId() != null )
{
artifact.setGroupId( relocation.getGroupId() );
+ project.setGroupId( relocation.getGroupId() );
}
if ( relocation.getArtifactId() != null )
{
artifact.setArtifactId( relocation.getArtifactId()
);
+ project.setArtifactId( relocation.getArtifactId()
);
}
if ( relocation.getVersion() != null )
{
//note: see MNG-3454. This causes a problem, but
fixing it may break more.
artifact.setVersionRange(
VersionRange.createFromVersion( relocation.getVersion() ) );
+ project.setVersion( relocation.getVersion() );
}
if ( artifact.getDependencyFilter() != null &&
@@ -213,8 +257,34 @@
}
while ( !done );
+ return project;
+ }
+
+ /**
+ * Retrieve the metadata for the project from the repository.
+ * Uses the ProjectBuilder, to enable post-processing and inheritance
calculation before retrieving the
+ * associated artifacts.
+ */
+ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository
localRepository, List remoteRepositories )
+ throws ArtifactMetadataRetrievalException
+ {
+ MavenProject project = retrieveRelocatedProject( artifact,
localRepository, remoteRepositories );
+ Artifact pomArtifact;
+ if ( project != null )
+ {
+ pomArtifact = project.getArtifact();
+ }
+ else
+ {
+ pomArtifact = artifactFactory.createProjectArtifact(
artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getScope() );
+ }
+
+
// last ditch effort to try to get this set...
- if ( artifact.getDownloadUrl() == null )
+ if ( artifact.getDownloadUrl() == null && pomArtifact != null )
{
// TODO: this could come straight from the project, negating the
need to set it in the project itself?
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
Modified:
maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
URL:
http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java?rev=675087&r1=675086&r2=675087&view=diff
==============================================================================
---
maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
(original)
+++
maven/components/branches/maven-2.0.x/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java
Tue Jul 8 19:23:29 2008
@@ -178,6 +178,14 @@
return projectArtifacts;
}
+
+ public Artifact retrieveRelocatedArtifact( Artifact artifact,
+ ArtifactRepository
localRepository,
+ List remoteRepositories )
+ throws ArtifactMetadataRetrievalException
+ {
+ return artifact;
+ }
}
public Source source()
@@ -215,7 +223,7 @@
public void contextualize( Context context )
throws ContextException
{
- this.container = (PlexusContainer) context.get(
PlexusConstants.PLEXUS_KEY );
+ container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY
);
}
}
\ No newline at end of file