Author: epunzalan
Date: Fri Feb 3 19:37:44 2006
New Revision: 374828
URL: http://svn.apache.org/viewcvs?rev=374828&view=rev
Log:
PR: MRM-43
Added javadoc annotations and some code improvements
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/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.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=374828&r1=374827&r2=374828&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
Fri Feb 3 19:37:44 2006
@@ -63,11 +63,19 @@
private ProxyConfiguration config;
+ /**
+ * Constructor.
+ *
+ * @param configuration the configuration object to base the behavior of
this instance
+ */
public DefaultProxyManager( ProxyConfiguration configuration )
{
config = configuration;
}
+ /**
+ * @see org.apache.maven.repository.proxy.ProxyManager#get(String)
+ */
public File get( String path )
throws ProxyException, ResourceDoesNotExistException
{
@@ -81,38 +89,43 @@
return cachedFile;
}
+ /**
+ * @see
org.apache.maven.repository.proxy.ProxyManager#getRemoteFile(String)
+ */
public File getRemoteFile( String path )
throws ProxyException, ResourceDoesNotExistException
{
- try
- {
- Artifact artifact = ArtifactUtils.buildArtifact( path,
artifactFactory );
+ Artifact artifact = ArtifactUtils.buildArtifact( path, artifactFactory
);
- File remoteFile;
- if ( artifact != null )
- {
- remoteFile = getArtifactFile( artifact );
- }
- else if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) )
- {
- remoteFile = getRepositoryFile( path, false );
- }
- else
- {
- // as of now, only metadata fits here
- remoteFile = getRepositoryFile( path );
- }
-
- return remoteFile;
+ File remoteFile;
+ if ( artifact != null )
+ {
+ remoteFile = getArtifactFile( artifact );
+ }
+ else if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) )
+ {
+ remoteFile = getRepositoryFile( path, false );
}
- catch ( TransferFailedException e )
+ else
{
- throw new ProxyException( e.getMessage(), e );
+ // as of now, only metadata fits here
+ remoteFile = getRepositoryFile( path );
}
+
+ return remoteFile;
}
+ /**
+ * Used to download an artifact object from the remote repositories.
+ *
+ * @param artifact the artifact object to be downloaded from a remote
repository
+ * @return File object representing the remote artifact in the repository
cache
+ * @throws ProxyException when an error occurred during retrieval of the
requested artifact
+ * @throws ResourceDoesNotExistException when the requested artifact
cannot be found in any of the
+ * configured repositories
+ */
private File getArtifactFile( Artifact artifact )
- throws TransferFailedException, ResourceDoesNotExistException
+ throws ResourceDoesNotExistException, ProxyException
{
ArtifactRepository repoCache = config.getRepositoryCache();
@@ -120,22 +133,54 @@
if ( !artifactFile.exists() )
{
- wagon.getArtifact( artifact, config.getRepositories() );
+ try
+ {
+ wagon.getArtifact( artifact, config.getRepositories() );
+ }
+ catch ( TransferFailedException e )
+ {
+ throw new ProxyException( e.getMessage(), e );
+ }
artifactFile = artifact.getFile();
}
return artifactFile;
}
+ /**
+ * Used to retrieve a remote file from the remote repositories. This
method is used only when the requested
+ * path cannot be resolved into a repository object, for example, an
Artifact.
+ *
+ * @param path the remote path to use to search for the requested file
+ * @return File object representing the remote file in the repository cache
+ * @throws ResourceDoesNotExistException when the requested path cannot be
found in any of the configured
+ * repositories.
+ * @throws ProxyException when an error occurred during the retrieval of
the requested path
+ */
private File getRepositoryFile( String path )
throws ResourceDoesNotExistException, ProxyException
{
return getRepositoryFile( path, true );
}
+ /**
+ * Used to retrieve a remote file from the remote repositories. This
method is used only when the requested
+ * path cannot be resolved into a repository object, for example, an
Artifact.
+ *
+ * @param path the remote path to use to search for the requested file
+ * @param useChecksum forces the download to whether use a checksum (if
present in the remote repository) or not
+ * @return File object representing the remote file in the repository cache
+ * @throws ResourceDoesNotExistException when the requested path cannot be
found in any of the configured
+ * repositories.
+ * @throws ProxyException when an error occurred during the retrieval of
the requested path
+ */
private File getRepositoryFile( String path, boolean useChecksum )
throws ResourceDoesNotExistException, ProxyException
{
+ Map checksums = null;
+ Wagon wagon = null;
+ boolean connected = false;
+
ArtifactRepository cache = config.getRepositoryCache();
File target = new File( cache.getBasedir(), path );
@@ -145,17 +190,17 @@
try
{
- Wagon wagon = this.wagon.getWagon( repository.getProtocol() );
+ wagon = this.wagon.getWagon( repository.getProtocol() );
//@todo configure wagon
- Map checksums = null;
if ( useChecksum )
{
checksums = prepareChecksums( wagon );
}
- if ( connectToRepository( wagon, repository ) )
+ connected = connectToRepository( wagon, repository );
+ if ( connected )
{
File temp = new File( target.getAbsolutePath() + ".tmp" );
temp.deleteOnExit();
@@ -207,11 +252,29 @@
getLogger().info( "Skipping repository " + repository.getUrl()
+ ": no wagon configured for protocol " +
repository.getProtocol() );
}
+ finally
+ {
+ if ( wagon != null && checksums != null )
+ {
+ releaseChecksums( wagon, checksums );
+ }
+
+ if ( connected )
+ {
+ disconnectWagon( wagon );
+ }
+ }
}
throw new ResourceDoesNotExistException( "Could not find " + path + "
in any of the repositories." );
}
+ /**
+ * Used to add checksum observers as transfer listeners to the wagon object
+ *
+ * @param wagon the wagon object to use the checksum with
+ * @return map of ChecksumObservers added into the wagon transfer listeners
+ */
private Map prepareChecksums( Wagon wagon )
{
Map checksums = new HashMap();
@@ -232,6 +295,12 @@
return checksums;
}
+ /**
+ * Used to remove the ChecksumObservers from the wagon 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
+ */
private void releaseChecksums( Wagon wagon, Map checksumMap )
{
for ( Iterator checksums = checksumMap.values().iterator();
checksums.hasNext(); )
@@ -241,6 +310,13 @@
}
}
+ /**
+ * Used to request the wagon 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
+ */
private boolean connectToRepository( Wagon wagon, ProxyRepository
repository )
{
boolean connected = false;
@@ -261,6 +337,14 @@
return connected;
}
+ /**
+ * Used to verify the checksum during a wagon download
+ *
+ * @param checksumMap the map of ChecksumObservers present in the wagon 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
+ * @return true when the checksum succeeds and false when the checksum
failed.
+ */
private boolean doChecksumCheck( Map checksumMap, String path, Wagon wagon
)
{
for ( Iterator checksums = checksumMap.keySet().iterator();
checksums.hasNext(); )
@@ -329,6 +413,11 @@
return true;
}
+ /**
+ * Used to disconnect the wagon from its repository
+ *
+ * @param wagon the connected wagon object
+ */
private void disconnectWagon( Wagon wagon )
{
try
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=374828&r1=374827&r2=374828&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
Fri Feb 3 19:37:44 2006
@@ -21,13 +21,34 @@
import java.io.File;
/**
+ * Class used to bridge the servlet to the repository proxy implementation.
+ *
* @author Edwin Punzalan
*/
public interface ProxyManager
{
+ /**
+ * Used to retrieve a cached path or retrieve one if the cache does not
contain it yet.
+ *
+ * @param path the expected repository path
+ * @return File object referencing the requested path in the cache
+ * @throws ProxyException when an exception occurred during the retrieval
of the requested path
+ * @throws ResourceDoesNotExistException when the requested object can't
be found in any of the
+ * configured repositories
+ */
public File get( String path )
throws ProxyException, ResourceDoesNotExistException;
+ /**
+ * Used to force remote download of the requested path from any the
configured repositories. This method will
+ * only bypass the cache for searching but the requested path will
still be cached.
+ *
+ * @param path the expected repository path
+ * @return File object referencing the requested path in the cache
+ * @throws ProxyException when an exception occurred during the retrieval
of the requested path
+ * @throws ResourceDoesNotExistException when the requested object can't
be found in any of the
+ * configured repositories
+ */
public File getRemoteFile( String path )
throws ProxyException, ResourceDoesNotExistException;
}
Modified:
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java
URL:
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java?rev=374828&r1=374827&r2=374828&view=diff
==============================================================================
---
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java
(original)
+++
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java
Fri Feb 3 19:37:44 2006
@@ -28,6 +28,8 @@
import java.util.List;
/**
+ * Class to represent the configuration file for the proxy
+ *
* @author Edwin Punzalan
* @plexus.component
role="org.apache.maven.repository.proxy.configuration.ProxyConfiguration"
*/
@@ -45,16 +47,31 @@
private ArtifactRepository repoCache;
private List repositories = new ArrayList();
+ /**
+ * Method to set/unset the web-view of the repository cache
+ *
+ * @param browsable set to true to enable the web-view of the proxy
repository cache
+ */
public void setBrowsable( boolean browsable )
{
this.browsable = browsable;
}
+ /**
+ * Used to determine if the repsented configuration allows web view of the
repository cache
+ *
+ * @return true if the repository cache is configured for web view.
+ */
public boolean isBrowsable()
{
return browsable;
}
+ /**
+ * Used to set the location where the proxy should cache the configured
repositories
+ *
+ * @param repoCacheURL
+ */
public void setRepositoryCachePath( String repoCacheURL )
{
ArtifactRepositoryPolicy standardPolicy;
@@ -67,26 +84,53 @@
standardPolicy, standardPolicy );
}
+ /**
+ * Used to retrieve an ArtifactRepository Object of the proxy cache
+ *
+ * @return the ArtifactRepository representation of the proxy cache
+ */
public ArtifactRepository getRepositoryCache()
{
return repoCache;
}
+ /**
+ * Used to retrieved the absolute path of the repository cache
+ *
+ * @return path to the proxy cache
+ */
public String getRepositoryCachePath()
{
return repoCache.getBasedir();
}
+ /**
+ * Used to add proxied repositories.
+ *
+ * @param repository the repository to be proxied
+ */
public void addRepository( ProxyRepository repository )
{
repositories.add( repository );
}
+ /**
+ * Used to retrieve an unmodifyable list of proxied repositories. They
returned list determines the search sequence
+ * for retrieving artifacts.
+ *
+ * @return a list of ProxyRepository objects representing proxied
repositories
+ */
public List getRepositories()
{
return Collections.unmodifiableList( repositories );
}
+ /**
+ * Used to set the list of repositories to be proxied. This replaces any
repositories already added to this
+ * configuraion instance. Useful for re-arranging an existing proxied
list.
+ *
+ * @param repositories
+ */
public void setRepositories( List repositories )
{
this.repositories = repositories;
Modified:
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java
URL:
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java?rev=374828&r1=374827&r2=374828&view=diff
==============================================================================
---
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java
(original)
+++
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java
Fri Feb 3 19:37:44 2006
@@ -20,6 +20,9 @@
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
/**
+ * Class to represent the Proxy repository. Currently does not provide
additional methods from
+ * DefaultArtifactRepository but is expected to do so like enabled/disabled
when a UI is present.
+ *
* @author Edwin Punzalan
*/
public class ProxyRepository