You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2014/06/28 13:55:25 UTC
[3/7] Squashed the indexer-artifact into indexer-core.
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-artifact/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
----------------------------------------------------------------------
diff --git a/indexer-artifact/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java b/indexer-artifact/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
deleted file mode 100644
index 0881010..0000000
--- a/indexer-artifact/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
+++ /dev/null
@@ -1,760 +0,0 @@
-package org.apache.maven.index.artifact;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 java.text.ParseException;
-import java.text.SimpleDateFormat;
-
-import junit.framework.TestCase;
-
-import org.apache.maven.index.artifact.Gav;
-import org.apache.maven.index.artifact.M2GavCalculator;
-
-public class M2GavCalculatorTest
- extends TestCase
-{
- private M2GavCalculator gavCalculator;
-
- private SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
-
- @Override
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- gavCalculator = new M2GavCalculator();
- }
-
- protected Long parseTimestamp( String timeStamp )
- throws ParseException
- {
- if ( timeStamp == null )
- {
- return null;
- }
- else
- {
- return Long.valueOf( formatter.parse( timeStamp ).getTime() );
- }
- }
-
- public void testGav()
- throws Exception
- {
- Gav gav;
- String path;
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-25-javadoc.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0RC1-20070504.160758-25", gav.getVersion() );
- assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "javadoc", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 25 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20070504.160758" ), gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0RC1-20070504.160758-25-javadoc.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-25-javadoc.jar", path );
-
- gav =
- gavCalculator.pathToGav( "/com/sun/xml/ws/jaxws-local-transport/2.1.3/jaxws-local-transport-2.1.3.pom.md5" );
-
- assertEquals( "com.sun.xml.ws", gav.getGroupId() );
- assertEquals( "jaxws-local-transport", gav.getArtifactId() );
- assertEquals( "2.1.3", gav.getVersion() );
- assertEquals( "2.1.3", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "jaxws-local-transport-2.1.3.pom.md5", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.md5, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/com/sun/xml/ws/jaxws-local-transport/2.1.3/jaxws-local-transport-2.1.3.pom.md5", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0RC1-20070504.160758-2", gav.getVersion() );
- assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 2 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20070504.160758" ), gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0RC1-20070504.160758-2.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar.md5" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0RC1-20070504.160758-2", gav.getVersion() );
- assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 2 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20070504.160758" ), gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0RC1-20070504.160758-2.jar.md5", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.md5, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar.md5", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0RC1-20070504.160758-2", gav.getVersion() );
- assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 2 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20070504.160758" ), gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0RC1-20070504.160758-2.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2.jar", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2-sources.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0RC1-20070504.160758-2", gav.getVersion() );
- assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "sources", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 2 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20070504.160758" ), gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0RC1-20070504.160758-2-sources.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0RC1-SNAPSHOT/jruby-1.0RC1-20070504.160758-2-sources.jar", path );
-
- gav =
- gavCalculator.pathToGav( "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT.jar.sha1" );
-
- assertEquals( "com.stchome.products.dsms.services", gav.getGroupId() );
- assertEquals( "dsms-intervention-service", gav.getArtifactId() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getVersion() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "dsms-intervention-service-2.4.2-64-SNAPSHOT.jar.sha1", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.sha1, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT.jar.sha1",
- path );
-
- gav =
- gavCalculator.pathToGav( "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT-javadoc.jar.sha1" );
-
- assertEquals( "com.stchome.products.dsms.services", gav.getGroupId() );
- assertEquals( "dsms-intervention-service", gav.getArtifactId() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getVersion() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "javadoc", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "dsms-intervention-service-2.4.2-64-SNAPSHOT-javadoc.jar.sha1", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.sha1, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT-javadoc.jar.sha1",
- path );
-
- gav =
- gavCalculator.pathToGav( "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT.jar" );
-
- assertEquals( "com.stchome.products.dsms.services", gav.getGroupId() );
- assertEquals( "dsms-intervention-service", gav.getArtifactId() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getVersion() );
- assertEquals( "2.4.2-64-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "dsms-intervention-service-2.4.2-64-SNAPSHOT.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/com/stchome/products/dsms/services/dsms-intervention-service/2.4.2-64-SNAPSHOT/dsms-intervention-service-2.4.2-64-SNAPSHOT.jar",
- path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0/jruby-1.0-javadoc.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0", gav.getVersion() );
- assertEquals( "1.0", gav.getBaseVersion() );
- assertEquals( "javadoc", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0-javadoc.jar", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0/jruby-1.0-javadoc.jar", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0/jruby-1.0-javadoc.jar.sha1" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0", gav.getVersion() );
- assertEquals( "1.0", gav.getBaseVersion() );
- assertEquals( "javadoc", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0-javadoc.jar.sha1", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.sha1, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0/jruby-1.0-javadoc.jar.sha1", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0/jruby-1.0.jar" );
-
- assertEquals( "org.jruby", gav.getGroupId() );
- assertEquals( "jruby", gav.getArtifactId() );
- assertEquals( "1.0", gav.getVersion() );
- assertEquals( "1.0", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "jruby-1.0.jar", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/jruby/jruby/1.0/jruby-1.0.jar", path );
-
- gav = gavCalculator.pathToGav( "/activemq/activemq-core/1.2/activemq-core-1.2.pom" );
-
- assertEquals( "activemq", gav.getGroupId() );
- assertEquals( "activemq-core", gav.getArtifactId() );
- assertEquals( "1.2", gav.getVersion() );
- assertEquals( "1.2", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "activemq-core-1.2.pom", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/activemq/activemq-core/1.2/activemq-core-1.2.pom", path );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0/maven-metadata.xml" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/org/jruby/jruby/1.0-SNAPSHOT/maven-metadata.xml" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/junit/junit/3.8/junit-3.8.jar" );
- assertEquals( "junit", gav.getGroupId() );
- assertEquals( "junit", gav.getArtifactId() );
- assertEquals( "3.8", gav.getVersion() );
- assertEquals( "3.8", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "junit-3.8.jar", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- gav = gavCalculator.pathToGav( "/foo1/foo1/0.0.1-SNAPSHOT/foo1-0.0.1-SNAPSHOT.pom" );
- assertEquals( "foo1", gav.getGroupId() );
- assertEquals( "foo1", gav.getArtifactId() );
- assertEquals( "0.0.1-SNAPSHOT", gav.getVersion() );
- assertEquals( "0.0.1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "foo1-0.0.1-SNAPSHOT.pom", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo1/foo1/0.0.1-SNAPSHOT/foo1-0.0.1-SNAPSHOT.pom", path );
-
- // NEXUS-3148
- gav = gavCalculator.pathToGav( "/foo1/foo1/0.0.1SNAPSHOT/foo1-0.0.1SNAPSHOT.pom" );
- assertEquals( "foo1", gav.getGroupId() );
- assertEquals( "foo1", gav.getArtifactId() );
- assertEquals( "0.0.1SNAPSHOT", gav.getVersion() );
- assertEquals( "0.0.1SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "foo1-0.0.1SNAPSHOT.pom", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo1/foo1/0.0.1SNAPSHOT/foo1-0.0.1SNAPSHOT.pom", path );
-
- gav = gavCalculator.pathToGav( "/foo1/foo1/0.0.1.SNAPSHOT/foo1-0.0.1.SNAPSHOT.pom" );
- assertEquals( "foo1", gav.getGroupId() );
- assertEquals( "foo1", gav.getArtifactId() );
- assertEquals( "0.0.1.SNAPSHOT", gav.getVersion() );
- assertEquals( "0.0.1.SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "foo1-0.0.1.SNAPSHOT.pom", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo1/foo1/0.0.1.SNAPSHOT/foo1-0.0.1.SNAPSHOT.pom", path );
-
- // NEXUS-3148 ends
-
- gav = gavCalculator.pathToGav( "/foo1/foo1/0.0.1-SNAPSHOT/foo1-0.0.1-SNAPSHOT-jdk14.jar" );
- assertEquals( "foo1", gav.getGroupId() );
- assertEquals( "foo1", gav.getArtifactId() );
- assertEquals( "0.0.1-SNAPSHOT", gav.getVersion() );
- assertEquals( "0.0.1-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "jdk14", gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "foo1-0.0.1-SNAPSHOT-jdk14.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo1/foo1/0.0.1-SNAPSHOT/foo1-0.0.1-SNAPSHOT-jdk14.jar", path );
-
- gav = gavCalculator.pathToGav( "/foo1/foo1/1.0.0-beta-4-SNAPSHOT/foo1-1.0.0-beta-4-20080623.175436-1.jar" );
- assertEquals( "foo1", gav.getGroupId() );
- assertEquals( "foo1", gav.getArtifactId() );
- assertEquals( "1.0.0-beta-4-20080623.175436-1", gav.getVersion() );
- assertEquals( "1.0.0-beta-4-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 1 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080623.175436" ), gav.getSnapshotTimeStamp() );
- assertEquals( "foo1-1.0.0-beta-4-20080623.175436-1.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo1/foo1/1.0.0-beta-4-SNAPSHOT/foo1-1.0.0-beta-4-20080623.175436-1.jar", path );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-4-SNAPSHOT/nexus-webapp-1.0.0-beta-4-20080623.203653-349.pom" );
- assertEquals( "org.sonatype.nexus", gav.getGroupId() );
- assertEquals( "nexus-webapp", gav.getArtifactId() );
- assertEquals( "1.0.0-beta-4-20080623.203653-349", gav.getVersion() );
- assertEquals( "1.0.0-beta-4-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( Integer.valueOf( 349 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080623.203653" ), gav.getSnapshotTimeStamp() );
- assertEquals( "nexus-webapp-1.0.0-beta-4-20080623.203653-349.pom", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-4-SNAPSHOT/nexus-webapp-1.0.0-beta-4-20080623.203653-349.pom",
- path );
-
- gav =
- gavCalculator.pathToGav( "/org/apache/maven/artifact/maven-artifact/3.0-SNAPSHOT/maven-artifact-3.0-20080411.005221-75.pom.asc" );
- assertEquals( "org.apache.maven.artifact", gav.getGroupId() );
- assertEquals( "maven-artifact", gav.getArtifactId() );
- assertEquals( "3.0-20080411.005221-75", gav.getVersion() );
- assertEquals( "3.0-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( Integer.valueOf( 75 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080411.005221" ), gav.getSnapshotTimeStamp() );
- assertEquals( "maven-artifact-3.0-20080411.005221-75.pom.asc", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
- assertEquals( true, gav.isSignature() );
- assertEquals( Gav.SignatureType.gpg, gav.getSignatureType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/org/apache/maven/artifact/maven-artifact/3.0-SNAPSHOT/maven-artifact-3.0-20080411.005221-75.pom.asc",
- path );
-
- gav =
- gavCalculator.pathToGav( "/org/apache/maven/artifact/maven-artifact/3.0-SNAPSHOT/maven-artifact-3.0-20080411.005221-75.pom.asc.sha1" );
- assertEquals( "org.apache.maven.artifact", gav.getGroupId() );
- assertEquals( "maven-artifact", gav.getArtifactId() );
- assertEquals( "3.0-20080411.005221-75", gav.getVersion() );
- assertEquals( "3.0-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( Integer.valueOf( 75 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080411.005221" ), gav.getSnapshotTimeStamp() );
- assertEquals( "maven-artifact-3.0-20080411.005221-75.pom.asc.sha1", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.sha1, gav.getHashType() );
- assertEquals( true, gav.isSignature() );
- assertEquals( Gav.SignatureType.gpg, gav.getSignatureType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals(
- "/org/apache/maven/artifact/maven-artifact/3.0-SNAPSHOT/maven-artifact-3.0-20080411.005221-75.pom.asc.sha1",
- path );
-
- gav =
- gavCalculator.pathToGav( "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080302.032223-6-bin.zip.sha1" );
- assertEquals( "org.apache.maven", gav.getGroupId() );
- assertEquals( "maven-core", gav.getArtifactId() );
- assertEquals( "2.0.9-20080302.032223-6", gav.getVersion() );
- assertEquals( "2.0.9-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "zip", gav.getExtension() );
- assertEquals( Integer.valueOf( 6 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080302.032223" ), gav.getSnapshotTimeStamp() );
- assertEquals( "maven-core-2.0.9-20080302.032223-6-bin.zip.sha1", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( true, gav.isHash() );
- assertEquals( Gav.HashType.sha1, gav.getHashType() );
- assertEquals( false, gav.isSignature() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080302.032223-6-bin.zip.sha1",
- path );
-
- gav =
- gavCalculator.pathToGav( "/org/apache/maven/maven-core/2.0.9-SNAPSHOT/maven-core-2.0.9-20080302.032223-6-bin.tar.gz" );
- assertEquals( "org.apache.maven", gav.getGroupId() );
- assertEquals( "maven-core", gav.getArtifactId() );
- assertEquals( "2.0.9-20080302.032223-6", gav.getVersion() );
- assertEquals( "2.0.9-SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( Integer.valueOf( 6 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080302.032223" ), gav.getSnapshotTimeStamp() );
- assertEquals( "maven-core-2.0.9-20080302.032223-6-bin.tar.gz", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
- assertEquals( false, gav.isSignature() );
-
- gav = gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.4.0/nexus-webapp-1.4.0-bundle.tar.gz" );
- assertEquals( "org.sonatype.nexus", gav.getGroupId() );
- assertEquals( "nexus-webapp", gav.getArtifactId() );
- assertEquals( "1.4.0", gav.getVersion() );
- assertEquals( "1.4.0", gav.getBaseVersion() );
- assertEquals( "bundle", gav.getClassifier() );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "nexus-webapp-1.4.0-bundle.tar.gz", gav.getName() );
- assertEquals( false, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
- assertEquals( false, gav.isSignature() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/sonatype/nexus/nexus-webapp/1.4.0/nexus-webapp-1.4.0-bundle.tar.gz", path );
-
- gav = gavCalculator.pathToGav( "/foo/artifact/SNAPSHOT/artifact-SNAPSHOT.jar" );
- assertEquals( "foo", gav.getGroupId() );
- assertEquals( "artifact", gav.getArtifactId() );
- assertEquals( "SNAPSHOT", gav.getVersion() );
- assertEquals( "SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( null, gav.getSnapshotBuildNumber() );
- assertEquals( null, gav.getSnapshotTimeStamp() );
- assertEquals( "artifact-SNAPSHOT.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo/artifact/SNAPSHOT/artifact-SNAPSHOT.jar", path );
-
- gav = gavCalculator.pathToGav( "/foo/artifact/SNAPSHOT/artifact-20080623.175436-1.jar" );
- assertEquals( "foo", gav.getGroupId() );
- assertEquals( "artifact", gav.getArtifactId() );
- assertEquals( "20080623.175436-1", gav.getVersion() );
- assertEquals( "SNAPSHOT", gav.getBaseVersion() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( Integer.valueOf( 1 ), gav.getSnapshotBuildNumber() );
- assertEquals( parseTimestamp( "20080623.175436" ), gav.getSnapshotTimeStamp() );
- assertEquals( "artifact-20080623.175436-1.jar", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- path = gavCalculator.gavToPath( gav );
- assertEquals( "/foo/artifact/SNAPSHOT/artifact-20080623.175436-1.jar", path );
- }
-
- public void testNegGav()
- throws Exception
- {
- Gav gav;
-
- // NEXUS-4132
- gav =
- gavCalculator.pathToGav( "/com/electrabel/connection-register-ear/1.2-SNAPSHOT/connection-register-ear-1.2-20101214.143755.ear" );
- assertNull( "Should fail, since the filename lacks the -BBB build number, hence, is not valid snapshot", gav );
- // NEXUS-4132 END
- }
-
- public void testGavExtreme()
- throws Exception
- {
- Gav gav;
-
- gav = gavCalculator.pathToGav( "/" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/some/stupid/path" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/some/stupid/path/more/in/it" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/something/that/looks/" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/something/that/looks/like-an-artifact.blah" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "/something/that/looks/like-an-artifact.pom" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "org/apache/maven/scm/maven-scm" );
- assertEquals( null, gav );
-
- gav = gavCalculator.pathToGav( "org/apache/geronimo/javamail/geronimo-javamail_1.4_mail" );
- assertEquals( null, gav );
-
- // this is metadata, will return null
- gav = gavCalculator.pathToGav( "/something/that/looks/maven-metadata.xml" );
- assertEquals( null, gav );
-
- // this is metadata, will return null
- gav = gavCalculator.pathToGav( "/something/that/looks/like-SNAPSHOT/maven-metadata.xml" );
- assertEquals( null, gav );
-
- // this is metadata, will return null
- gav = gavCalculator.pathToGav( "/org/codehaus/plexus/plexus-container-default/maven-metadata.xml" );
- assertEquals( null, gav );
- }
-
- public void testIssueNexus57()
- throws Exception
- {
- // broken path, baseVersion and version mismatch (2.0-SNAPSHOT vs 2.0-alpha-1...)
- Gav gav =
- gavCalculator.pathToGav( "/org/apache/maven/plugins/maven-dependency-plugin/2.0-SNAPSHOT/maven-dependency-plugin-2.0-alpha-1-20070109.165112-13.jar" );
-
- assertNull( "We expect null since baseVersion and version mismatch in path!", gav );
- }
-
- public void testGavExtensionAndClassifier()
- throws Exception
- {
- Gav gav;
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5/nexus-webapp-1.0.0-beta-5.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "1.0.0-beta-5", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5/nexus-webapp-1.0.0-beta-5-bundle.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bundle", gav.getClassifier() );
- assertEquals( "1.0.0-beta-5", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/codehaus/tycho/tycho-distribution/0.3.0-SNAPSHOT/tycho-distribution-0.3.0-SNAPSHOT-bin.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "0.3.0-SNAPSHOT", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/codehaus/tycho/tycho-distribution/SNAPSHOT/tycho-distribution-SNAPSHOT-bin.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "SNAPSHOT", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/codehaus/tycho/tycho-distribution/0.3.0-SNAPSHOT/tycho-distribution-0.3.0-20080818.153246-33-bin.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "0.3.0-20080818.153246-33", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-4.2/nexus-webapp-1.0.0-beta-4.2-javadoc.jar" );
- assertNotNull( gav );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( "javadoc", gav.getClassifier() );
- assertEquals( "1.0.0-beta-4.2", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/codehaus/tycho/tycho-distribution/0.3.0-SNAPSHOT/tycho-distribution-0.3.0-20080818.153246-33-bin.zip" );
- assertNotNull( gav );
- assertEquals( "zip", gav.getExtension() );
- assertEquals( "bin", gav.getClassifier() );
- assertEquals( "0.3.0-20080818.153246-33", gav.getVersion() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/tools/nexus-migration-app/1.0.0-beta-6-SNAPSHOT/nexus-migration-app-1.0.0-beta-6-20080809.181715-2-cli.jar" );
- assertNotNull( gav );
- assertEquals( "jar", gav.getExtension() );
- assertEquals( "cli", gav.getClassifier() );
- assertEquals( "1.0.0-beta-6-20080809.181715-2", gav.getVersion() );
- }
-
- public void testGavSnapshotVersion()
- throws Exception
- {
- Gav gav;
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5-SNAPSHOT/nexus-webapp-1.0.0-beta-5-SNAPSHOT.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "1.0.0-beta-5-SNAPSHOT", gav.getVersion() );
- assertTrue( gav.isSnapshot() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5-SNAPSHOT-1234/nexus-webapp-1.0.0-beta-5-SNAPSHOT-1234.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "1.0.0-beta-5-SNAPSHOT-1234", gav.getVersion() );
- assertFalse( gav.isSnapshot() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5-SNAPSHOT/nexus-webapp-1.0.0-beta-5-SNAPSHOT-bundle.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bundle", gav.getClassifier() );
- assertEquals( "1.0.0-beta-5-SNAPSHOT", gav.getVersion() );
- assertTrue( gav.isSnapshot() );
-
- gav =
- gavCalculator.pathToGav( "/org/sonatype/nexus/nexus-webapp/1.0.0-beta-5-SNAPSHOT-1234/nexus-webapp-1.0.0-beta-5-SNAPSHOT-1234-bundle.tar.gz" );
- assertNotNull( gav );
- assertEquals( "tar.gz", gav.getExtension() );
- assertEquals( "bundle", gav.getClassifier() );
- assertEquals( "1.0.0-beta-5-SNAPSHOT-1234", gav.getVersion() );
- assertFalse( gav.isSnapshot() );
- }
-
- public void testGavLooseStrictedSnapshot()
- throws Exception
- {
- Gav gav;
-
- gav = gavCalculator.pathToGav( "/org/sonatype/nexus-3148/1.0.SNAPSHOT/nexus-3148-1.0.20100111.064938-1.pom" );
- assertNotNull( gav );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( "1.0.20100111.064938-1", gav.getVersion() );
- assertEquals( "1.0.SNAPSHOT", gav.getBaseVersion() );
- assertEquals( "org.sonatype", gav.getGroupId() );
- assertEquals( "nexus-3148", gav.getArtifactId() );
- assertEquals( null, gav.getClassifier() );
- assertEquals( "pom", gav.getExtension() );
- assertEquals( new Integer( 1 ), gav.getSnapshotBuildNumber() );
- // the timestamp is UTC, not EST timezoned!
- // also, the Gav is it seems TZ sensitive!!!
- assertEquals( parseTimestamp( "20100111.064938" ), gav.getSnapshotTimeStamp() );
- assertEquals( "nexus-3148-1.0.20100111.064938-1.pom", gav.getName() );
- assertEquals( true, gav.isSnapshot() );
- assertEquals( false, gav.isHash() );
- assertEquals( null, gav.getHashType() );
-
- String path = gavCalculator.gavToPath( gav );
- assertEquals( "/org/sonatype/nexus-3148/1.0.SNAPSHOT/nexus-3148-1.0.20100111.064938-1.pom", path );
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-artifact/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
----------------------------------------------------------------------
diff --git a/indexer-artifact/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java b/indexer-artifact/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
deleted file mode 100644
index 8fd1691..0000000
--- a/indexer-artifact/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.apache.maven.index.artifact;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.index.artifact.M2ArtifactRecognizer;
-
-import junit.framework.TestCase;
-
-public class MavenArtifactRecognizerTest
- extends TestCase
-{
-
- public void testIsPom()
- {
- assertEquals( true, M2ArtifactRecognizer.isPom( "aaa.pom" ) );
- assertEquals( true, M2ArtifactRecognizer.isPom( "zxc-1-2-3.pom" ) );
- assertEquals( false, M2ArtifactRecognizer.isPom( "aaa.jar" ) );
- assertEquals( false, M2ArtifactRecognizer.isPom( "aaa.pom-a" ) );
- }
-
- public void testIsSnapshot1()
- {
- // NEXUS-3148
- assertEquals( true, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0SNAPSHOT/aid-1.0SNAPSHOT.jar" ) );
-
- assertEquals( true, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0-SNAPSHOT/aid-1.0-SNAPSHOT.jar" ) );
- assertEquals( true, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0-SNAPSHOT/aid-1.0-SNAPSHOT.pom" ) );
- assertEquals( true, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0-SNAPSHOT/aid-1.2.3-.pom" ) );
- assertEquals( false, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0/xsd-SNAPsHOT.jar" ) );
- assertEquals( false, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0/xsd-SNAPHOT.pom" ) );
- assertEquals( false, M2ArtifactRecognizer.isSnapshot( "/org/somewhere/aid/1.0/a/b/c/xsd-1.2.3NAPSHOT.pom" ) );
- assertEquals( false, M2ArtifactRecognizer.isSnapshot( "/javax/mail/mail/1.4/mail-1.4.jar" ) );
- }
-
- public void testIsSnapshot2()
- {
- assertEquals(
- true,
- M2ArtifactRecognizer.isSnapshot( "/org/somewhere/appassembler-maven-plugin/1.0-SNAPSHOT/appassembler-maven-plugin-1.0-20060714.142547-1.pom" ) );
- assertEquals(
- false,
- M2ArtifactRecognizer.isSnapshot( "/org/somewhere/appassembler-maven-plugin/1.0/appassembler-maven-plugin-1.0-20060714.142547-1.pom" ) );
- }
-
- public void testIsMetadata()
- {
- assertEquals( true, M2ArtifactRecognizer.isMetadata( "maven-metadata.xml" ) );
- assertEquals( false, M2ArtifactRecognizer.isMetadata( "aven-metadata.xml" ) );
- assertEquals( false, M2ArtifactRecognizer.isMetadata( "/javax/mail/mail/1.4/mail-1.4.jar" ) );
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/ArtifactPackagingMapper.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/ArtifactPackagingMapper.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/ArtifactPackagingMapper.java
new file mode 100644
index 0000000..6783884
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/ArtifactPackagingMapper.java
@@ -0,0 +1,46 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.io.File;
+
+/**
+ * A utility component that resolves POM packaging to artifact extension. Different implementations may provide
+ * different means to do it.
+ *
+ * @author cstamas
+ */
+public interface ArtifactPackagingMapper
+{
+ /**
+ * Returns the extension belonging to given packaging, like "jar" for "jar", "jar" for "ear", etc.
+ *
+ * @param packaging
+ * @return
+ */
+ String getExtensionForPackaging( String packaging );
+
+ /**
+ * Sets the file to source the user provided mappings from, and resets the mappings, forcing it to reload the file.
+ *
+ * @param file
+ */
+ void setPropertiesFile( File file );
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
new file mode 100644
index 0000000..9f3caa5
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java
@@ -0,0 +1,171 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * A very simple artifact packaging mapper, that has everything for quick-start wired in this class. Also, it takes into
+ * account the "${nexus-work}/conf/packaging2extension-mapping.properties" file into account if found. To override the
+ * "defaults" in this class, simply add lines to properties file with same keys.
+ *
+ * @author cstamas
+ */
+@Component( role = ArtifactPackagingMapper.class )
+public class DefaultArtifactPackagingMapper
+ extends AbstractLogEnabled
+ implements ArtifactPackagingMapper
+{
+
+ public static final String MAPPING_PROPERTIES_FILE = "packaging2extension-mapping.properties";
+
+ private File propertiesFile;
+
+ private volatile Map<String, String> packaging2extensionMapping;
+
+ private final static Map<String, String> defaults;
+
+ static
+ {
+ defaults = new HashMap<String, String>();
+ defaults.put( "ejb-client", "jar" );
+ defaults.put( "ejb", "jar" );
+ defaults.put( "rar", "jar" );
+ defaults.put( "par", "jar" );
+ defaults.put( "maven-plugin", "jar" );
+ defaults.put( "maven-archetype", "jar" );
+ defaults.put( "plexus-application", "jar" );
+ defaults.put( "eclipse-plugin", "jar" );
+ defaults.put( "eclipse-feature", "jar" );
+ defaults.put( "eclipse-application", "zip" );
+ defaults.put( "nexus-plugin", "jar" );
+ defaults.put( "java-source", "jar" );
+ defaults.put( "javadoc", "jar" );
+ defaults.put( "test-jar", "jar" );
+ }
+
+ public void setPropertiesFile( File propertiesFile )
+ {
+ this.propertiesFile = propertiesFile;
+ this.packaging2extensionMapping = null;
+ }
+
+ public Map<String, String> getPackaging2extensionMapping()
+ {
+ if ( packaging2extensionMapping == null )
+ {
+ synchronized ( this )
+ {
+ if ( packaging2extensionMapping == null )
+ {
+ packaging2extensionMapping = new HashMap<String, String>();
+
+ // merge defaults
+ packaging2extensionMapping.putAll( defaults );
+
+ if ( propertiesFile != null && propertiesFile.exists() )
+ {
+ getLogger().info( "Found user artifact packaging mapping file, applying it..." );
+
+ Properties userMappings = new Properties();
+
+ FileInputStream fis = null;
+
+ try
+ {
+ fis = new FileInputStream( propertiesFile );
+
+ userMappings.load( fis );
+
+ if ( userMappings.keySet().size() > 0 )
+ {
+ for ( Object key : userMappings.keySet() )
+ {
+ packaging2extensionMapping.put( key.toString(),
+ userMappings.getProperty( key.toString() ) );
+ }
+
+ getLogger().info(
+ propertiesFile.getAbsolutePath()
+ + " user artifact packaging mapping file contained "
+ + userMappings.keySet().size() + " mappings, applied them all succesfully." );
+ }
+ }
+ catch ( IOException e )
+ {
+ getLogger().warn(
+ "Got IO exception during read of file: " + propertiesFile.getAbsolutePath() );
+ }
+ finally
+ {
+ IOUtil.close( fis );
+ }
+
+ }
+ else
+ {
+ // make it silent if using defaults
+ getLogger().debug(
+ "User artifact packaging mappings file not found, will work with defaults..." );
+ }
+ }
+ }
+ }
+
+ return packaging2extensionMapping;
+ }
+
+ public void setPackaging2extensionMapping( Map<String, String> packaging2extensionMapping )
+ {
+ this.packaging2extensionMapping = packaging2extensionMapping;
+ }
+
+ public Map<String, String> getDefaults()
+ {
+ return defaults;
+ }
+
+ public String getExtensionForPackaging( String packaging )
+ {
+ if ( packaging == null )
+ {
+ return "jar";
+ }
+
+ if ( getPackaging2extensionMapping().containsKey( packaging ) )
+ {
+ return getPackaging2extensionMapping().get( packaging );
+ }
+ else
+ {
+ // default's to packaging name, ie. "jar", "war", "pom", etc.
+ return packaging;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/Gav.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/Gav.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/Gav.java
new file mode 100644
index 0000000..d7c2d59
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/Gav.java
@@ -0,0 +1,423 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * An immutable value class representing unique artifact coordinates.
+ *
+ * @author cstamas
+ * @author jvanzyl
+ */
+public class Gav
+{
+ /**
+ * Enumeration representing Maven artifact hash types
+ */
+ public enum HashType
+ {
+ sha1, md5
+ }
+
+ /**
+ * Enumeration representing Maven artifact signature types
+ */
+ public enum SignatureType
+ {
+ gpg;
+
+ @Override
+ public String toString()
+ {
+ switch ( this )
+ {
+ case gpg:
+ {
+ return "asc";
+ }
+
+ default:
+ {
+ return "unknown-signature-type";
+ }
+ }
+ }
+ }
+
+ private final String groupId;
+
+ private final String artifactId;
+
+ private final String version;
+
+ private final String baseVersion;
+
+ private final String classifier;
+
+ private final String extension;
+
+ private final Integer snapshotBuildNumber;
+
+ private final Long snapshotTimeStamp;
+
+ private final String name;
+
+ private final boolean snapshot;
+
+ private final boolean hash;
+
+ private final HashType hashType;
+
+ private final boolean signature;
+
+ private final SignatureType signatureType;
+
+ public Gav( String groupId, String artifactId, String version )
+ {
+ this( groupId, artifactId, version, null, null, null, null, null, false, null, false, null );
+ }
+
+ public Gav( String groupId, String artifactId, String version, String classifier, String extension,
+ Integer snapshotBuildNumber, Long snapshotTimeStamp, String name, boolean hash, HashType hashType,
+ boolean signature, SignatureType signatureType )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ this.snapshot = VersionUtils.isSnapshot( version );
+
+ if ( !snapshot )
+ {
+ this.baseVersion = null;
+ }
+ else
+ {
+ if ( version.contains( "SNAPSHOT" ) )
+ {
+ // this is not a timestamped version
+ this.baseVersion = null;
+ }
+ else
+ {
+ // this is a timestamped version (verified against pattern, see above)
+ // we have XXXXXX-YYYYMMDD.HHMMSS-B
+ // but XXXXXX may contain "-" too!
+
+ // if ( new DefaultNexusEnforcer().isStrict() )
+ // {
+ // this.baseVersion = version.substring( 0, version.lastIndexOf( '-' ) );
+ // this.baseVersion = baseVersion.substring( 0, baseVersion.lastIndexOf( '-' ) ) + "-SNAPSHOT";
+ // }
+ // also there may be no XXXXXX (i.e. when version is strictly named SNAPSHOT
+ // BUT this is not the proper scheme, we will simply loosen up here if requested
+ // else
+ // {
+ // trim the part of 'YYYYMMDD.HHMMSS-BN
+ String tempBaseVersion = version.substring( 0, version.lastIndexOf( '-' ) );
+ tempBaseVersion = tempBaseVersion.substring( 0, tempBaseVersion.length() - 15 );
+
+ if ( tempBaseVersion.length() > 0 )
+ {
+ this.baseVersion = tempBaseVersion + "SNAPSHOT";
+ }
+ else
+ {
+ this.baseVersion = "SNAPSHOT";
+ }
+ // }
+ }
+ }
+
+ this.classifier = classifier;
+ this.extension = extension;
+ this.snapshotBuildNumber = snapshotBuildNumber;
+ this.snapshotTimeStamp = snapshotTimeStamp;
+ this.name = name;
+ this.hash = hash;
+ this.hashType = hashType;
+ this.signature = signature;
+ this.signatureType = signatureType;
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public String getBaseVersion()
+ {
+ if ( baseVersion == null )
+ {
+ return getVersion();
+ }
+ else
+ {
+ return baseVersion;
+ }
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean isSnapshot()
+ {
+ return snapshot;
+ }
+
+ public Integer getSnapshotBuildNumber()
+ {
+ return snapshotBuildNumber;
+ }
+
+ public Long getSnapshotTimeStamp()
+ {
+ return snapshotTimeStamp;
+ }
+
+ public boolean isHash()
+ {
+ return hash;
+ }
+
+ public HashType getHashType()
+ {
+ return hashType;
+ }
+
+ public boolean isSignature()
+ {
+ return signature;
+ }
+
+ public SignatureType getSignatureType()
+ {
+ return signatureType;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 1;
+ result = 31 * result + ( groupId == null ? 0 : groupId.hashCode() );
+ result = 31 * result + ( artifactId == null ? 0 : artifactId.hashCode() );
+ result = 31 * result + ( version == null ? 0 : version.hashCode() );
+ result = 31 * result + ( baseVersion == null ? 0 : baseVersion.hashCode() );
+ result = 31 * result + ( classifier == null ? 0 : classifier.hashCode() );
+ result = 31 * result + ( extension == null ? 0 : extension.hashCode() );
+ result = 31 * result + ( name == null ? 0 : name.hashCode() );
+ result = 31 * result + ( snapshot ? 1231 : 1237 );
+ result = 31 * result + ( snapshotBuildNumber == null ? 0 : snapshotBuildNumber.hashCode() );
+ result = 31 * result + ( snapshotTimeStamp == null ? 0 : snapshotTimeStamp.hashCode() );
+ result = 31 * result + ( hash ? 1231 : 1237 );
+ result = 31 * result + ( hashType == null ? 0 : hashType.hashCode() );
+ result = 31 * result + ( signature ? 1231 : 1237 );
+ result = 31 * result + ( signatureType == null ? 0 : signatureType.hashCode() );
+ return result;
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ {
+ return true;
+ }
+ if ( obj == null )
+ {
+ return false;
+ }
+ if ( getClass() != obj.getClass() )
+ {
+ return false;
+ }
+
+ Gav other = (Gav) obj;
+
+ if ( groupId == null )
+ {
+ if ( other.groupId != null )
+ {
+ return false;
+ }
+ }
+ else if ( !groupId.equals( other.groupId ) )
+ {
+ return false;
+ }
+
+ if ( artifactId == null )
+ {
+ if ( other.artifactId != null )
+ {
+ return false;
+ }
+ }
+ else if ( !artifactId.equals( other.artifactId ) )
+ {
+ return false;
+ }
+
+ if ( version == null )
+ {
+ if ( other.version != null )
+ {
+ return false;
+ }
+ }
+ else if ( !version.equals( other.version ) )
+ {
+ return false;
+ }
+
+ if ( baseVersion == null )
+ {
+ if ( other.baseVersion != null )
+ {
+ return false;
+ }
+ }
+ else if ( !baseVersion.equals( other.baseVersion ) )
+ {
+ return false;
+ }
+
+ if ( classifier == null )
+ {
+ if ( other.classifier != null )
+ {
+ return false;
+ }
+ }
+ else if ( !classifier.equals( other.classifier ) )
+ {
+ return false;
+ }
+
+ if ( extension == null )
+ {
+ if ( other.extension != null )
+ {
+ return false;
+ }
+ }
+ else if ( !extension.equals( other.extension ) )
+ {
+ return false;
+ }
+
+ if ( name == null )
+ {
+ if ( other.name != null )
+ {
+ return false;
+ }
+ }
+ else if ( !name.equals( other.name ) )
+ {
+ return false;
+ }
+
+ if ( snapshot != other.snapshot )
+ {
+ return false;
+ }
+
+ if ( snapshotBuildNumber == null )
+ {
+ if ( other.snapshotBuildNumber != null )
+ {
+ return false;
+ }
+ }
+ else if ( !snapshotBuildNumber.equals( other.snapshotBuildNumber ) )
+ {
+ return false;
+ }
+
+ if ( snapshotTimeStamp == null )
+ {
+ if ( other.snapshotTimeStamp != null )
+ {
+ return false;
+ }
+ }
+ else if ( !snapshotTimeStamp.equals( other.snapshotTimeStamp ) )
+ {
+ return false;
+ }
+
+ if ( hash != other.hash )
+ {
+ return false;
+ }
+
+ if ( hashType == null )
+ {
+ if ( other.hashType != null )
+ {
+ return false;
+ }
+ }
+ else if ( !hashType.equals( other.hashType ) )
+ {
+ return false;
+ }
+
+ if ( signature != other.signature )
+ {
+ return false;
+ }
+
+ if ( signatureType == null )
+ {
+ if ( other.signatureType != null )
+ {
+ return false;
+ }
+ }
+ else if ( !signatureType.equals( other.signatureType ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/GavCalculator.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/GavCalculator.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/GavCalculator.java
new file mode 100644
index 0000000..3e674f4
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/GavCalculator.java
@@ -0,0 +1,48 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * An interface to calculate <code>Gav</code> based on provided artifact path and to calculate an artifact path from
+ * provided <code>Gav</code>.
+ *
+ * @author Tamas Cservenak
+ */
+public interface GavCalculator
+{
+ /**
+ * Calculates GAV from provided <em>repository path</em>. The path has to be absolute starting from repository root.
+ * If path represents a proper artifact path (conforming to given layout), GAV is "calculated" from it and is
+ * returned. If path represents some file that is not an artifact, but is part of the repository layout (like
+ * maven-metadata.xml), or in any other case it returns null.
+ *
+ * @param path the repository path
+ * @return Gav parsed from the path
+ */
+ Gav pathToGav( String path );
+
+ /**
+ * Reassembles the repository path from the supplied GAV. It will be an absolute path.
+ *
+ * @param gav
+ * @return the path calculated from GAV, obeying current layout.
+ */
+ String gavToPath( Gav gav );
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/M1ArtifactRecognizer.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/M1ArtifactRecognizer.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/M1ArtifactRecognizer.java
new file mode 100644
index 0000000..30f463b
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/M1ArtifactRecognizer.java
@@ -0,0 +1,60 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Utility methods for basic "detection" of artifact kind in M1 repository.
+ */
+public class M1ArtifactRecognizer
+{
+ /**
+ * Is this item M1 Checksum?
+ */
+ public static boolean isChecksum( String path )
+ {
+ return path.endsWith( ".sha1" ) || path.endsWith( ".md5" );
+ }
+
+ /**
+ * Is this item M1 POM?
+ */
+ public static boolean isPom( String path )
+ {
+ return path.endsWith( ".pom" ) || path.endsWith( ".pom.sha1" ) || path.endsWith( ".pom.md5" );
+ }
+
+ /**
+ * Is this item M1 snapshot?
+ */
+ public static boolean isSnapshot( String path )
+ {
+ return path.indexOf( "SNAPSHOT" ) != -1;
+ }
+
+ /**
+ * Is this item M1 metadata? There is no such!
+ */
+ public static boolean isMetadata( String path )
+ {
+ return path.endsWith( "maven-metadata.xml" ) || path.endsWith( "maven-metadata.xml.sha1" )
+ || path.endsWith( "maven-metadata.xml.md5" );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/M1GavCalculator.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/M1GavCalculator.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/M1GavCalculator.java
new file mode 100644
index 0000000..be0615d
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/M1GavCalculator.java
@@ -0,0 +1,213 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * An M1 <code>GavCalculator</code>. Heavily under-maintained.
+ *
+ * @author Jason van Zyl
+ * @author Tamas Cservenak
+ */
+@Component( role = GavCalculator.class, hint = "maven1" )
+public class M1GavCalculator
+ implements GavCalculator
+{
+
+ private static final Pattern pat1 = Pattern.compile( "^([^0-9]+)-([0-9].+)\\.([^0-9]+)(\\.md5|\\.sha1){0,1}$" );
+
+ private static final Pattern pat2 = Pattern.compile( "^([a-z0-9-_]+)-([0-9-].+)\\.([^0-9]+)(\\.md5|\\.sha1){0,1}$" );
+
+ public Gav pathToGav( String str )
+ {
+ try
+ {
+ String s = str.startsWith( "/" ) ? str.substring( 1 ) : str;
+
+ int n1 = s.lastIndexOf( '/' );
+
+ if ( n1 == -1 )
+ {
+ return null;
+ }
+
+ int n2 = s.lastIndexOf( '/', n1 - 1 );
+
+ if ( n2 == -1 )
+ {
+ return null;
+ }
+
+ String g = s.substring( 0, n2 ).replace( '/', '.' );
+ String middle = s.substring( n2 + 1, n1 );
+ String n = s.substring( n1 + 1 );
+
+ String classifier = null;
+ if ( "java-sources".equals( middle ) )
+ {
+ classifier = "sources";
+ }
+ else if ( "javadocs".equals( middle ) )
+ {
+ classifier = "javadoc";
+ }
+ else if ( "ejbs".equals( middle )
+ && ( n.endsWith( "client.jar" ) || n.endsWith( "client.jar.sha1" ) || n.endsWith( "client.jar.md5" ) ) )
+ {
+ classifier = "client";
+ }
+
+ boolean checksum = false;
+ Gav.HashType checksumType = null;
+ if ( s.endsWith( ".md5" ) )
+ {
+ checksum = true;
+ checksumType = Gav.HashType.md5;
+ s = s.substring( 0, s.length() - 4 );
+ }
+ else if ( s.endsWith( ".sha1" ) )
+ {
+ checksum = true;
+ checksumType = Gav.HashType.sha1;
+ s = s.substring( 0, s.length() - 5 );
+ }
+
+ if ( s.endsWith( "maven-metadata.xml" ) )
+ {
+ return null;
+ }
+
+ String ext = s.substring( s.lastIndexOf( '.' ) + 1 );
+
+ Matcher m = pat1.matcher( n );
+ if ( m.matches() )
+ {
+ String a = m.group( 1 );
+ String version = m.group( 2 );
+ if ( classifier != null )
+ {
+ version = version.substring( 0, version.length() - ( classifier.length() + 1 ) );
+ }
+
+ return new Gav( g, a, version, classifier, ext, null, null, n, checksum, checksumType, false,
+ null );
+ }
+ else
+ {
+ m = pat2.matcher( n );
+ if ( m.matches() )
+ {
+ String a = m.group( 1 );
+ String version = m.group( 2 );
+ if ( classifier != null )
+ {
+ version = version.substring( 0, version.length() - ( classifier.length() + 1 ) );
+ }
+
+ return new Gav( g, a, version, classifier, ext, null, null, n, checksum, checksumType,
+ false, null );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+ catch ( StringIndexOutOfBoundsException e )
+ {
+ return null;
+ }
+ catch ( IndexOutOfBoundsException e )
+ {
+ return null;
+ }
+ }
+
+ /**
+ * // XXX this is not accurate, m1 is using packaging as an artifact folder name.
+ *
+ * @see org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout#pathOf(org.apache.maven.artifact.Artifact)
+ * @see org.apache.maven.artifact.handler.DefaultArtifactHandler#getDirectory()
+ */
+ public String gavToPath( Gav gav )
+ {
+ StringBuilder path = new StringBuilder( "/" );
+
+ path.append( gav.getGroupId() );
+
+ path.append( "/" );
+
+ if ( gav.getClassifier() == null )
+ {
+ path.append( gav.getExtension() );
+
+ path.append( "s" );
+ }
+ else
+ {
+ if ( gav.getClassifier().startsWith( "source" ) )
+ {
+ path.append( "java-source" );
+ }
+ else if ( gav.getClassifier().startsWith( "client" ) )
+ {
+ path.append( "ejb" );
+ }
+ else
+ {
+ path.append( gav.getClassifier() );
+ }
+ path.append( "s" );
+ }
+
+ path.append( "/" );
+
+ path.append( gav.getArtifactId() );
+
+ path.append( "-" );
+
+ path.append( gav.getVersion() );
+
+ if ( gav.getClassifier() != null )
+ {
+ path.append( "-" );
+
+ path.append( gav.getClassifier() );
+ }
+
+ path.append( "." );
+
+ path.append( gav.getExtension() );
+
+ if ( gav.isHash() )
+ {
+ path.append( "." );
+
+ path.append( gav.getHashType().toString() );
+ }
+
+ return path.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/M2ArtifactRecognizer.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/M2ArtifactRecognizer.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/M2ArtifactRecognizer.java
new file mode 100644
index 0000000..6dd9f1a
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/M2ArtifactRecognizer.java
@@ -0,0 +1,67 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Utility methods for basic "detection" of artifact kind in M2 repository.
+ */
+public class M2ArtifactRecognizer
+{
+ /**
+ * Is this item M2 Checksum?
+ */
+ public static boolean isChecksum( String path )
+ {
+ return path.endsWith( ".sha1" ) || path.endsWith( ".md5" );
+ }
+
+ /**
+ * Is this item M2 POM?
+ */
+ public static boolean isPom( String path )
+ {
+ return path.endsWith( ".pom" ) || path.endsWith( ".pom.sha1" ) || path.endsWith( ".pom.md5" );
+ }
+
+ /**
+ * Is this item M2 Snapshot?
+ *
+ * @param path
+ * @return
+ */
+ public static boolean isSnapshot( String path )
+ {
+ return path.indexOf( "SNAPSHOT" ) != -1;
+ }
+
+ /**
+ * Is this item M2 metadata?
+ */
+ public static boolean isMetadata( String path )
+ {
+ return path.endsWith( "maven-metadata.xml" ) || path.endsWith( "maven-metadata.xml.sha1" )
+ || path.endsWith( "maven-metadata.xml.md5" );
+ }
+
+ public static boolean isSignature( String path )
+ {
+ return path.endsWith( ".asc" );
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/M2GavCalculator.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/M2GavCalculator.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/M2GavCalculator.java
new file mode 100644
index 0000000..8ec1570
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/M2GavCalculator.java
@@ -0,0 +1,302 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * An M2 <code>GavCalculator</code>.
+ *
+ * @author Jason van Zyl
+ * @author Tamas Cservenak
+ */
+@Component( role = GavCalculator.class, hint = "maven2" )
+public class M2GavCalculator
+ implements GavCalculator
+{
+ public Gav pathToGav( String str )
+ {
+ try
+ {
+ String s = str.startsWith( "/" ) ? str.substring( 1 ) : str;
+
+ int vEndPos = s.lastIndexOf( '/' );
+
+ if ( vEndPos == -1 )
+ {
+ return null;
+ }
+
+ int aEndPos = s.lastIndexOf( '/', vEndPos - 1 );
+
+ if ( aEndPos == -1 )
+ {
+ return null;
+ }
+
+ int gEndPos = s.lastIndexOf( '/', aEndPos - 1 );
+
+ if ( gEndPos == -1 )
+ {
+ return null;
+ }
+
+ String groupId = s.substring( 0, gEndPos ).replace( '/', '.' );
+ String artifactId = s.substring( gEndPos + 1, aEndPos );
+ String version = s.substring( aEndPos + 1, vEndPos );
+ String fileName = s.substring( vEndPos + 1 );
+
+ boolean checksum = false;
+ boolean signature = false;
+ Gav.HashType checksumType = null;
+ Gav.SignatureType signatureType = null;
+ if ( s.endsWith( ".md5" ) )
+ {
+ checksum = true;
+ checksumType = Gav.HashType.md5;
+ s = s.substring( 0, s.length() - 4 );
+ }
+ else if ( s.endsWith( ".sha1" ) )
+ {
+ checksum = true;
+ checksumType = Gav.HashType.sha1;
+ s = s.substring( 0, s.length() - 5 );
+ }
+
+ if ( s.endsWith( ".asc" ) )
+ {
+ signature = true;
+ signatureType = Gav.SignatureType.gpg;
+ s = s.substring( 0, s.length() - 4 );
+ }
+
+ if ( s.endsWith( "maven-metadata.xml" ) )
+ {
+ return null;
+ }
+
+ boolean snapshot = version.endsWith( "SNAPSHOT" );
+
+ if ( snapshot )
+ {
+ return getSnapshotGav( s, vEndPos, groupId, artifactId, version, fileName, checksum, signature,
+ checksumType, signatureType );
+ }
+ else
+ {
+ return getReleaseGav( s, vEndPos, groupId, artifactId, version, fileName, checksum, signature,
+ checksumType, signatureType );
+ }
+ }
+ catch ( NumberFormatException e )
+ {
+ return null;
+ }
+ catch ( StringIndexOutOfBoundsException e )
+ {
+ return null;
+ }
+ }
+
+ private Gav getReleaseGav( String s, int vEndPos, String groupId, String artifactId, String version,
+ String fileName, boolean checksum, boolean signature, Gav.HashType checksumType,
+ Gav.SignatureType signatureType )
+ {
+ if ( !fileName.startsWith( artifactId + "-" + version + "." )
+ && !fileName.startsWith( artifactId + "-" + version + "-" ) )
+ {
+ // The path does not represents an artifact (filename does not match artifactId-version)!
+ return null;
+ }
+
+ int nTailPos = vEndPos + artifactId.length() + version.length() + 2;
+
+ String tail = s.substring( nTailPos );
+
+ int nExtPos = tail.indexOf( '.' );
+
+ if ( nExtPos == -1 )
+ {
+ // NX-563: not allowing extensionless paths to be interpreted as artifact
+ return null;
+ }
+
+ String ext = tail.substring( nExtPos + 1 );
+
+ String classifier = tail.charAt( 0 ) == '-' ? tail.substring( 1, nExtPos ) : null;
+
+ return new Gav( groupId, artifactId, version, classifier, ext, null, null, fileName, checksum, checksumType,
+ signature, signatureType );
+ }
+
+ private Gav getSnapshotGav( String s, int vEndPos, String groupId, String artifactId, String version,
+ String fileName, boolean checksum, boolean signature, Gav.HashType checksumType,
+ Gav.SignatureType signatureType )
+ {
+
+ Integer snapshotBuildNo = null;
+
+ Long snapshotTimestamp = null;
+
+ int vSnapshotStart = vEndPos + artifactId.length() + version.length() - 9 + 3;
+
+ String vSnapshot = s.substring( vSnapshotStart, vSnapshotStart + 8 );
+
+ String classifier = null;
+
+ String ext = null;
+
+ if ( "SNAPSHOT".equals( vSnapshot ) )
+ {
+ int nTailPos = vEndPos + artifactId.length() + version.length() + 2;
+
+ String tail = s.substring( nTailPos );
+
+ int nExtPos = tail.indexOf( '.' );
+
+ if ( nExtPos == -1 )
+ {
+ // NX-563: not allowing extensionless paths to be interpreted as artifact
+ return null;
+ }
+
+ ext = tail.substring( nExtPos + 1 );
+
+ classifier = tail.charAt( 0 ) == '-' ? tail.substring( 1, nExtPos ) : null;
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder( vSnapshot );
+ sb.append( s.substring( vSnapshotStart + sb.length(), vSnapshotStart + sb.length() + 8 ) );
+
+ try
+ {
+ SimpleDateFormat df = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
+ snapshotTimestamp = Long.valueOf( df.parse( sb.toString() ).getTime() );
+ }
+ catch ( ParseException e )
+ {
+ }
+
+ int buildNumberPos = vSnapshotStart + sb.length();
+ StringBuilder bnr = new StringBuilder();
+ while ( s.charAt( buildNumberPos ) >= '0' && s.charAt( buildNumberPos ) <= '9' )
+ {
+ sb.append( s.charAt( buildNumberPos ) );
+ bnr.append( s.charAt( buildNumberPos ) );
+ buildNumberPos++;
+ }
+ String snapshotBuildNumber = sb.toString();
+ snapshotBuildNo = Integer.parseInt( bnr.toString() );
+
+ int n = version.length() > 9 ? version.length() - 9 + 1 : 0;
+
+ String tail = s.substring( vEndPos + artifactId.length() + n + snapshotBuildNumber.length() + 2 );
+
+ int nExtPos = tail.indexOf( '.' );
+
+ if ( nExtPos == -1 )
+ {
+ // NX-563: not allowing extensionless paths to be interpreted as artifact
+ return null;
+ }
+
+ ext = tail.substring( nExtPos + 1 );
+
+ classifier = tail.charAt( 0 ) == '-' ? tail.substring( 1, nExtPos ) : null;
+
+ version = version.substring( 0, version.length() - 8 ) + snapshotBuildNumber;
+ }
+
+ return new Gav( groupId, artifactId, version, classifier, ext, snapshotBuildNo, snapshotTimestamp, fileName,
+ checksum, checksumType, signature, signatureType );
+ }
+
+ public String gavToPath( Gav gav )
+ {
+ StringBuilder path = new StringBuilder( "/" );
+
+ path.append( gav.getGroupId().replaceAll( "(?m)(.)\\.", "$1/" ) ); // replace all '.' except the first char
+
+ path.append( "/" );
+
+ path.append( gav.getArtifactId() );
+
+ path.append( "/" );
+
+ path.append( gav.getBaseVersion() );
+
+ path.append( "/" );
+
+ path.append( calculateArtifactName( gav ) );
+
+ return path.toString();
+ }
+
+ public String calculateArtifactName( Gav gav )
+ {
+ if ( gav.getName() != null && gav.getName().trim().length() > 0 )
+ {
+ return gav.getName();
+ }
+ else
+ {
+ StringBuilder path = new StringBuilder( gav.getArtifactId() );
+
+ path.append( "-" );
+
+ path.append( gav.getVersion() );
+
+ if ( gav.getClassifier() != null && gav.getClassifier().trim().length() > 0 )
+ {
+ path.append( "-" );
+
+ path.append( gav.getClassifier() );
+ }
+
+ if ( gav.getExtension() != null )
+ {
+ path.append( "." );
+
+ path.append( gav.getExtension() );
+ }
+
+ if ( gav.isSignature() )
+ {
+ path.append( "." );
+
+ path.append( gav.getSignatureType().toString() );
+ }
+
+ if ( gav.isHash() )
+ {
+ path.append( "." );
+
+ path.append( gav.getHashType().toString() );
+ }
+
+ return path.toString();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a99549a1/indexer-core/src/main/java/org/apache/maven/index/artifact/VersionUtils.java
----------------------------------------------------------------------
diff --git a/indexer-core/src/main/java/org/apache/maven/index/artifact/VersionUtils.java b/indexer-core/src/main/java/org/apache/maven/index/artifact/VersionUtils.java
new file mode 100644
index 0000000..8ae6b02
--- /dev/null
+++ b/indexer-core/src/main/java/org/apache/maven/index/artifact/VersionUtils.java
@@ -0,0 +1,40 @@
+package org.apache.maven.index.artifact;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 java.util.regex.Pattern;
+
+/**
+ * Utility methods for working with artifact version strings.
+ */
+public class VersionUtils
+{
+
+ private static String SNAPSHOT_VERSION = "SNAPSHOT";
+
+ private static final Pattern VERSION_FILE_PATTERN =
+ Pattern.compile(
+ "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$|^([0-9]{8}.[0-9]{6})-([0-9]+)$|^(.*)([0-9]{8}.[0-9]{6})-([0-9]+)$" );
+
+ public static boolean isSnapshot( String version )
+ {
+ return VERSION_FILE_PATTERN.matcher( version ).matches() || version.endsWith( SNAPSHOT_VERSION );
+ }
+}