From: Joakim Erdfelt Date: Fri, 26 Oct 2007 18:16:43 +0000 (+0000) Subject: [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error X-Git-Tag: archiva-1.0-beta-3~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76aabf37a092d4a5ec008ca7064565460ee0f493;p=archiva.git [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error Fixed parsing of filenames to look for "." or "-" after the version to help determine if this artifact has a classifier or just a double-extension. Added unit tests to repository.content.* classes for double extension. Added unit test to RepositoryServlet for GET of artifact with double extension. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@588732 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index 89206b68b..c509e51b6 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -67,7 +67,7 @@ public class ArtifactExtensionMapping } // Return type - return type; + return type.replace( '-', '.' ); } public static String guessTypeFromFilename( File file ) diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java index 59c68276a..6df3aafdc 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java @@ -143,10 +143,25 @@ public class DefaultPathParser } // 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() ) && diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java index 2ccfe182f..3778e5ed2 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java @@ -113,6 +113,28 @@ public class FilenameParser 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() { @@ -207,4 +229,6 @@ public class FilenameParser return ver.toString(); } + + } diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java index 8ceecbe0f..23535e784 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java @@ -51,6 +51,22 @@ public class DefaultPathParserTest "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. diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java index ba0e2a9d7..9c98fc237 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java @@ -97,11 +97,26 @@ public class FilenameParserTest 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" ); diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java index 2ae322178..58a82a01c 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java @@ -58,6 +58,21 @@ public class LegacyPathParserTest { 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. diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java index 2a3de5a51..f66c6c913 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java @@ -295,6 +295,33 @@ public class RepositoryRequestTest 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 { diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java index 3c5b9cae0..4e01fe487 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java @@ -217,4 +217,25 @@ public class RepositoryServletNoProxyTest 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() ); + } }