You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/02/08 03:10:16 UTC

svn commit: r375827 - in /maven/repository-manager/trunk/maven-repository-proxy/src: main/java/org/apache/maven/repository/proxy/ test/java/org/apache/maven/repository/proxy/ test/java/org/apache/maven/repository/proxy/configuration/

Author: epunzalan
Date: Tue Feb  7 18:10:14 2006
New Revision: 375827

URL: http://svn.apache.org/viewcvs?rev=375827&view=rev
Log:
PR: MRM-43

Added a factory and made sure the proxy instance will always have a configuration when run.  Current unit tests status also included.

Added:
    maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java
    maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java
Modified:
    maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
    maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java
    maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java

Modified: maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java?rev=375827&r1=375826&r2=375827&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java Tue Feb  7 18:10:14 2006
@@ -45,7 +45,7 @@
 
 /**
  * @author Edwin Punzalan
- * @plexus.component role="org.apache.maven.repository.proxy.ProxyManager"
+ * @plexus.component role="org.apache.maven.repository.proxy.ProxyManager" role-hint="default"
  */
 public class DefaultProxyManager
     extends AbstractLogEnabled
@@ -54,7 +54,7 @@
     /**
      * @plexus.requirement
      */
-    private WagonManager wagon;
+    private WagonManager wagonManager;
 
     /**
      * @plexus.requirement
@@ -63,14 +63,14 @@
 
     private ProxyConfiguration config;
 
-    /**
-     * Constructor.
-     *
-     * @param configuration the configuration object to base the behavior of this instance
-     */
-    public DefaultProxyManager( ProxyConfiguration configuration )
+    public void setConfiguration( ProxyConfiguration config )
     {
-        config = configuration;
+        this.config = config;
+    }
+
+    public ProxyConfiguration getConfiguration()
+    {
+        return config;
     }
 
     /**
@@ -79,7 +79,9 @@
     public File get( String path )
         throws ProxyException, ResourceDoesNotExistException
     {
-        //@todo use wagon for cache use file:// as URL
+        checkConfiguration();
+
+        //@todo use wagonManager for cache use file:// as URL
         String cachePath = config.getRepositoryCachePath();
         File cachedFile = new File( cachePath, path );
         if ( !cachedFile.exists() )
@@ -95,6 +97,8 @@
     public File getRemoteFile( String path )
         throws ProxyException, ResourceDoesNotExistException
     {
+        checkConfiguration();
+
         Artifact artifact = ArtifactUtils.buildArtifact( path, artifactFactory );
 
         File remoteFile;
@@ -135,7 +139,7 @@
         {
             try
             {
-                wagon.getArtifact( artifact, config.getRepositories() );
+                wagonManager.getArtifact( artifact, config.getRepositories() );
             }
             catch ( TransferFailedException e )
             {
@@ -190,9 +194,9 @@
 
             try
             {
-                wagon = this.wagon.getWagon( repository.getProtocol() );
+                wagon = wagonManager.getWagon( repository.getProtocol() );
 
-                //@todo configure wagon
+                //@todo configure wagonManager
 
                 if ( useChecksum )
                 {
@@ -249,7 +253,7 @@
             }
             catch ( UnsupportedProtocolException e )
             {
-                getLogger().info( "Skipping repository " + repository.getUrl() + ": no wagon configured for protocol " +
+                getLogger().info( "Skipping repository " + repository.getUrl() + ": no wagonManager configured for protocol " +
                     repository.getProtocol() );
             }
             finally
@@ -270,10 +274,10 @@
     }
 
     /**
-     * Used to add checksum observers as transfer listeners to the wagon object
+     * Used to add checksum observers as transfer listeners to the wagonManager object
      *
-     * @param wagon the wagon object to use the checksum with
-     * @return map of ChecksumObservers added into the wagon transfer listeners
+     * @param wagon the wagonManager object to use the checksum with
+     * @return map of ChecksumObservers added into the wagonManager transfer listeners
      */
     private Map prepareChecksums( Wagon wagon )
     {
@@ -296,10 +300,10 @@
     }
 
     /**
-     * Used to remove the ChecksumObservers from the wagon object
+     * Used to remove the ChecksumObservers from the wagonManager object
      *
-     * @param wagon the wagon object to remote the ChecksumObservers from
-     * @param checksumMap the map representing the list of ChecksumObservers added to the wagon object
+     * @param wagon the wagonManager object to remote the ChecksumObservers from
+     * @param checksumMap the map representing the list of ChecksumObservers added to the wagonManager object
      */
     private void releaseChecksums( Wagon wagon, Map checksumMap )
     {
@@ -311,11 +315,11 @@
     }
 
     /**
-     * Used to request the wagon object to connect to a repository
+     * Used to request the wagonManager object to connect to a repository
      *
-     * @param wagon the wagon object that will be used to connect to the repository
-     * @param repository the repository object to connect the wagon to
-     * @return true when the wagon is able to connect to the repository
+     * @param wagon the wagonManager object that will be used to connect to the repository
+     * @param repository the repository object to connect the wagonManager to
+     * @return true when the wagonManager is able to connect to the repository
      */
     private boolean connectToRepository( Wagon wagon, ProxyRepository repository )
     {
@@ -338,11 +342,11 @@
     }
 
     /**
-     * Used to verify the checksum during a wagon download
+     * Used to verify the checksum during a wagonManager download
      *
-     * @param checksumMap the map of ChecksumObservers present in the wagon as transferlisteners
+     * @param checksumMap the map of ChecksumObservers present in the wagonManager as transferlisteners
      * @param path path of the remote object whose checksum is to be verified
-     * @param wagon the wagon object used to download the requested path
+     * @param wagon the wagonManager object used to download the requested path
      * @return true when the checksum succeeds and false when the checksum failed.
      */
     private boolean doChecksumCheck( Map checksumMap, String path, Wagon wagon )
@@ -413,10 +417,19 @@
         return true;
     }
 
+    private void checkConfiguration()
+        throws ProxyException
+    {
+        if ( config == null )
+        {
+            throw new ProxyException( "No proxy configuration defined." );
+        }
+    }
+
     /**
-     * Used to disconnect the wagon from its repository
+     * Used to disconnect the wagonManager from its repository
      *
-     * @param wagon the connected wagon object
+     * @param wagon the connected wagonManager object
      */
     private void disconnectWagon( Wagon wagon )
     {
@@ -426,7 +439,7 @@
         }
         catch ( ConnectionException e )
         {
-            getLogger().error( "Problem disconnecting from wagon - ignoring: " + e.getMessage() );
+            getLogger().error( "Problem disconnecting from wagonManager - ignoring: " + e.getMessage() );
         }
     }
 }

Modified: maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java?rev=375827&r1=375826&r2=375827&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManager.java Tue Feb  7 18:10:14 2006
@@ -17,6 +17,7 @@
  */
 
 import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
 
 import java.io.File;
 
@@ -27,6 +28,8 @@
  */
 public interface ProxyManager
 {
+    static String ROLE = ProxyManager.class.getName();
+
     /**
      * Used to retrieve a cached path or retrieve one if the cache does not contain it yet.
      *
@@ -36,7 +39,7 @@
      * @throws ResourceDoesNotExistException when the requested object can't be found in any of the
      *      configured repositories
      */
-    public File get( String path )
+    File get( String path )
         throws ProxyException, ResourceDoesNotExistException;
 
     /**
@@ -49,6 +52,20 @@
      * @throws ResourceDoesNotExistException when the requested object can't be found in any of the
      *      configured repositories
      */
-    public File getRemoteFile( String path )
+    File getRemoteFile( String path )
         throws ProxyException, ResourceDoesNotExistException;
+
+    /**
+     * Used by the factory to set the configuration of the proxy
+     *
+     * @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();
 }

Added: maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java?rev=375827&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java (added)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyManagerFactory.java Tue Feb  7 18:10:14 2006
@@ -0,0 +1,52 @@
+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.repository.proxy.configuration.ProxyConfiguration;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
+/**
+ * @author Edwin Punzalan
+ *
+ * @plexus.component role="org.apache.maven.repository.proxy.ProxyManagerFactory"
+ */
+public class ProxyManagerFactory
+    implements Contextualizable
+{
+    public static String ROLE = "org.apache.maven.repository.proxy.ProxyManagerFactory";
+
+    private PlexusContainer container;
+
+    public ProxyManager getProxyManager( String proxy_type, ProxyConfiguration config )
+        throws ComponentLookupException
+    {
+        ProxyManager proxy = (ProxyManager) container.lookup( ProxyManager.ROLE, proxy_type );
+        proxy.setConfiguration( config );
+        return proxy;
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+}

Added: maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java?rev=375827&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java (added)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java Tue Feb  7 18:10:14 2006
@@ -0,0 +1,96 @@
+package org.apache.maven.repository.proxy;
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Edwin Punzalan
+ */
+public class DefaultProxyManagerTest
+    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." );
+        }
+
+        try
+        {
+            proxy.getRemoteFile( "/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 testCache()
+    {
+        
+    }
+
+    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" );
+
+        return config;
+    }
+}

Modified: maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java?rev=375827&r1=375826&r2=375827&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/configuration/ProxyConfigurationTest.java Tue Feb  7 18:10:14 2006
@@ -52,7 +52,6 @@
         File cacheFile = new File( "target/proxy-cache" );
         config.setRepositoryCachePath( "file://" + cacheFile.getAbsolutePath() );
         ArtifactRepository cache = config.getRepositoryCache();
-        System.out.println( cache.getUrl() );
         assertEquals( cacheFile.getAbsolutePath(), cache.getBasedir() );
         assertEquals( config.getRepositoryCachePath(), cache.getBasedir() );
     }