Author: jvanzyl
Date: Fri Feb  8 18:24:38 2008
New Revision: 620063

URL: http://svn.apache.org/viewvc?rev=620063&view=rev
Log:
o one problem left and then some more collapsing, and then a first attempt at 
the graph based work through the whole                                          
         
  system, the differences in behavior will be interesting  

Removed:
    maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/factory/
Modified:
    maven/artifact/branches/CAP/notes.txt
    
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
    
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
    
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
    
maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java

Modified: maven/artifact/branches/CAP/notes.txt
URL: 
http://svn.apache.org/viewvc/maven/artifact/branches/CAP/notes.txt?rev=620063&r1=620062&r2=620063&view=diff
==============================================================================
--- maven/artifact/branches/CAP/notes.txt (original)
+++ maven/artifact/branches/CAP/notes.txt Fri Feb  8 18:24:38 2008
@@ -70,4 +70,14 @@
  the optimized retrieval mechanism. We still need to do some work to separate 
out 4) as we're doing some classpath
  calculations already which we will need to further decouple but that should 
be relatively straight forward.
 
-                
+ 7 February 2008 (Friday)
+
+ The number of methods in the artifact factory is simply insane, for each type 
that we ended up with in Maven just started
+ being effectively hard-coded in the factory which is totally unscalable, any 
new types with handlers become a nightmare
+ to maintain. I have reduced everything to two constructors in the 
DefaultArtifact and I would like to reduce it to being
+ one. Right now I have to account for needing to use a version string, or 
creating a range which is completely confusing
+ to anyone using the API. You should just need one constructor with a version 
string and everything else should be taken
+ care of for you. Right now there are bits of code all over the place that do 
the if/else versionRange detection. 
+
+ inheritedScope goes away entirely from the model when a graph is used because 
the scope selected will be a function of
+ how the graph is processed.
\ No newline at end of file

Modified: 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java?rev=620063&r1=620062&r2=620063&view=diff
==============================================================================
--- 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
 (original)
+++ 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
 Fri Feb  8 18:24:38 2008
@@ -129,7 +129,6 @@
     }
 
     public static Artifact copyArtifact( Artifact artifact )
-        throws InvalidVersionSpecificationException
     {
         DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), 
artifact.getArtifactId(), artifact.getVersion(),
             artifact.getType(), artifact.getClassifier(), 
artifact.isOptional(), artifact.getScope(), null );

Modified: 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?rev=620063&r1=620062&r2=620063&view=diff
==============================================================================
--- 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
 (original)
+++ 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
 Fri Feb  8 18:24:38 2008
@@ -93,16 +93,7 @@
             throw new InvalidArtifactRTException( groupId, artifactId, 
version, type, "Version cannot be null." );
         }
 
-        VersionRange versionRange;
-
-        try
-        {
-            versionRange = VersionRange.createFromVersionSpec( version );
-        }
-        catch ( InvalidVersionSpecificationException e )
-        {
-            throw new InvalidArtifactRTException( groupId, artifactId, 
version, type, "Invalid version." );
-        }
+        VersionRange versionRange = VersionRange.createFromVersion( version );
 
         initialize( groupId, artifactId, versionRange, type, classifier, 
optional, scope, inheritedScope );
     }
@@ -128,24 +119,36 @@
                              String scope,
                              String inheritedScope )
     {
-        this.versionRange = versionRange;
-
         this.groupId = groupId;
 
         this.artifactId = artifactId;
 
+        this.versionRange = versionRange;
+
+        selectVersionFromNewRangeIfAvailable();
+
         this.scope = scope;
 
         this.type = type;
 
         this.classifier = classifier;
 
+        // We were relying on the artifact handler to get the classifier here. 
+
         this.optional = optional;
 
+        // Scope information
+
+        //this.scope = Artifact.SCOPE_RUNTIME;
+
         if ( inheritedScope == null )
         {
             this.scope = scope;
         }
+        else if( Artifact.SCOPE_TEST.equals( scope ) || 
Artifact.SCOPE_PROVIDED.equals( scope ) )
+        {
+            // do nothing
+        }
         else if ( Artifact.SCOPE_COMPILE.equals( scope ) && 
Artifact.SCOPE_COMPILE.equals( inheritedScope ) )
         {
             // added to retain compile artifactScope. Remove if you want 
compile inherited as runtime
@@ -167,8 +170,6 @@
             // system scopes come through unchanged...
             this.scope = Artifact.SCOPE_SYSTEM;
         }
-
-        selectVersionFromNewRangeIfAvailable();
 
         validateIdentity();
     }

Modified: 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java?rev=620063&r1=620062&r2=620063&view=diff
==============================================================================
--- 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
 (original)
+++ 
maven/artifact/branches/CAP/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java
 Fri Feb  8 18:24:38 2008
@@ -41,6 +41,19 @@
 
     private final boolean systemScope;
 
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer()
+            .append( "\n" )
+            .append( "compile  = " ).append( compileScope ).append( "\n" )
+            .append( "runtime  = " ).append( runtimeScope ).append( "\n" )
+            .append( "test     = " ).append( testScope ).append( "\n" )
+            .append( "provided = " ).append( providedScope ).append( "\n" )
+            .append( "system   = " ).append( systemScope );
+
+        return sb.toString();
+    }
+
     public ScopeArtifactFilter( String scope )
     {
         if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) )

Modified: 
maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=620063&r1=620062&r2=620063&view=diff
==============================================================================
--- 
maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
 (original)
+++ 
maven/artifact/branches/CAP/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
 Fri Feb  8 18:24:38 2008
@@ -332,7 +332,7 @@
 
         ArtifactResolutionResult res = collect( a );
 
-        assertTrue( res.hasVersionRangeViolations() );        
+        assertTrue( res.hasVersionRangeViolations() );
     }
 
     public void testUnboundedRangeBelowLastRelease()
@@ -618,8 +618,10 @@
         ArtifactSpec b = createArtifactSpec( "b", "1.0" );
         ArtifactSpec c = createArtifactSpec( "c", "1.0" );
         a.addDependency( c );
+        //                                                      provided
         ArtifactSpec dNearest = createArtifactSpec( "d", "2.0", nearestScope );
         b.addDependency( dNearest );
+        //                                                       compile
         ArtifactSpec dFarthest = createArtifactSpec( "d", "3.0", farthestScope 
);
         c.addDependency( dFarthest );
 
@@ -643,14 +645,29 @@
             filter = new ScopeArtifactFilter( expectedScope );
         }
 
-        ArtifactResolutionResult res = collect( createSet( new 
Object[]{a.artifact, b.artifact} ), filter );
+        Set artifactSet = createSet( new Object[]{a.artifact, b.artifact} );
+
+        System.out.println( "filter = " + filter );
+
+        ArtifactResolutionResult res = collect( artifactSet, filter );
+
         Artifact artifact = getArtifact( "d", res.getArtifacts() );
+
         assertNotNull( "MNG-1895 Dependency was not added to resolution", 
artifact );
+
         assertEquals( "Check artifactScope", expectedScope, 
artifact.getScope() );
+
+        // compile / provided / compile
+        System.out.println( "d = " + artifact );
         assertEquals( "Check version with expect scope[" + expectedScope + 
"]", expectedVersion, artifact.getVersion() );
 
         ArtifactSpec d = createArtifactSpec( "d", "1.0" );
-        res = collect( createSet( new Object[]{a.artifact, b.artifact, 
d.artifact} ), filter );
+
+        artifactSet = createSet( new Object[]{a.artifact, b.artifact, 
d.artifact} );
+
+        System.out.println( "artifactSet = " + artifactSet );
+
+        res = collect( artifactSet, filter );
         artifact = getArtifact( "d", res.getArtifacts() );
         assertNotNull( "MNG-1895 Dependency was not added to resolution", 
artifact );
         assertEquals( "Check artifactScope", d.artifact.getScope(), 
artifact.getScope() );
@@ -772,7 +789,7 @@
     private ArtifactSpec createArtifactSpec( String id, String version, String 
scope, String inheritedScope, boolean optional )
         throws InvalidVersionSpecificationException
     {
-        Artifact artifact = new DefaultArtifact( GROUP_ID, id, version, "jar", 
null, optional, scope, inheritedScope );
+        Artifact artifact = new DefaultArtifact( GROUP_ID, id, 
VersionRange.createFromVersionSpec( version ), "jar", null, optional, scope, 
inheritedScope );
 
         ArtifactSpec spec = null;
 
@@ -822,6 +839,9 @@
         private ArtifactSpec addDependency( String id, String version, String 
scope, boolean optional )
             throws InvalidVersionSpecificationException
         {
+            // inherited scope is this artifacts scope
+            // dependency scope is as stated here
+                                                                // provided 
compile
             ArtifactSpec dep = createArtifactSpec( id, version, scope, 
this.artifact.getScope(), optional );
 
             return addDependency( dep );
@@ -871,18 +891,41 @@
 
             for ( Iterator i = dependencies.iterator(); i.hasNext(); )
             {
+
                 Artifact d = (Artifact) i.next();
 
-                Artifact artifact;
+                VersionRange versionRange;
+
+                if ( d.getVersionRange() != null )
+                {
+                    versionRange = d.getVersionRange();
+                }
+                else
+                {
+                    versionRange = VersionRange.createFromVersionSpec( 
d.getVersion() );
+                }
+
+                Artifact  artifact;
 
                 if ( d.getScope().equals( Artifact.SCOPE_TEST ) || 
d.getScope().equals( Artifact.SCOPE_PROVIDED ) )
                 {
-                    /* don't call createDependencyArtifact as it'll ignore 
test and provided scopes */
+                    // don't call createDependencyArtifact as it'll ignore 
test and provided scopes
+                    // jvz!!
+                    //artifact = new DefaultArtifact( d.getGroupId(), 
d.getArtifactId(), d.getVersion(), d.getType(),
+                      //  d.getClassifier(), false, d.getScope(), 
inheritedScope );
+
                     artifact = null;
+
+                    /*
+                    artifact = new DefaultArtifact( d.getGroupId(), 
d.getArtifactId(), versionRange, d.getType(),
+                        d.getClassifier(), d.isOptional(), d.getScope(), 
inheritedScope );
+                        */
+
                 }
                 else
                 {
-                    artifact = new DefaultArtifact( d.getGroupId(), 
d.getArtifactId(), d.getVersionRange(), d.getType(), d.getClassifier(), 
d.isOptional(), d.getScope(), inheritedScope );
+                    artifact = new DefaultArtifact( d.getGroupId(), 
d.getArtifactId(), versionRange, d.getType(),
+                        d.getClassifier(), d.isOptional(), d.getScope(), 
inheritedScope );
                 }
 
                 if ( artifact != null && ( dependencyFilter == null || 
dependencyFilter.include( artifact ) ) )


Reply via email to