From: Edwin L. Punzalan Date: Sat, 25 Feb 2006 00:17:39 +0000 (+0000) Subject: PR: MRM-59 X-Git-Tag: archiva-0.9-alpha-1~908 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76e034ab47da88fcecb01fdcc20c655058b965d4;p=archiva.git PR: MRM-59 Made the proxy able to respond to m1 path requests git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@380871 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java index cf4d9dc03..dd9c1a7d4 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java @@ -49,7 +49,7 @@ import java.util.Map; /** * @author Edwin Punzalan - * @plexus.component role="org.apache.maven.repository.proxy.ProxyManager" role-hint="default" + * @plexus.component role="org.apache.maven.repository.proxy.ProxyManager" */ public class DefaultProxyManager extends AbstractLogEnabled diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java index 84f0173a7..2a52fcda6 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java @@ -49,7 +49,8 @@ public class ProxyManagerFactory public ProxyManager getProxyManager( String proxy_type, ProxyConfiguration config ) throws ComponentLookupException { - ProxyManager proxy = (ProxyManager) container.lookup( ProxyManager.ROLE, proxy_type ); + ProxyManager proxy = (ProxyManager) container.lookup( ProxyManager.ROLE ); + config.setLayout( proxy_type ); proxy.setConfiguration( config ); return proxy; } diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java index 3d3936241..76490fe64 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout; import org.apache.maven.repository.proxy.repository.ProxyRepository; import java.io.File; @@ -52,6 +53,8 @@ public class ProxyConfiguration private List repositories = new ArrayList(); + private ArtifactRepositoryLayout layout; + /** * Method to set/unset the web-view of the repository cache * @@ -83,11 +86,9 @@ public class ProxyConfiguration standardPolicy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); - ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); - repoCache = artifactRepositoryFactory.createArtifactRepository( "localCache", "file://" + new File( path ).getAbsolutePath(), - layout, standardPolicy, standardPolicy ); + getLayout(), standardPolicy, standardPolicy ); } /** @@ -159,7 +160,6 @@ public class ProxyConfiguration this.setBrowsable( rcc.isBrowsable() ); List repoList = new ArrayList(); - ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); for ( Iterator repos = rcc.getRepos().iterator(); repos.hasNext(); ) { RepoConfiguration repoConfig = (RepoConfiguration) repos.next(); @@ -167,7 +167,7 @@ public class ProxyConfiguration //skip local store repo if ( !repoConfig.getKey().equals( "global" ) ) { - ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), layout ); + ProxyRepository repo = new ProxyRepository( repoConfig.getKey(), repoConfig.getUrl(), getLayout() ); repo.setCacheFailures( repoConfig.getCacheFailures() ); repo.setCachePeriod( repoConfig.getCachePeriod() ); repo.setHardfail( repoConfig.getHardFail() ); @@ -186,4 +186,26 @@ public class ProxyConfiguration this.setRepositories( repoList ); } + + public ArtifactRepositoryLayout getLayout() + { + if ( layout == null ) + { + setLayout( "default" ); + } + + return layout; + } + + public void setLayout( String layout ) + { + if ( "legacy".equalsIgnoreCase( layout ) ) + { + this.layout = new LegacyRepositoryLayout(); + } + else + { + this.layout = new DefaultRepositoryLayout(); + } + } } diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/LegacyProxyManagerTest.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/LegacyProxyManagerTest.java new file mode 100644 index 000000000..ae9caf770 --- /dev/null +++ b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/LegacyProxyManagerTest.java @@ -0,0 +1,150 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout; +import org.apache.maven.repository.proxy.configuration.ProxyConfiguration; +import org.apache.maven.repository.proxy.repository.ProxyRepository; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.File; + +/** + * @author Edwin Punzalan + */ +public class LegacyProxyManagerTest + extends PlexusTestCase +{ + private ProxyManager proxy; + + protected void setUp() + throws Exception + { + super.setUp(); + + ProxyManagerFactory factory = (ProxyManagerFactory) container.lookup( ProxyManagerFactory.ROLE ); + proxy = factory.getProxyManager( "default", getTestConfiguration() ); + } + + public void testExceptions() + { + proxy.setConfiguration( null ); + + try + { + proxy.get( "/invalid" ); + fail( "Expected empty configuration error." ); + } + catch ( ProxyException e ) + { + assertEquals( "Expected Exception not thrown.", "No proxy configuration defined.", e.getMessage() ); + } + catch ( ResourceDoesNotExistException e ) + { + fail( "Expected Exception not thrown." ); + } + } + + public void testArtifactDownload() + throws Exception + { + //test download + File file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); + assertTrue( "File must be downloaded.", file.exists() ); + assertTrue( "Downloaded file should be present in the cache.", + file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + + //test cache + file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); + + try + { + file = proxy.get( "/commons-logging/jars/commons-logging-2.0.jar" ); + fail( "Expected ResourceDoesNotExistException exception not thrown" ); + } + catch ( ResourceDoesNotExistException e ) + { + assertTrue( true ); + } + } + + public void testArtifactChecksum() + throws Exception + { + //force the downlod from the remote repository, use getRemoteFile() + File file = proxy.getRemoteFile( "/commons-logging/jars/commons-logging-1.0.jar.md5" ); + assertTrue( "File must be downloaded.", file.exists() ); + assertTrue( "Downloaded file should be present in the cache.", + file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + } + + public void testNonArtifactWithNoChecksum() + throws Exception + { + File file = proxy.get( "/not-standard/repository/file.txt" ); + assertTrue( "File must be downloaded.", file.exists() ); + assertTrue( "Downloaded file should be present in the cache.", + file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + } + + public void testNonArtifactWithMD5Checksum() + throws Exception + { + File file = proxy.get( "/checksumed-md5/repository/file.txt" ); + assertTrue( "File must be downloaded.", file.exists() ); + assertTrue( "Downloaded file should be present in the cache.", + file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + } + + public void testNonArtifactWithSHA1Checksum() + throws Exception + { + File file = proxy.get( "/checksumed-sha1/repository/file.txt" ); + assertTrue( "File must be downloaded.", file.exists() ); + assertTrue( "Downloaded file should be present in the cache.", + file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + } + + protected void tearDown() + throws Exception + { + container.release( proxy ); + + super.tearDown(); + } + + private ProxyConfiguration getTestConfiguration() + throws ComponentLookupException + { + ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); + + config.setRepositoryCachePath( "target/proxy-cache" ); + + ArtifactRepositoryLayout layout = new LegacyRepositoryLayout(); + + File repo1File = getTestFile( "src/test/m1-remote-repo" ); + + ProxyRepository repo1 = new ProxyRepository( "m1-test-repo", "file://" + repo1File.getAbsolutePath(), layout ); + + config.addRepository( repo1 ); + + return config; + } +} diff --git a/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt new file mode 100644 index 000000000..08657d777 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt @@ -0,0 +1 @@ +test file only \ No newline at end of file diff --git a/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt.md5 b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt.md5 new file mode 100644 index 000000000..3839dd62f --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt.md5 @@ -0,0 +1 @@ +a473f827aa9d5df4e84c802e054c50f7 \ No newline at end of file diff --git a/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt new file mode 100644 index 000000000..08657d777 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt @@ -0,0 +1 @@ +test file only \ No newline at end of file diff --git a/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt.sha1 b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt.sha1 new file mode 100644 index 000000000..d12e1a485 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt.sha1 @@ -0,0 +1 @@ +afb037c2bd96fe1ef1cfd220e82682d088d60d3e \ No newline at end of file diff --git a/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar new file mode 100644 index 000000000..33232cd09 Binary files /dev/null and b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar differ diff --git a/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar.md5 b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar.md5 new file mode 100644 index 000000000..7c997d231 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar.md5 @@ -0,0 +1 @@ +240b26992977c9ad119efb91cb21f8f8 \ No newline at end of file diff --git a/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/poms/commons-logging-1.0.pom b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/poms/commons-logging-1.0.pom new file mode 100644 index 000000000..402a9df37 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/commons-logging/poms/commons-logging-1.0.pom @@ -0,0 +1,6 @@ + + 4.0.0 + commons-logging + commons-logging + 1.0 + diff --git a/maven-repository-proxy/src/test/m1-remote-repo/not-standard/repository/file.txt b/maven-repository-proxy/src/test/m1-remote-repo/not-standard/repository/file.txt new file mode 100644 index 000000000..08657d777 --- /dev/null +++ b/maven-repository-proxy/src/test/m1-remote-repo/not-standard/repository/file.txt @@ -0,0 +1 @@ +test file only \ No newline at end of file