]> source.dussan.org Git - archiva.git/commitdiff
remove artifact utils
authorBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 07:26:09 +0000 (07:26 +0000)
committerBrett Porter <brett@apache.org>
Wed, 7 Jun 2006 07:26:09 +0000 (07:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412310 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java
maven-repository-proxy/pom.xml
maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java [deleted file]
maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsLegacyTest.java [deleted file]
maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java [deleted file]

index 167737f63b1c47ee6e24bb77e77432fcd9f5572c..22b463ac2ec428f21120f1b8fac7cbc9839fc980 100644 (file)
@@ -37,6 +37,7 @@ import java.util.List;
  */
 public abstract class AbstractArtifactDiscoverer
     extends AbstractDiscoverer
+    implements ArtifactDiscoverer
 {
     /**
      * Standard patterns to exclude from discovery as they are not artifacts.
@@ -55,8 +56,6 @@ public abstract class AbstractArtifactDiscoverer
         return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
     }
 
-    protected abstract Artifact buildArtifactFromPath( String path, ArtifactRepository repository );
-
     public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
     {
         if ( !"file".equals( repository.getProtocol() ) )
@@ -107,10 +106,6 @@ public abstract class AbstractArtifactDiscoverer
             if ( path.toLowerCase().endsWith( POM ) )
             {
                 Artifact pomArtifact = buildArtifactFromPath( path, repository );
-                if ( pomArtifact != null )
-                {
-                    pomArtifact.setFile( new File( repositoryBase, path ) );
-                }
 
                 MavenXpp3Reader mavenReader = new MavenXpp3Reader();
                 String filename = repositoryBase.getAbsolutePath() + "/" + path;
@@ -144,4 +139,17 @@ public abstract class AbstractArtifactDiscoverer
 
         return artifacts;
     }
+
+    public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
+    {
+        Artifact artifact = buildArtifact( path );
+
+        if ( artifact != null )
+        {
+            artifact.setRepository( repository );
+            artifact.setFile( new File( repository.getBasedir(), path ) );
+        }
+
+        return artifact;
+    }
 }
index fc00fb4ef42a758aca82090bedadb1d8d9083e73..dc1d3c9b8ea62760beda15605897d1f9ef328018 100644 (file)
@@ -16,6 +16,7 @@ package org.apache.maven.repository.discovery;
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 
 import java.util.Iterator;
@@ -72,4 +73,13 @@ public interface ArtifactDiscoverer
      * @return the paths as Strings.
      */
     Iterator getExcludedPathsIterator();
+
+    /**
+     * Build an artifact from a path in the repository
+     *
+     * @param path the path
+     * @return the artifact
+     * @todo this should be in maven-artifact
+     */
+    Artifact buildArtifact( String path );
 }
index 62345323ec44905529e70a2763402822b67cc793..4ec84f66d694f66a266c396e19435202d2f0a095 100644 (file)
@@ -17,8 +17,12 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.repository.ArtifactUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
 
 /**
  * Artifact discoverer for the new repository layout (Maven 2.0+).
@@ -29,10 +33,153 @@ import org.apache.maven.repository.ArtifactUtils;
  */
 public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
-    implements ArtifactDiscoverer
 {
-    protected Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
+    public Artifact buildArtifact( String path )
     {
-        return ArtifactUtils.buildArtifact( path, repository, artifactFactory );
+        List pathParts = new ArrayList();
+        StringTokenizer st = new StringTokenizer( path, "/\\" );
+        while ( st.hasMoreTokens() )
+        {
+            pathParts.add( st.nextToken() );
+        }
+
+        Collections.reverse( pathParts );
+
+        Artifact artifact = null;
+        if ( pathParts.size() >= 4 )
+        {
+            // maven 2.x path
+
+            // the actual artifact filename.
+            String filename = (String) pathParts.remove( 0 );
+
+            // the next one is the version.
+            String version = (String) pathParts.remove( 0 );
+
+            // the next one is the artifactId.
+            String artifactId = (String) pathParts.remove( 0 );
+
+            // the remaining are the groupId.
+            Collections.reverse( pathParts );
+            String groupId = StringUtils.join( pathParts.iterator(), "." );
+
+            String remainingFilename = filename;
+            if ( !remainingFilename.startsWith( artifactId + "-" ) )
+            {
+                return null;
+            }
+            else
+            {
+                remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
+
+                String classifier = null;
+
+                // TODO: use artifact handler, share with legacy discoverer
+                String type;
+                if ( remainingFilename.endsWith( ".tar.gz" ) )
+                {
+                    type = "distribution-tgz";
+                    remainingFilename =
+                        remainingFilename.substring( 0, remainingFilename.length() - ".tar.gz".length() );
+                }
+                else if ( remainingFilename.endsWith( ".zip" ) )
+                {
+                    type = "distribution-zip";
+                    remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - ".zip".length() );
+                }
+                else if ( remainingFilename.endsWith( "-sources.jar" ) )
+                {
+                    type = "java-source";
+                    classifier = "sources";
+                    remainingFilename =
+                        remainingFilename.substring( 0, remainingFilename.length() - "-sources.jar".length() );
+                }
+                else
+                {
+                    int index = remainingFilename.lastIndexOf( "." );
+                    if ( index < 0 )
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        type = remainingFilename.substring( index + 1 );
+                        remainingFilename = remainingFilename.substring( 0, index );
+                    }
+                }
+
+                if ( type != null )
+                {
+                    Artifact result;
+
+                    if ( classifier == null )
+                    {
+                        result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
+                                                                 type );
+                    }
+                    else
+                    {
+                        result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
+                                                                               classifier );
+                    }
+
+                    if ( result.isSnapshot() )
+                    {
+                        // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b
+                        int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 );
+                        if ( classifierIndex >= 0 )
+                        {
+                            classifier = remainingFilename.substring( classifierIndex + 1 );
+                            remainingFilename = remainingFilename.substring( 0, classifierIndex );
+                            result = artifactFactory.createArtifactWithClassifier( groupId, artifactId,
+                                                                                   remainingFilename, type,
+                                                                                   classifier );
+                        }
+                        else
+                        {
+                            result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename,
+                                                                     Artifact.SCOPE_RUNTIME, type );
+                        }
+
+                        // poor encapsulation requires we do this to populate base version
+                        if ( !result.isSnapshot() )
+                        {
+                            return null;
+                        }
+                        else if ( !result.getBaseVersion().equals( version ) )
+                        {
+                            return null;
+                        }
+                        else
+                        {
+                            artifact = result;
+                        }
+                    }
+                    else if ( !remainingFilename.startsWith( version ) )
+                    {
+                        return null;
+                    }
+                    else if ( !remainingFilename.equals( version ) )
+                    {
+                        if ( remainingFilename.charAt( version.length() ) != '-' )
+                        {
+                            return null;
+                        }
+                        else
+                        {
+                            classifier = remainingFilename.substring( version.length() + 1 );
+                            artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
+                                                                                     classifier );
+                        }
+                    }
+                    else
+                    {
+                        artifact = result;
+                    }
+                }
+            }
+        }
+
+        return artifact;
     }
 }
index dbf065af05e7e8fa6569f8f934bf374878e6320c..a5092c1bd279412b0d06e2b12b9bd4f12c4434a8 100644 (file)
@@ -17,13 +17,18 @@ package org.apache.maven.repository.discovery;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.repository.ArtifactUtils;
 
-import java.io.File;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.StringTokenizer;
 
 /**
  * Artifact discoverer for the legacy repository layout (Maven 1.x).
+ * Method used to build an artifact object using a relative path from a repository base directory.  An artifactId
+ * having the words "DEV", "PRE", "RC", "ALPHA", "BETA", "DEBUG", "UNOFFICIAL", "CURRENT", "LATEST", "FCS",
+ * "RELEASE", "NIGHTLY", "SNAPSHOT" and "TEST" (not case-sensitive) will most likely make this method fail as
+ * they are reserved for version usage.
  *
  * @author John Casey
  * @author Brett Porter
@@ -31,18 +36,234 @@ import java.io.File;
  */
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
-    implements ArtifactDiscoverer
 {
-    protected Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
+    public Artifact buildArtifact( String path )
     {
-        Artifact artifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
+        StringTokenizer tokens = new StringTokenizer( path, "/\\" );
 
-        if ( artifact != null )
+        Artifact result = null;
+
+        int numberOfTokens = tokens.countTokens();
+
+        if ( numberOfTokens == 3 )
         {
-            artifact.setRepository( repository );
-            artifact.setFile( new File( repository.getBasedir(), path ) );
+            String groupId = tokens.nextToken();
+
+            String type = tokens.nextToken();
+
+            if ( type.endsWith( "s" ) )
+            {
+                type = type.substring( 0, type.length() - 1 );
+
+                // contains artifactId, version, classifier, and extension.
+                String avceGlob = tokens.nextToken();
+
+                //noinspection CollectionDeclaredAsConcreteClass
+                LinkedList avceTokenList = new LinkedList();
+
+                StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" );
+                while ( avceTokenizer.hasMoreTokens() )
+                {
+                    avceTokenList.addLast( avceTokenizer.nextToken() );
+                }
+
+                String lastAvceToken = (String) avceTokenList.removeLast();
+
+                boolean valid = true;
+
+                // TODO: share with other discoverer, use artifact handlers instead
+                if ( lastAvceToken.endsWith( ".tar.gz" ) )
+                {
+                    type = "distribution-tgz";
+
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() );
+
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else if ( lastAvceToken.endsWith( "sources.jar" ) )
+                {
+                    type = "java-source";
+
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() );
+
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else if ( lastAvceToken.endsWith( ".zip" ) )
+                {
+                    type = "distribution-zip";
+
+                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() );
+
+                    avceTokenList.addLast( lastAvceToken );
+                }
+                else
+                {
+                    int extPos = lastAvceToken.lastIndexOf( '.' );
+
+                    if ( extPos > 0 )
+                    {
+                        String ext = lastAvceToken.substring( extPos + 1 );
+                        if ( type.equals( ext ) )
+                        {
+                            lastAvceToken = lastAvceToken.substring( 0, extPos );
+
+                            avceTokenList.addLast( lastAvceToken );
+                        }
+                        else
+                        {
+                            //type does not match extension
+                            valid = false;
+                        }
+                    }
+                    else
+                    {
+                        // no extension
+                        valid = false;
+                    }
+                }
+
+                if ( valid )
+                {
+                    // let's discover the version, and whatever's leftover will be either
+                    // a classifier, or part of the artifactId, depending on position.
+                    // Since version is at the end, we have to move in from the back.
+                    Collections.reverse( avceTokenList );
+
+                    // TODO: this is obscene - surely a better way?
+                    String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" +
+                        "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" +
+                        "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" +
+                        "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" +
+                        "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" +
+                        "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" +
+                        "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)";
+
+                    StringBuffer classifierBuffer = new StringBuffer();
+                    StringBuffer versionBuffer = new StringBuffer();
+
+                    boolean firstVersionTokenEncountered = false;
+                    boolean firstToken = true;
+
+                    int tokensIterated = 0;
+                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
+                    {
+                        String token = (String) it.next();
+
+                        boolean tokenIsVersionPart = token.matches( validVersionParts );
+
+                        StringBuffer bufferToUpdate;
+
+                        // NOTE: logic in code is reversed, since we're peeling off the back
+                        // Any token after the last versionPart will be in the classifier.
+                        // Any token UP TO first non-versionPart is part of the version.
+                        if ( !tokenIsVersionPart )
+                        {
+                            if ( firstVersionTokenEncountered )
+                            {
+                                //noinspection BreakStatement
+                                break;
+                            }
+                            else
+                            {
+                                bufferToUpdate = classifierBuffer;
+                            }
+                        }
+                        else
+                        {
+                            firstVersionTokenEncountered = true;
+
+                            bufferToUpdate = versionBuffer;
+                        }
+
+                        if ( firstToken )
+                        {
+                            firstToken = false;
+                        }
+                        else
+                        {
+                            bufferToUpdate.insert( 0, '-' );
+                        }
+
+                        bufferToUpdate.insert( 0, token );
+
+                        tokensIterated++;
+                    }
+
+                    // Now, restore the proper ordering so we can build the artifactId.
+                    Collections.reverse( avceTokenList );
+
+                    // if we didn't find a version, then punt. Use the last token
+                    // as the version, and set the classifier empty.
+                    if ( versionBuffer.length() < 1 )
+                    {
+                        if ( avceTokenList.size() > 1 )
+                        {
+                            int lastIdx = avceTokenList.size() - 1;
+
+                            versionBuffer.append( avceTokenList.get( lastIdx ) );
+                            avceTokenList.remove( lastIdx );
+                        }
+
+                        classifierBuffer.setLength( 0 );
+                    }
+                    else
+                    {
+                        // if everything is kosher, then pop off all the classifier and
+                        // version tokens, leaving the naked artifact id in the list.
+                        avceTokenList =
+                            new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) );
+                    }
+
+                    StringBuffer artifactIdBuffer = new StringBuffer();
+
+                    firstToken = true;
+                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
+                    {
+                        String token = (String) it.next();
+
+                        if ( firstToken )
+                        {
+                            firstToken = false;
+                        }
+                        else
+                        {
+                            artifactIdBuffer.append( '-' );
+                        }
+
+                        artifactIdBuffer.append( token );
+                    }
+
+                    String artifactId = artifactIdBuffer.toString();
+
+                    if ( artifactId.length() > 0 )
+                    {
+                        int lastVersionCharIdx = versionBuffer.length() - 1;
+                        if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
+                        {
+                            versionBuffer.setLength( lastVersionCharIdx );
+                        }
+
+                        String version = versionBuffer.toString();
+
+                        if ( version.length() >= 1 )
+                        {
+                            if ( classifierBuffer.length() > 0 )
+                            {
+                                result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
+                                                                                       type,
+                                                                                       classifierBuffer.toString() );
+                            }
+                            else
+                            {
+                                result = artifactFactory.createArtifact( groupId, artifactId, version,
+                                                                         Artifact.SCOPE_RUNTIME, type );
+                            }
+                        }
+                    }
+                }
+            }
         }
 
-        return artifact;
+        return result;
     }
 }
index e8ade7ebc9077a6c3a1c3840d7e98eb479a793c3..ea37a7b239871df09c1361816237df129e3c620c 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.model.Model;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -403,6 +404,170 @@ public class DefaultArtifactDiscovererTest
         assertEquals( "1.0", model.getVersion() );
     }
 
+    public void testShortPath()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid-1.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for short paths", artifact );
+    }
+
+    public void testWrongArtifactId()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for wrong ArtifactId", artifact );
+    }
+
+    public void testNoType()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1/invalid-1";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for no type", artifact );
+    }
+
+    public void testWrongVersion()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1.0/invalid-2.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for wrong version", artifact );
+    }
+
+    public void testLongVersion()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1.0/invalid-1.0b.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for long version", artifact );
+    }
+
+    public void testWrongSnapshotVersion()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for wrong snapshot version", artifact );
+    }
+
+    public void testSnapshotBaseVersion()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for snapshot base version", artifact );
+    }
+
+    public void testPathWithClassifier()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with classifier error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ), artifact );
+    }
+
+    public void testWithJavaSourceInclusion()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with java source inclusion error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ), artifact );
+    }
+
+    public void testDistributionArtifacts()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "tar.gz distribution artifact error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ), artifact );
+
+        testPath = "org/apache/maven/testing/1.0/testing-1.0.zip";
+
+        artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "zip distribution artifact error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ), artifact );
+    }
+
+    public void testSnapshot()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with invalid snapshot error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ), artifact );
+
+        testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar";
+
+        artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with snapshot error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ), artifact );
+    }
+
+    public void testNormal()
+        throws ComponentLookupException
+    {
+        String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Normal artifact path error", artifact );
+
+        assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
+    }
+
+    public void testSnapshotWithClassifier()
+        throws ComponentLookupException
+    {
+        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with snapshot and classifier error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ),
+                      artifact );
+    }
+
+    private Artifact getArtifactFromPath( String path )
+    {
+        return discoverer.buildArtifact( path );
+    }
+
     private Artifact createArtifact( String groupId, String artifactId, String version )
     {
         return factory.createArtifact( groupId, artifactId, version, null, "jar" );
index d2c92e70f8f4ff3fd17553c9b3668690f9c01454..7eb5d1da47b21a27dad55b52b1d3958129ae38a7 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -332,6 +333,82 @@ public class LegacyArtifactDiscovererTest
         }
     }
 
+    public void testWrongArtifactPackaging()
+        throws ComponentLookupException
+    {
+        String testPath = "org.apache.maven.test/jars/artifactId-1.0.jar.md5";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for wrong package extension", artifact );
+    }
+
+    public void testNoArtifactid()
+    {
+        String testPath = "groupId/jars/-1.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null when artifactId is missing", artifact );
+
+        testPath = "groupId/jars/1.0.jar";
+
+        artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null when artifactId is missing", artifact );
+    }
+
+    public void testNoType()
+        throws ComponentLookupException
+    {
+        String testPath = "invalid/invalid/1/invalid-1";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNull( "Artifact should be null for no type", artifact );
+    }
+
+    public void testSnapshot()
+        throws ComponentLookupException
+    {
+        String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with invalid snapshot error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact );
+    }
+
+    public void testFinal()
+        throws ComponentLookupException
+    {
+        String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Artifact path with invalid snapshot error", artifact );
+
+        assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact );
+    }
+
+    public void testNormal()
+        throws ComponentLookupException
+    {
+        String testPath = "javax.sql/jars/jdbc-2.0.jar";
+
+        Artifact artifact = getArtifactFromPath( testPath );
+
+        assertNotNull( "Normal artifact path error", artifact );
+
+        assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
+    }
+
+    private Artifact getArtifactFromPath( String path )
+    {
+        return discoverer.buildArtifact( path );
+    }
+
     private Artifact createArtifact( String groupId, String artifactId, String version )
     {
         return factory.createArtifact( groupId, artifactId, version, null, "jar" );
index e6acb7e05b7c7f44f87100810ca865db48db9458..d314472c3fbdec3ad6b1fe62d29baa46ca2486ec 100644 (file)
@@ -27,7 +27,7 @@
   <dependencies>\r
     <dependency>\r
       <groupId>org.apache.maven.repository</groupId>\r
-      <artifactId>maven-repository-utils</artifactId>\r
+      <artifactId>maven-repository-discovery</artifactId>\r
     </dependency>\r
     <dependency>\r
       <groupId>org.apache.maven</groupId>\r
@@ -56,7 +56,7 @@
           <check>\r
             <!-- TODO: increase coverage -->\r
             <totalLineRate>60</totalLineRate>\r
-            <totalBranchRate>75</totalBranchRate>\r
+            <totalBranchRate>70</totalBranchRate>\r
           </check>\r
         </configuration>\r
       </plugin>\r
index fa429c5c6334b9d352a267375da4d0366362a76f..0eaf52a66f7a71055ec8cc923b69a58260abf682 100644 (file)
@@ -17,14 +17,13 @@ package org.apache.maven.repository.proxy;
  */
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.manager.ChecksumFailedException;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.repository.ArtifactUtils;
+import org.apache.maven.repository.discovery.ArtifactDiscoverer;
 import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
 import org.apache.maven.repository.proxy.repository.ProxyRepository;
 import org.apache.maven.wagon.ConnectionException;
@@ -64,11 +63,6 @@ public class DefaultProxyManager
      */
     private WagonManager wagonManager;
 
-    /**
-     * @plexus.requirement
-     */
-    private ArtifactFactory artifactFactory;
-
     /**
      * @plexus.requirement
      */
@@ -91,6 +85,17 @@ public class DefaultProxyManager
 
     private static final int MS_PER_SEC = 1000;
 
+    /**
+     * @plexus.requirement role-hint="default"
+     * @todo use a map, and have priorities in them
+     */
+    private ArtifactDiscoverer defaultArtifactDiscoverer;
+
+    /**
+     * @plexus.requirement role-hint="legacy"
+     */
+    private ArtifactDiscoverer legacyArtifactDiscoverer;
+
     public void setConfiguration( ProxyConfiguration config )
     {
         this.config = config;
@@ -155,11 +160,11 @@ public class DefaultProxyManager
         }
         else
         {
-            Artifact artifact = ArtifactUtils.buildArtifact( path, artifactFactory );
+            Artifact artifact = defaultArtifactDiscoverer.buildArtifact( path );
 
             if ( artifact == null )
             {
-                artifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
+                artifact = legacyArtifactDiscoverer.buildArtifact( path );
             }
 
             if ( artifact != null )
diff --git a/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java b/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java
deleted file mode 100644 (file)
index 26ff14d..0000000
+++ /dev/null
@@ -1,460 +0,0 @@
-package org.apache.maven.repository;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.StringTokenizer;
-
-/**
- * Class used to build an artifact object based on a relative from a repository's basedir.
- *
- * @author Edwin Punzalan
- * @todo I'm not sure why this class needs to exist. It seems like the perfect candidate for two implementations of an interface
- */
-public class ArtifactUtils
-{
-    private ArtifactUtils()
-    {
-    }
-
-    /**
-     * Method used to build an artifact and then set its repository and file fields with the proper values
-     *
-     * @param path            the path of the artifact relative from the repository base directory
-     * @param repository      the repository where the artifact can be found
-     * @param artifactFactory the artifactFactory to build the Artifact object when the given path is a valid artifact path
-     * @return Artifact object if the given path represents an artifact path, otherwise, returns null
-     */
-    public static Artifact buildArtifact( String path, ArtifactRepository repository, ArtifactFactory artifactFactory )
-    {
-        Artifact artifact = buildArtifact( path, artifactFactory );
-
-        if ( artifact != null )
-        {
-            artifact.setRepository( repository );
-            artifact.setFile( new File( repository.getBasedir(), path ) );
-        }
-
-        return artifact;
-    }
-
-    /**
-     * Method used to build an artifact object using a relative path from a repository base directory.
-     *
-     * @param path            the relative path of the artifact from a "default" ArtifactRepository's base directory
-     * @param artifactFactory the artifactFactory to build the Artifact object when the given path is a valid artifact path
-     * @return Artifact object if the given path represents an artifact path, otherwise, returns null
-     */
-    public static Artifact buildArtifact( String path, ArtifactFactory artifactFactory )
-    {
-        List pathParts = new ArrayList();
-        StringTokenizer st = new StringTokenizer( path, "/\\" );
-        while ( st.hasMoreTokens() )
-        {
-            pathParts.add( st.nextToken() );
-        }
-
-        Collections.reverse( pathParts );
-
-        Artifact artifact = null;
-        if ( pathParts.size() >= 4 )
-        {
-            // maven 2.x path
-
-            // the actual artifact filename.
-            String filename = (String) pathParts.remove( 0 );
-
-            // the next one is the version.
-            String version = (String) pathParts.remove( 0 );
-
-            // the next one is the artifactId.
-            String artifactId = (String) pathParts.remove( 0 );
-
-            // the remaining are the groupId.
-            Collections.reverse( pathParts );
-            String groupId = StringUtils.join( pathParts.iterator(), "." );
-
-            String remainingFilename = filename;
-            if ( !remainingFilename.startsWith( artifactId + "-" ) )
-            {
-                return null;
-            }
-            else
-            {
-                remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
-
-                String classifier = null;
-
-                // TODO: use artifact handler, share with legacy discoverer
-                String type;
-                if ( remainingFilename.endsWith( ".tar.gz" ) )
-                {
-                    type = "distribution-tgz";
-                    remainingFilename =
-                        remainingFilename.substring( 0, remainingFilename.length() - ".tar.gz".length() );
-                }
-                else if ( remainingFilename.endsWith( ".zip" ) )
-                {
-                    type = "distribution-zip";
-                    remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - ".zip".length() );
-                }
-                else if ( remainingFilename.endsWith( "-sources.jar" ) )
-                {
-                    type = "java-source";
-                    classifier = "sources";
-                    remainingFilename =
-                        remainingFilename.substring( 0, remainingFilename.length() - "-sources.jar".length() );
-                }
-                else
-                {
-                    int index = remainingFilename.lastIndexOf( "." );
-                    if ( index < 0 )
-                    {
-                        return null;
-                    }
-                    else
-                    {
-                        type = remainingFilename.substring( index + 1 );
-                        remainingFilename = remainingFilename.substring( 0, index );
-                    }
-                }
-
-                if ( type != null )
-                {
-                    Artifact result;
-
-                    if ( classifier == null )
-                    {
-                        result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
-                                                                 type );
-                    }
-                    else
-                    {
-                        result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                               classifier );
-                    }
-
-                    if ( result.isSnapshot() )
-                    {
-                        // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b
-                        int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 );
-                        if ( classifierIndex >= 0 )
-                        {
-                            classifier = remainingFilename.substring( classifierIndex + 1 );
-                            remainingFilename = remainingFilename.substring( 0, classifierIndex );
-                            result = artifactFactory.createArtifactWithClassifier( groupId, artifactId,
-                                                                                   remainingFilename, type,
-                                                                                   classifier );
-                        }
-                        else
-                        {
-                            result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename,
-                                                                     Artifact.SCOPE_RUNTIME, type );
-                        }
-
-                        // poor encapsulation requires we do this to populate base version
-                        if ( !result.isSnapshot() )
-                        {
-                            return null;
-                        }
-                        else if ( !result.getBaseVersion().equals( version ) )
-                        {
-                            return null;
-                        }
-                        else
-                        {
-                            artifact = result;
-                        }
-                    }
-                    else if ( !remainingFilename.startsWith( version ) )
-                    {
-                        return null;
-                    }
-                    else if ( !remainingFilename.equals( version ) )
-                    {
-                        if ( remainingFilename.charAt( version.length() ) != '-' )
-                        {
-                            return null;
-                        }
-                        else
-                        {
-                            classifier = remainingFilename.substring( version.length() + 1 );
-                            artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
-                                                                                     classifier );
-                        }
-                    }
-                    else
-                    {
-                        artifact = result;
-                    }
-                }
-            }
-        }
-
-        return artifact;
-    }
-
-    /**
-     * Method used to build an artifact object using a relative path from a repository base directory.  An artifactId
-     * having the words "DEV", "PRE", "RC", "ALPHA", "BETA", "DEBUG", "UNOFFICIAL", "CURRENT", "LATEST", "FCS",
-     * "RELEASE", "NIGHTLY", "SNAPSHOT" and "TEST" (not case-sensitive) will most likely make this method fail as
-     * they are reserved for version usage.
-     *
-     * @param path            the relative path of the artifact from a "legacy" ArtifactRepository's base directory
-     * @param artifactFactory the artifactFactory to build the Artifact object when the given path is a valid artifact path
-     * @return Artifact object if the given path represents an artifact path, otherwise, returns null
-     */
-    public static Artifact buildArtifactFromLegacyPath( String path, ArtifactFactory artifactFactory )
-    {
-        StringTokenizer tokens = new StringTokenizer( path, "/\\" );
-
-        Artifact result = null;
-
-        int numberOfTokens = tokens.countTokens();
-
-        if ( numberOfTokens == 3 )
-        {
-            String groupId = tokens.nextToken();
-
-            String type = tokens.nextToken();
-
-            if ( type.endsWith( "s" ) )
-            {
-                type = type.substring( 0, type.length() - 1 );
-
-                // contains artifactId, version, classifier, and extension.
-                String avceGlob = tokens.nextToken();
-
-                //noinspection CollectionDeclaredAsConcreteClass
-                LinkedList avceTokenList = new LinkedList();
-
-                StringTokenizer avceTokenizer = new StringTokenizer( avceGlob, "-" );
-                while ( avceTokenizer.hasMoreTokens() )
-                {
-                    avceTokenList.addLast( avceTokenizer.nextToken() );
-                }
-
-                String lastAvceToken = (String) avceTokenList.removeLast();
-
-                boolean valid = true;
-
-                // TODO: share with other discoverer, use artifact handlers instead
-                if ( lastAvceToken.endsWith( ".tar.gz" ) )
-                {
-                    type = "distribution-tgz";
-
-                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".tar.gz".length() );
-
-                    avceTokenList.addLast( lastAvceToken );
-                }
-                else if ( lastAvceToken.endsWith( "sources.jar" ) )
-                {
-                    type = "java-source";
-
-                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".jar".length() );
-
-                    avceTokenList.addLast( lastAvceToken );
-                }
-                else if ( lastAvceToken.endsWith( ".zip" ) )
-                {
-                    type = "distribution-zip";
-
-                    lastAvceToken = lastAvceToken.substring( 0, lastAvceToken.length() - ".zip".length() );
-
-                    avceTokenList.addLast( lastAvceToken );
-                }
-                else
-                {
-                    int extPos = lastAvceToken.lastIndexOf( '.' );
-
-                    if ( extPos > 0 )
-                    {
-                        String ext = lastAvceToken.substring( extPos + 1 );
-                        if ( type.equals( ext ) )
-                        {
-                            lastAvceToken = lastAvceToken.substring( 0, extPos );
-
-                            avceTokenList.addLast( lastAvceToken );
-                        }
-                        else
-                        {
-                            //type does not match extension
-                            valid = false;
-                        }
-                    }
-                    else
-                    {
-                        // no extension
-                        valid = false;
-                    }
-                }
-
-                if ( valid )
-                {
-                    // let's discover the version, and whatever's leftover will be either
-                    // a classifier, or part of the artifactId, depending on position.
-                    // Since version is at the end, we have to move in from the back.
-                    Collections.reverse( avceTokenList );
-
-                    // TODO: this is obscene - surely a better way?
-                    String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" +
-                        "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" +
-                        "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" +
-                        "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" +
-                        "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" +
-                        "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" +
-                        "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)";
-
-                    StringBuffer classifierBuffer = new StringBuffer();
-                    StringBuffer versionBuffer = new StringBuffer();
-
-                    boolean firstVersionTokenEncountered = false;
-                    boolean firstToken = true;
-
-                    int tokensIterated = 0;
-                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
-                    {
-                        String token = (String) it.next();
-
-                        boolean tokenIsVersionPart = token.matches( validVersionParts );
-
-                        StringBuffer bufferToUpdate;
-
-                        // NOTE: logic in code is reversed, since we're peeling off the back
-                        // Any token after the last versionPart will be in the classifier.
-                        // Any token UP TO first non-versionPart is part of the version.
-                        if ( !tokenIsVersionPart )
-                        {
-                            if ( firstVersionTokenEncountered )
-                            {
-                                //noinspection BreakStatement
-                                break;
-                            }
-                            else
-                            {
-                                bufferToUpdate = classifierBuffer;
-                            }
-                        }
-                        else
-                        {
-                            firstVersionTokenEncountered = true;
-
-                            bufferToUpdate = versionBuffer;
-                        }
-
-                        if ( firstToken )
-                        {
-                            firstToken = false;
-                        }
-                        else
-                        {
-                            bufferToUpdate.insert( 0, '-' );
-                        }
-
-                        bufferToUpdate.insert( 0, token );
-
-                        tokensIterated++;
-                    }
-
-                    // Now, restore the proper ordering so we can build the artifactId.
-                    Collections.reverse( avceTokenList );
-
-                    // if we didn't find a version, then punt. Use the last token
-                    // as the version, and set the classifier empty.
-                    if ( versionBuffer.length() < 1 )
-                    {
-                        if ( avceTokenList.size() > 1 )
-                        {
-                            int lastIdx = avceTokenList.size() - 1;
-
-                            versionBuffer.append( avceTokenList.get( lastIdx ) );
-                            avceTokenList.remove( lastIdx );
-                        }
-
-                        classifierBuffer.setLength( 0 );
-                    }
-                    else
-                    {
-                        // if everything is kosher, then pop off all the classifier and
-                        // version tokens, leaving the naked artifact id in the list.
-                        avceTokenList =
-                            new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) );
-                    }
-
-                    StringBuffer artifactIdBuffer = new StringBuffer();
-
-                    firstToken = true;
-                    for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
-                    {
-                        String token = (String) it.next();
-
-                        if ( firstToken )
-                        {
-                            firstToken = false;
-                        }
-                        else
-                        {
-                            artifactIdBuffer.append( '-' );
-                        }
-
-                        artifactIdBuffer.append( token );
-                    }
-
-                    String artifactId = artifactIdBuffer.toString();
-
-                    if ( artifactId.length() > 0 )
-                    {
-                        int lastVersionCharIdx = versionBuffer.length() - 1;
-                        if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
-                        {
-                            versionBuffer.setLength( lastVersionCharIdx );
-                        }
-
-                        String version = versionBuffer.toString();
-
-                        if ( version.length() >= 1 )
-                        {
-                            if ( classifierBuffer.length() > 0 )
-                            {
-                                result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
-                                                                                       type,
-                                                                                       classifierBuffer.toString() );
-                            }
-                            else
-                            {
-                                result = artifactFactory.createArtifact( groupId, artifactId, version,
-                                                                         Artifact.SCOPE_RUNTIME, type );
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        return result;
-    }
-}
diff --git a/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsLegacyTest.java b/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsLegacyTest.java
deleted file mode 100644 (file)
index 8a1359f..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-package org.apache.maven.repository;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-
-/**
- * @author Edwin Punzalan
- */
-public class ArtifactUtilsLegacyTest
-    extends PlexusTestCase
-{
-    private ArtifactFactory factory;
-
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        factory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
-    }
-
-    protected void tearDown()
-        throws Exception
-    {
-        container.release( factory );
-
-        super.tearDown();
-    }
-
-    public void testWrongArtifactPackaging()
-        throws ComponentLookupException
-    {
-        String testPath = "org.apache.maven.test/jars/artifactId-1.0.jar.md5";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for wrong package extension", artifact );
-    }
-
-    public void testNoArtifactid()
-    {
-        String testPath = "groupId/jars/-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null when artifactId is missing", artifact );
-
-        testPath = "groupId/jars/1.0.jar";
-
-        artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null when artifactId is missing", artifact );
-    }
-
-    public void testNoType()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1/invalid-1";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for no type", artifact );
-    }
-
-    public void testSnapshot()
-        throws ComponentLookupException
-    {
-        String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with invalid snapshot error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact );
-    }
-
-    public void testFinal()
-        throws ComponentLookupException
-    {
-        String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with invalid snapshot error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact );
-    }
-
-    public void testNormal()
-        throws ComponentLookupException
-    {
-        String testPath = "javax.sql/jars/jdbc-2.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Normal artifact path error", artifact );
-
-        assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
-    }
-
-    private Artifact getArtifactFromPath( String path )
-    {
-        return ArtifactUtils.buildArtifactFromLegacyPath( path, factory );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version )
-    {
-        return factory.createArtifact( groupId, artifactId, version, null, "jar" );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version, String type )
-    {
-        return factory.createArtifact( groupId, artifactId, version, null, type );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
-    {
-        return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
-    }
-}
diff --git a/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java b/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java
deleted file mode 100644 (file)
index 443758c..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-package org.apache.maven.repository;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-
-/**
- * @author Edwin Punzalan
- */
-public class ArtifactUtilsTest
-    extends PlexusTestCase
-{
-    private ArtifactFactory factory;
-
-    protected void tearDown()
-        throws Exception
-    {
-        container.release( factory );
-
-        super.tearDown();
-    }
-
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-
-        factory = (ArtifactFactory) container.lookup( ArtifactFactory.ROLE );
-    }
-
-    public void testShortPath()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for short paths", artifact );
-    }
-
-    public void testWrongArtifactId()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for wrong ArtifactId", artifact );
-    }
-
-    public void testNoType()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1/invalid-1";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for no type", artifact );
-    }
-
-    public void testWrongVersion()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1.0/invalid-2.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for wrong version", artifact );
-    }
-
-    public void testLongVersion()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1.0/invalid-1.0b.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for long version", artifact );
-    }
-
-    public void testWrongSnapshotVersion()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for wrong snapshot version", artifact );
-    }
-
-    public void testSnapshotBaseVersion()
-        throws ComponentLookupException
-    {
-        String testPath = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNull( "Artifact should be null for snapshot base version", artifact );
-    }
-
-    public void testPathWithClassifier()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with classifier error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ), artifact );
-    }
-
-    public void testWithJavaSourceInclusion()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/testing/1.0/testing-1.0-sources.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with java source inclusion error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ), artifact );
-    }
-
-    public void testDistributionArtifacts()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/testing/1.0/testing-1.0.tar.gz";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "tar.gz distribution artifact error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ), artifact );
-
-        testPath = "org/apache/maven/testing/1.0/testing-1.0.zip";
-
-        artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "zip distribution artifact error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ), artifact );
-    }
-
-    public void testSnapshot()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with invalid snapshot error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ), artifact );
-
-        testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar";
-
-        artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with snapshot error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ), artifact );
-    }
-
-    public void testNormal()
-        throws ComponentLookupException
-    {
-        String testPath = "javax/sql/jdbc/2.0/jdbc-2.0.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Normal artifact path error", artifact );
-
-        assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
-    }
-
-    public void testSnapshotWithClassifier()
-        throws ComponentLookupException
-    {
-        String testPath = "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar";
-
-        Artifact artifact = getArtifactFromPath( testPath );
-
-        assertNotNull( "Artifact path with snapshot and classifier error", artifact );
-
-        assertEquals( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1", "jar", "javadoc" ),
-                      artifact );
-    }
-
-    private Artifact getArtifactFromPath( String path )
-    {
-        return ArtifactUtils.buildArtifact( path, factory );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version )
-    {
-        return factory.createArtifact( groupId, artifactId, version, null, "jar" );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version, String type )
-    {
-        return factory.createArtifact( groupId, artifactId, version, null, type );
-    }
-
-    private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
-    {
-        return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
-    }
-}