Author: brett Date: Wed Jun 7 00:26:09 2006 New Revision: 412310 URL: http://svn.apache.org/viewvc?rev=412310&view=rev Log: remove artifact utils
Removed: maven/repository-manager/trunk/maven-repository-utils/src/main/java/org/apache/maven/repository/ArtifactUtils.java maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsLegacyTest.java maven/repository-manager/trunk/maven-repository-utils/src/test/java/org/apache/maven/repository/ArtifactUtilsTest.java Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java maven/repository-manager/trunk/maven-repository-proxy/pom.xml maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java Wed Jun 7 00:26:09 2006 @@ -37,6 +37,7 @@ */ public abstract class AbstractArtifactDiscoverer extends AbstractDiscoverer + implements ArtifactDiscoverer { /** * Standard patterns to exclude from discovery as they are not artifacts. @@ -55,8 +56,6 @@ 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 @@ 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; @@ -143,5 +138,18 @@ } 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; } } Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java Wed Jun 7 00:26:09 2006 @@ -16,6 +16,7 @@ * 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 @@ * @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 ); } Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java Wed Jun 7 00:26:09 2006 @@ -17,8 +17,12 @@ */ 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 @@ */ 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; } } Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java Wed Jun 7 00:26:09 2006 @@ -17,13 +17,18 @@ */ 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 @@ */ 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; } } Modified: maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java Wed Jun 7 00:26:09 2006 @@ -23,6 +23,7 @@ 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; @@ -401,6 +402,170 @@ assertEquals( "org.apache.testgroup", model.getGroupId() ); assertEquals( "discovery", model.getArtifactId() ); 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 ) Modified: maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java (original) +++ maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java Wed Jun 7 00:26:09 2006 @@ -22,6 +22,7 @@ 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; @@ -330,6 +331,82 @@ assertNotNull( "Check repository set", artifact.getRepository() ); assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() ); } + } + + 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 ) Modified: maven/repository-manager/trunk/maven-repository-proxy/pom.xml URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-proxy/pom.xml?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-proxy/pom.xml (original) +++ maven/repository-manager/trunk/maven-repository-proxy/pom.xml Wed Jun 7 00:26:09 2006 @@ -27,7 +27,7 @@ <dependencies> <dependency> <groupId>org.apache.maven.repository</groupId> - <artifactId>maven-repository-utils</artifactId> + <artifactId>maven-repository-discovery</artifactId> </dependency> <dependency> <groupId>org.apache.maven</groupId> @@ -56,7 +56,7 @@ <check> <!-- TODO: increase coverage --> <totalLineRate>60</totalLineRate> - <totalBranchRate>75</totalBranchRate> + <totalBranchRate>70</totalBranchRate> </check> </configuration> </plugin> Modified: maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java?rev=412310&r1=412309&r2=412310&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java (original) +++ maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java Wed Jun 7 00:26:09 2006 @@ -17,14 +17,13 @@ */ 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; @@ -67,11 +66,6 @@ /** * @plexus.requirement */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ private ArtifactRepositoryFactory repositoryFactory; /** @@ -91,6 +85,17 @@ 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 @@ } 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 )