}
// Return type
- return type;
+ return type.replace( '-', '.' );
}
public static String guessTypeFromFilename( File file )
}
// Do we have a classifier?
- artifact.setClassifier( parser.remaining() );
-
- // Set the type.
- artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ switch(parser.seperator())
+ {
+ case '-':
+ // Definately a classifier.
+ artifact.setClassifier( parser.remaining() );
+
+ // Set the type.
+ artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ break;
+ case '.':
+ // We have an dual extension possibility.
+ String extension = parser.remaining() + '.' + parser.getExtension();
+ artifact.setType( extension.replace( '.', '-' ) );
+ break;
+ case 0:
+ // End of the filename, only a simple extension left. - Set the type.
+ artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
+ break;
+ }
// Special case for maven plugins
if ( StringUtils.equals( "jar", artifact.getType() ) &&
return null;
}
+
+ /**
+ * Get the current seperator character.
+ *
+ * @return the seperator character (either '.' or '-'), or 0 if no seperator character available.
+ */
+ protected char seperator()
+ {
+ // Past the end of the string?
+ if ( offset >= name.length() )
+ {
+ return 0;
+ }
+
+ // Before the start of the string?
+ if ( offset <= 0 )
+ {
+ return 0;
+ }
+
+ return name.charAt( offset - 1 );
+ }
protected String getName()
{
return ver.toString();
}
+
+
}
"wrong artifact id" );
}
+ /**
+ * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+ */
+ public void testGoodButDualExtensions()
+ throws LayoutException
+ {
+ String groupId = "org.project";
+ String artifactId = "example-presentation";
+ String version = "3.2";
+ String classifier = null;
+ String type = "xml-zip";
+ String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
/**
* [MRM-432] Oddball version spec.
* Example of an oddball / unusual version spec.
assertEquals( "ganymede-ssh2", parser.expect( "ganymede-ssh2" ) );
assertEquals( "build250", parser.expect( "build250" ) );
+ assertEquals( '-', parser.seperator() );
assertEquals( "sources", parser.remaining() );
assertNull( parser.expect( "jar" ) );
}
+ public void testExpectWithRemainingDualExtensions()
+ {
+ FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" );
+
+ assertEquals( "example-presentation-3.2.xml", parser.getName() );
+ assertEquals( "zip", parser.getExtension() );
+
+ assertEquals( "example-presentation", parser.expect( "example-presentation" ) );
+ assertEquals( "3.2", parser.expect( "3.2" ) );
+ assertEquals( '.', parser.seperator() );
+ assertEquals( "xml", parser.remaining() );
+
+ }
+
public void testNextNonVersion()
{
FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
{
assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
}
+
+ /**
+ * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+ */
+ public void testGoodButDualExtensions()
+ throws LayoutException
+ {
+ String groupId = "org.project";
+ String artifactId = "example-presentation";
+ String version = "3.2.xml";
+ String type = "distribution-zip";
+ String path = "org.project/zips/example-presentation-3.2.xml.zip";
+
+ assertLayout( path, groupId, artifactId, version, type );
+ }
/**
* [MRM-432] Oddball version spec.
return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
}
+ /**
+ * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+ */
+ public void testToNativePathArtifactDefaultToDefaultDualExtension()
+ throws Exception
+ {
+ ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+ // Test (artifact) default to default - dual extension
+ assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest
+ .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) );
+ }
+
+ /**
+ * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+ */
+ public void testToNativePathArtifactLegacyToDefaultDualExtension()
+ throws Exception
+ {
+ ManagedRepositoryContent repository = createManagedRepo( "default" );
+
+ // Test (artifact) legacy to default - dual extension
+ // NOTE: The detection of a dual extension is flawed.
+ assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
+ .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) );
+ }
+
public void testToNativePathMetadataDefaultToDefault()
throws Exception
{
assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
}
+
+ /**
+ * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
+ */
+ public void testGetNoProxyDualExtensionDefaultLayout()
+ throws Exception
+ {
+ String expectedContents = "the-contents-of-the-dual-extension";
+ String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
+
+ File checksumFile = new File( repoRootInternal, dualExtensionPath );
+ checksumFile.getParentFile().mkdirs();
+
+ FileUtils.writeStringToFile( checksumFile, expectedContents, null );
+
+ WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
+ WebResponse response = sc.getResponse( request );
+ assertResponseOK( response );
+
+ assertEquals( "Expected file contents", expectedContents, response.getText() );
+ }
}