diff options
author | Brett Porter <brett@apache.org> | 2006-08-26 05:47:59 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2006-08-26 05:47:59 +0000 |
commit | 209ef5ca84ee8de9e5ee61952e0d380749c3074b (patch) | |
tree | 1f64a28aa8f3bfab1ab17cb8715fe6eb0485391e /archiva-proxy | |
parent | 72cbf8748f2f0cb7dad3b45cd5668461aa4a76b2 (diff) | |
download | archiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.tar.gz archiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.zip |
rename archiva artifacts
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-proxy')
60 files changed, 3490 insertions, 0 deletions
diff --git a/archiva-proxy/pom.xml b/archiva-proxy/pom.xml new file mode 100644 index 000000000..a4cfbcfdd --- /dev/null +++ b/archiva-proxy/pom.xml @@ -0,0 +1,52 @@ +<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>archiva-proxy</artifactId>
+ <name>Archiva Proxy</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-discoverer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-file</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-provider-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>1.2_Java1.3</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java new file mode 100644 index 000000000..90a21726a --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyRequestHandler.java @@ -0,0 +1,672 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.repository.digest.DigestUtils; +import org.apache.maven.repository.digest.DigesterException; +import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DiscovererException; +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.observers.ChecksumObserver; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * An implementation of the proxy handler. This class is not thread safe (the class itself is, but the wagons it uses + * are not) - it is declared <code>per-lookup</code> for that reason. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + * @plexus.component instantiation-strategy="per-lookup" + * @todo use wagonManager for cache use file:// as URL + * @todo this currently duplicates a lot of the wagon manager, and doesn't do things like snapshot resolution, etc. + * The checksum handling is inconsistent with that of the wagon manager. + * Should we have a more artifact based one? This will merge metadata so should behave correctly, and it is able to + * correct some limitations of the wagon manager (eg, it can retrieve newer SNAPSHOT files without metadata) + */ +public class DefaultProxyRequestHandler + extends AbstractLogEnabled + implements ProxyRequestHandler +{ + /** + * @plexus.requirement role-hint="default" + * @todo use a map, and have priorities in them + */ + private ArtifactDiscoverer defaultArtifactDiscoverer; + + /** + * @plexus.requirement role-hint="legacy" + */ + private ArtifactDiscoverer legacyArtifactDiscoverer; + + /** + * @plexus.requirement role="org.apache.maven.wagon.Wagon" + */ + private Map/*<String,Wagon>*/ wagons; + + public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException + { + return get( path, proxiedRepositories, managedRepository, null ); + } + + public File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException + { + return get( managedRepository, path, proxiedRepositories, wagonProxy, false ); + } + + public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException + { + return getAlways( path, proxiedRepositories, managedRepository, null ); + } + + public File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, + ProxyInfo wagonProxy ) + throws ResourceDoesNotExistException, ProxyException + { + return get( managedRepository, path, proxiedRepositories, wagonProxy, true ); + } + + private File get( ArtifactRepository managedRepository, String path, List proxiedRepositories, ProxyInfo wagonProxy, + boolean force ) + throws ProxyException, ResourceDoesNotExistException + { + File target = new File( managedRepository.getBasedir(), path ); + + for ( Iterator i = proxiedRepositories.iterator(); i.hasNext(); ) + { + ProxiedArtifactRepository repository = (ProxiedArtifactRepository) i.next(); + + if ( !force && repository.isCachedFailure( path ) ) + { + processCachedRepositoryFailure( repository, "Cached failure found for: " + path ); + } + else + { + get( path, target, repository, managedRepository, wagonProxy, force ); + } + } + + if ( !target.exists() ) + { + throw new ResourceDoesNotExistException( "Could not find " + path + " in any of the repositories." ); + } + + return target; + } + + private void get( String path, File target, ProxiedArtifactRepository repository, + ArtifactRepository managedRepository, ProxyInfo wagonProxy, boolean force ) + throws ProxyException + { + ArtifactRepositoryPolicy policy; + + if ( path.endsWith( ".md5" ) || path.endsWith( ".sha1" ) ) + { + // always read from the managed repository, no need to make remote request + } + else if ( path.endsWith( "maven-metadata.xml" ) ) + { + File metadataFile = new File( target.getParentFile(), ".metadata-" + repository.getRepository().getId() ); + + policy = repository.getRepository().getReleases(); + + // if it is snapshot metadata, use a different policy + if ( path.endsWith( "-SNAPSHOT/maven-metadata.xml" ) ) + { + policy = repository.getRepository().getSnapshots(); + } + + if ( force || !metadataFile.exists() || isOutOfDate( policy, metadataFile ) ) + { + getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, metadataFile, + policy, force ); + + mergeMetadataFiles( target, metadataFile ); + } + } + else + { + Artifact artifact = null; + try + { + artifact = defaultArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() ); + } + + if ( artifact == null ) + { + try + { + artifact = legacyArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() ); + } + } + + if ( artifact != null ) + { + ArtifactRepository artifactRepository = repository.getRepository(); + + // we use the release policy for tracking failures, but only check for updates on snapshots + // also, we don't look for updates on timestamp snapshot files, only non-unique-version ones + policy = artifact.isSnapshot() ? artifactRepository.getSnapshots() : artifactRepository.getReleases(); + + boolean needsUpdate = false; + if ( artifact.getVersion().endsWith( "-SNAPSHOT" ) && isOutOfDate( policy, target ) ) + { + needsUpdate = true; + } + + if ( needsUpdate || force || !target.exists() ) + { + getFileFromRepository( artifactRepository.pathOf( artifact ), repository, + managedRepository.getBasedir(), wagonProxy, target, policy, force ); + } + } + else + { + // Some other unknown file in the repository, proxy as is + if ( force || !target.exists() ) + { + policy = repository.getRepository().getReleases(); + getFileFromRepository( path, repository, managedRepository.getBasedir(), wagonProxy, target, policy, + force ); + } + } + } + + if ( target.exists() ) + { + // in case it previously failed and we've since found it + repository.clearFailure( path ); + } + } + + private void mergeMetadataFiles( File target, File metadataFile ) + throws ProxyException + { + MetadataXpp3Reader reader = new MetadataXpp3Reader(); + if ( metadataFile.exists() ) + { + Metadata metadata = null; + if ( target.exists() ) + { + FileReader fileReader = null; + try + { + fileReader = new FileReader( target ); + metadata = reader.read( fileReader ); + } + catch ( XmlPullParserException e ) + { + throw new ProxyException( "Unable to parse existing metadata: " + e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new ProxyException( "Unable to read existing metadata: " + e.getMessage(), e ); + } + finally + { + IOUtil.close( fileReader ); + } + } + + FileReader fileReader = null; + boolean changed = false; + try + { + fileReader = new FileReader( metadataFile ); + Metadata newMetadata = reader.read( fileReader ); + + if ( metadata != null ) + { + changed = metadata.merge( newMetadata ); + } + else + { + metadata = newMetadata; + changed = true; + } + } + catch ( IOException e ) + { + // ignore the merged file + getLogger().warn( "Unable to read new metadata: " + e.getMessage() ); + } + catch ( XmlPullParserException e ) + { + // ignore the merged file + getLogger().warn( "Unable to parse new metadata: " + e.getMessage() ); + } + finally + { + IOUtil.close( fileReader ); + } + + if ( changed ) + { + FileWriter fileWriter = null; + try + { + fileWriter = new FileWriter( target ); + new MetadataXpp3Writer().write( fileWriter, metadata ); + } + catch ( IOException e ) + { + getLogger().warn( "Unable to store new metadata: " + e.getMessage() ); + } + finally + { + IOUtil.close( fileWriter ); + } + } + } + } + + private void getFileFromRepository( String path, ProxiedArtifactRepository repository, String repositoryCachePath, + ProxyInfo httpProxy, File target, ArtifactRepositoryPolicy policy, + boolean force ) + throws ProxyException + { + if ( !policy.isEnabled() ) + { + getLogger().debug( "Skipping disabled repository " + repository.getName() ); + return; + } + + Map checksums = null; + Wagon wagon = null; + + File temp = new File( target.getAbsolutePath() + ".tmp" ); + temp.deleteOnExit(); + + boolean connected = false; + try + { + String protocol = repository.getRepository().getProtocol(); + wagon = (Wagon) wagons.get( protocol ); + if ( wagon == null ) + { + throw new ProxyException( "Unsupported remote protocol: " + protocol ); + } + + //@todo configure wagon (ssh settings, etc) + + checksums = prepareChecksumListeners( wagon ); + + connected = connectToRepository( wagon, repository, httpProxy ); + if ( connected ) + { + int tries = 0; + boolean success; + + do + { + tries++; + + getLogger().debug( "Trying " + path + " from " + repository.getName() + "..." ); + + boolean downloaded = true; + if ( force || !target.exists() ) + { + wagon.get( path, temp ); + } + else + { + downloaded = wagon.getIfNewer( path, temp, target.lastModified() ); + } + + if ( downloaded ) + { + success = checkChecksum( checksums, path, wagon, repositoryCachePath ); + + if ( tries > 1 && !success ) + { + processRepositoryFailure( repository, + "Checksum failures occurred while downloading " + path, path, + policy ); + return; + } + } + else + { + // getIfNewer determined we were up to date + success = true; + } + } + while ( !success ); + + // temp won't exist if we called getIfNewer and it was older, but its still a successful return + if ( temp.exists() ) + { + moveTempToTarget( temp, target ); + } + } + //try next repository + } + catch ( TransferFailedException e ) + { + processRepositoryFailure( repository, e, path, policy ); + } + catch ( AuthorizationException e ) + { + processRepositoryFailure( repository, e, path, policy ); + } + catch ( ResourceDoesNotExistException e ) + { + // hard failure setting doesn't affect "not found". + getLogger().debug( "Artifact not found in repository: " + repository.getName() + ": " + e.getMessage() ); + } + finally + { + temp.delete(); + + if ( wagon != null && checksums != null ) + { + releaseChecksumListeners( wagon, checksums ); + } + + if ( connected ) + { + disconnectWagon( wagon ); + } + } + } + + private static boolean isOutOfDate( ArtifactRepositoryPolicy policy, File target ) + { + return policy != null && policy.checkOutOfDate( new Date( target.lastModified() ) ); + } + + /** + * Used to add checksum observers as transfer listeners to the wagonManager object + * + * @param wagon the wagonManager object to use the checksum with + * @return map of ChecksumObservers added into the wagonManager transfer listeners + */ + private Map prepareChecksumListeners( Wagon wagon ) + { + Map checksums = new LinkedHashMap(); + try + { + ChecksumObserver checksum = new ChecksumObserver( "SHA-1" ); + wagon.addTransferListener( checksum ); + checksums.put( "sha1", checksum ); + + checksum = new ChecksumObserver( "MD5" ); + wagon.addTransferListener( checksum ); + checksums.put( "md5", checksum ); + } + catch ( NoSuchAlgorithmException e ) + { + getLogger().error( "An error occurred while preparing checksum observers: " + e.getMessage() ); + } + return checksums; + } + + private void releaseChecksumListeners( Wagon wagon, Map checksumMap ) + { + for ( Iterator checksums = checksumMap.values().iterator(); checksums.hasNext(); ) + { + ChecksumObserver listener = (ChecksumObserver) checksums.next(); + wagon.removeTransferListener( listener ); + } + } + + private boolean connectToRepository( Wagon wagon, ProxiedArtifactRepository repository, ProxyInfo httpProxy ) + { + boolean connected = false; + try + { + ArtifactRepository artifactRepository = repository.getRepository(); + Repository wagonRepository = new Repository( artifactRepository.getId(), artifactRepository.getUrl() ); + if ( repository.isUseNetworkProxy() && httpProxy != null ) + { + wagon.connect( wagonRepository, httpProxy ); + } + else + { + wagon.connect( wagonRepository ); + } + connected = true; + } + catch ( ConnectionException e ) + { + getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); + } + catch ( AuthenticationException e ) + { + getLogger().info( "Could not connect to " + repository.getName() + ": " + e.getMessage() ); + } + + return connected; + } + + private boolean checkChecksum( Map checksumMap, String path, Wagon wagon, String repositoryCachePath ) + throws ProxyException + { + releaseChecksumListeners( wagon, checksumMap ); + + boolean correctChecksum = false; + + boolean allNotFound = true; + + for ( Iterator i = checksumMap.keySet().iterator(); i.hasNext() && !correctChecksum; ) + { + String checksumExt = (String) i.next(); + ChecksumObserver checksum = (ChecksumObserver) checksumMap.get( checksumExt ); + String checksumPath = path + "." + checksumExt; + File checksumFile = new File( repositoryCachePath, checksumPath ); + + File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" ); + tempChecksumFile.deleteOnExit(); + + try + { + wagon.get( checksumPath, tempChecksumFile ); + + allNotFound = false; + + String remoteChecksum = DigestUtils.cleanChecksum( FileUtils.fileRead( tempChecksumFile ), + checksumExt.toUpperCase(), + path.substring( path.lastIndexOf( '/' ) ) ); + + String actualChecksum = checksum.getActualChecksum().toUpperCase(); + remoteChecksum = remoteChecksum.toUpperCase(); + + if ( remoteChecksum.equals( actualChecksum ) ) + { + moveTempToTarget( tempChecksumFile, checksumFile ); + + correctChecksum = true; + } + else + { + getLogger().warn( + "The checksum '" + actualChecksum + "' did not match the remote value: " + remoteChecksum ); + } + } + catch ( TransferFailedException e ) + { + getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().debug( "The checksum did not exist: " + checksumPath + "; " + e.getMessage() ); + // do nothing try the next checksum + // remove it if it is present locally in case there is an old incorrect one + if ( checksumFile.exists() ) + { + checksumFile.delete(); + } + } + catch ( AuthorizationException e ) + { + getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( IOException e ) + { + getLogger().warn( "An error occurred while reading the temporary checksum file: " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + catch ( DigesterException e ) + { + getLogger().warn( "The checksum was invalid: " + checksumPath + ": " + e.getMessage() ); + // do nothing try the next checksum + + allNotFound = false; + } + finally + { + tempChecksumFile.delete(); + } + } + return correctChecksum || allNotFound; + } + + /** + * 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 target The final location of the downloaded file + * @throws ProxyException when the temp file cannot replace the target file + */ + private void moveTempToTarget( File temp, File target ) + throws ProxyException + { + if ( target.exists() && !target.delete() ) + { + throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() ); + } + + if ( !temp.renameTo( target ) ) + { + getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." ); + + try + { + FileUtils.copyFile( temp, target ); + } + catch ( IOException e ) + { + throw new ProxyException( "Cannot copy tmp file to its final location", e ); + } + finally + { + temp.delete(); + } + } + } + + /** + * Used to disconnect the wagonManager from its repository + * + * @param wagon the connected wagonManager object + */ + private void disconnectWagon( Wagon wagon ) + { + try + { + wagon.disconnect(); + } + catch ( ConnectionException e ) + { + getLogger().error( "Problem disconnecting from wagonManager - ignoring: " + e.getMessage() ); + } + } + + private void processRepositoryFailure( ProxiedArtifactRepository repository, Throwable t, String path, + ArtifactRepositoryPolicy policy ) + throws ProxyException + { + repository.addFailure( path, policy ); + + String message = t.getMessage(); + if ( repository.isHardFail() ) + { + repository.addFailure( path, policy ); + throw new ProxyException( + "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message, t ); + } + + getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); + getLogger().debug( "Cause", t ); + } + + private void processRepositoryFailure( ProxiedArtifactRepository repository, String message, String path, + ArtifactRepositoryPolicy policy ) + throws ProxyException + { + repository.addFailure( path, policy ); + + processCachedRepositoryFailure( repository, message ); + } + + private void processCachedRepositoryFailure( ProxiedArtifactRepository repository, String message ) + throws ProxyException + { + if ( repository.isHardFail() ) + { + throw new ProxyException( + "An error occurred in hardfailing repository " + repository.getName() + "...\n " + message ); + } + + getLogger().warn( "Skipping repository " + repository.getName() + ": " + message ); + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java new file mode 100644 index 000000000..ff3aaa3ff --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxiedArtifactRepository.java @@ -0,0 +1,197 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; + +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +/** + * A proxied artifact repository - contains the artifact repository and additional information about + * the proxied repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class ProxiedArtifactRepository +{ + /** + * Whether to cache failures or not. + */ + private boolean cacheFailures; + + /** + * Whether failures on this repository cause the whole group to fail. + */ + private boolean hardFail; + + /** + * Whether to use the network proxy for any requests. + */ + private boolean useNetworkProxy; + + /** + * The artifact repository on the other end of the proxy. + */ + private final ArtifactRepository repository; + + /** + * Cache of failures that have already occurred, containing paths from the repository root. The value given + * specifies when the failure should expire. + */ + private Map/*<String,Long>*/ failureCache = new HashMap/*<String,Long>*/(); + + /** + * A user friendly name for the repository. + */ + private String name; + + public ProxiedArtifactRepository( ArtifactRepository repository ) + { + this.repository = repository; + } + + public boolean isHardFail() + { + return hardFail; + } + + public boolean isUseNetworkProxy() + { + return useNetworkProxy; + } + + public boolean isCacheFailures() + { + return cacheFailures; + } + + public ArtifactRepository getRepository() + { + return repository; + } + + /** + * Check if there is a previously cached failure for requesting the given path. + * + * @param path the path + * @return whether there is a failure + */ + public boolean isCachedFailure( String path ) + { + boolean failed = false; + if ( cacheFailures ) + { + Long time = (Long) failureCache.get( path ); + if ( time != null ) + { + if ( System.currentTimeMillis() < time.longValue() ) + { + failed = true; + } + else + { + clearFailure( path ); + } + } + } + return failed; + } + + /** + * Add a failure to the cache. + * + * @param path the path that failed + * @param policy the policy for when the failure should expire + */ + public void addFailure( String path, ArtifactRepositoryPolicy policy ) + { + failureCache.put( path, new Long( calculateExpiryTime( policy ) ) ); + } + + private long calculateExpiryTime( ArtifactRepositoryPolicy policy ) + { + String updatePolicy = policy.getUpdatePolicy(); + long time; + if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( updatePolicy ) ) + { + time = 0; + } + else if ( ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY.equals( updatePolicy ) ) + { + // Get midnight boundary + Calendar cal = Calendar.getInstance(); + cal.set( Calendar.HOUR_OF_DAY, 0 ); + cal.set( Calendar.MINUTE, 0 ); + cal.set( Calendar.SECOND, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + cal.add( Calendar.DAY_OF_MONTH, 1 ); + time = cal.getTime().getTime(); + } + else if ( updatePolicy.startsWith( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) + { + String s = updatePolicy.substring( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 ); + int minutes = Integer.valueOf( s ).intValue(); + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.MINUTE, minutes ); + time = cal.getTime().getTime(); + } + else + { + // else assume "never" + time = Long.MAX_VALUE; + } + return time; + } + + /** + * Remove a failure. + * + * @param path the path that had previously failed + */ + public void clearFailure( String path ) + { + failureCache.remove( path ); + } + + public String getName() + { + return name; + } + + public void setCacheFailures( boolean cacheFailures ) + { + this.cacheFailures = cacheFailures; + } + + public void setHardFail( boolean hardFail ) + { + this.hardFail = hardFail; + } + + public void setUseNetworkProxy( boolean useNetworkProxy ) + { + this.useNetworkProxy = useNetworkProxy; + } + + public void setName( String name ) + { + this.name = name; + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java new file mode 100644 index 000000000..cd6ecc323 --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyException.java @@ -0,0 +1,34 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Edwin Punzalan + */ +public class ProxyException + extends Exception +{ + public ProxyException( String message ) + { + super( message ); + } + + public ProxyException( String message, Throwable t ) + { + super( message, t ); + } +} diff --git a/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java new file mode 100644 index 000000000..4b8e3e5da --- /dev/null +++ b/archiva-proxy/src/main/java/org/apache/maven/repository/proxy/ProxyRequestHandler.java @@ -0,0 +1,101 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.proxy.ProxyInfo; + +import java.io.File; +import java.util.List; + +/** + * An individual request handler for the proxy. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public interface ProxyRequestHandler +{ + /** + * The Plexus role of the component. + */ + String ROLE = ProxyRequestHandler.class.getName(); + + /** + * Used to retrieve an artifact at a particular path, giving the cached version if it exists. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File get( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to retrieve an artifact at a particular path, giving the cached version if it exists. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @param wagonProxy a network proxy to use when transferring files if needed + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File get( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to force remote download of the requested path from any the configured repositories. This method will + * only bypass the cache for searching but the requested path will still be cached. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository ) + throws ProxyException, ResourceDoesNotExistException; + + /** + * Used to force remote download of the requested path from any the configured repositories. This method will + * only bypass the cache for searching but the requested path will still be cached. + * + * @param path the expected repository path + * @param proxiedRepositories the repositories being proxied to + * @param managedRepository the locally managed repository to cache artifacts in + * @param wagonProxy a network proxy to use when transferring files if needed + * @return File object referencing the requested path in the cache + * @throws ProxyException when an exception occurred during the retrieval of the requested path + * @throws org.apache.maven.wagon.ResourceDoesNotExistException + * when the requested object can't be found in any of the + * configured repositories + */ + File getAlways( String path, List proxiedRepositories, ArtifactRepository managedRepository, ProxyInfo wagonProxy ) + throws ProxyException, ResourceDoesNotExistException; +} diff --git a/archiva-proxy/src/site/apt/how-to.apt b/archiva-proxy/src/site/apt/how-to.apt new file mode 100644 index 000000000..14cf1ef4b --- /dev/null +++ b/archiva-proxy/src/site/apt/how-to.apt @@ -0,0 +1,73 @@ +ProxyManager
+
+ The ProxyManager is designed to be used as a simple object or bean for use by
+ a command-line application or web application.
+
+Configuration
+
+ An instance of a ProxyManager requires a configuration object that will
+ define its behavior called ProxyConfiguration. The ProxyConfiguration is a
+ plexus component and can be looked up to get an instance of it. Below is a sample
+ plexus lookup statement:
+
+----------
+ ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE );
+----------
+
+ Currently, a ProxyConfiguration lookup will return an empty instance of the
+ ProxyConfiguration which means it doesn't have any default definitions yet on
+ how the ProxyManager should behave. So the next step is to explicitly define
+ its behavior.
+
+----------
+ ProxyConfiguration config = (ProxyConfiguration) container.lookup( ProxyConfiguration.ROLE );
+
+ config.setRepositoryCachePath( "/user/proxy-cache" );
+
+ ArtifactRepositoryLayout defLayout = new DefaultRepositoryLayout();
+
+ File repo1File = new File( "src/test/remote-repo1" );
+
+ ProxyRepository repo1 = new ProxyRepository( "central", "http://www.ibiblio.org/maven2", defLayout );
+
+ config.addRepository( repo1 );
+----------
+
+ The above statements sets up the ProxyConfiguration to use the directory
+ <<</user/proxy-cache>>> as the location of the proxy's repository cache.
+ Then it creates a ProxyRepository instance with an id of <<<central>>> to
+ look for remote files in ibiblio.org.
+
+Instantiation
+
+ To create or retrieve an instance of a ProxyManager, one will need to use the
+ ProxyManagerFactory.
+
+----------
+ ProxyManagerFactory factory = (ProxyManagerFactory) container.lookup( ProxyManagerFactory.ROLE );
+ proxy = factory.getProxyManager( "default", config );
+----------
+
+ The factory requires two parameters. The first parameter is the proxy_type
+ that you will want to use. And the second parameter is the ProxyConfiguration
+ which we already did above. The proxy_type defines the client that the
+ ProxyManager is expected to service. Currently, only <<<default>>>
+ ProxyManager type is available and is defined to be for Maven 2.x clients.
+
+Usage
+
+* The get() method
+
+ The ProxyManager get( target ) method is used to retrieve a path file. This
+ method first looks into the cache if the target exists. If it does not, then
+ the ProxyManager will search all the ProxyRepositories present in its
+ ProxyConfiguration. When the target path is found, the ProxyManager creates
+ a copy of it in its cache and returns a File instance of the cached copy.
+
+* The getRemoteFile() method
+
+ The ProxyManager getRemoteFile( path ) method is used to force the
+ ProxyManager to ignore the contents of its cache and search all the
+ ProxyRepository objects for the specified path and retrieve it when
+ available. When successful, the ProxyManager creates a copy of the remote
+ file in its cache and then returns a File instance of the cached copy.
\ No newline at end of file diff --git a/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java new file mode 100644 index 000000000..3837ca91f --- /dev/null +++ b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java @@ -0,0 +1,1772 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.Snapshot; +import org.apache.maven.artifact.repository.metadata.Versioning; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.easymock.MockControl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + +/** + * Test the proxy handler. + * + * @author Brett Porter + */ +public class ProxyRequestHandlerTest + extends PlexusTestCase +{ + private ProxyRequestHandler requestHandler; + + private List proxiedRepositories; + + private List legacyProxiedRepositories; + + private ArtifactRepository defaultManagedRepository; + + private ArtifactRepository legacyManagedRepository; + + private ArtifactRepository proxiedRepository1; + + private ArtifactRepository proxiedRepository2; + + private ArtifactRepository legacyProxiedRepository; + + private ArtifactRepositoryLayout defaultLayout; + + private ArtifactRepositoryFactory factory; + + private MockControl wagonMockControl; + + private Wagon wagonMock; + + private static final ArtifactRepositoryPolicy DEFAULT_POLICY = + new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, null ); + + private static final ArtifactRepositoryPolicy ALWAYS_UPDATE_POLICY = + new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, null ); + + protected void setUp() + throws Exception + { + super.setUp(); + + requestHandler = (ProxyRequestHandler) lookup( ProxyRequestHandler.ROLE ); + + factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); + + File repoLocation = getTestFile( "target/test-repository/managed" ); + // faster only to delete this one before copying, the others are done case by case + FileUtils.deleteDirectory( new File( repoLocation, "org/apache/maven/test/get-merged-metadata" ) ); + copyDirectoryStructure( getTestFile( "src/test/repositories/managed" ), repoLocation ); + + defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); + + defaultManagedRepository = createRepository( "managed-repository", repoLocation ); + + repoLocation = getTestFile( "target/test-repository/legacy-managed" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/legacy-managed" ), repoLocation ); + + ArtifactRepositoryLayout legacyLayout = + (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); + + legacyManagedRepository = createRepository( "managed-repository", repoLocation ); + + File location = getTestFile( "src/test/repositories/proxied1" ); + proxiedRepository1 = createRepository( "proxied1", location ); + + location = getTestFile( "src/test/repositories/proxied2" ); + proxiedRepository2 = createRepository( "proxied2", location ); + + proxiedRepositories = new ArrayList( 2 ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + location = getTestFile( "src/test/repositories/legacy-proxied" ); + legacyProxiedRepository = createRepository( "legacy-proxied", location, legacyLayout ); + + legacyProxiedRepositories = Collections.singletonList( createProxiedRepository( legacyProxiedRepository ) ); + + wagonMockControl = MockControl.createNiceControl( Wagon.class ); + wagonMock = (Wagon) wagonMockControl.getMock(); + WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" ); + delegate.setDelegate( wagonMock ); + } + + public void testGetDefaultLayoutNotPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testGetDefaultLayoutAlreadyPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testGetDefaultLayoutRemoteUpdate() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetWhenInBothProxiedRepos() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetInSecondProxiedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testNotFoundInAnyProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "File returned was: " + file + "; should have got a not found exception" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected, but check file was not created + assertFalse( expectedFile.exists() ); + } + } + + public void testGetInSecondProxiedRepoFirstFails() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + wagonMockControl.verify(); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetButAllRepositoriesFail() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepository2 = createRepository( "proxied2", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + ProxiedArtifactRepository proxiedArtifactRepository2 = createProxiedRepository( proxiedRepository2 ); + proxiedRepositories.add( proxiedArtifactRepository2 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + assertTrue( "Check failure", proxiedArtifactRepository1.isCachedFailure( path ) ); + assertTrue( "Check failure", proxiedArtifactRepository2.isCachedFailure( path ) ); + + // TODO: do we really want failures to present as a not found? + // TODO: How much information on each failure should we pass back to the user vs. logging in the proxy? + } + } + + public void testGetInSecondProxiedRepoFirstHardFails() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + TransferFailedException failedException = new TransferFailedException( "transfer failed" ); + wagonMockControl.setThrowable( failedException ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ProxyException e ) + { + // expect a failure + wagonMockControl.verify(); + + assertEquals( "Check cause", failedException, e.getCause() ); + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + } + + public void testGetInSecondProxiedRepoFirstFailsFromCache() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + // fail from the cache, even though it is in the first repo now + + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetInSecondProxiedRepoFirstHardFailsFromCache() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + // fail from the cache, even though it is in the first repo now + + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createHardFailProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ProxyException e ) + { + // expect a failure + assertTrue( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + } + + public void testGetInSecondProxiedRepoFirstFailsDisabledCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ).getAbsoluteFile(); + + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedArtifactRepository.setCacheFailures( false ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + wagonMockControl.verify(); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetWhenInBothProxiedReposFirstHasExpiredCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testGetAlwaysAlreadyPresent() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysAlreadyPresentRemovedFromProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + // TODO: is this the correct behaviour, or should it be considered removed too? + } + + public void testGetAlwaysWithCachedFailure() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, DEFAULT_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetRemovesTemporaryFileOnSuccess() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File tempFile = new File( file.getParentFile(), file.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + + public void testGetRemovesTemporaryFileOnError() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + } + + public void testGetRemovesTemporaryChecksumFileOnSuccess() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File tempFile = new File( file.getParentFile(), file.getName() + ".sha1.tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + + public void testGetRemovesTemporaryChecksumFileOnError() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + + mockFailedChecksums( path, expectedFile ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + File tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + + tempFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ); + assertFalse( "Check temporary file removed", tempFile.exists() ); + } + } + + public void testGetChecksumBothCorrect() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectSha1NoMd5() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectSha1BadMd5() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "sha1" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + } + + public void testGetCorrectMd5NoSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "md5" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetCorrectMd5BadSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File checksumFile = getChecksumFile( file, "md5" ); + assertTrue( "Check file created", checksumFile.exists() ); + assertEquals( "Check checksum", "8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar", + FileUtils.fileRead( checksumFile ).trim() ); + + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetWithNoChecksums() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + assertFalse( "Check file not created", getChecksumFile( file, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( file, "sha1" ).exists() ); + } + + public void testGetBadMd5BadSha1() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expect a failure + assertFalse( "Check file not created", expectedFile.exists() ); + + assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); + } + } + + public void testGetChecksumTransferFailed() + throws ResourceDoesNotExistException, ProxyException, IOException, TransferFailedException, + AuthorizationException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + proxiedRepository1 = createRepository( "proxied1", "test://..." ); + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository1 = createProxiedRepository( proxiedRepository1 ); + proxiedRepositories.add( proxiedArtifactRepository1 ); + + wagonMock.get( path, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) ); + + mockFailedChecksums( path, expectedFile ); + + wagonMockControl.replay(); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // as expected + wagonMockControl.verify(); + + assertFalse( "Check file not created", expectedFile.exists() ); + + assertFalse( "Check file not created", getChecksumFile( expectedFile, "md5" ).exists() ); + assertFalse( "Check file not created", getChecksumFile( expectedFile, "sha1" ).exists() ); + } + } + + public void testGetAlwaysBadChecksumPresentLocallyAbsentRemote() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + + assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".sha1" ).exists() ); + assertFalse( "Check checksum removed", new File( file.getParentFile(), file.getName() + ".md5" ).exists() ); + } + + public void testGetChecksumPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysChecksumPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetChecksumNotPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetAlwaysChecksumNotPresentInManagedRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetMetadataNotPresent() + throws ProxyException, IOException + { + String path = "org/apache/maven/test/dummy-artifact/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "Found file: " + file + "; but was expecting a failure" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected + + assertFalse( expectedFile.exists() ); + } + } + + public void testGetMetadataProxied() + throws ProxyException, ResourceDoesNotExistException, IOException + { + String path = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + FileUtils.deleteDirectory( expectedFile.getParentFile() ); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + String expectedContents = getExpectedMetadata( "get-default-metadata", "1.0" ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataMergeRepos() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-merged-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = getExpectedMetadata( "get-merged-metadata", getVersioning( + Arrays.asList( new String[]{"0.9", "1.0", "2.0", "3.0", "5.0", "4.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataRemovedFromProxies() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetReleaseMetadataNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetSnapshotMetadataNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( new File( proxiedRepository1.getBasedir(), path ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetReleaseMetadataExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetSnapshotMetadataExpired() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", "1.0-SNAPSHOT", getVersioning( "20050831.111213", 2 ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetMetadataNotUpdated() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( proxiedFile.lastModified() ); + + proxiedRepository1.getReleases().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check content doesn't match proxy version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetMetadataUpdated() + throws IOException, ResourceDoesNotExistException, ProxyException, ParseException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + new File( expectedFile.getParentFile(), ".metadata-proxied1" ).setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match old version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testGetAlwaysMetadata() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-updated-metadata/maven-metadata.xml"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( new File( defaultManagedRepository.getBasedir(), path ) ); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.getAlways( path, proxiedRepositories, defaultManagedRepository ); + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + String expectedContents = + getExpectedMetadata( "get-updated-metadata", getVersioning( Arrays.asList( new String[]{"1.0", "2.0"} ) ) ); + + assertEquals( "Check content matches", expectedContents, FileUtils.fileRead( file ) ); + assertFalse( "Check content doesn't match old version", + unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testSnapshotNonExistant() + throws ProxyException, IOException + { + String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + try + { + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + fail( "File returned was: " + file + "; should have got a not found exception" ); + } + catch ( ResourceDoesNotExistException e ) + { + // expected, but check file was not created + assertFalse( expectedFile.exists() ); + } + } + + public void testTimestampDrivenSnapshotNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testNewerTimestampDrivenSnapshotOnFirstRepo() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testOlderTimestampDrivenSnapshotOnFirstRepo() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getFutureDate().getTime() ); + + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + +/* TODO: won't pass until Wagon preserves timestamp on download + public void testNewerTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File repoLocation = getTestFile( "target/test-repository/proxied1" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/proxied1" ), repoLocation ); + proxiedRepository1 = createRepository( "proxied1", repoLocation ); + + new File( proxiedRepository1.getBasedir(), path ).setLastModified( getPastDate().getTime() ); + + proxiedRepositories.clear(); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } +*/ + + public void testOlderTimestampDrivenSnapshotOnSecondRepoThanFirstNotPresentAlready() + throws ParseException, ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File repoLocation = getTestFile( "target/test-repository/proxied2" ); + FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( getTestFile( "src/test/repositories/proxied2" ), repoLocation ); + proxiedRepository2 = createRepository( "proxied2", repoLocation ); + + new File( proxiedRepository2.getBasedir(), path ).setLastModified( getPastDate().getTime() ); + + proxiedRepositories.clear(); + proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + proxiedFile = new File( proxiedRepository2.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotExpired() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + proxiedFile.setLastModified( getFutureDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + String expectedContents = FileUtils.fileRead( expectedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotUpdated() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = + "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + expectedFile.setLastModified( proxiedFile.lastModified() ); + + proxiedRepository1.getSnapshots().setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testTimestampDrivenSnapshotNotPresentAlreadyExpiredCacheFailure() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + proxiedRepositories.clear(); + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( proxiedRepository1 ); + proxiedArtifactRepository.addFailure( path, ALWAYS_UPDATE_POLICY ); + proxiedRepositories.add( proxiedArtifactRepository ); + proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) ); + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + + assertFalse( "Check failure", proxiedArtifactRepository.isCachedFailure( path ) ); + } + + public void testMetadataDrivenSnapshotNotPresentAlready() + throws ResourceDoesNotExistException, ProxyException, IOException + { + String path = + "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + } + + public void testGetMetadataDrivenSnapshotRemoteUpdate() + throws ResourceDoesNotExistException, ProxyException, IOException, ParseException + { + // Metadata driven snapshots (using a full timestamp) are treated like a release. It is the timing of the + // updates to the metadata files that triggers which will be downloaded + + String path = + "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + + assertTrue( expectedFile.exists() ); + + expectedFile.setLastModified( getPastDate().getTime() ); + + File file = requestHandler.get( path, proxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + } + + public void testLegacyManagedRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), + "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyManagedRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( proxiedRepository1.getBasedir(), + "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testLegacyProxyRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + + expectedFile.delete(); + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = + new File( legacyProxiedRepository.getBasedir(), "org.apache.maven.test/jars/get-default-layout-1.0.jar" ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyProxyRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; + File expectedFile = new File( defaultManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), + "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + public void testLegacyManagedAndProxyRepoGetNotPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + + assertFalse( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( proxiedFile ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + // TODO: timestamp preservation requires support for that in wagon +// assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() ); + } + + public void testLegacyManagedAndProxyRepoGetAlreadyPresent() + throws IOException, ResourceDoesNotExistException, ProxyException + { + String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar"; + File expectedFile = new File( legacyManagedRepository.getBasedir(), path ); + String expectedContents = FileUtils.fileRead( expectedFile ); + long originalModificationTime = expectedFile.lastModified(); + + assertTrue( expectedFile.exists() ); + + File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository ); + + assertEquals( "Check file matches", expectedFile, file ); + assertTrue( "Check file created", file.exists() ); + assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) ); + File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path ); + String unexpectedContents = FileUtils.fileRead( proxiedFile ); + assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) ); + assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() ); + assertEquals( "Check file timestamp is that of original managed file", originalModificationTime, + file.lastModified() ); + } + + private static Versioning getVersioning( List versions ) + { + Versioning versioning = new Versioning(); + for ( Iterator i = versions.iterator(); i.hasNext(); ) + { + String v = (String) i.next(); + versioning.addVersion( v ); + } + return versioning; + } + + private static String getExpectedMetadata( String artifactId, Versioning versioning ) + throws IOException + { + return getExpectedMetadata( artifactId, null, versioning ); + } + + private static String getExpectedMetadata( String artifactId, String version, Versioning versioning ) + throws IOException + { + StringWriter expectedContents = new StringWriter(); + + Metadata m = new Metadata(); + m.setGroupId( "org.apache.maven.test" ); + m.setArtifactId( artifactId ); + m.setVersion( version ); + m.setVersioning( versioning ); + m.setModelEncoding( null ); + + new MetadataXpp3Writer().write( expectedContents, m ); + return expectedContents.toString(); + } + + private static String getExpectedMetadata( String artifactId, String version ) + throws IOException + { + return getExpectedMetadata( artifactId, version, null ); + } + + private static Versioning getVersioning( String timestamp, int buildNumber ) + { + Versioning versioning = new Versioning(); + versioning.setSnapshot( new Snapshot() ); + versioning.getSnapshot().setTimestamp( timestamp ); + versioning.getSnapshot().setBuildNumber( buildNumber ); + return versioning; + } + + private static Date getPastDate() + throws ParseException + { + return new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2000-01-01" ); + } + + private static Date getFutureDate() + { + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.YEAR, 1 ); + return cal.getTime(); + } + + private void mockFailedChecksums( String path, File expectedFile ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + // must do it twice as it will re-attempt it + wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".sha1", new File( expectedFile.getParentFile(), expectedFile.getName() + ".sha1.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + + wagonMock.get( path + ".md5", new File( expectedFile.getParentFile(), expectedFile.getName() + ".md5.tmp" ) ); + wagonMockControl.setThrowable( new TransferFailedException( "transfer failed" ) ); + } + + private File getChecksumFile( File file, String algorithm ) + { + return new File( file.getParentFile(), file.getName() + "." + algorithm ); + } + + /** + * A faster recursive copy that omits .svn directories. + * + * @param sourceDirectory the source directory to copy + * @param destDirectory the target location + * @throws java.io.IOException if there is a copying problem + * @todo get back into plexus-utils, share with converter module + */ + private static void copyDirectoryStructure( File sourceDirectory, File destDirectory ) + throws IOException + { + if ( !sourceDirectory.exists() ) + { + throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); + } + + File[] files = sourceDirectory.listFiles(); + + String sourcePath = sourceDirectory.getAbsolutePath(); + + for ( int i = 0; i < files.length; i++ ) + { + File file = files[i]; + + String dest = file.getAbsolutePath(); + + dest = dest.substring( sourcePath.length() + 1 ); + + File destination = new File( destDirectory, dest ); + + if ( file.isFile() ) + { + destination = destination.getParentFile(); + + FileUtils.copyFileToDirectory( file, destination ); + } + else if ( file.isDirectory() ) + { + if ( !".svn".equals( file.getName() ) ) + { + if ( !destination.exists() && !destination.mkdirs() ) + { + throw new IOException( + "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); + } + + copyDirectoryStructure( file, destination ); + } + } + else + { + throw new IOException( "Unknown file type: " + file.getAbsolutePath() ); + } + } + } + + private static ProxiedArtifactRepository createProxiedRepository( ArtifactRepository repository ) + { + ProxiedArtifactRepository proxiedArtifactRepository = new ProxiedArtifactRepository( repository ); + proxiedArtifactRepository.setName( repository.getId() ); + proxiedArtifactRepository.setCacheFailures( true ); + return proxiedArtifactRepository; + } + + private static ProxiedArtifactRepository createHardFailProxiedRepository( ArtifactRepository repository ) + { + ProxiedArtifactRepository proxiedArtifactRepository = createProxiedRepository( repository ); + proxiedArtifactRepository.setHardFail( true ); + return proxiedArtifactRepository; + } + + private ArtifactRepository createRepository( String id, File repoLocation ) + throws MalformedURLException + { + return createRepository( id, repoLocation.toURI().toURL().toExternalForm() ); + } + + private ArtifactRepository createRepository( String id, File location, ArtifactRepositoryLayout layout ) + throws MalformedURLException + { + return createRepository( id, location.toURI().toURL().toExternalForm(), layout ); + } + + private ArtifactRepository createRepository( String id, String url ) + { + return createRepository( id, url, defaultLayout ); + } + + private ArtifactRepository createRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout ) + { + return factory.createArtifactRepository( id, url, repositoryLayout, null, null ); + } +} diff --git a/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java new file mode 100644 index 000000000..023195e4d --- /dev/null +++ b/archiva-proxy/src/test/java/org/apache/maven/repository/proxy/WagonDelegate.java @@ -0,0 +1,198 @@ +package org.apache.maven.repository.proxy; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.wagon.ConnectionException; +import org.apache.maven.wagon.ResourceDoesNotExistException; +import org.apache.maven.wagon.TransferFailedException; +import org.apache.maven.wagon.Wagon; +import org.apache.maven.wagon.authentication.AuthenticationException; +import org.apache.maven.wagon.authentication.AuthenticationInfo; +import org.apache.maven.wagon.authorization.AuthorizationException; +import org.apache.maven.wagon.events.SessionListener; +import org.apache.maven.wagon.events.TransferListener; +import org.apache.maven.wagon.proxy.ProxyInfo; +import org.apache.maven.wagon.repository.Repository; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * A dummy wagon implementation + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class WagonDelegate + implements Wagon +{ + private Wagon delegate; + + private String contentToGet; + + public void get( String resourceName, File destination ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.get( resourceName, destination ); + create( destination ); + } + + public boolean getIfNewer( String resourceName, File destination, long timestamp ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + boolean result = delegate.getIfNewer( resourceName, destination, timestamp ); + createIfMissing( destination ); + return result; + } + + public void put( File source, String destination ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.put( source, destination ); + } + + public void putDirectory( File sourceDirectory, String destinationDirectory ) + throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + { + delegate.putDirectory( sourceDirectory, destinationDirectory ); + } + + public boolean supportsDirectoryCopy() + { + return delegate.supportsDirectoryCopy(); + } + + public Repository getRepository() + { + return delegate.getRepository(); + } + + public void connect( Repository source ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source ); + } + + public void connect( Repository source, ProxyInfo proxyInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, proxyInfo ); + } + + public void connect( Repository source, AuthenticationInfo authenticationInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, authenticationInfo ); + } + + public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo ) + throws ConnectionException, AuthenticationException + { + delegate.connect( source, authenticationInfo, proxyInfo ); + } + + public void openConnection() + throws ConnectionException, AuthenticationException + { + delegate.openConnection(); + } + + public void disconnect() + throws ConnectionException + { + delegate.disconnect(); + } + + public void addSessionListener( SessionListener listener ) + { + delegate.addSessionListener( listener ); + } + + public void removeSessionListener( SessionListener listener ) + { + delegate.removeSessionListener( listener ); + } + + public boolean hasSessionListener( SessionListener listener ) + { + return delegate.hasSessionListener( listener ); + } + + public void addTransferListener( TransferListener listener ) + { + delegate.addTransferListener( listener ); + } + + public void removeTransferListener( TransferListener listener ) + { + delegate.removeTransferListener( listener ); + } + + public boolean hasTransferListener( TransferListener listener ) + { + return delegate.hasTransferListener( listener ); + } + + public boolean isInteractive() + { + return delegate.isInteractive(); + } + + public void setInteractive( boolean interactive ) + { + delegate.setInteractive( interactive ); + } + + public void setDelegate( Wagon delegate ) + { + this.delegate = delegate; + } + + void setContentToGet( String content ) + { + contentToGet = content; + } + + private void createIfMissing( File destination ) + { + // since the mock won't actually copy a file, create an empty one to simulate file existence + if ( !destination.exists() ) + { + create( destination ); + } + } + + private void create( File destination ) + { + try + { + destination.getParentFile().mkdirs(); + if ( contentToGet == null ) + { + destination.createNewFile(); + } + else + { + FileUtils.fileWrite( destination.getAbsolutePath(), contentToGet ); + } + } + catch ( IOException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + } +} diff --git a/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..bf26f6b57 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-present-1.0.jar
+(managed)
diff --git a/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar new file mode 100644 index 000000000..77dbb7858 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar @@ -0,0 +1 @@ +get-default-layout-1.0.jar diff --git a/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..9f4121a86 --- /dev/null +++ b/archiva-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-present-1.0.jar
+(proxied)
diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar new file mode 100644 index 000000000..62a1e1c71 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar @@ -0,0 +1,3 @@ +get-bad-local-checksum-1.0.jar
+(managed)
+
diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 new file mode 100644 index 000000000..de9618d2f --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 @@ -0,0 +1 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar
diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..a3b38382c --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar @@ -0,0 +1,3 @@ +get-default-layout-present-1.0.jar +(managed) + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..8404eb8a9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-merged-metadata</artifactId> + <versioning> + <versions> + <version>0.9</version> + <!-- unique --> + <version>1.0</version> + <!-- merged with proxied2 --> + <version>2.0</version> + <!-- merged with proxied1 --> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..b71eb7b74 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1,2 @@ +get-present-metadata-snapshot-1.0-20050831.101112-1.jar
+(managed)
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..0c2d93e3c --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-present-timestamped-snapshot-1.0-SNAPSHOT.jar
+(managed)
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar new file mode 100644 index 000000000..54dc5ee86 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-from-proxies/1.0/get-removed-from-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-removed-from-proxies-1.0.jar +(managed) + diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml new file mode 100644 index 000000000..7bd77c137 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-removed-metadata/1.0/maven-metadata.xml @@ -0,0 +1,19 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 new file mode 100644 index 000000000..76b43d62a --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1 @@ -0,0 +1,25 @@ +<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>get-updated-metadata</artifactId>
+ <versioning>
+ <versions>
+ <version>1.0</version>
+ </versions>
+ </versioning>
+</metadata>
diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 new file mode 100644 index 000000000..6354f21bc --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/.metadata-proxied1 @@ -0,0 +1,27 @@ +<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<metadata>
+ <groupId>org.apache.maven.test</groupId>
+ <artifactId>get-updated-metadata</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <versioning>
+ <snapshot>
+ <timestamp>20050831.1011112</timestamp>
+ <buildNumber>1</buildNumber>
+ </snapshot>
+ </versioning>
+</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..cd7216a64 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,27 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-updated-metadata</artifactId> + <version>1.0-SNAPSHOT</version> + <versioning> + <snapshot> + <timestamp>20050831.1011112</timestamp> + <buildNumber>1</buildNumber> + </snapshot> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml new file mode 100644 index 000000000..5cd8af101 --- /dev/null +++ b/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/maven-metadata.xml @@ -0,0 +1,25 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-updated-metadata</artifactId> + <versioning> + <versions> + <version>1.0</version> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar new file mode 100644 index 000000000..b5d8045c9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar @@ -0,0 +1,3 @@ +get-bad-local-checksum-1.0.jar
+(proxied 1)
+
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar new file mode 100644 index 000000000..98fae8093 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-both-bad-1.0.jar
+
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 new file mode 100644 index 000000000..5fd0ae2b7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar new file mode 100644 index 000000000..7fa9ec4a0 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar @@ -0,0 +1 @@ +get-checksum-both-right-1.0.jar
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 new file mode 100644 index 000000000..9b9e3374c --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.md5 @@ -0,0 +1 @@ +e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 new file mode 100644 index 000000000..cdd9a336b --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar.sha1 @@ -0,0 +1 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 new file mode 100644 index 000000000..8fc645ca3 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-from-managed-repo/1.0/get-checksum-from-managed-repo-1.0.jar.sha1 @@ -0,0 +1,2 @@ +066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-from-managed-repo-1.0.jar
+(proxied 1)
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar new file mode 100644 index 000000000..68e3480fc --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-md5-bad-sha1-1.0.jar
+
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 new file mode 100644 index 000000000..d785caa7f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.md5 @@ -0,0 +1 @@ +8a02aa67549d27b2a03cd4547439c6d3 *get-checksum-md5-bad-sha1-1.0.jar
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-bad-sha1/1.0/get-checksum-md5-bad-sha1-1.0.jar.sha1 @@ -0,0 +1 @@ +invalid checksum file
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar new file mode 100644 index 000000000..915323d0e --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-md5-only-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 new file mode 100644 index 000000000..f5ecac3db --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar.md5 @@ -0,0 +1 @@ +f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar new file mode 100644 index 000000000..f02c91843 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-sha1-bad-md5-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 new file mode 100644 index 000000000..a2d3f29ea --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.md5 @@ -0,0 +1 @@ +invalid checksum file
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 new file mode 100644 index 000000000..425623525 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar.sha1 @@ -0,0 +1 @@ +3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar
diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar new file mode 100644 index 000000000..efd9ed015 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar @@ -0,0 +1,2 @@ +get-checksum-sha1-only-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 new file mode 100644 index 000000000..e64dccfd8 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar.sha1 @@ -0,0 +1 @@ +748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar new file mode 100644 index 000000000..15fd36d5d --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar @@ -0,0 +1,3 @@ +get-default-layout-present-1.0.jar +(proxied 1) + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar new file mode 100644 index 000000000..a129891a7 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar @@ -0,0 +1,2 @@ +get-default-layout-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml new file mode 100644 index 000000000..7855530fb --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml @@ -0,0 +1,21 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-default-metadata</artifactId> + <version>1.0</version> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar new file mode 100644 index 000000000..3cc35fa29 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-in-both-proxies-1.0.jar +(proxied 1) + diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..f697f68a9 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-merged-metadata</artifactId> + <versioning> + <versions> + <version>2.0</version> + <!-- merge with managed --> + <version>3.0</version> + <!-- merge with proxied2 --> + <version>5.0</version> + <!-- unique --> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..139c17b97 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1 @@ +get-metadata-snapshot-1.0-SNAPSHOT.jar
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar new file mode 100644 index 000000000..8bbffa00f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar @@ -0,0 +1,2 @@ +get-present-metadata-snapshot-1.0-20050831.101112-1.jar
+(proxied 1)
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..0bf178413 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-present-timestamped-snapshot-1.0-SNAPSHOT.jar
+(proxied 1)
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..dfacfaa15 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar
+(proxied 1)
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..af86df92f --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar @@ -0,0 +1 @@ +get-timestamped-snapshot-1.0-SNAPSHOT.jar
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..67a3c6206 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,27 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-updated-metadata</artifactId> + <version>1.0-SNAPSHOT</version> + <versioning> + <snapshot> + <timestamp>20050831.111213</timestamp> + <buildNumber>2</buildNumber> + </snapshot> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml new file mode 100644 index 000000000..27c44b418 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/get-updated-metadata/maven-metadata.xml @@ -0,0 +1,26 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-updated-metadata</artifactId> + <versioning> + <versions> + <version>1.0</version> + <version>2.0</version> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar new file mode 100644 index 000000000..e46d60ac3 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar @@ -0,0 +1,3 @@ +get-in-both-proxies-1.0.jar +(proxied 2) + diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar new file mode 100644 index 000000000..3460f656d --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar @@ -0,0 +1,2 @@ +get-in-second-proxy-1.0.jar + diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml new file mode 100644 index 000000000..5a7a94818 --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-merged-metadata/maven-metadata.xml @@ -0,0 +1,30 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<metadata> + <groupId>org.apache.maven.test</groupId> + <artifactId>get-merged-metadata</artifactId> + <versioning> + <versions> + <version>1.0</version> + <!-- merged with managed --> + <version>3.0</version> + <!-- merged with proxied1 --> + <version>4.0</version> + <!-- unique --> + </versions> + </versioning> +</metadata>
\ No newline at end of file diff --git a/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar new file mode 100644 index 000000000..915b2b22c --- /dev/null +++ b/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar @@ -0,0 +1,2 @@ +get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar
+(proxied 2)
\ No newline at end of file diff --git a/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml b/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml new file mode 100644 index 000000000..a3a47dbbe --- /dev/null +++ b/archiva-proxy/src/test/resources/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.xml @@ -0,0 +1,34 @@ +<!-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<component-set> + <components> + <component> + <role>org.apache.maven.wagon.Wagon</role> + <role-hint>test</role-hint> + <implementation>org.apache.maven.repository.proxy.WagonDelegate</implementation> + </component> + <component> + <role>org.codehaus.plexus.logging.LoggerManager</role> + <implementation>org.codehaus.plexus.logging.console.ConsoleLoggerManager</implementation> + <lifecycle-handler>basic</lifecycle-handler> + + <configuration> + <threshold>ERROR</threshold> + </configuration> + </component> + </components> +</component-set> |