Author: brett
Date: Tue Jul 19 19:27:18 2005
New Revision: 219833

URL: http://svn.apache.org/viewcvs?rev=219833&view=rev
Log:
PR: MNG-505
prepare for version ranges in the artifact collector

Modified:
    
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
    
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java

Modified: 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?rev=219833&r1=219832&r2=219833&view=diff
==============================================================================
--- 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
 (original)
+++ 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
 Tue Jul 19 19:27:18 2005
@@ -41,11 +41,6 @@
     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.
      *
      * @todo should be final
@@ -72,6 +67,10 @@
 
     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 @@
 
         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 @@
     {
         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 void setVersion( String version )
     {
         this.version = version;
+        this.versionRange = null;
     }
 
     public String getType()
@@ -264,6 +268,9 @@
         {
             return false;
         }
+
+        // We don't consider the version range in the comparison, just the 
resolved version
+
         return true;
     }
 
@@ -319,6 +326,7 @@
                     }
                     if ( result == 0 )
                     {
+                        // We don't consider the version range in the 
comparison, just the resolved version
                         result = version.compareTo( a.getVersion() );
                     }
                 }

Modified: 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
URL: 
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=219833&r1=219832&r2=219833&view=diff
==============================================================================
--- 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
 (original)
+++ 
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
 Tue Jul 19 19:27:18 2005
@@ -70,7 +70,7 @@
         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 @@
             // 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 @@
             {
                 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 @@
         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 @@
         {
             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() );
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to