From: Edwin L. Punzalan Date: Sat, 4 Feb 2006 03:37:44 +0000 (+0000) Subject: PR: MRM-43 X-Git-Tag: archiva-0.9-alpha-1~946 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=83eabf59297adb896d080deb8506e4216208ab17;p=archiva.git PR: MRM-43 Added javadoc annotations and some code improvements git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@374828 13f79535-47bb-0310-9956-ffa450edef68 --- 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 c9a32cc90..a0a2239ff 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 @@ -63,11 +63,19 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager 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 ); - - 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 ); - } + Artifact artifact = ArtifactUtils.buildArtifact( path, artifactFactory ); - return remoteFile; + File remoteFile; + if ( artifact != null ) + { + remoteFile = getArtifactFile( artifact ); } - catch ( TransferFailedException e ) + else if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) ) { - throw new ProxyException( e.getMessage(), e ); + remoteFile = getRepositoryFile( path, false ); } + else + { + // 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 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager } } + /** + * 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 @@ public class DefaultProxyManager 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 @@ public class DefaultProxyManager return true; } + /** + * Used to disconnect the wagon from its repository + * + * @param wagon the connected wagon object + */ private void disconnectWagon( Wagon wagon ) { try 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 1901da33c..239d3e784 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 @@ -21,13 +21,34 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; 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; } diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java index 02918ca80..7d54c9b4e 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/configuration/ProxyConfiguration.java @@ -28,6 +28,8 @@ import java.util.Collections; 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 @@ public class ProxyConfiguration 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 @@ public class ProxyConfiguration 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; diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java index 2d01b5be1..80c3c8ae6 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/repository/ProxyRepository.java @@ -20,6 +20,9 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; 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