]> source.dussan.org Git - archiva.git/commitdiff
[MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
authorJoakim Erdfelt <joakime@apache.org>
Fri, 26 Oct 2007 18:16:43 +0000 (18:16 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Fri, 26 Oct 2007 18:16:43 +0000 (18:16 +0000)
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

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/DefaultPathParser.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/FilenameParser.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/DefaultPathParserTest.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/FilenameParserTest.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/LegacyPathParserTest.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java

index 89206b68b5e02da1d6e91e9f5671f7cbf4f1509c..c509e51b6a31942419ac3a69d7b2264b6342d4d7 100644 (file)
@@ -67,7 +67,7 @@ public class ArtifactExtensionMapping
         }
 
         // Return type
-        return type;
+        return type.replace( '-', '.' );
     }
 
     public static String guessTypeFromFilename( File file )
index 59c68276a2b0c4a0cbcf2bfef8bd03a291392ec1..6df3aafdcc797bf2347f4dd8bcaca41f27a1d826 100644 (file)
@@ -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() ) && 
index 2ccfe182fa10375f2a8cdf7672575b7b05f64918..3778e5ed27f3ddab5220e1bcc2d1e37b8197447a 100644 (file)
@@ -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();
     }
+
+    
 }
index 8ceecbe0fe71565d24a861adddf96a8903d5e7f1..23535e78497920583452a043b41118b401c6cf99 100644 (file)
@@ -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.
index ba0e2a9d7a8b0f881bddc7b50d1b444d7368690d..9c98fc237b2bc142c53e8d63ff2e7b5bf0e1e799 100644 (file)
@@ -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" );
index 2ae322178619bd76350088592c7ff483e7edd404..58a82a01cb79fe55c27be1c23bdcbdd7fb5e8e6c 100644 (file)
@@ -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.
index 2a3de5a51a454c36b3a1398744f50a7f62cc6321..f66c6c913ca2854fa115e71c6d471362303e4c02 100644 (file)
@@ -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
     {
index 3c5b9cae0db0823b400ad7e5b0fe0edeb38c6b9a..4e01fe48778f276ae28afefaac3bbad31cc8e052 100644 (file)
@@ -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() );
+    }
 }