*/
public abstract class AbstractArtifactDiscoverer
extends AbstractDiscoverer
+ implements ArtifactDiscoverer
{
/**
* Standard patterns to exclude from discovery as they are not artifacts.
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() ) )
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;
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;
+ }
}
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Iterator;
* @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 );
}
*/
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+).
*/
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;
}
}
*/
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
*/
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;
}
}
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;
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" );
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;
}
}
+ 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" );
<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
<check>\r
<!-- TODO: increase coverage -->\r
<totalLineRate>60</totalLineRate>\r
- <totalBranchRate>75</totalBranchRate>\r
+ <totalBranchRate>70</totalBranchRate>\r
</check>\r
</configuration>\r
</plugin>\r
*/
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;
*/
private WagonManager wagonManager;
- /**
- * @plexus.requirement
- */
- private ArtifactFactory artifactFactory;
-
/**
* @plexus.requirement
*/
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;
}
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 )
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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 );
- }
-}
+++ /dev/null
-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 );
- }
-}