From bda451364bb40872946bf16ebb1c25ca5697f00c Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 8 Jun 2006 04:59:55 +0000 Subject: [PATCH] [MRM-118] proxy config is not a component git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412658 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/proxy/DefaultProxyManager.java | 25 ++++++------------- .../maven/repository/proxy/ProxyManager.java | 10 +------- .../proxy/DefaultProxyManagerTest.java | 21 +++++++++------- .../proxy/LegacyProxyManagerTest.java | 21 +++++++++------- .../configuration/ProxyConfigurationTest.java | 2 +- 5 files changed, 33 insertions(+), 46 deletions(-) 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 9679aa13d..5afe0d9b7 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 @@ -52,7 +52,7 @@ import java.util.Map; * @author Edwin Punzalan * @plexus.component role="org.apache.maven.repository.proxy.ProxyManager" * @todo too much of wagon manager is reproduced here because checksums need to be downloaded separately - is that necessary? - * @todo this isn't reusing the parts of wagon manager than handle snapshots [!] + * @todo this isn't reusing the parts of artifact resolver that handles snapshots - should this be more artifact based than file-based? * @todo currently, cache must be in the same layout as the request, which prohibits any mapping */ public class DefaultProxyManager @@ -69,21 +69,15 @@ public class DefaultProxyManager */ private ArtifactRepositoryFactory repositoryFactory; - /** - * @plexus.requirement - */ - private ProxyConfiguration config; - /** * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" */ private Map repositoryLayoutMap; - /** - * A map - */ private Map failuresCache = new HashMap(); + private ProxyConfiguration config; + private static final int MS_PER_SEC = 1000; /** @@ -102,11 +96,6 @@ public class DefaultProxyManager this.config = config; } - public ProxyConfiguration getConfiguration() - { - return config; - } - /** * @see org.apache.maven.repository.proxy.ProxyManager#get(String) */ @@ -120,15 +109,15 @@ public class DefaultProxyManager File cachedFile = new File( cachePath, path ); if ( !cachedFile.exists() ) { - cachedFile = getRemoteFile( path ); + cachedFile = getAlways( path ); } return cachedFile; } /** - * @see org.apache.maven.repository.proxy.ProxyManager#getRemoteFile(String) + * @see org.apache.maven.repository.proxy.ProxyManager#getAlways(String) */ - public File getRemoteFile( String path ) + public File getAlways( String path ) throws ProxyException, ResourceDoesNotExistException { checkConfiguration(); @@ -393,7 +382,7 @@ public class DefaultProxyManager { wagon = wagonManager.getWagon( repository.getProtocol() ); - //@todo configure wagonManager [!] + //@todo configure wagon (ssh settings, etc) if ( useChecksum ) { diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java index b03bde0ba..1c4c94514 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java @@ -25,7 +25,6 @@ import java.io.File; * Class used to bridge the servlet to the repository proxy implementation. * * @author Edwin Punzalan - * @todo the names get() and getRemoteFile() are confusing [!] */ public interface ProxyManager { @@ -53,7 +52,7 @@ public interface ProxyManager * @throws ResourceDoesNotExistException when the requested object can't be found in any of the * configured repositories */ - File getRemoteFile( String path ) + File getAlways( String path ) throws ProxyException, ResourceDoesNotExistException; /** @@ -62,11 +61,4 @@ public interface ProxyManager * @param config the ProxyConfiguration to set the behavior of the proxy */ void setConfiguration( ProxyConfiguration config ); - - /** - * Used to retrieve the configuration describing the behavior of the proxy - * - * @return the ProxyConfiguration of this proxy - */ - ProxyConfiguration getConfiguration(); } diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java index a15c595ef..40f982fff 100644 --- a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java +++ b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java @@ -34,6 +34,8 @@ public class DefaultProxyManagerTest { private ProxyManager proxy; + private ProxyConfiguration configuration; + protected void setUp() throws Exception { @@ -41,7 +43,8 @@ public class DefaultProxyManagerTest proxy = (ProxyManager) container.lookup( ProxyManager.ROLE ); - proxy.setConfiguration( getTestConfiguration() ); + configuration = getTestConfiguration(); + proxy.setConfiguration( configuration ); } public void testExceptions() @@ -70,7 +73,7 @@ public class DefaultProxyManagerTest File file = proxy.get( "/commons-logging/commons-logging/1.0/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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); //test cache proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" ); @@ -89,11 +92,11 @@ public class DefaultProxyManagerTest public void testArtifactChecksum() throws Exception { - //force the downlod from the remote repository, use getRemoteFile() - File file = proxy.getRemoteFile( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5" ); + //force the downlod from the remote repository, use getAlways() + File file = proxy.getAlways( "/commons-logging/commons-logging/1.0/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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithNoChecksum() @@ -102,7 +105,7 @@ public class DefaultProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithMD5Checksum() @@ -111,7 +114,7 @@ public class DefaultProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithSHA1Checksum() @@ -120,7 +123,7 @@ public class DefaultProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } protected void tearDown() @@ -134,7 +137,7 @@ public class DefaultProxyManagerTest private ProxyConfiguration getTestConfiguration() throws ComponentLookupException { - ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); + ProxyConfiguration config = new ProxyConfiguration(); config.setRepositoryCachePath( "target/proxy-cache" ); 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 index b0f6d1a7a..eb9a6b076 100644 --- 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 @@ -34,6 +34,8 @@ public class LegacyProxyManagerTest { private ProxyManager proxy; + private ProxyConfiguration configuration; + protected void setUp() throws Exception { @@ -41,7 +43,8 @@ public class LegacyProxyManagerTest proxy = (ProxyManager) container.lookup( ProxyManager.ROLE ); - proxy.setConfiguration( getTestConfiguration() ); + configuration = getTestConfiguration(); + proxy.setConfiguration( configuration ); } public void testExceptions() @@ -70,7 +73,7 @@ public class LegacyProxyManagerTest File file = proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); assertTrue( "File must be downloaded: " + file.getAbsolutePath(), file.exists() ); assertTrue( "Downloaded file should be present in the cache.", - file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); //test cache proxy.get( "/commons-logging/jars/commons-logging-1.0.jar" ); @@ -89,11 +92,11 @@ public class LegacyProxyManagerTest 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" ); + //force the downlod from the remote repository, use getAlways() + File file = proxy.getAlways( "/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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithNoChecksum() @@ -102,7 +105,7 @@ public class LegacyProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithMD5Checksum() @@ -111,7 +114,7 @@ public class LegacyProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } public void testNonArtifactWithSHA1Checksum() @@ -120,7 +123,7 @@ public class LegacyProxyManagerTest 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() ) ); + file.getAbsolutePath().startsWith( configuration.getRepositoryCachePath() ) ); } protected void tearDown() @@ -134,7 +137,7 @@ public class LegacyProxyManagerTest private ProxyConfiguration getTestConfiguration() throws ComponentLookupException { - ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); + ProxyConfiguration config = new ProxyConfiguration(); config.setRepositoryCachePath( getTestFile( "target/m1-proxy-cache" ).getAbsolutePath() ); diff --git a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java index 53f583a98..8e47ea2d6 100644 --- a/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java +++ b/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java @@ -41,7 +41,7 @@ public class ProxyConfigurationTest { super.setUp(); - config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE ); + config = new ProxyConfiguration(); } public void testRepositoryCache()