PR: MNG-505

prepare for version ranges in the artifact collector

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219833 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-20 02:27:18 +00:00
parent 1e8e1d21ff
commit d5e54a5744
2 changed files with 33 additions and 27 deletions

View File

@ -40,11 +40,6 @@ public class DefaultArtifact
private final String artifactId;
/**
* The resolved version for the artifact after conflict resolution and all transformations.
*/
private String version;
/**
* The resolved version for the artifact after conflict resolution, that has not been transformed.
*
@ -72,6 +67,10 @@ public class DefaultArtifact
private List dependencyTrail;
private String version;
private VersionRange versionRange;
public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type,
String classifier, ArtifactHandler artifactHandler )
{
@ -79,8 +78,9 @@ public class DefaultArtifact
this.artifactId = artifactId;
// TODO: this would be where we might have a min/max instead
this.version = versionRange != null ? versionRange.getRecommendedVersion().toString() : null;
this.versionRange = versionRange;
this.version = versionRange == null ? null : versionRange.getRecommendedVersion().toString();
this.artifactHandler = artifactHandler;
@ -97,23 +97,26 @@ public class DefaultArtifact
{
if ( empty( groupId ) )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The groupId cannot be empty." );
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
"The groupId cannot be empty." );
}
if ( artifactId == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type,
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
"The artifactId cannot be empty." );
}
if ( type == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The type cannot be empty." );
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
"The type cannot be empty." );
}
if ( version == null )
if ( getVersion() == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The version cannot be empty." );
throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type,
"The version cannot be empty." );
}
}
@ -155,6 +158,7 @@ public class DefaultArtifact
public void setVersion( String version )
{
this.version = version;
this.versionRange = null;
}
public String getType()
@ -264,6 +268,9 @@ public class DefaultArtifact
{
return false;
}
// We don't consider the version range in the comparison, just the resolved version
return true;
}
@ -319,6 +326,7 @@ public class DefaultArtifact
}
if ( result == 0 )
{
// We don't consider the version range in the comparison, just the resolved version
result = version.compareTo( a.getVersion() );
}
}

View File

@ -70,7 +70,7 @@ public class DefaultArtifactCollector
for ( Iterator i = resolvedArtifacts.values().iterator(); i.hasNext(); )
{
ResolutionNode node = (ResolutionNode) i.next();
if ( node != root )
if ( !node.equals( root ) )
{
Artifact artifact = node.getArtifact();
@ -120,11 +120,11 @@ public class DefaultArtifactCollector
// previous one is more dominant
if ( previous.getDepth() <= node.getDepth() )
{
checkScopeUpdate( node, previous, artifactFactory, listeners );
checkScopeUpdate( node, previous, listeners );
}
else
{
checkScopeUpdate( previous, node, artifactFactory, listeners );
checkScopeUpdate( previous, node, listeners );
}
if ( previous.getDepth() <= node.getDepth() )
@ -147,14 +147,15 @@ public class DefaultArtifactCollector
{
try
{
ResolutionGroup rGroup = source.retrieve( child.getArtifact(), localRepository, remoteRepositories );
ResolutionGroup rGroup = source.retrieve( child.getArtifact(), localRepository,
remoteRepositories );
child.addDependencies( rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter );
}
catch ( CyclicDependencyException e )
{
// would like to throw this, but we have crappy stuff in the repo
// no logger to use here either just now
// TODO: should the remoteRepositories list be null here?!
fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners,
new ResolutionNode( e.getArtifact(), null, child ) );
@ -174,15 +175,14 @@ public class DefaultArtifactCollector
fireEvent( ResolutionListener.FINISH_PROCESSING_CHILDREN, listeners, node );
}
private void checkScopeUpdate( ResolutionNode node, ResolutionNode previous, ArtifactFactory artifactFactory,
List listeners )
private void checkScopeUpdate( ResolutionNode node, ResolutionNode previous, List listeners )
{
boolean updateScope = false;
Artifact newArtifact = node.getArtifact();
Artifact previousArtifact = previous.getArtifact();
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) &&
( Artifact.SCOPE_TEST.equals( previousArtifact.getScope() ) ||
if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) && (
Artifact.SCOPE_TEST.equals( previousArtifact.getScope() ) ||
Artifact.SCOPE_PROVIDED.equals( previousArtifact.getScope() ) ) )
{
updateScope = true;
@ -198,12 +198,10 @@ public class DefaultArtifactCollector
{
fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, previous, newArtifact );
Artifact artifact = artifactFactory.createArtifact( previousArtifact.getGroupId(),
previousArtifact.getArtifactId(),
previousArtifact.getVersion(), newArtifact.getScope(),
previousArtifact.getType() );
// TODO: can I just change the scope?
previous.setArtifact( artifact );
// previously we cloned the artifact, but it is more effecient to just update the scope
// if problems are later discovered that the original object needs its original scope value, cloning may
// again be appropriate
previousArtifact.setScope( newArtifact.getScope() );
}
}