/**
* @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
/**
* @plexus.requirement
*/
- private WagonManager wagon;
+ private WagonManager wagonManager;
/**
* @plexus.requirement
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;
}
/**
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() )
public File getRemoteFile( String path )
throws ProxyException, ResourceDoesNotExistException
{
+ checkConfiguration();
+
Artifact artifact = ArtifactUtils.buildArtifact( path, artifactFactory );
File remoteFile;
{
try
{
- wagon.getArtifact( artifact, config.getRepositories() );
+ wagonManager.getArtifact( artifact, config.getRepositories() );
}
catch ( TransferFailedException e )
{
try
{
- wagon = this.wagon.getWagon( repository.getProtocol() );
+ wagon = wagonManager.getWagon( repository.getProtocol() );
- //@todo configure wagon
+ //@todo configure wagonManager
if ( useChecksum )
{
}
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
}
/**
- * 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 )
{
}
/**
- * 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 )
{
}
/**
- * 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 )
{
}
/**
- * 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 )
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 )
{
}
catch ( ConnectionException e )
{
- getLogger().error( "Problem disconnecting from wagon - ignoring: " + e.getMessage() );
+ getLogger().error( "Problem disconnecting from wagonManager - ignoring: " + e.getMessage() );
}
}
}
*/
import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
import java.io.File;
*/
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.
*
* @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;
/**
* @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();
}
--- /dev/null
+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 );
+ }
+}
--- /dev/null
+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;
+ }
+}
File cacheFile = new File( "target/proxy-cache" );\r
config.setRepositoryCachePath( "file://" + cacheFile.getAbsolutePath() );\r
ArtifactRepository cache = config.getRepositoryCache();\r
- System.out.println( cache.getUrl() );\r
assertEquals( cacheFile.getAbsolutePath(), cache.getBasedir() );\r
assertEquals( config.getRepositoryCachePath(), cache.getBasedir() );\r
}\r