From 2102fd5298e06f0197d3eef290abf9f3b311409c Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 1 Sep 2006 02:40:33 +0000 Subject: [PATCH] [MRM-155] check paths are translated correctly when there is a mismatch between the requested repository layout and the managed repository layout 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 --- .../proxy/DefaultProxyRequestHandler.java | 11 ++++-- .../proxy/ProxyRequestHandlerTest.java | 34 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java index 323f8e62e..892fd290c 100644 --- a/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java +++ b/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultProxyRequestHandler.java @@ -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 ) diff --git a/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ProxyRequestHandlerTest.java b/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ProxyRequestHandlerTest.java index 568c89b42..a1c9da8ff 100644 --- a/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ProxyRequestHandlerTest.java +++ b/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ProxyRequestHandlerTest.java @@ -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(); -- 2.39.5