]> source.dussan.org Git - archiva.git/commitdiff
[MRM-155] check paths are translated correctly when there is a mismatch between the...
authorBrett Porter <brett@apache.org>
Fri, 1 Sep 2006 02:40:33 +0000 (02:40 +0000)
committerBrett Porter <brett@apache.org>
Fri, 1 Sep 2006 02:40:33 +0000 (02:40 +0000)
Submitted by: Nicolas de Loof (applied with changes)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@439143 13f79535-47bb-0310-9956-ffa450edef68

archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java
archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ProxyRequestHandlerTest.java

index 323f8e62e56efba7bb5389fd5f40afbf8c0a6ea6..892fd290cf4a6c6c4e8b073b47a7716549d6aff1 100644 (file)
@@ -124,7 +124,7 @@ public class DefaultProxyRequestHandler
             }
             else
             {
-                get( path, target, repository, managedRepository, wagonProxy, force );
+                target = get( path, target, repository, managedRepository, wagonProxy, force );
             }
         }
 
@@ -136,7 +136,11 @@ public class DefaultProxyRequestHandler
         return target;
     }
 
-    private void get( String path, File target, ProxiedArtifactRepository repository,
+    /**
+     * @return the target File may not be same as the target argument, if a
+     *         maven1 to maven2 path convertion occured.
+     */
+    private File get( String path, File target, ProxiedArtifactRepository repository,
                       ArtifactRepository managedRepository, ProxyInfo wagonProxy, boolean force )
         throws ProxyException
     {
@@ -192,6 +196,8 @@ public class DefaultProxyRequestHandler
 
             if ( artifact != null )
             {
+                target = new File( managedRepository.getBasedir(), managedRepository.pathOf( artifact ) );
+
                 ArtifactRepository artifactRepository = repository.getRepository();
 
                 // we use the release policy for tracking failures, but only check for updates on snapshots
@@ -227,6 +233,7 @@ public class DefaultProxyRequestHandler
             // in case it previously failed and we've since found it
             repository.clearFailure( path );
         }
+        return target;
     }
 
     private void mergeMetadataFiles( File target, File metadataFile )
index 568c89b42fc771b3331ed790b4ae03ea38a829f9..a1c9da8ffd35146fd77bcc113bdea1efbc9be6ed 100644 (file)
@@ -110,7 +110,7 @@ public class ProxyRequestHandlerTest
         ArtifactRepositoryLayout legacyLayout =
             (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
 
-        legacyManagedRepository = createRepository( "managed-repository", repoLocation );
+        legacyManagedRepository = createRepository( "managed-repository", repoLocation, legacyLayout );
 
         File location = getTestFile( "src/test/repositories/proxied1" );
         proxiedRepository1 = createRepository( "proxied1", location );
@@ -1592,6 +1592,38 @@ public class ProxyRequestHandlerTest
                       file.lastModified() );
     }
 
+    public void testLegacyRequestConvertedToDefaultPathInManagedRepo()
+        throws Exception
+    {
+        // Check that a Maven1 legacy request is translated to a maven2 path in
+        // the managed repository.
+
+        String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
+        assertTrue( expectedFile.exists() );
+
+        File file = requestHandler.get( legacyPath, legacyProxiedRepositories, defaultManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+    }
+
+    public void testDefaultRequestConvertedToLegacyPathInManagedRepo()
+        throws Exception
+    {
+        // Check that a Maven2 default request is translated to a legacy path in
+        // the managed repository.
+
+        String legacyPath = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( legacyManagedRepository.getBasedir(), legacyPath );
+        assertTrue( expectedFile.exists() );
+
+        File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+    }
+
     private static Versioning getVersioning( List versions )
     {
         Versioning versioning = new Versioning();