diff options
Diffstat (limited to 'archiva-modules')
25 files changed, 896 insertions, 614 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy/pom.xml b/archiva-modules/archiva-base/archiva-proxy/pom.xml index da1b41ff5..f1715cdd5 100644 --- a/archiva-modules/archiva-base/archiva-proxy/pom.xml +++ b/archiva-modules/archiva-base/archiva-proxy/pom.xml @@ -49,6 +49,22 @@ <artifactId>commons-io</artifactId> </dependency> <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>org.sonatype.sisu</groupId> + <artifactId>sisu-inject-plexus</artifactId> + </dependency> + <dependency> + <groupId>org.sonatype.sisu</groupId> + <artifactId>sisu-guice</artifactId> + </dependency> + <dependency> + <groupId>org.apache.archiva</groupId> + <artifactId>archiva-plexus-bridge</artifactId> + </dependency> + <dependency> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-file</artifactId> <scope>test</scope> @@ -95,22 +111,4 @@ <scope>test</scope> </dependency> </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <excludes> - <exclude>**/Abstract*</exclude> - <exclude>**/*TestCase.java</exclude> - <exclude>**/*Tests.java</exclude> - <exclude>**/*TestSuite.java</exclude> - <exclude>**/RelocateTransfer*</exclude> - </excludes> - </configuration> - </plugin> - </plugins> - </build> </project> diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java index 4b51cb0a2..8ed01c7c3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -19,17 +19,6 @@ package org.apache.maven.archiva.proxy; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; - import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; import org.apache.commons.collections.CollectionUtils; @@ -65,43 +54,65 @@ import org.apache.maven.wagon.authentication.AuthenticationException; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.maven.wagon.proxy.ProxyInfo; import org.apache.maven.wagon.repository.Repository; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.taskqueue.TaskQueueException; import org.codehaus.plexus.util.SelectorUtils; +import org.codehaus.redback.components.springutils.ComponentContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; /** * DefaultRepositoryProxyConnectors - * + * * @version $Id$ * @todo exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than - * your average brown onion - * @plexus.component role-hint="default" + * your average brown onion + * plexus.component role-hint="default" */ +@Service( "repositoryProxyConnectors#default" ) public class DefaultRepositoryProxyConnectors - implements RepositoryProxyConnectors, RegistryListener, Initializable + implements RepositoryProxyConnectors, RegistryListener { private Logger log = LoggerFactory.getLogger( DefaultRepositoryProxyConnectors.class ); /** - * @plexus.requirement + * plexus.requirement */ + @Inject + @Named( value = "archivaConfiguration#default" ) private ArchivaConfiguration archivaConfiguration; /** - * @plexus.requirement + * plexus.requirement */ + @Inject private RepositoryContentFactory repositoryFactory; /** - * @plexus.requirement + * plexus.requirement */ + @Inject private MetadataTools metadataTools; + @Inject + private ComponentContainer componentContainer; + /** * @plexus.requirement role="org.apache.maven.archiva.policies.PreDownloadPolicy" */ @@ -118,8 +129,9 @@ public class DefaultRepositoryProxyConnectors private Map<String, DownloadErrorPolicy> downloadErrorPolicies; /** - * @plexus.requirement role-hint="default" + * plexus.requirement role-hint="default" */ + @Inject private UrlFailureCache urlFailureCache; private Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>(); @@ -127,15 +139,125 @@ public class DefaultRepositoryProxyConnectors private Map<String, ProxyInfo> networkProxyMap = new HashMap<String, ProxyInfo>(); /** - * @plexus.requirement + * plexus.requirement */ + @Inject private WagonFactory wagonFactory; - + /** - * @plexus.requirement role="org.apache.archiva.scheduler.ArchivaTaskScheduler" role-hint="repository" + * plexus.requirement role="org.apache.archiva.scheduler.ArchivaTaskScheduler" role-hint="repository" */ + @Inject + @Named( value = "archivaTaskScheduler#repository" ) private ArchivaTaskScheduler scheduler; + @PostConstruct + public void initialize() + { + initConnectorsAndNetworkProxies(); + archivaConfiguration.addChangeListener( this ); + this.postDownloadPolicies = componentContainer.buildMapWithRole( PostDownloadPolicy.class ); + this.preDownloadPolicies = componentContainer.buildMapWithRole( PreDownloadPolicy.class ); + this.downloadErrorPolicies = componentContainer.buildMapWithRole( DownloadErrorPolicy.class ); + } + + @SuppressWarnings( "unchecked" ) + private void initConnectorsAndNetworkProxies() + { + synchronized ( this.proxyConnectorMap ) + { + ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); + this.proxyConnectorMap.clear(); + + List<ProxyConnectorConfiguration> proxyConfigs = + archivaConfiguration.getConfiguration().getProxyConnectors(); + for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) + { + String key = proxyConfig.getSourceRepoId(); + + try + { + // Create connector object. + ProxyConnector connector = new ProxyConnector(); + + connector.setSourceRepository( + repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) ); + connector.setTargetRepository( + repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) ); + + connector.setProxyId( proxyConfig.getProxyId() ); + connector.setPolicies( proxyConfig.getPolicies() ); + connector.setOrder( proxyConfig.getOrder() ); + connector.setDisabled( proxyConfig.isDisabled() ); + + // Copy any blacklist patterns. + List<String> blacklist = new ArrayList<String>(); + if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) + { + blacklist.addAll( proxyConfig.getBlackListPatterns() ); + } + connector.setBlacklist( blacklist ); + + // Copy any whitelist patterns. + List<String> whitelist = new ArrayList<String>(); + if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) + { + whitelist.addAll( proxyConfig.getWhiteListPatterns() ); + } + connector.setWhitelist( whitelist ); + + // Get other connectors + List<ProxyConnector> connectors = this.proxyConnectorMap.get( key ); + if ( connectors == null ) + { + // Create if we are the first. + connectors = new ArrayList<ProxyConnector>(); + } + + // Add the connector. + connectors.add( connector ); + + // Ensure the list is sorted. + Collections.sort( connectors, proxyOrderSorter ); + + // Set the key to the list of connectors. + this.proxyConnectorMap.put( key, connectors ); + } + catch ( RepositoryNotFoundException e ) + { + log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + } + catch ( RepositoryException e ) + { + log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + } + } + + } + + synchronized ( this.networkProxyMap ) + { + this.networkProxyMap.clear(); + + List<NetworkProxyConfiguration> networkProxies = + archivaConfiguration.getConfiguration().getNetworkProxies(); + for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) + { + String key = networkProxyConfig.getId(); + + ProxyInfo proxy = new ProxyInfo(); + + proxy.setType( networkProxyConfig.getProtocol() ); + proxy.setHost( networkProxyConfig.getHost() ); + proxy.setPort( networkProxyConfig.getPort() ); + proxy.setUserName( networkProxyConfig.getUsername() ); + proxy.setPassword( networkProxyConfig.getPassword() ); + + this.networkProxyMap.put( key, proxy ); + } + } + } + public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) throws ProxyDownloadException { @@ -175,12 +297,12 @@ public class DefaultRepositoryProxyConnectors catch ( NotFoundException e ) { log.debug( "Artifact " + Keys.toKey( artifact ) + " not found on repository \"" - + targetRepository.getRepository().getId() + "\"." ); + + targetRepository.getRepository().getId() + "\"." ); } catch ( NotModifiedException e ) { log.debug( "Artifact " + Keys.toKey( artifact ) + " not updated on repository \"" - + targetRepository.getRepository().getId() + "\"." ); + + targetRepository.getRepository().getId() + "\"." ); } catch ( ProxyException e ) { @@ -241,18 +363,20 @@ public class DefaultRepositoryProxyConnectors } catch ( NotFoundException e ) { - log.debug( "Resource " + path + " not found on repository \"" - + targetRepository.getRepository().getId() + "\"." ); + log.debug( "Resource " + path + " not found on repository \"" + targetRepository.getRepository().getId() + + "\"." ); } catch ( NotModifiedException e ) { - log.debug( "Resource " + path + " not updated on repository \"" - + targetRepository.getRepository().getId() + "\"." ); + log.debug( + "Resource " + path + " not updated on repository \"" + targetRepository.getRepository().getId() + + "\"." ); } catch ( ProxyException e ) { - log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() - + "\" for resource " + path + ", continuing to next repository. Error message: " + e.getMessage() ); + log.warn( + "Transfer error from repository \"" + targetRepository.getRepository().getId() + "\" for resource " + + path + ", continuing to next repository. Error message: " + e.getMessage() ); log.debug( "Full stack trace", e ); } } @@ -297,18 +421,18 @@ public class DefaultRepositoryProxyConnectors catch ( NotFoundException e ) { log.debug( "Metadata " + logicalPath + " not found on remote repository \"" - + targetRepository.getRepository().getId() + "\".", e ); + + targetRepository.getRepository().getId() + "\".", e ); } catch ( NotModifiedException e ) { log.debug( "Metadata " + logicalPath + " not updated on remote repository \"" - + targetRepository.getRepository().getId() + "\".", e ); + + targetRepository.getRepository().getId() + "\".", e ); } catch ( ProxyException e ) { log.warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() - + "\" for versioned Metadata " + logicalPath + ", continuing to next repository. Error message: " - + e.getMessage() ); + + "\" for versioned Metadata " + logicalPath + + ", continuing to next repository. Error message: " + e.getMessage() ); log.debug( "Full stack trace", e ); } } @@ -384,7 +508,7 @@ public class DefaultRepositoryProxyConnectors /** * Simple method to test if the file exists on the local disk. - * + * * @param file the file to test. (may be null) * @return true if file exists. false if the file param is null, doesn't exist, or is not of type File. */ @@ -410,19 +534,19 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the file. - * - * @param connector the connector configuration to use. - * @param remoteRepository the remote repository get the resource from. - * @param remotePath the path in the remote repository to the resource to get. - * @param repository the managed repository that will hold the file - * @param resource the local file to place the downloaded resource into + * + * @param connector the connector configuration to use. + * @param remoteRepository the remote repository get the resource from. + * @param remotePath the path in the remote repository to the resource to get. + * @param repository the managed repository that will hold the file + * @param resource the local file to place the downloaded resource into * @param requestProperties the request properties to utilize for policy handling. - * @param executeConsumers whether to execute the consumers after proxying + * @param executeConsumers whether to execute the consumers after proxying * @return the local file that was downloaded, or null if not downloaded. - * @throws NotFoundException if the file was not found on the remote repository. + * @throws NotFoundException if the file was not found on the remote repository. * @throws NotModifiedException if the localFile was present, and the resource was present on remote repository, but - * the remote resource is not newer than the local File. - * @throws ProxyException if transfer was unsuccessful. + * the remote resource is not newer than the local File. + * @throws ProxyException if transfer was unsuccessful. */ private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, ManagedRepositoryContent repository, File resource, Properties requestProperties, @@ -443,9 +567,8 @@ public class DefaultRepositoryProxyConnectors // Path must belong to whitelist. if ( !matchesPattern( remotePath, connector.getWhitelist() ) ) { - log.debug( "Path [" + remotePath - + "] is not part of defined whitelist (skipping transfer from repository [" - + remoteRepository.getRepository().getName() + "])." ); + log.debug( "Path [{}] is not part of defined whitelist (skipping transfer from repository [{}]).", + remotePath, remoteRepository.getRepository().getName() ); return null; } } @@ -453,8 +576,8 @@ public class DefaultRepositoryProxyConnectors // Is target path part of blacklist? if ( matchesPattern( remotePath, connector.getBlacklist() ) ) { - log.debug( "Path [" + remotePath + "] is part of blacklist (skipping transfer from repository [" - + remoteRepository.getRepository().getName() + "])." ); + log.debug( "Path [{}] is part of blacklist (skipping transfer from repository [{}]).", remotePath, + remoteRepository.getRepository().getName() ); return null; } @@ -468,7 +591,7 @@ public class DefaultRepositoryProxyConnectors String emsg = "Transfer not attempted on " + url + " : " + e.getMessage(); if ( fileExists( resource ) ) { - log.debug( emsg + ": using already present local file." ); + log.debug( "{} : using already present local file.", emsg ); return resource; } @@ -488,7 +611,7 @@ public class DefaultRepositoryProxyConnectors { RepositoryURL repoUrl = remoteRepository.getURL(); String protocol = repoUrl.getProtocol(); - wagon = (Wagon) wagonFactory.getWagon( "wagon#" + protocol ); + wagon = wagonFactory.getWagon( "wagon#" + protocol ); if ( wagon == null ) { throw new ProxyException( "Unsupported target repository protocol: " + protocol ); @@ -526,6 +649,10 @@ public class DefaultRepositoryProxyConnectors urlFailureCache.cacheFailure( url ); throw e; } + catch ( WagonFactoryException e ) + { + throw new ProxyException( e.getMessage(), e ); + } finally { if ( wagon != null ) @@ -548,7 +675,7 @@ public class DefaultRepositoryProxyConnectors } catch ( PolicyViolationException e ) { - log.warn( "Transfer invalidated from " + url + " : " + e.getMessage() ); + log.warn( "Transfer invalidated from {} : {}", url, e.getMessage() ); executeConsumers = false; if ( !fileExists( tmpResource ) ) { @@ -596,16 +723,16 @@ public class DefaultRepositoryProxyConnectors } catch ( TaskQueueException e ) { - log.error( "Unable to queue repository task to execute consumers on resource file ['" + - localFile.getName() + "']." ); + log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName() + + "']." ); } } /** * Moves the file into repository location if it exists - * + * * @param fileToMove this could be either the main artifact, sha1 or md5 checksum file. - * @param directory directory to write files to + * @param directory directory to write files to */ private void moveFileIfExists( File fileToMove, File directory ) throws ProxyException @@ -621,14 +748,14 @@ public class DefaultRepositoryProxyConnectors * <p> * Quietly transfer the checksum file from the remote repository to the local file. * </p> - * - * @param wagon the wagon instance (should already be connected) to use. + * + * @param wagon the wagon instance (should already be connected) to use. * @param remoteRepository the remote repository to transfer from. - * @param remotePath the remote path to the resource to get. - * @param repository the managed repository that will hold the file - * @param resource the local file that should contain the downloaded contents - * @param tmpDirectory the temporary directory to download to - * @param ext the type of checksum to transfer (example: ".md5" or ".sha1") + * @param remotePath the remote path to the resource to get. + * @param repository the managed repository that will hold the file + * @param resource the local file that should contain the downloaded contents + * @param tmpDirectory the temporary directory to download to + * @param ext the type of checksum to transfer (example: ".md5" or ".sha1") * @throws ProxyException if copying the downloaded file into place did not succeed. */ private File transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, @@ -653,12 +780,12 @@ public class DefaultRepositoryProxyConnectors catch ( NotFoundException e ) { urlFailureCache.cacheFailure( url ); - log.debug( "Transfer failed, checksum not found: " + url ); + log.debug( "Transfer failed, checksum not found: {}", url ); // Consume it, do not pass this on. } catch ( NotModifiedException e ) { - log.debug( "Transfer skipped, checksum not modified: " + url ); + log.debug( "Transfer skipped, checksum not modified: {}", url ); // Consume it, do not pass this on. } catch ( ProxyException e ) @@ -673,12 +800,12 @@ public class DefaultRepositoryProxyConnectors /** * Perform the transfer of the remote file to the local file specified. - * - * @param wagon the wagon instance to use. + * + * @param wagon the wagon instance to use. * @param remoteRepository the remote repository to use - * @param remotePath the remote path to attempt to get - * @param repository the managed repository that will hold the file - * @param origFile the local file to save to + * @param remotePath the remote path to attempt to get + * @param repository the managed repository that will hold the file + * @param origFile the local file to save to * @return The local file that was transfered. * @throws ProxyException if there was a problem moving the downloaded file into place. * @throws WagonException if there was a problem tranfering the file. @@ -696,7 +823,7 @@ public class DefaultRepositoryProxyConnectors if ( !origFile.exists() ) { - log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() ); + log.debug( "Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName() ); wagon.get( remotePath, destFile ); success = true; @@ -705,13 +832,12 @@ public class DefaultRepositoryProxyConnectors } else { - log.debug( "Retrieving " + remotePath + " from " + remoteRepository.getRepository().getName() - + " if updated" ); + log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() ); success = wagon.getIfNewer( remotePath, destFile, origFile.lastModified() ); if ( !success ) { - throw new NotModifiedException( "Not downloaded, as local file is newer than remote side: " - + origFile.getAbsolutePath() ); + throw new NotModifiedException( + "Not downloaded, as local file is newer than remote side: " + origFile.getAbsolutePath() ); } if ( destFile.exists() ) @@ -722,8 +848,9 @@ public class DefaultRepositoryProxyConnectors } catch ( ResourceDoesNotExistException e ) { - throw new NotFoundException( "Resource [" + remoteRepository.getURL() + "/" + remotePath - + "] does not exist: " + e.getMessage(), e ); + throw new NotFoundException( + "Resource [" + remoteRepository.getURL() + "/" + remotePath + "] does not exist: " + e.getMessage(), + e ); } catch ( WagonException e ) { @@ -741,13 +868,13 @@ public class DefaultRepositoryProxyConnectors /** * Apply the policies. - * - * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) - * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy - * setting) - * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)} - * ) - * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String,Properties,File)}) + * + * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) + * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy + * setting) + * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)} + * ) + * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) */ private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings, Properties request, File localFile ) @@ -807,8 +934,8 @@ public class DefaultRepositoryProxyConnectors if ( !previousExceptions.containsKey( content.getId() ) ) { throw new ProxyDownloadException( - "An error occurred in downloading from the remote repository, and the policy is to fail immediately", - content.getId(), exception ); + "An error occurred in downloading from the remote repository, and the policy is to fail immediately", + content.getId(), exception ); } } else @@ -818,13 +945,14 @@ public class DefaultRepositoryProxyConnectors } log.warn( "Transfer error from repository \"" + content.getRepository().getId() + "\" for artifact " - + Keys.toKey( artifact ) + ", continuing to next repository. Error message: " + exception.getMessage() ); + + Keys.toKey( artifact ) + ", continuing to next repository. Error message: " + + exception.getMessage() ); log.debug( "Full stack trace", exception ); } /** * Creates a working directory in the repository root for this request - * + * * @param repository * @return file location of working directory * @throws IOException @@ -848,8 +976,8 @@ public class DefaultRepositoryProxyConnectors /** * Used to move the temporary file to its real destination. This is patterned from the way WagonManager handles its * downloaded files. - * - * @param temp The completed download file + * + * @param temp The completed download file * @param target The final location of the downloaded file * @throws ProxyException when the temp file cannot replace the target file */ @@ -875,12 +1003,12 @@ public class DefaultRepositoryProxyConnectors if ( target.exists() ) { log.debug( "Tried to copy file " + temp.getName() + " to " + target.getAbsolutePath() - + " but file with this name already exists." ); + + " but file with this name already exists." ); } else { - throw new ProxyException( "Cannot copy tmp file " + temp.getAbsolutePath() - + " to its final location", e ); + throw new ProxyException( + "Cannot copy tmp file " + temp.getAbsolutePath() + " to its final location", e ); } } finally @@ -892,13 +1020,14 @@ public class DefaultRepositoryProxyConnectors /** * Using wagon, connect to the remote repository. - * - * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) - * @param wagon the wagon instance to establish the connection on. + * + * @param connector the connector configuration to utilize (for obtaining network proxy configuration from) + * @param wagon the wagon instance to establish the connection on. * @param remoteRepository the remote repository to connect to. * @return true if the connection was successful. false if not connected. */ - private boolean connectToRepository( ProxyConnector connector, Wagon wagon, RemoteRepositoryContent remoteRepository ) + private boolean connectToRepository( ProxyConnector connector, Wagon wagon, + RemoteRepositoryContent remoteRepository ) { boolean connected = false; @@ -913,9 +1042,8 @@ public class DefaultRepositoryProxyConnectors if ( networkProxy != null ) { // TODO: move to proxyInfo.toString() - String msg = - "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort() - + " to connect to remote repository " + remoteRepository.getURL(); + String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort() + + " to connect to remote repository " + remoteRepository.getURL(); if ( networkProxy.getNonProxyHosts() != null ) { msg += "; excluding hosts: " + networkProxy.getNonProxyHosts(); @@ -969,8 +1097,8 @@ public class DefaultRepositoryProxyConnectors /** * Tests whitelist and blacklist patterns against path. - * - * @param path the path to test. + * + * @param path the path to test. * @param patterns the list of patterns to check. * @return true if the path matches at least 1 pattern in the provided patterns list. */ @@ -985,14 +1113,14 @@ public class DefaultRepositoryProxyConnectors { path = "/" + path; } - + for ( String pattern : patterns ) { if ( !pattern.startsWith( "/" ) ) { pattern = "/" + pattern; } - + if ( SelectorUtils.matchPath( pattern, path, false ) ) { return true; @@ -1024,8 +1152,8 @@ public class DefaultRepositoryProxyConnectors { if ( ConfigurationNames.isNetworkProxy( propertyName ) || ConfigurationNames.isManagedRepositories( propertyName ) - || ConfigurationNames.isRemoteRepositories( propertyName ) - || ConfigurationNames.isProxyConnector( propertyName ) ) + || ConfigurationNames.isRemoteRepositories( propertyName ) || ConfigurationNames.isProxyConnector( + propertyName ) ) { initConnectorsAndNetworkProxies(); } @@ -1036,105 +1164,4 @@ public class DefaultRepositoryProxyConnectors /* do nothing */ } - @SuppressWarnings( "unchecked" ) - private void initConnectorsAndNetworkProxies() - { - synchronized ( this.proxyConnectorMap ) - { - ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); - this.proxyConnectorMap.clear(); - - List<ProxyConnectorConfiguration> proxyConfigs = - archivaConfiguration.getConfiguration().getProxyConnectors(); - for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) - { - String key = proxyConfig.getSourceRepoId(); - - try - { - // Create connector object. - ProxyConnector connector = new ProxyConnector(); - - connector.setSourceRepository( repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) ); - connector.setTargetRepository( repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) ); - - connector.setProxyId( proxyConfig.getProxyId() ); - connector.setPolicies( proxyConfig.getPolicies() ); - connector.setOrder( proxyConfig.getOrder() ); - connector.setDisabled( proxyConfig.isDisabled() ); - - // Copy any blacklist patterns. - List<String> blacklist = new ArrayList<String>(); - if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) - { - blacklist.addAll( proxyConfig.getBlackListPatterns() ); - } - connector.setBlacklist( blacklist ); - - // Copy any whitelist patterns. - List<String> whitelist = new ArrayList<String>(); - if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) - { - whitelist.addAll( proxyConfig.getWhiteListPatterns() ); - } - connector.setWhitelist( whitelist ); - - // Get other connectors - List<ProxyConnector> connectors = this.proxyConnectorMap.get( key ); - if ( connectors == null ) - { - // Create if we are the first. - connectors = new ArrayList<ProxyConnector>(); - } - - // Add the connector. - connectors.add( connector ); - - // Ensure the list is sorted. - Collections.sort( connectors, proxyOrderSorter ); - - // Set the key to the list of connectors. - this.proxyConnectorMap.put( key, connectors ); - } - catch ( RepositoryNotFoundException e ) - { - log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); - } - catch ( RepositoryException e ) - { - log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); - } - } - - } - - synchronized ( this.networkProxyMap ) - { - this.networkProxyMap.clear(); - - List<NetworkProxyConfiguration> networkProxies = - archivaConfiguration.getConfiguration().getNetworkProxies(); - for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) - { - String key = networkProxyConfig.getId(); - - ProxyInfo proxy = new ProxyInfo(); - - proxy.setType( networkProxyConfig.getProtocol() ); - proxy.setHost( networkProxyConfig.getHost() ); - proxy.setPort( networkProxyConfig.getPort() ); - proxy.setUserName( networkProxyConfig.getUsername() ); - proxy.setPassword( networkProxyConfig.getPassword() ); - - this.networkProxyMap.put( key, proxy ); - } - } - } - - public void initialize() - throws InitializationException - { - initConnectorsAndNetworkProxies(); - archivaConfiguration.addChangeListener( this ); - } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java index 6e56faa4d..965d2cfb3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/WagonFactory.java @@ -22,17 +22,17 @@ package org.apache.maven.archiva.proxy; import org.apache.maven.wagon.Wagon; /** - * Create a Wagon instance for the given protocol. Implementation will be provided by a Spring service locator. - * + * Create a Wagon instance for the given protocol. */ public interface WagonFactory { /** * Create a new Wagon instance for the given protocol. - * - * @param protocol the protocol to find the Wagon for, which must be prefixed with <code>wagon#</code>, for example - * <code>wagon#http</code>. - * @return the Wagon instance + * + * @param protocol the protocol to find the Wagon for, which must be prefixed with <code>wagon#</code>, for example + * <code>wagon#http</code>. + * @return the Wagon instance */ - Wagon getWagon( String protocol ); + Wagon getWagon( String protocol ) + throws WagonFactoryException; } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml index baae58725..f25d5a74f 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/resources/META-INF/spring-context.xml @@ -16,15 +16,19 @@ ~ KIND, either express or implied. See the License for the ~ specific language governing permissions and limitations ~ under the License. ---> + --> + <beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd" + default-lazy-init="true"> + + <context:annotation-config/> + <context:component-scan base-package="org.apache.maven.archiva.proxy"/> + - <bean id="wagonFactory" - class="org.springframework.beans.factory.config.ServiceLocatorFactoryBean"> - <property name="serviceLocatorInterface" - value="org.apache.maven.archiva.proxy.WagonFactory" /> - </bean> </beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java index 2082e724a..7fbcda0fd 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java @@ -1,24 +1,26 @@ package org.apache.archiva.metadata.repository; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.springframework.stereotype.Service; +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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. +*/ +@Service("repositorySessionFactory") public class TestRepositorySessionFactory implements RepositorySessionFactory { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java index 68185312f..56a56bf27 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/AbstractProxyTestCase.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.proxy; * under the License. */ +import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -33,10 +34,16 @@ import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.wagon.Wagon; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.ArgumentsMatcher; import org.easymock.MockControl; - +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import javax.inject.Named; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -53,9 +60,15 @@ import java.util.Locale; * * @version $Id$ */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) public abstract class AbstractProxyTestCase - extends PlexusInSpringTestCase + extends TestCase { + + @Inject + protected ApplicationContext applicationContext; + protected static final String ID_LEGACY_PROXIED = "legacy-proxied"; protected static final String ID_PROXIED1 = "proxied1"; @@ -88,6 +101,90 @@ public abstract class AbstractProxyTestCase protected static final String REPOPATH_LEGACY_MANAGED_TARGET = "target/test-repository/legacy-managed"; + protected MockControl wagonMockControl; + + protected Wagon wagonMock; + + + protected RepositoryProxyConnectors proxyHandler; + + protected ManagedRepositoryContent managedDefaultRepository; + + protected File managedDefaultDir; + + protected ManagedRepositoryContent managedLegacyRepository; + + protected File managedLegacyDir; + + protected MockConfiguration config; + + @Inject + @Named( value = "wagon#test" ) + WagonDelegate delegate; + + @Before + public void setUp() + throws Exception + { + super.setUp(); + + proxyHandler = applicationContext.getBean( RepositoryProxyConnectors.class ); + + config = + (MockConfiguration) applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class ); + + // Setup source repository (using default layout) + String repoPath = "target/test-repository/managed/" + getName(); + File repoLocation = new File( repoPath ); + + managedDefaultRepository = + createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" ); + + managedDefaultDir = new File( managedDefaultRepository.getRepoRoot() ); + + ManagedRepositoryConfiguration repoConfig = managedDefaultRepository.getRepository(); + + config.getConfiguration().addManagedRepository( repoConfig ); + + // Setup source repository (using legacy layout) + repoLocation = new File( REPOPATH_LEGACY_MANAGED_TARGET ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( new File( REPOPATH_LEGACY_MANAGED ), repoLocation ); + + managedLegacyRepository = + createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository", REPOPATH_LEGACY_MANAGED_TARGET, + "legacy" ); + + managedLegacyDir = new File( managedLegacyRepository.getRepoRoot() ); + + repoConfig = managedLegacyRepository.getRepository(); + + config.getConfiguration().addManagedRepository( repoConfig ); + + // Setup target (proxied to) repository. + saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", + new File( REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" ); + + // Setup target (proxied to) repository. + saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", + new File( REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" ); + + // Setup target (proxied to) repository using legacy layout. + saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", + new File( REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" ); + + // Setup the proxy handler. + //proxyHandler = applicationContext.getBean (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); + + // Setup the wagon mock. + wagonMockControl = MockControl.createNiceControl( Wagon.class ); + wagonMock = (Wagon) wagonMockControl.getMock(); + + delegate.setDelegate( wagonMock ); + + System.out.println( "\n.\\ " + getName() + "() \\._________________________________________\n" ); + } + protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher() { @@ -97,8 +194,8 @@ public abstract class AbstractProxyTestCase { return false; } - return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ), ArrayUtils.remove( actual, - 1 ) ); + return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ), + ArrayUtils.remove( actual, 1 ) ); } public String toString( Object[] arguments ) @@ -140,21 +237,6 @@ public abstract class AbstractProxyTestCase } }; - protected MockControl wagonMockControl; - - protected Wagon wagonMock; - - protected RepositoryProxyConnectors proxyHandler; - - protected ManagedRepositoryContent managedDefaultRepository; - - protected File managedDefaultDir; - - protected ManagedRepositoryContent managedLegacyRepository; - - protected File managedLegacyDir; - - protected MockConfiguration config; protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents ) throws Exception @@ -215,7 +297,7 @@ public abstract class AbstractProxyTestCase return; } - Collection<File> tmpFiles = FileUtils.listFiles( workingDir, new String[]{"tmp"}, false ); + Collection<File> tmpFiles = FileUtils.listFiles( workingDir, new String[]{ "tmp" }, false ); if ( !tmpFiles.isEmpty() ) { StringBuffer emsg = new StringBuffer(); @@ -309,8 +391,8 @@ public abstract class AbstractProxyTestCase repo.setLocation( path ); repo.setLayout( layout ); - ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, - layout ); + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class ); repoContent.setRepository( repo ); return repoContent; } @@ -392,10 +474,10 @@ public abstract class AbstractProxyTestCase config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) ); config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) ); config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) ); - config.triggerChange( prefix + ".policies.propagate-errors", connectorConfig.getPolicy( "propagate-errors", - "" ) ); - config.triggerChange( prefix + ".policies.propagate-errors-on-update", connectorConfig.getPolicy( - "propagate-errors-on-update", "" ) ); + config.triggerChange( prefix + ".policies.propagate-errors", + connectorConfig.getPolicy( "propagate-errors", "" ) ); + config.triggerChange( prefix + ".policies.propagate-errors-on-update", + connectorConfig.getPolicy( "propagate-errors-on-update", "" ) ); } protected void saveManagedRepositoryConfig( String id, String name, String path, String layout ) @@ -440,99 +522,21 @@ public abstract class AbstractProxyTestCase protected File saveTargetedRepositoryConfig( String id, String originalPath, String targetPath, String layout ) throws IOException { - File repoLocation = getTestFile( targetPath ); + File repoLocation = new File( targetPath ); FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( getTestFile( originalPath ), repoLocation ); + copyDirectoryStructure( new File( originalPath ), repoLocation ); saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); return repoLocation; } - /** - * {@inheritDoc} - * - * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getConfigLocation() - */ - @Override - protected String getSpringConfigLocation() - { - return "org/apache/maven/archiva/proxy/spring-context.xml"; - } - - @Override - protected void setUp() - throws Exception - { - super.setUp(); - - config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); - - // Setup source repository (using default layout) - String repoPath = "target/test-repository/managed/" + getName(); - File repoLocation = getTestFile( repoPath ); - - managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, - "default" ); - - managedDefaultDir = new File( managedDefaultRepository.getRepoRoot() ); - - ManagedRepositoryConfiguration repoConfig = managedDefaultRepository.getRepository(); - - config.getConfiguration().addManagedRepository( repoConfig ); - - // Setup source repository (using legacy layout) - repoLocation = getTestFile( REPOPATH_LEGACY_MANAGED_TARGET ); - FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( getTestFile( REPOPATH_LEGACY_MANAGED ), repoLocation ); - - managedLegacyRepository = createRepository( ID_LEGACY_MANAGED, "Legacy Managed Repository", - REPOPATH_LEGACY_MANAGED_TARGET, "legacy" ); - - managedLegacyDir = new File( managedLegacyRepository.getRepoRoot() ); - - repoConfig = managedLegacyRepository.getRepository(); - - config.getConfiguration().addManagedRepository( repoConfig ); - - // Setup target (proxied to) repository. - saveRemoteRepositoryConfig( ID_PROXIED1, "Proxied Repository 1", new File( - REPOPATH_PROXIED1 ).toURL().toExternalForm(), "default" ); - - // Setup target (proxied to) repository. - saveRemoteRepositoryConfig( ID_PROXIED2, "Proxied Repository 2", new File( - REPOPATH_PROXIED2 ).toURL().toExternalForm(), "default" ); - - // Setup target (proxied to) repository using legacy layout. - saveRemoteRepositoryConfig( ID_LEGACY_PROXIED, "Proxied Legacy Repository", new File( - REPOPATH_PROXIED_LEGACY ).toURL().toExternalForm(), "legacy" ); - - // Setup the proxy handler. - try - { - proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); - } - catch ( Exception e ) - { - // TODO: handle in plexus-spring instead - applicationContext.close(); - throw e; - } - - // Setup the wagon mock. - wagonMockControl = MockControl.createNiceControl( Wagon.class ); - wagonMock = (Wagon) wagonMockControl.getMock(); - WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" ); - delegate.setDelegate( wagonMock ); - - System.out.println( "\n.\\ " + getName() + "() \\._________________________________________\n" ); - } /** * Copy the specified resource directory from the src/test/repository/managed/ to * the testable directory under target/test-repository/managed/${testName}/ * - * @param resourceDir + * @param resourcePath * @throws IOException */ protected void setupTestableManagedRepository( String resourcePath ) @@ -610,9 +614,9 @@ public abstract class AbstractProxyTestCase String managedLegacyPath = managedLegacyDir.getCanonicalPath(); String testFile = file.getCanonicalPath(); - assertTrue( "Unit Test Failure: File <" + testFile + - "> should be have been defined within the legacy managed path of <" + managedLegacyPath + ">", - testFile.startsWith( managedLegacyPath ) ); + assertTrue( + "Unit Test Failure: File <" + testFile + "> should be have been defined within the legacy managed path of <" + + managedLegacyPath + ">", testFile.startsWith( managedLegacyPath ) ); assertFalse( "File < " + testFile + "> should not exist in managed legacy repository.", file.exists() ); } @@ -623,9 +627,9 @@ public abstract class AbstractProxyTestCase String managedDefaultPath = managedDefaultDir.getCanonicalPath(); String testFile = file.getCanonicalPath(); - assertTrue( "Unit Test Failure: File <" + testFile + - "> should be have been defined within the managed default path of <" + managedDefaultPath + ">", - testFile.startsWith( managedDefaultPath ) ); + assertTrue( "Unit Test Failure: File <" + testFile + + "> should be have been defined within the managed default path of <" + managedDefaultPath + + ">", testFile.startsWith( managedDefaultPath ) ); assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() ); } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java index d4bf2943e..fd951e44e 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/CacheFailuresTransferTest.java @@ -27,7 +27,9 @@ import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.archiva.policies.urlcache.UrlFailureCache; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.junit.Test; +import javax.inject.Inject; import java.io.File; /** @@ -41,6 +43,7 @@ public class CacheFailuresTransferTest // TODO: test some hard failures (eg TransferFailedException) // TODO: test the various combinations of fetchFrom* (note: need only test when caching is enabled) + @Test public void testGetWithCacheFailuresOn() throws Exception { @@ -64,7 +67,7 @@ public class CacheFailuresTransferTest wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setMatcher(customWagonGetMatcher); + wagonMockControl.setMatcher( customWagonGetMatcher ); wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); @@ -84,6 +87,7 @@ public class CacheFailuresTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetWithCacheFailuresOff() throws Exception { @@ -101,13 +105,13 @@ public class CacheFailuresTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setMatcher(customWagonGetMatcher); + wagonMockControl.setMatcher( customWagonGetMatcher ); wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); wagonMockControl.replay(); @@ -120,7 +124,7 @@ public class CacheFailuresTransferTest wagonMockControl.reset(); wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - wagonMockControl.setMatcher(customWagonGetMatcher); + wagonMockControl.setMatcher( customWagonGetMatcher ); wagonMockControl.setThrowable( new ResourceDoesNotExistException( "resource does not exist." ), 2 ); wagonMockControl.replay(); @@ -132,6 +136,7 @@ public class CacheFailuresTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetWhenInBothProxiedButFirstCacheFailure() throws Exception { @@ -163,10 +168,13 @@ public class CacheFailuresTransferTest assertNoTempFiles( expectedFile ); } + @Inject + UrlFailureCache urlFailureCache; + protected UrlFailureCache lookupUrlFailureCache() throws Exception { - UrlFailureCache urlFailureCache = (UrlFailureCache) lookup( "urlFailureCache" ); + //UrlFailureCache urlFailureCache = (UrlFailureCache) lookup( "urlFailureCache" ); assertNotNull( "URL Failure Cache cannot be null.", urlFailureCache ); return urlFailureCache; } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java index 02ae47594..12554ea3d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ChecksumTransferTest.java @@ -26,6 +26,7 @@ import org.apache.maven.archiva.policies.ChecksumPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.junit.Test; import java.io.File; @@ -37,6 +38,7 @@ import java.io.File; public class ChecksumTransferTest extends AbstractProxyTestCase { + @Test public void testGetChecksumWhenConnectorIsDisabled() throws Exception { @@ -57,7 +59,8 @@ public class ChecksumTransferTest assertNull(downloadedFile); } - + + @Test public void testGetChecksumBothCorrect() throws Exception { @@ -83,6 +86,7 @@ public class ChecksumTransferTest "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" ); } + @Test public void testGetChecksumCorrectSha1NoMd5() throws Exception { @@ -108,6 +112,7 @@ public class ChecksumTransferTest null ); } + @Test public void testGetChecksumNoSha1CorrectMd5() throws Exception { @@ -132,6 +137,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" ); } + @Test public void testGetWithNoChecksumsUsingIgnoredSetting() throws Exception { @@ -156,6 +162,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, null ); } + @Test public void testGetChecksumBadSha1BadMd5IgnoredSetting() throws Exception { @@ -180,6 +187,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" ); } + @Test public void testGetChecksumBadSha1BadMd5FailSetting() throws Exception { @@ -202,6 +210,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, null ); } + @Test public void testGetChecksumBadSha1BadMd5FixSetting() throws Exception { @@ -227,6 +236,7 @@ public class ChecksumTransferTest "a292491a35925465e693a44809a078b5 get-checksum-both-bad-1.0.jar" ); } + @Test public void testGetChecksumCorrectSha1BadMd5UsingFailSetting() throws Exception { @@ -249,6 +259,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, null ); } + @Test public void testGetChecksumNoSha1CorrectMd5UsingFailSetting() throws Exception { @@ -274,6 +285,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" ); } + @Test public void testGetWithNoChecksumsUsingFailSetting() throws Exception { @@ -296,6 +308,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, null, null ); } + @Test public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting() throws Exception { @@ -321,6 +334,7 @@ public class ChecksumTransferTest "invalid checksum file" ); } + @Test public void testGetChecksumCorrectSha1BadMd5UsingFixSetting() throws Exception { @@ -346,6 +360,7 @@ public class ChecksumTransferTest "c35f3b76268b73a4ba617f6f275c49ab get-checksum-sha1-bad-md5-1.0.jar" ); } + @Test public void testGetChecksumNoSha1CorrectMd5UsingFixSetting() throws Exception { @@ -371,6 +386,7 @@ public class ChecksumTransferTest "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" ); } + @Test public void testGetWithNoChecksumsUsingFixSetting() throws Exception { @@ -396,6 +412,7 @@ public class ChecksumTransferTest "3f7341545f21226b6f49a3c2704cb9be get-default-layout-1.0.jar" ); } + @Test public void testGetChecksumNotFoundOnRemote() throws Exception { @@ -444,6 +461,7 @@ public class ChecksumTransferTest null ); } + @Test public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting() throws Exception { @@ -470,6 +488,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" ); } + @Test public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting() throws Exception { @@ -497,6 +516,7 @@ public class ChecksumTransferTest assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" ); } + @Test public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ErrorHandlingTest.java index 2ee17e8cc..a24e0c32f 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ErrorHandlingTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ErrorHandlingTest.java @@ -30,6 +30,7 @@ import org.apache.maven.archiva.repository.layout.LayoutException; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.authorization.AuthorizationException; +import org.junit.Test; import java.io.File; @@ -55,6 +56,7 @@ public class ErrorHandlingTest private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2"; + @Test public void testPropagateErrorImmediatelyWithErrorThenSuccess() throws Exception { @@ -69,6 +71,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateErrorImmediatelyWithNotFoundThenError() throws Exception { @@ -85,6 +88,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED2 ); } + @Test public void testPropagateErrorImmediatelyWithSuccessThenError() throws Exception { @@ -98,6 +102,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 ); } + @Test public void testPropagateErrorImmediatelyWithNotFoundThenSuccess() throws Exception { @@ -113,6 +118,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 ); } + @Test public void testPropagateErrorAtEndWithErrorThenSuccess() throws Exception { @@ -128,6 +134,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateErrorAtEndWithSuccessThenError() throws Exception { @@ -141,6 +148,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 ); } + @Test public void testPropagateErrorAtEndWithNotFoundThenError() throws Exception { @@ -158,6 +166,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED2 ); } + @Test public void testPropagateErrorAtEndWithErrorThenNotFound() throws Exception { @@ -175,6 +184,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateErrorAtEndWithErrorThenError() throws Exception { @@ -192,6 +202,7 @@ public class ErrorHandlingTest confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} ); } + @Test public void testPropagateErrorAtEndWithNotFoundThenSuccess() throws Exception { @@ -207,6 +218,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 ); } + @Test public void testIgnoreErrorWithErrorThenSuccess() throws Exception { @@ -222,6 +234,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 ); } + @Test public void testIgnoreErrorWithSuccessThenError() throws Exception { @@ -235,6 +248,7 @@ public class ErrorHandlingTest confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 ); } + @Test public void testIgnoreErrorWithNotFoundThenError() throws Exception { @@ -252,6 +266,7 @@ public class ErrorHandlingTest confirmNotDownloadedNoError( path ); } + @Test public void testIgnoreErrorWithErrorThenNotFound() throws Exception { @@ -269,6 +284,7 @@ public class ErrorHandlingTest confirmNotDownloadedNoError( path ); } + @Test public void testIgnoreErrorWithErrorThenError() throws Exception { @@ -286,6 +302,7 @@ public class ErrorHandlingTest confirmNotDownloadedNoError( path ); } + @Test public void testPropagateOnUpdateAlwaysArtifactNotPresent() throws Exception { @@ -302,6 +319,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateOnUpdateAlwaysArtifactPresent() throws Exception { @@ -318,6 +336,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent() throws Exception { @@ -335,6 +354,7 @@ public class ErrorHandlingTest confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } ); } + @Test public void testPropagateOnUpdateAlwaysQueueArtifactPresent() throws Exception { @@ -352,6 +372,7 @@ public class ErrorHandlingTest confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } ); } + @Test public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent() throws Exception { @@ -369,6 +390,7 @@ public class ErrorHandlingTest confirmNotDownloadedNoError( path ); } + @Test public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent() throws Exception { @@ -387,6 +409,7 @@ public class ErrorHandlingTest assertTrue( expectedFile.exists() ); } + @Test public void testPropagateOnUpdateNotPresentArtifactNotPresent() throws Exception { @@ -403,6 +426,7 @@ public class ErrorHandlingTest confirmSingleFailure( path, ID_MOCKED_PROXIED1 ); } + @Test public void testPropagateOnUpdateNotPresentArtifactPresent() throws Exception { @@ -420,6 +444,7 @@ public class ErrorHandlingTest assertTrue( expectedFile.exists() ); } + @Test public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent() throws Exception { @@ -437,6 +462,7 @@ public class ErrorHandlingTest confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } ); } + @Test public void testPropagateOnUpdateNotPresentQueueArtifactPresent() throws Exception { @@ -455,6 +481,7 @@ public class ErrorHandlingTest assertTrue( expectedFile.exists() ); } + @Test public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent() throws Exception { @@ -472,6 +499,7 @@ public class ErrorHandlingTest confirmNotDownloadedNoError( path ); } + @Test public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java index 39bd94a27..555c7d9a3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/HttpProxyTransferTest.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.proxy; * under the License. */ +import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -33,25 +34,35 @@ import org.apache.maven.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.archiva.repository.ManagedRepositoryContent; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import org.mortbay.jetty.Handler; import org.mortbay.jetty.Request; import org.mortbay.jetty.Server; import org.mortbay.jetty.handler.AbstractHandler; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.io.File; -import java.io.IOException; +import javax.inject.Inject; +import javax.inject.Named; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; /** * Integration test for connecting over a HTTP proxy. * * @version $Id: ManagedDefaultTransferTest.java 677852 2008-07-18 08:16:24Z brett $ */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) public class HttpProxyTransferTest - extends PlexusInSpringTestCase + extends TestCase { private static final String PROXY_ID = "proxy"; @@ -67,14 +78,22 @@ public class HttpProxyTransferTest private ManagedRepositoryContent managedDefaultRepository; + @Inject + private ApplicationContext applicationContext; + private Server server; - @Override - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); + proxyHandler = applicationContext.getBean( RepositoryProxyConnectors.class ); + + config = + (MockConfiguration) applicationContext.getBean( "archivaConfiguration#mock", ArchivaConfiguration.class ); + // Setup source repository (using default layout) String repoPath = "target/test-repository/managed/" + getName(); @@ -95,12 +114,12 @@ public class HttpProxyTransferTest repo.setLocation( repoPath ); repo.setLayout( "default" ); - ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, - "default" ); + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class ); + repoContent.setRepository( repo ); managedDefaultRepository = repoContent; - config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" ); config.getConfiguration().addManagedRepository( repo ); Handler handler = new AbstractHandler() @@ -140,21 +159,11 @@ public class HttpProxyTransferTest config.getConfiguration().addRemoteRepository( repoConfig ); - // Setup the proxy handler. - try - { - proxyHandler = (RepositoryProxyConnectors) lookup( RepositoryProxyConnectors.class.getName() ); - } - catch ( Exception e ) - { - server.stop(); - applicationContext.close(); - throw e; - } + } - @Override - protected void tearDown() + @After + public void tearDown() throws Exception { super.tearDown(); @@ -162,6 +171,7 @@ public class HttpProxyTransferTest server.stop(); } + @Test public void testGetOverHttpProxy() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java index 08adc0ce5..2a03aa7d3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedDefaultTransferTest.java @@ -27,6 +27,7 @@ import org.apache.maven.archiva.policies.ChecksumPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.junit.Test; import java.io.File; @@ -38,6 +39,7 @@ import java.io.File; public class ManagedDefaultTransferTest extends AbstractProxyTestCase { + @Test public void testGetDefaultLayoutNotPresentConnectorOffline() throws Exception { @@ -58,7 +60,8 @@ public class ManagedDefaultTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNull("File should not have been downloaded", downloadedFile); } - + + @Test public void testGetDefaultLayoutNotPresent() throws Exception { @@ -83,6 +86,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetDefaultLayoutNotPresentPassthrough() throws Exception { @@ -116,6 +120,7 @@ public class ManagedDefaultTransferTest * * @throws Exception */ + @Test public void testGetDefaultLayoutAlreadyPresentPolicyOnce() throws Exception { @@ -146,6 +151,7 @@ public class ManagedDefaultTransferTest * * @throws Exception */ + @Test public void testGetDefaultLayoutAlreadyPresentPassthrough() throws Exception { @@ -189,6 +195,7 @@ public class ManagedDefaultTransferTest * * @throws Exception */ + @Test public void testGetDefaultLayoutAlreadyPresentNewerThanRemotePolicyIgnored() throws Exception { @@ -234,6 +241,7 @@ public class ManagedDefaultTransferTest * * @throws Exception */ + @Test public void testGetDefaultLayoutAlreadyPresentOlderThanRemotePolicyIgnored() throws Exception { @@ -269,6 +277,7 @@ public class ManagedDefaultTransferTest * * @throws Exception */ + @Test public void testGetDefaultLayoutRemoteUpdate() throws Exception { @@ -293,6 +302,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetWhenInBothProxiedRepos() throws Exception { @@ -323,6 +333,7 @@ public class ManagedDefaultTransferTest StringUtils.equals( actualContents, badContents ) ); } + @Test public void testGetInSecondProxiedRepo() throws Exception { @@ -346,6 +357,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testNotFoundInAnyProxies() throws Exception { @@ -370,6 +382,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetInSecondProxiedRepoFirstFails() throws Exception { @@ -403,6 +416,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetAllRepositoriesFail() throws Exception { @@ -446,6 +460,7 @@ public class ManagedDefaultTransferTest // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy? } + @Test public void testGetFromLegacyProxyAlreadyPresentInManaged_NewerThanRemote() throws Exception { @@ -473,7 +488,8 @@ public class ManagedDefaultTransferTest assertNotModified( expectedFile, expectedTimestamp ); assertNoTempFiles( expectedFile ); } - + + @Test public void testGetFromLegacyProxyAlreadyPresentInManaged_OlderThanRemote() throws Exception { @@ -501,6 +517,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetFromLegacyProxyNotPresentInManaged() throws Exception { @@ -523,6 +540,7 @@ public class ManagedDefaultTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetFromLegacyProxyPluginNotPresentInManaged() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java index 71d596cf9..7fcb198e6 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/ManagedLegacyTransferTest.java @@ -24,6 +24,7 @@ import org.apache.maven.archiva.policies.CachedFailuresPolicy; import org.apache.maven.archiva.policies.ChecksumPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; +import org.junit.Test; import java.io.File; @@ -39,6 +40,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does not * exist in the managed legacy repository, but does exist on a remote default layout repository. */ + @Test public void testManagedLegacyNotPresentRemoteDefaultPresent() throws Exception { @@ -63,6 +65,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that already * exist in the managed legacy repository, and also exist on a remote default layout repository. */ + @Test public void testManagedLegacyPresentRemoteDefaultPresent() throws Exception { @@ -90,6 +93,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does not * exist in the managed legacy repository, and does not exist on a remote legacy layout repository. */ + @Test public void testManagedLegacyNotPresentRemoteLegacyPresent() throws Exception { @@ -113,6 +117,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does exist in the * managed legacy repository, and also exists on a remote legacy layout repository. */ + @Test public void testManagedLegacyPresentRemoteLegacyPresent() throws Exception { @@ -137,6 +142,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does exist in the * managed legacy repository, and does not exist on a remote legacy layout repository. */ + @Test public void testManagedLegacyPresentRemoteLegacyNotPresent() throws Exception { @@ -159,6 +165,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does exist in the * managed legacy repository, and does not exists on a remote default layout repository. */ + @Test public void testManagedLegacyPresentRemoteDefaultNotPresent() throws Exception { @@ -181,6 +188,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does not exist in the * managed legacy repository, and does not exists on a remote legacy layout repository. */ + @Test public void testManagedLegacyNotPresentRemoteLegacyNotPresent() throws Exception { @@ -203,6 +211,7 @@ public class ManagedLegacyTransferTest * Incoming request on a Managed Legacy repository, for content that does not exist in the * managed legacy repository, and does not exists on a remote default layout repository. */ + @Test public void testManagedLegacyNotPresentRemoteDefaultNotPresent() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java index 70e2ab540..5450774e3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java @@ -37,6 +37,8 @@ import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter; import org.apache.maven.wagon.TransferFailedException; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.StringWriter; @@ -45,13 +47,13 @@ import java.util.Arrays; /** * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files * present in the repository. - * + * <p/> * Test Case Naming is as follows. - * + * <p/> * <code> * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote * </code> - * + * <p/> * <pre> * Which should leave the following matrix of test cases. * @@ -90,11 +92,18 @@ import java.util.Arrays; public class MetadataTransferTest extends AbstractProxyTestCase { - /** - * @plexus.requirement - */ + private MetadataTools metadataTools; - + + @Before + public void init() + throws Exception + { + super.setUp(); + metadataTools = applicationContext.getBean( MetadataTools.class ); + } + + @Test public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled() throws Exception { @@ -104,7 +113,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true ); assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -113,13 +122,16 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + managedDefaultRepository.toMetadataPath( + metadata ) ); assertNull( "Should not have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); } // TODO: same test for other fetch* methods + @Test public void testFetchFromTwoProxiesWhenFirstConnectionFails() throws Exception { @@ -143,9 +155,9 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) ); wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); - - wagonMockControl.setMatcher(customWagonGetMatcher); - + + wagonMockControl.setMatcher( customWagonGetMatcher ); + wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) ); wagonMockControl.replay(); @@ -154,17 +166,18 @@ public class MetadataTransferTest wagonMockControl.verify(); - assertProjectMetadataContents( requestedResource, new String[] { "1.0.1" }, "1.0.1", "1.0.1" ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" ); assertNoRepoMetadata( "badproxied1", requestedResource ); - assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } ); + assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } ); } /** * Attempt to get the project metadata for non-existant artifact. - * + * <p/> * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned - * to the requesting client. + * to the requesting client. */ + @Test public void testGetProjectMetadataNotProxiedNotLocal() throws Exception { @@ -181,6 +194,7 @@ public class MetadataTransferTest assertResourceNotFound( requestedResource ); } + @Test public void testGetProjectMetadataNotProxiedOnLocal() throws Exception { @@ -196,9 +210,10 @@ public class MetadataTransferTest // Nothing fetched. Should only contain contents of what is in the repository. // A metadata update is not performed in this use case. Local metadata content is only // updated via the metadata updater consumer. - assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null ); } + @Test public void testGetProjectMetadataProxiedNotLocalMultipleRemotes() throws Exception { @@ -220,11 +235,12 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // Nothing fetched. Should only contain contents of what is in the repository. - assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1" }, "1.0.1", "1.0.1" ); - assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0" } ); - assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" ); + assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } ); + assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } ); } + @Test public void testGetProjectMetadataProxiedNotLocalNotRemote() throws Exception { @@ -251,6 +267,7 @@ public class MetadataTransferTest assertNoRepoMetadata( ID_PROXIED2, requestedResource ); } + @Test public void testGetProjectMetadataProxiedNotLocalOnRemote() throws Exception { @@ -260,7 +277,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -269,10 +286,11 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // Remote fetched. Local created/updated. - assertProjectMetadataContents( requestedResource, new String[] { "1.0.5" }, "1.0.5", "1.0.5" ); - assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.5" } ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" ); + assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } ); } + @Test public void testGetProjectMetadataProxiedOnLocalMultipleRemote() throws Exception { @@ -282,11 +300,11 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); @@ -294,11 +312,12 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // metadata fetched from both repos, and merged with local version. - assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1", "2.0" }, "2.0", "2.0" ); - assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0", "2.0" } ); - assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0", "1.0.1" } ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" ); + assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } ); + assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } ); } + @Test public void testGetProjectMetadataProxiedOnLocalNotRemote() throws Exception { @@ -308,11 +327,11 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); @@ -322,11 +341,12 @@ public class MetadataTransferTest // metadata not fetched from both repos, and local version exists. // Since there was no updated metadata content from a remote/proxy, a metadata update on // the local file never ran. Local only updates are performed via the metadata updater consumer. - assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); } + @Test public void testGetProjectMetadataProxiedOnLocalOnRemote() throws Exception { @@ -336,26 +356,27 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22" }, null, null ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); // One proxy setup, metadata fetched from remote, local exists. assertFetchProjectOrGroup( requestedResource ); // Remote fetched. Local updated. - assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" ); - assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.22", "2.0" } ); + assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" ); + assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } ); } /** * A request for a release maven-metadata.xml file that does not exist locally, and the managed * repository has no proxied repositories set up. - * + * <p/> * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned - * to the requesting client. + * to the requesting client. */ + @Test public void testGetReleaseMetadataNotProxiedNotLocal() throws Exception { @@ -375,10 +396,11 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that does exist locally, and the managed * repository has no proxied repositories set up. - * + * <p/> * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository - * information, and then returned to the client. + * information, and then returned to the client. */ + @Test public void testGetReleaseMetadataNotProxiedOnLocal() throws Exception { @@ -395,12 +417,13 @@ public class MetadataTransferTest /** * A request for a release maven-metadata.xml file that does not exist on the managed repository, but * exists on multiple remote repositories. - * + * <p/> * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific - * file location on the managed repository, a merge of the contents to the requested - * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is - * returned to the client. + * file location on the managed repository, a merge of the contents to the requested + * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is + * returned to the client. */ + @Test public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes() throws Exception { @@ -409,9 +432,9 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -427,10 +450,11 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote * proxied repository. - * + * <p/> * Expected result: the maven-metadata.xml file is created locally, based off of managed repository - * information, and then return to the client. + * information, and then return to the client. */ + @Test public void testGetReleaseMetadataProxiedNotLocalNotRemote() throws Exception { @@ -439,7 +463,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); @@ -452,12 +476,13 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that does not exist on the managed repository, but * exists on 1 remote repository. - * + * <p/> * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific - * file location on the managed repository, a merge of the contents to the requested - * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is - * returned to the client. + * file location on the managed repository, a merge of the contents to the requested + * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is + * returned to the client. */ + @Test public void testGetReleaseMetadataProxiedNotLocalOnRemote() throws Exception { @@ -479,12 +504,13 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that exists in the managed repository, but * not on any remote repository. - * + * <p/> * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and - * is not downloaded. There is no repository specific metadata file on the managed - * repository. The managed repository maven-metadata.xml is returned to the - * client as-is. + * is not downloaded. There is no repository specific metadata file on the managed + * repository. The managed repository maven-metadata.xml is returned to the + * client as-is. */ + @Test public void testGetReleaseMetadataProxiedOnLocalNotRemote() throws Exception { @@ -493,7 +519,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertReleaseMetadataContents( requestedResource ); @@ -506,11 +532,12 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple * remote repositories. - * + * <p/> * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded - * and merged into the contents of the existing managed repository copy of - * the maven-metadata.xml file. + * and merged into the contents of the existing managed repository copy of + * the maven-metadata.xml file. */ + @Test public void testGetReleaseMetadataProxiedOnLocalMultipleRemote() throws Exception { @@ -519,9 +546,9 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertReleaseMetadataContents( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -537,11 +564,12 @@ public class MetadataTransferTest /** * A request for a maven-metadata.xml file that exists in the managed repository, and on one * remote repository. - * + * <p/> * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded - * and merged into the contents of the existing managed repository copy of - * the maven-metadata.xml file. + * and merged into the contents of the existing managed repository copy of + * the maven-metadata.xml file. */ + @Test public void testGetReleaseMetadataProxiedOnLocalOnRemote() throws Exception { @@ -550,7 +578,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertReleaseMetadataContents( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -561,11 +589,13 @@ public class MetadataTransferTest assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource ); } + @Test public void testGetSnapshotMetadataNotProxiedNotLocal() throws Exception { // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally). - String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); assertNoMetadata( requestedResource ); @@ -577,11 +607,13 @@ public class MetadataTransferTest assertNoMetadata( requestedResource ); } + @Test public void testGetSnapshotMetadataNotProxiedOnLocal() throws Exception { // The artifactId exists locally (but not on a remote repo) - String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); assertResourceExists( requestedResource ); @@ -593,17 +625,19 @@ public class MetadataTransferTest assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 ); } + @Test public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes() throws Exception { - String requestedResource = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -617,16 +651,18 @@ public class MetadataTransferTest assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 ); } + @Test public void testGetSnapshotMetadataProxiedNotLocalNotRemote() throws Exception { // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally). - String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertNoMetadata( requestedResource ); @@ -638,6 +674,7 @@ public class MetadataTransferTest assertNoRepoMetadata( ID_PROXIED1, requestedResource ); } + @Test public void testGetSnapshotMetadataProxiedNotLocalOnRemote() throws Exception { @@ -647,7 +684,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); @@ -659,6 +696,7 @@ public class MetadataTransferTest assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 ); } + @Test public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote() throws Exception { @@ -667,9 +705,9 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -683,18 +721,20 @@ public class MetadataTransferTest assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 ); } + @Test public void testGetSnapshotMetadataProxiedOnLocalNotRemote() throws Exception { // The artifactId exists locally (but not on a remote repo) - String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceExists( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -709,16 +749,18 @@ public class MetadataTransferTest assertNoRepoMetadata( ID_PROXIED2, requestedResource ); } + @Test public void testGetSnapshotMetadataProxiedOnLocalOnRemote() throws Exception { // The artifactId exists locally (but not on a remote repo) - String requestedResource = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml"; + String requestedResource = + "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml"; setupTestableManagedRepository( requestedResource ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -731,6 +773,7 @@ public class MetadataTransferTest assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 ); } + @Test public void testGetGroupMetadataNotProxiedNotLocal() throws Exception { @@ -747,6 +790,7 @@ public class MetadataTransferTest assertResourceNotFound( requestedResource ); } + @Test public void testGetGroupMetadataNotProxiedOnLocal() throws Exception { @@ -762,9 +806,10 @@ public class MetadataTransferTest // Nothing fetched. Should only contain contents of what is in the repository. // A metadata update is not performed in this use case. Local metadata content is only // updated via the metadata updater consumer. - assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } ); } + @Test public void testGetGroupMetadataProxiedNotLocalMultipleRemotes() throws Exception { @@ -774,9 +819,9 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); @@ -786,11 +831,12 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // Nothing fetched. Should only contain contents of what is in the repository. - assertGroupMetadataContents( requestedResource, new String[] { "plugin2", "plugin1" } ); - assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1" } ); - assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin2" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } ); + assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } ); + assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } ); } + @Test public void testGetGroupsMetadataProxiedNotLocalNotRemote() throws Exception { @@ -800,7 +846,7 @@ public class MetadataTransferTest // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, - SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false); + SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); @@ -817,6 +863,7 @@ public class MetadataTransferTest assertNoRepoMetadata( ID_PROXIED2, requestedResource ); } + @Test public void testGetGroupMetadataProxiedNotLocalOnRemote() throws Exception { @@ -835,10 +882,11 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // Remote fetched. Local created/updated. - assertGroupMetadataContents( requestedResource, new String[] { "plugin3" } ); - assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin3" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } ); + assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } ); } + @Test public void testGetGroupMetadataProxiedOnLocalMultipleRemote() throws Exception { @@ -852,7 +900,7 @@ public class MetadataTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); @@ -860,11 +908,12 @@ public class MetadataTransferTest assertFetchProjectOrGroup( requestedResource ); // metadata fetched from both repos, and merged with local version. - assertGroupMetadataContents( requestedResource, new String[] { "plugin1", "plugin2", "plugin4" } ); - assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1", "plugin4" } ); - assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin1", "plugin2" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } ); + assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } ); + assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } ); } + @Test public void testGetGroupMetadataProxiedOnLocalNotRemote() throws Exception { @@ -878,7 +927,7 @@ public class MetadataTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); @@ -888,11 +937,12 @@ public class MetadataTransferTest // metadata not fetched from both repos, and local version exists. // Since there was no updated metadata content from a remote/proxy, a metadata update on // the local file never ran. Local only updates are performed via the metadata updater consumer. - assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource ); } + @Test public void testGetGroupMetadataProxiedOnLocalOnRemote() throws Exception { @@ -904,15 +954,15 @@ public class MetadataTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); // One proxy setup, metadata fetched from remote, local exists. assertFetchProjectOrGroup( requestedResource ); // Remote fetched. Local updated. - assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7", "plugin4" } ); - assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin7", "plugin4" } ); + assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } ); + assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } ); } /** @@ -928,7 +978,9 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + managedDefaultRepository.toMetadataPath( + metadata ) ); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -952,7 +1004,9 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + managedDefaultRepository.toMetadataPath( + metadata ) ); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); @@ -971,7 +1025,9 @@ public class MetadataTransferTest VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + managedDefaultRepository.toMetadataPath( + metadata ) ); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -995,7 +1051,9 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) ); + File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + managedDefaultRepository.toMetadataPath( + metadata ) ); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); @@ -1050,7 +1108,8 @@ public class MetadataTransferTest /** * Ensures that the proxied repository specific maven metadata file does NOT exist in the * managed repository. - * @param proxiedRepoId the proxied repository id to validate with. + * + * @param proxiedRepoId the proxied repository id to validate with. * @param requestedResource the resource requested. */ private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource ) @@ -1184,11 +1243,10 @@ public class MetadataTransferTest * Test for the existance of the snapshot metadata in the default managed repository, and if it exists, * does it contain the expected release maven-metadata.xml contents? * - * @param requestedResource the requested resource - * @param expectedDate the date in "yyyyMMdd" format - * @param expectedTime the time in "hhmmss" format + * @param requestedResource the requested resource + * @param expectedDate the date in "yyyyMMdd" format + * @param expectedTime the time in "hhmmss" format * @param expectedBuildnumber the build number - * * @throws Exception */ private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime, @@ -1207,12 +1265,11 @@ public class MetadataTransferTest * Test for the existance of the proxied repository specific snapshot metadata in the default managed * repository, and if it exists, does it contain the expected release maven-metadata.xml contents? * - * @param proxiedRepoId the repository id of the proxied repository. - * @param requestedResource the requested resource - * @param expectedDate the date in "yyyyMMdd" format - * @param expectedTime the time in "hhmmss" format + * @param proxiedRepoId the repository id of the proxied repository. + * @param requestedResource the requested resource + * @param expectedDate the date in "yyyyMMdd" format + * @param expectedTime the time in "hhmmss" format * @param expectedBuildnumber the build number - * * @throws Exception */ private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource, @@ -1260,6 +1317,7 @@ public class MetadataTransferTest /** * Ensures that the repository specific maven metadata file exists, and contains the appropriate * list of expected versions within. + * * @param proxiedRepoId * @param requestedResource * @param expectedProxyVersions @@ -1334,12 +1392,4 @@ public class MetadataTransferTest assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() ); } - protected void setUp() - throws Exception - { - super.setUp(); - - metadataTools = (MetadataTools) lookup( MetadataTools.class ); - } - } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java index f4f16151d..6e3572f24 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MockConfiguration.java @@ -22,28 +22,45 @@ package org.apache.maven.archiva.proxy; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ConfigurationListener; +import org.apache.maven.archiva.configuration.FileType; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryListener; import org.easymock.MockControl; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.io.File; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; /** - * MockConfiguration + * MockConfiguration * * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration" - * role-hint="mock" + * <p/> + * plexus.component role="org.apache.maven.archiva.configuration.ArchivaConfiguration" + * role-hint="mock" */ +@Service( "archivaConfiguration#mock" ) public class MockConfiguration implements ArchivaConfiguration { + + @Inject + protected ApplicationContext applicationContext; + private Configuration configuration = new Configuration(); private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>(); + private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>(); private MockControl registryControl; @@ -56,6 +73,44 @@ public class MockConfiguration registryMock = (Registry) registryControl.getMock(); } + @PostConstruct + public void initialize() + throws Exception + { + + // random name or cleanup ?? + String repoPath = "target/test-repository/managed/" + "foo";//getName(); + File repoLocation = new File( repoPath ); + ManagedRepositoryContent managedDefaultRepository = + createRepository( AbstractProxyTestCase.ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, + "default" ); + ManagedRepositoryConfiguration repoConfig = managedDefaultRepository.getRepository(); + configuration.addManagedRepository( repoConfig ); + + configuration.setRepositoryScanning( new RepositoryScanningConfiguration(){ + @Override + public List<FileType> getFileTypes() + { + return Collections.emptyList(); + } + } ); + } + + protected ManagedRepositoryContent createRepository( String id, String name, String path, String layout ) + throws Exception + { + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); + repo.setId( id ); + repo.setName( name ); + repo.setLocation( path ); + repo.setLayout( layout ); + + ManagedRepositoryContent repoContent = + applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class ); + repoContent.setRepository( repo ); + return repoContent; + } + public void addChangeListener( RegistryListener listener ) { registryListeners.add( listener ); @@ -74,7 +129,7 @@ public class MockConfiguration public void triggerChange( String name, String value ) { - for(RegistryListener listener: registryListeners) + for ( RegistryListener listener : registryListeners ) { try { @@ -89,7 +144,7 @@ public class MockConfiguration public void addListener( ConfigurationListener listener ) { - configListeners.add(listener); + configListeners.add( listener ); } public void removeListener( ConfigurationListener listener ) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java index 46eafd18e..0e87f8fbd 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/SnapshotTransferTest.java @@ -24,6 +24,7 @@ import org.apache.maven.archiva.policies.CachedFailuresPolicy; import org.apache.maven.archiva.policies.ChecksumPolicy; import org.apache.maven.archiva.policies.ReleasesPolicy; import org.apache.maven.archiva.policies.SnapshotsPolicy; +import org.junit.Test; import java.io.File; @@ -35,6 +36,7 @@ import java.io.File; public class SnapshotTransferTest extends AbstractProxyTestCase { + @Test public void testSnapshotNonExistant() throws Exception { @@ -55,6 +57,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testTimestampDrivenSnapshotNotPresentAlready() throws Exception { @@ -77,6 +80,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testNewerTimestampDrivenSnapshotOnFirstRepo() throws Exception { @@ -99,6 +103,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testOlderTimestampDrivenSnapshotOnFirstRepo() throws Exception { @@ -190,6 +195,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } */ + @Test public void testTimestampDrivenSnapshotNotExpired() throws Exception { @@ -213,6 +219,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testTimestampDrivenSnapshotNotUpdated() throws Exception { @@ -237,6 +244,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure() throws Exception { @@ -262,6 +270,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testMetadataDrivenSnapshotNotPresentAlready() throws Exception { @@ -284,6 +293,7 @@ public class SnapshotTransferTest assertNoTempFiles( expectedFile ); } + @Test public void testGetMetadataDrivenSnapshotRemoteUpdate() throws Exception { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonDelegate.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonDelegate.java index e59fddb4a..901567022 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonDelegate.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonDelegate.java @@ -38,11 +38,13 @@ import org.apache.maven.wagon.proxy.ProxyInfoProvider; import org.apache.maven.wagon.repository.Repository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; /** * A dummy wagon implementation * */ +@Service("wagon#test") public class WagonDelegate implements Wagon { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java index 84f028eed..0c7e9fbcb 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/WagonFactoryTest.java @@ -19,24 +19,43 @@ package org.apache.maven.archiva.proxy; * under the License. */ +import junit.framework.TestCase; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.maven.wagon.Wagon; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; /** * Test the WagonFactory works through Spring to be bound into the RepositoryProxyConnectors implementation. * */ +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} ) public class WagonFactoryTest - extends PlexusInSpringTestCase + extends TestCase { + + @Inject + WagonFactory factory; + + @Test public void testLookupSuccessiveWagons() + throws Exception { - WagonFactory factory = (WagonFactory) lookup( WagonFactory.class ); - + Wagon first = factory.getWagon( "wagon#file" ); Wagon second = factory.getWagon( "wagon#file" ); + + // ensure we support only protocol name too + Wagon third = factory.getWagon( "file" ); assertNotSame( first, second ); + + assertNotSame( first, third ); } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml index 6a9baca85..db2e53079 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/resources/META-INF/spring-context.xml @@ -8,7 +8,7 @@ ~ "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 + ~ 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 @@ -20,7 +20,12 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-3.0.xsd" + default-lazy-init="true"> <bean id="repositorySessionFactory" class="org.apache.archiva.metadata.repository.TestRepositorySessionFactory"/> </beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java index dbcffead1..5a20880c5 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java @@ -24,7 +24,6 @@ import org.codehaus.plexus.taskqueue.TaskQueueException; /** * The component that takes care of scheduling in the application. - * */ public interface ArchivaTaskScheduler<T extends Task> { @@ -35,10 +34,10 @@ public interface ArchivaTaskScheduler<T extends Task> /** * Adds the task to the scanning queue. - * + * * @param task * @throws TaskQueueException */ - public void queueTask( T task ) + void queueTask( T task ) throws TaskQueueException; } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml index 34756a585..fbc1d34e3 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml @@ -16,6 +16,24 @@ <artifactId>archiva-scheduler-api</artifactId> </dependency> <dependency> + <groupId>org.codehaus.redback.components</groupId> + <artifactId>spring-quartz</artifactId> + </dependency> + <dependency> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> + <exclusions> + <exclusion> + <groupId>c3p0</groupId> + <artifactId>c3p0</artifactId> + </exclusion> + <exclusion> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>org.apache.archiva</groupId> <artifactId>repository-statistics</artifactId> </dependency> @@ -33,10 +51,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-quartz</artifactId> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java index 5096ff2c2..481615a00 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java @@ -101,7 +101,7 @@ public class ArchivaRepositoryScanningTaskExecutor public void initialize() throws InitializationException { - log.info( "Initialized " + this.getClass().getName() ); + log.info( "Initialized {}", this.getClass().getName() ); } @SuppressWarnings( "unchecked" ) diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java index 08ed231dc..67881abfc 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java @@ -30,22 +30,22 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationEvent; import org.apache.maven.archiva.configuration.ConfigurationListener; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; -import org.codehaus.plexus.scheduler.CronExpressionValidator; -import org.codehaus.plexus.scheduler.Scheduler; -import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; +import org.codehaus.redback.components.scheduler.CronExpressionValidator; +import org.codehaus.redback.components.scheduler.Scheduler; import org.quartz.CronTrigger; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.SchedulerException; +import org.quartz.impl.JobDetailImpl; +import org.quartz.impl.triggers.CronTriggerImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Named; import java.text.ParseException; @@ -56,12 +56,12 @@ import java.util.Set; /** * Default implementation of a scheduling component for archiva. - * + * <p/> * plexus.component role="org.apache.archiva.scheduler.ArchivaTaskScheduler" role-hint="repository" */ -@Service("archivaTaskScheduler#repository") +@Service( "archivaTaskScheduler#repository" ) public class RepositoryArchivaTaskScheduler - implements ArchivaTaskScheduler<RepositoryTask>, Startable, ConfigurationListener + implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener { private Logger log = LoggerFactory.getLogger( RepositoryArchivaTaskScheduler.class ); @@ -71,10 +71,14 @@ public class RepositoryArchivaTaskScheduler @Inject private Scheduler scheduler; + @Inject + CronExpressionValidator cronValidator; + /** * plexus.requirement role-hint="repository-scanning" */ - @Inject @Named(value = "taskQueue#repository-scanning") + @Inject + @Named( value = "taskQueue#repository-scanning" ) private TaskQueue repositoryScanningQueue; /** @@ -87,12 +91,12 @@ public class RepositoryArchivaTaskScheduler * plexus.requirement */ @Inject - @Named(value = "repositoryStatisticsManager#default") + @Named( value = "repositoryStatisticsManager#default" ) private RepositoryStatisticsManager repositoryStatisticsManager; /** * TODO: could have multiple implementations - * + * <p/> * plexus.requirement */ @Inject @@ -114,24 +118,12 @@ public class RepositoryArchivaTaskScheduler private List<String> queuedRepos = new ArrayList<String>(); + @PostConstruct public void startup() throws ArchivaException { archivaConfiguration.addListener( this ); - try - { - start(); - } - catch ( StartingException e ) - { - throw new ArchivaException( e.getMessage(), e ); - } - } - - public void start() - throws StartingException - { List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); @@ -149,7 +141,7 @@ public class RepositoryArchivaTaskScheduler } catch ( SchedulerException e ) { - throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); + throw new ArchivaException( "Unable to start scheduler: " + e.getMessage(), e ); } try @@ -161,8 +153,8 @@ public class RepositoryArchivaTaskScheduler } catch ( MetadataRepositoryException e ) { - log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: " + - e.getMessage(), e ); + log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: " + + e.getMessage(), e ); } } } @@ -171,24 +163,21 @@ public class RepositoryArchivaTaskScheduler { repositorySession.close(); } + } + + @PreDestroy public void stop() - throws StoppingException + throws SchedulerException { - try + for ( String job : jobs ) { - for ( String job : jobs ) - { - scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP ); - } - jobs.clear(); - queuedRepos.clear(); - } - catch ( SchedulerException e ) - { - throw new StoppingException( "Unable to unschedule tasks", e ); + scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP ); } + jobs.clear(); + queuedRepos.clear(); + } @SuppressWarnings( "unchecked" ) @@ -252,7 +241,7 @@ public class RepositoryArchivaTaskScheduler { if ( isProcessingRepositoryTask( task ) ) { - log.debug( "Repository task '" + task + "' is already queued. Skipping task." ); + log.debug( "Repository task '{}' is already queued. Skipping task.", task ); } else { @@ -348,35 +337,32 @@ public class RepositoryArchivaTaskScheduler // get the cron string for these database scanning jobs String cronString = repoConfig.getRefreshCronExpression(); - CronExpressionValidator cronValidator = new CronExpressionValidator(); if ( !cronValidator.validate( cronString ) ) { - log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() + - "] is invalid. Defaulting to hourly." ); + log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() + + "] is invalid. Defaulting to hourly." ); cronString = CRON_HOURLY; } // setup the unprocessed artifact job - JobDetail repositoryJob = new JobDetail( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, - RepositoryTaskJob.class ); + JobDetailImpl repositoryJob = + new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, RepositoryTaskJob.class ); - JobDataMap dataMap = new JobDataMap(); - dataMap.put( TASK_QUEUE, repositoryScanningQueue ); - dataMap.put( TASK_REPOSITORY, repoConfig.getId() ); - repositoryJob.setJobDataMap( dataMap ); + repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue ); + repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() ); try { - CronTrigger trigger = new CronTrigger( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), - REPOSITORY_SCAN_GROUP, cronString ); + CronTriggerImpl trigger = + new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, cronString ); jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() ); scheduler.scheduleJob( repositoryJob, trigger ); } catch ( ParseException e ) { - log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '" + - repoConfig.getId() + "': " + e.getMessage() ); + log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '" + + repoConfig.getId() + "': " + e.getMessage() ); } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java index ab265a5ea..9417ff686 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java @@ -19,9 +19,9 @@ package org.apache.archiva.scheduler.repository; * under the License. */ -import org.codehaus.plexus.scheduler.AbstractJob; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; +import org.codehaus.redback.components.scheduler.AbstractJob; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml index 84d6cda5c..2fd029c41 100755 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml @@ -21,10 +21,12 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" + xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd" + http://www.springframework.org/schema/context/spring-context-3.0.xsd + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" default-lazy-init="true"> <context:annotation-config/> @@ -37,4 +39,8 @@ <property name="executor" ref="taskExecutor#repository-scanning"/> <property name="queue" ref="taskQueue#repository-scanning"/> </bean> + <alias name="archivaTaskScheduler#repository" alias="scheduler#repository"/> + + <task:scheduler id="scheduler" pool-size="10"/> + </beans>
\ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index d05f6eb55..849a626c9 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -241,20 +241,28 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-quartz</artifactId> + <groupId>org.codehaus.redback.components</groupId> + <artifactId>spring-taskqueue</artifactId> + </dependency> + <dependency> + <groupId>org.codehaus.redback.components</groupId> + <artifactId>spring-quartz</artifactId> + </dependency> + <dependency> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> <exclusions> <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-component-api</artifactId> + <groupId>c3p0</groupId> + <artifactId>c3p0</artifactId> + </exclusion> + <exclusion> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> </exclusion> </exclusions> </dependency> <dependency> - <groupId>org.codehaus.redback.components</groupId> - <artifactId>spring-taskqueue</artifactId> - </dependency> - <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> |