]> source.dussan.org Git - archiva.git/commitdiff
PR: MRM-59
authorEdwin L. Punzalan <epunzalan@apache.org>
Sat, 25 Feb 2006 00:17:39 +0000 (00:17 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Sat, 25 Feb 2006 00:17:39 +0000 (00:17 +0000)
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

12 files changed:
maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java
maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java
maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/LegacyProxyManagerTest.java [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/checksumed-md5/repository/file.txt.md5 [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/checksumed-sha1/repository/file.txt.sha1 [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/commons-logging/jars/commons-logging-1.0.jar.md5 [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/commons-logging/poms/commons-logging-1.0.pom [new file with mode: 0644]
maven-repository-proxy/src/test/m1-remote-repo/not-standard/repository/file.txt [new file with mode: 0644]

index cf4d9dc03548f0a2d531a0986e07a8f3347dd92d..dd9c1a7d452c1d22a19f6f33b23ab4a0a65772e3 100644 (file)
@@ -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
index 84f0173a76d22c3d5c44abcc3026f031b0962250..2a52fcda6138efddf8cc566c85d55de5582f4488 100644 (file)
@@ -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;
     }
index 3d393624197078ab16864c038176290ebb0d4960..76490fe6486151cfb272d5625011270aab14ca2e 100644 (file)
@@ -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 (file)
index 0000000..ae9caf7
--- /dev/null
@@ -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 (file)
index 0000000..08657d7
--- /dev/null
@@ -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 (file)
index 0000000..3839dd6
--- /dev/null
@@ -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 (file)
index 0000000..08657d7
--- /dev/null
@@ -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 (file)
index 0000000..d12e1a4
--- /dev/null
@@ -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 (file)
index 0000000..33232cd
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 (file)
index 0000000..7c997d2
--- /dev/null
@@ -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 (file)
index 0000000..402a9df
--- /dev/null
@@ -0,0 +1,6 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>commons-logging</groupId>
+  <artifactId>commons-logging</artifactId>
+  <version>1.0</version>
+</project>
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 (file)
index 0000000..08657d7
--- /dev/null
@@ -0,0 +1 @@
+test file only
\ No newline at end of file