"(alpha[_.0-9]*)",
"(beta[_.0-9]*)",
"(rc[_.0-9]*)",
- "(test[_.0-9]*)",
+// "(test[_.0-9]*)", -- omitted for MRM-681, can be reinstated as part of MRM-712
"(debug[_.0-9]*)",
"(unofficial[_.0-9]*)",
"(current)",
"(incubator)",
"([ab][_.0-9]+)" };
- private static final String VersionMegaPattern = StringUtils.join( versionPatterns, '|' );
-
public static final String SNAPSHOT = "SNAPSHOT";
public static final Pattern UNIQUE_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}\\.[0-9]{6})-([0-9]+)$" );
public static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "^([0-9]{8})\\.([0-9]{6})$" );
public static final Pattern GENERIC_SNAPSHOT_PATTERN = Pattern.compile( "^(.*)-" + SNAPSHOT );
-
+
+ private static final Pattern VERSION_MEGA_PATTERN = Pattern.compile( StringUtils.join( versionPatterns, '|' ), Pattern.CASE_INSENSITIVE );
+
/**
* <p>
* Tests if the unknown string contains elements that identify it as a version string (or not).
{
String versionParts[] = StringUtils.split( unknown, '-' );
- Pattern pat = Pattern.compile( VersionMegaPattern, Pattern.CASE_INSENSITIVE );
Matcher mat;
int countValidParts = 0;
for ( int i = 0; i < versionParts.length; i++ )
{
String part = versionParts[i];
- mat = pat.matcher( part );
+ mat = VERSION_MEGA_PATTERN.matcher( part );
if ( mat.matches() )
{
*/
public static boolean isSimpleVersionKeyword( String identifier )
{
- Pattern pat = Pattern.compile( VersionMegaPattern, Pattern.CASE_INSENSITIVE );
- Matcher mat = pat.matcher( identifier );
+ Matcher mat = VERSION_MEGA_PATTERN.matcher( identifier );
return mat.matches();
}
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
-
-import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import java.util.regex.Pattern;
/**
* ArtifactExtensionMapping
static
{
typeToClassifierMap = new HashMap<String, String>();
- typeToClassifierMap.put( "java-source", "sources" );
- typeToClassifierMap.put( "javadoc.jar", "javadoc" );
- typeToClassifierMap.put( "javadoc", "javadoc" );
+ typeToClassifierMap.put( "java-sources", "sources" );
+ typeToClassifierMap.put( "javadoc.jars", "javadoc" );
+ typeToClassifierMap.put( "javadocs", "javadoc" );
}
public static String getClassifier( String type )
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
-
-import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
return type.replace( '-', '.' );
}
- public static String guessTypeFromFilename( File file )
+ /**
+ * Determine if a given artifact Id conforms to the naming scheme for a maven plugin.
+ *
+ * @param artifactId the artifactId to test.
+ * @return true if this artifactId conforms to the naming scheme for a maven plugin.
+ */
+ public static boolean isMavenPlugin( String artifactId )
{
- return guessTypeFromFilename( file.getName() );
+ return mavenPluginPattern.matcher( artifactId ).matches();
}
- public static String guessTypeFromFilename( String filename )
+ public static String mapExtensionAndClassifierToType( String classifier, String extension )
{
- if ( StringUtils.isBlank( filename ) )
+ if ( "sources".equals( classifier ) )
{
- return null;
+ return "java-source";
}
-
- String normalizedName = filename.toLowerCase().trim();
- int idx = normalizedName.lastIndexOf( '.' );
-
- if ( idx == ( -1 ) )
+ else if ( "javadoc".equals( classifier ) )
{
- return null;
+ return "javadoc";
}
+ return mapExtensionToType( extension );
+ }
- if ( normalizedName.endsWith( ".tar.gz" ) )
+ public static String mapExtensionToType( String extension )
+ {
+ if ( extension.equals( "tar.gz" ) )
{
return "distribution-tgz";
}
- if ( normalizedName.endsWith( ".tar.bz2" ) )
+ else if ( extension.equals( "tar.bz2" ) )
{
return "distribution-bzip";
}
- else if ( normalizedName.endsWith( ".zip" ) )
+ else if ( extension.equals( "zip" ) )
{
return "distribution-zip";
}
- else if ( normalizedName.endsWith( "-sources.jar" ) )
- {
- return "java-source";
- }
- else if ( normalizedName.endsWith( "-javadoc.jar" ) )
- {
- return "javadoc";
- }
- else
- {
- return normalizedName.substring( idx + 1 );
- }
- }
-
- /**
- * Determine if a given artifact Id conforms to the naming scheme for a maven plugin.
- *
- * @param artifactId the artifactId to test.
- * @return true if this artifactId conforms to the naming scheme for a maven plugin.
- */
- public static boolean isMavenPlugin( String artifactId )
- {
- return mavenPluginPattern.matcher( artifactId ).matches();
+ return extension;
}
}
artifact.setClassifier( parser.remaining() );
// Set the type.
- artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( artifact.getClassifier(), parser.getExtension() ) );
break;
case '.':
// We have an dual extension possibility.
break;
case 0:
// End of the filename, only a simple extension left. - Set the type.
- artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ artifact.setType( ArtifactExtensionMapping.mapExtensionToType( parser.getExtension() ) );
break;
}
private static final Pattern mavenPluginPattern = Pattern.compile( "(maven-.*-plugin)|(.*-maven-plugin)" );
- private static final Pattern extensionPattern = Pattern.compile( "(.tar.gz$)|(.tar.bz2$)|(.[a-z0-9]*$)",
- Pattern.CASE_INSENSITIVE );
+ private static final Pattern extensionPattern =
+ Pattern.compile( "(.tar.gz$)|(.tar.bz2$)|(.[a-z0-9]*$)", Pattern.CASE_INSENSITIVE );
+
+ private static final Pattern SNAPSHOT_PATTERN = Pattern.compile( "^([0-9]{8}\\.[0-9]{6}-[0-9]+)(.*)$" );
private static final Pattern section = Pattern.compile( "([^-]*)" );
protected String expect( String expected )
{
+ String value = null;
+
if ( name.startsWith( expected, offset ) )
+ {
+ value = expected;
+ }
+ else if ( VersionUtil.isGenericSnapshot( expected ) )
+ {
+ String version = name.substring( offset );
+
+ // check it starts with the same version up to the snapshot part
+ int leadingLength = expected.length() - 9;
+ if ( version.startsWith( expected.substring( 0, leadingLength ) ) && version.length() > leadingLength )
+ {
+ // If we expect a non-generic snapshot - look for the timestamp
+ Matcher m = SNAPSHOT_PATTERN.matcher( version.substring( leadingLength + 1 ) );
+ if ( m.matches() )
+ {
+ value = version.substring( 0, leadingLength + 1 ) + m.group( 1 );
+ }
+ }
+ }
+
+ if ( value != null )
{
// Potential hit. check for '.' or '-' at end of expected.
- int seperatorOffset = offset + expected.length();
+ int seperatorOffset = offset + value.length();
// Test for "out of bounds" first.
if ( seperatorOffset >= name.length() )
{
offset = name.length();
- return expected;
+ return value;
}
// Test for seperator char.
if ( ( seperatorChar == '-' ) || ( seperatorChar == '.' ) )
{
offset = seperatorOffset + 1;
- return expected;
+ return value;
}
}
return null;
}
-
+
/**
* Get the current seperator character.
- *
+ *
* @return the seperator character (either '.' or '-'), or 0 if no seperator character available.
*/
protected char seperator()
return ver.toString();
}
-
+
}
* under the License.
*/
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.LegacyArtifactPath;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.layout.LayoutException;
+import java.util.Collection;
+import java.util.Iterator;
+
/**
* LegacyPathParser is a parser for maven 1 (legacy layout) paths to
* ArtifactReference.
}
}
+ String classifier = ArtifactClassifierMapping.getClassifier( expectedType );
+ if ( classifier != null )
+ {
+ String version = artifact.getVersion();
+ if ( ! version.endsWith( "-" + classifier ) )
+ {
+ throw new LayoutException( INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
+ }
+ version = version.substring( 0, version.length() - classifier.length() - 1 );
+ artifact.setVersion( version );
+ artifact.setClassifier( classifier );
+ }
+
+ String extension = parser.getExtension();
+
// Set Type
- artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ artifact.setType( ArtifactExtensionMapping.mapExtensionAndClassifierToType( classifier, extension ) );
// Sanity Check: does it have an extension?
if ( StringUtils.isEmpty( artifact.getType() ) )
String trimPathType = expectedType.substring( 0, expectedType.length() - 1 );
String expectedExtension = ArtifactExtensionMapping.getExtension( trimPathType );
- String actualExtension = parser.getExtension();
- if ( !expectedExtension.equals( actualExtension ) )
+ if ( !expectedExtension.equals( extension ) )
{
- throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + actualExtension
+ throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on extension [" + extension
+ "] and layout specified type [" + expectedType + "] (which maps to extension: ["
+ expectedExtension + "]) on path [" + path + "]" );
}
- }
- String classifier = ArtifactClassifierMapping.getClassifier( artifact.getType() );
- if ( classifier != null )
- {
- String version = artifact.getVersion();
- if ( ! version.endsWith( "-" + classifier ) )
- {
- throw new LayoutException( INVALID_ARTIFACT_PATH + expectedType + " artifacts must use the classifier " + classifier );
- }
- version = version.substring( 0, version.length() - classifier.length() - 1 );
- artifact.setVersion( version );
- artifact.setClassifier( classifier );
+// if ( classifier != null && !filename.endsWith( "-" + classifier + "." + extension ) )
+// {
+// throw new LayoutException( INVALID_ARTIFACT_PATH + "mismatch on filename [" + filename
+// + "] and layout specified type [" + expectedType + "] (which maps to classifier: ["
+// + classifier + "]) on path [" + path + "]" );
+// }
}
return artifact;
assertLayout( path, groupId, artifactId, version, classifier, type );
}
+ /**
+ * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
+ * @throws LayoutException
+ */
+ public void testGoodLongSnapshotMavenTest()
+ throws LayoutException
+ {
+ String groupId = "a.group.id";
+ String artifactId = "artifact-id";
+ String version = "1.0-abc-1.1-20080221.062205-9";
+ String classifier = null;
+ String type = "pom";
+ String path = "a/group/id/artifact-id/1.0-abc-1.1-SNAPSHOT/artifact-id-1.0-abc-1.1-20080221.062205-9.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
+ * @throws LayoutException
+ */
+ public void testClassifiedSnapshotMavenTest()
+ throws LayoutException
+ {
+ String groupId = "a.group.id";
+ String artifactId = "artifact-id";
+ String version = "1.0-20070219.171202-34";
+ String classifier = "test-sources";
+ String type = "jar";
+ String path = "a/group/id/artifact-id/1.0-SNAPSHOT/artifact-id-1.0-20070219.171202-34-test-sources.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
/**
* [MRM-519] version identifiers within filename cause misidentification of version.
* Example uses "test" in artifact Id, which is also part of the versionKeyword list.
assertEquals( "libfobs4jmf-0.4.1.4-20080217.211715-4", parser.getName() );
assertEquals( "jnilib", parser.getExtension() );
}
+
+ public void testInterveningVersion()
+ {
+ FilenameParser parser = new FilenameParser( "artifact-id-1.0-abc-1.1-20080221.062205-9.pom" );
+
+ assertEquals( "artifact-id", parser.nextNonVersion() );
+ assertEquals( "1.0-abc-1.1-20080221.062205-9", parser.expect( "1.0-abc-1.1-SNAPSHOT" ) );
+ assertNull( null, parser.remaining() );
+ assertEquals( "artifact-id-1.0-abc-1.1-20080221.062205-9", parser.getName() );
+ assertEquals( "pom", parser.getExtension() );
+ }
+
+ public void testExpectWrongSnapshot()
+ {
+ FilenameParser parser = new FilenameParser( "artifact-id-1.0-20080221.062205-9.pom" );
+
+ assertEquals( "artifact-id", parser.nextNonVersion() );
+ assertNull( parser.expect( "2.0-SNAPSHOT" ) );
+ }
+
+ public void testClassifier()
+ {
+ FilenameParser parser = new FilenameParser( "artifact-id-1.0-20070219.171202-34-test-sources.jar" );
+
+ assertEquals( "artifact-id", parser.nextNonVersion() );
+ assertEquals( "1.0-20070219.171202-34", parser.nextVersion() );
+ assertEquals( "test-sources", parser.remaining() );
+ assertEquals( "artifact-id-1.0-20070219.171202-34-test-sources", parser.getName() );
+ assertEquals( "jar", parser.getExtension() );
+ }
}
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration;
import org.apache.maven.archiva.configuration.LegacyArtifactPath;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
assertLayout( path, groupId, artifactId, version, classifier, type );
+
+ assertLayout( "com.foo.lib/javadocs/foo-lib-2.1-alpha-1-javadoc.jar", "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "javadoc" );
}
/**
assertLayout( path, groupId, artifactId, version, classifier, type );
}
+ /**
+ * Test the classifier, and java-source type spec.
+ * @throws LayoutException
+ */
+ public void testBadClassifierFooLibSources()
+ throws LayoutException
+ {
+ String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1.jar";
+
+ try
+ {
+ parser.toArtifactReference( path );
+ fail( "Expected an exception" );
+ }
+ catch ( LayoutException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ /**
+ * Test the classifier, and java-source type spec.
+ * @throws LayoutException
+ */
+ public void testGoodFooLibTestSources()
+ throws LayoutException
+ {
+ String groupId = "com.foo.lib";
+ String artifactId = "foo-lib";
+ String version = "2.1-alpha-1-test-sources";
+ String type = "jar";
+ String classifier = null; // we can't parse this type of classifier in legacy format
+ String path = "com.foo.lib/jars/foo-lib-2.1-alpha-1-test-sources.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
public void testGoodFooTool()
throws LayoutException
{