maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r565903 - in /maven/components/branches/maven-2.0.x/maven-artifact/src: main/java/org/apache/maven/artifact/DefaultArtifact.java test/java/org/apache/maven/artifact/DefaultArtifactTest.java
Date Tue, 14 Aug 2007 20:45:35 GMT
Author: jdcasey
Date: Tue Aug 14 13:45:34 2007
New Revision: 565903

URL: http://svn.apache.org/viewvc?view=rev&rev=565903
Log:
[MNG-2961] WOO HOO! Finally fixed this horrible behavior of having to call isSnapshot(). Merging
from revId 565901 on trunk.

Modified:
    maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
    maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java

Modified: maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?view=diff&rev=565903&r1=565902&r2=565903
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
Tue Aug 14 13:45:34 2007
@@ -187,7 +187,7 @@
     public void setVersion( String version )
     {
         this.version = version;
-        this.baseVersion = version;
+        this.setBaseVersion( version );
         this.versionRange = null;
     }
 
@@ -283,7 +283,7 @@
         }
         appendArtifactTypeClassifierString( sb );
         sb.append( ":" );
-        if ( version != null || baseVersion != null )
+        if ( getBaseVersion() != null )
         {
             sb.append( getBaseVersion() );
         }
@@ -357,19 +357,26 @@
     {
         if ( baseVersion == null )
         {
-            baseVersion = version;
-
             if ( version == null )
             {
                 throw new NullPointerException( "version was null for " + groupId + ":" +
artifactId );
             }
+            setBaseVersion( version );
         }
         return baseVersion;
     }
 
     public void setBaseVersion( String baseVersion )
     {
-        this.baseVersion = baseVersion;
+        Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );
+        if ( m.matches() )
+        {
+            this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
+        }
+        else
+        {
+            this.baseVersion = baseVersion;
+        }
     }
 
     public int compareTo( Object o )
@@ -496,7 +503,7 @@
     public void selectVersion( String version )
     {
         this.version = version;
-        this.baseVersion = version;
+        setBaseVersion( version );
     }
 
     public void setGroupId( String groupId )
@@ -511,18 +518,9 @@
 
     public boolean isSnapshot()
     {
-        if ( version != null || baseVersion != null )
+        if ( getBaseVersion() != null )
         {
-            Matcher m = VERSION_FILE_PATTERN.matcher( getBaseVersion() );
-            if ( m.matches() )
-            {
-                setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION );
-                return true;
-            }
-            else
-            {
-                return getBaseVersion().endsWith( SNAPSHOT_VERSION ) || getBaseVersion().equals(
LATEST_VERSION );
-            }
+            return getBaseVersion().endsWith( SNAPSHOT_VERSION ) || getBaseVersion().equals(
LATEST_VERSION );
         }
         else
         {

Modified: maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java?view=diff&rev=565903&r1=565902&r2=565903
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java
Tue Aug 14 13:45:34 2007
@@ -19,21 +19,28 @@
  * under the License.
  */
 
-import junit.framework.TestCase;
 
 import org.apache.maven.artifact.handler.ArtifactHandlerMock;
 import org.apache.maven.artifact.versioning.VersionRange;
 
+import junit.framework.TestCase;
+
 public class DefaultArtifactTest
     extends TestCase
 {
 
     private DefaultArtifact artifact;
 
+    private DefaultArtifact snapshotArtifact;
+
     private String groupId = "groupid", artifactId = "artifactId", version = "1.0", scope
= "scope", type = "type",
         classifier = "classifier";
 
+    private String snapshotSpecVersion = "1.0-SNAPSHOT";
+    private String snapshotResolvedVersion = "1.0-20070606.010101-1";
+
     private VersionRange versionRange;
+    private VersionRange snapshotVersionRange;
 
     private ArtifactHandlerMock artifactHandler;
 
@@ -44,6 +51,19 @@
         artifactHandler = new ArtifactHandlerMock();
         versionRange = VersionRange.createFromVersion( version );
         artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, classifier,
artifactHandler );
+
+        snapshotVersionRange = VersionRange.createFromVersion( snapshotResolvedVersion );
+        snapshotArtifact = new DefaultArtifact( groupId, artifactId, snapshotVersionRange,
scope, type, classifier, artifactHandler );
+    }
+
+    public void testGetVersionReturnsResolvedVersionOnSnapshot()
+    {
+        assertEquals( snapshotResolvedVersion, snapshotArtifact.getVersion() );
+
+        // this is FOUL!
+//        snapshotArtifact.isSnapshot();
+
+        assertEquals( snapshotSpecVersion, snapshotArtifact.getBaseVersion() );
     }
 
     public void testGetDependencyConflictId()



Mime
View raw message