Next part for moving to java.nio

This commit is contained in:
Martin Stockhammer 2017-09-02 18:18:56 +02:00
parent ad9fee4399
commit 4781155596
16 changed files with 688 additions and 506 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Comparator; import java.util.Comparator;
import java.util.Optional;
/** /**
* *
@ -31,6 +32,11 @@ import java.util.Comparator;
*/ */
public class FileUtils public class FileUtils
{ {
/**
* Deletes the directory recursively and quietly.
*
* @param dir
*/
public static void deleteQuietly(Path dir) { public static void deleteQuietly(Path dir) {
try try
{ {
@ -55,4 +61,28 @@ public class FileUtils
} }
public static void deleteDirectory( Path dir ) throws IOException
{
if (!Files.isDirectory( dir )) {
throw new IOException("Given path is not a directory ");
}
boolean result = Files.walk(dir)
.sorted( Comparator.reverseOrder())
.map( file -> {
try
{
Files.delete( file );
return Optional.of(Boolean.TRUE);
}
catch ( IOException e )
{
return Optional.empty();
}
}).allMatch( Optional::isPresent );
if (!result) {
throw new IOException("Error during recursive delete of "+dir.toAbsolutePath());
}
}
} }

View File

@ -0,0 +1,113 @@
package org.apache.archiva.common.utils;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Martin Stockhammer <martin_s@apache.org>
*/
public class FileUtilsTest
{
@Test
public void testDeleteQuietly() throws IOException
{
Path tf = Files.createTempFile( "FileUtilsTest", ".txt" );
assertTrue(Files.exists(tf));
FileUtils.deleteQuietly( tf );
assertFalse(Files.exists(tf));
Path td = Files.createTempDirectory( "FileUtilsTest" );
Path f1 = td.resolve("file1.txt");
Path f2 = td.resolve("file2.txt");
Path d1 = td.resolve("dir1");
Files.createDirectory( d1 );
Path d11 = d1.resolve("dir11");
Files.createDirectory( d11 );
Path f111 = d11.resolve("file111.txt");
Path f112 = d11.resolve("file112.txt");
Files.write(f1,"file1".getBytes());
Files.write(f2, "file2".getBytes());
Files.write(f111, "file111".getBytes());
Files.write(f112, "file112".getBytes());
assertTrue(Files.exists(d1));
assertTrue(Files.exists(f1));
assertTrue(Files.exists(f2));
assertTrue(Files.exists(f111));
assertTrue(Files.exists(f112));
FileUtils.deleteQuietly( td );
assertFalse(Files.exists(f1));
assertFalse(Files.exists(f2));
assertFalse(Files.exists(f111));
assertFalse(Files.exists(f112));
assertFalse(Files.exists(d1));
}
@Test
public void testDelete() throws IOException
{
Path td = Files.createTempDirectory( "FileUtilsTest" );
Path f1 = td.resolve("file1.txt");
Path f2 = td.resolve("file2.txt");
Path d1 = td.resolve("dir1");
Files.createDirectory( d1 );
Path d11 = d1.resolve("dir11");
Files.createDirectory( d11 );
Path f111 = d11.resolve("file111.txt");
Path f112 = d11.resolve("file112.txt");
Files.write(f1,"file1".getBytes());
Files.write(f2, "file2".getBytes());
Files.write(f111, "file111".getBytes());
Files.write(f112, "file112".getBytes());
assertTrue(Files.exists(d1));
assertTrue(Files.exists(f1));
assertTrue(Files.exists(f2));
assertTrue(Files.exists(f111));
assertTrue(Files.exists(f112));
FileUtils.deleteDirectory( td );
assertFalse(Files.exists(f1));
assertFalse(Files.exists(f2));
assertFalse(Files.exists(f111));
assertFalse(Files.exists(f112));
assertFalse(Files.exists(d1));
}
@Test(expected = java.io.IOException.class)
public void testDeleteException() throws IOException
{
Path tf = Paths.get("aaserijdmcjdjhdejeidmdjdlasrjerjnbmckdkdk");
assertFalse(Files.exists(tf));
FileUtils.deleteDirectory( tf );
}
}

View File

@ -19,7 +19,8 @@ package org.apache.archiva.proxy.model;
* under the License. * under the License.
*/ */
import java.io.File;
import java.nio.file.Path;
/** /**
* A result from a proxy fetch operation. * A result from a proxy fetch operation.
@ -30,18 +31,18 @@ public class ProxyFetchResult
{ {
//The file returned //The file returned
private File file; private Path file;
//Was the local file modified by the fetch? //Was the local file modified by the fetch?
private boolean modified; private boolean modified;
public ProxyFetchResult( File file, boolean modified ) public ProxyFetchResult( Path file, boolean modified )
{ {
this.file = file; this.file = file;
this.modified = modified; this.modified = modified;
} }
public File getFile() public Path getFile()
{ {
return file; return file;
} }

View File

@ -23,7 +23,7 @@ import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import java.io.File; import java.nio.file.Path;
import java.util.List; import java.util.List;
/** /**
@ -45,7 +45,7 @@ public interface RepositoryProxyConnectors
* @return the file that was obtained, or null if no content was obtained * @return the file that was obtained, or null if no content was obtained
* @throws ProxyDownloadException if there was a problem fetching the content from the target repositories. * @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
*/ */
File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) Path fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException; throws ProxyDownloadException;
/** /**
@ -69,7 +69,7 @@ public interface RepositoryProxyConnectors
* @param path the path of the resource to fetch * @param path the path of the resource to fetch
* @return the file that was obtained, or null if no content was obtained * @return the file that was obtained, or null if no content was obtained
*/ */
File fetchFromProxies( ManagedRepositoryContent managedRepository, String path ); Path fetchFromProxies( ManagedRepositoryContent managedRepository, String path );
/** /**
* Get the List of {@link ProxyConnector} objects of the source repository. * Get the List of {@link ProxyConnector} objects of the source repository.

View File

@ -28,6 +28,7 @@ import org.apache.archiva.common.filelock.FileLockException;
import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.filelock.FileLockManager;
import org.apache.archiva.common.filelock.FileLockTimeoutException; import org.apache.archiva.common.filelock.FileLockTimeoutException;
import org.apache.archiva.common.filelock.Lock; import org.apache.archiva.common.filelock.Lock;
import org.apache.archiva.common.utils.FileUtil;
import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ConfigurationNames; import org.apache.archiva.configuration.ConfigurationNames;
@ -87,7 +88,10 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Proxy;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -302,10 +306,10 @@ public class DefaultRepositoryProxyConnectors
} }
@Override @Override
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) public Path fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
throws ProxyDownloadException throws ProxyDownloadException
{ {
File localFile = toLocalFile( repository, artifact ); Path localFile = toLocalFile( repository, artifact );
Properties requestProperties = new Properties(); Properties requestProperties = new Properties();
requestProperties.setProperty( "filetype", "artifact" ); requestProperties.setProperty( "filetype", "artifact" );
@ -334,13 +338,13 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File downloadedFile = Path downloadedFile =
transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
true ); true );
if ( fileExists( downloadedFile ) ) if ( fileExists( downloadedFile ) )
{ {
log.debug( "Successfully transferred: {}", downloadedFile.getAbsolutePath() ); log.debug( "Successfully transferred: {}", downloadedFile.toAbsolutePath() );
return downloadedFile; return downloadedFile;
} }
} }
@ -373,12 +377,12 @@ public class DefaultRepositoryProxyConnectors
} }
@Override @Override
public File fetchFromProxies( ManagedRepositoryContent repository, String path ) public Path fetchFromProxies( ManagedRepositoryContent repository, String path )
{ {
File localFile = new File( repository.getRepoRoot(), path ); Path localFile = Paths.get( repository.getRepoRoot(), path );
// no update policies for these paths // no update policies for these paths
if ( localFile.exists() ) if ( Files.exists(localFile) )
{ {
return null; return null;
} }
@ -402,13 +406,13 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
File downloadedFile = Path downloadedFile =
transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
false ); false );
if ( fileExists( downloadedFile ) ) if ( fileExists( downloadedFile ) )
{ {
log.debug( "Successfully transferred: {}", downloadedFile.getAbsolutePath() ); log.debug( "Successfully transferred: {}", downloadedFile.toAbsolutePath() );
return downloadedFile; return downloadedFile;
} }
} }
@ -449,7 +453,7 @@ public class DefaultRepositoryProxyConnectors
@Override @Override
public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath ) public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
{ {
File localFile = new File( repository.getRepoRoot(), logicalPath ); Path localFile = Paths.get( repository.getRepoRoot(), logicalPath );
Properties requestProperties = new Properties(); Properties requestProperties = new Properties();
requestProperties.setProperty( "filetype", "metadata" ); requestProperties.setProperty( "filetype", "metadata" );
@ -466,7 +470,7 @@ public class DefaultRepositoryProxyConnectors
RemoteRepositoryContent targetRepository = connector.getTargetRepository(); RemoteRepositoryContent targetRepository = connector.getTargetRepository();
File localRepoFile = toLocalRepoFile( repository, targetRepository, logicalPath ); Path localRepoFile = toLocalRepoFile( repository, targetRepository, logicalPath );
long originalMetadataTimestamp = getLastModified( localRepoFile ); long originalMetadataTimestamp = getLastModified( localRepoFile );
try try
@ -507,7 +511,7 @@ public class DefaultRepositoryProxyConnectors
metadataNeedsUpdating = true; metadataNeedsUpdating = true;
} }
if ( metadataNeedsUpdating || !localFile.exists() ) if ( metadataNeedsUpdating || !Files.exists(localFile))
{ {
try try
{ {
@ -515,7 +519,7 @@ public class DefaultRepositoryProxyConnectors
} }
catch ( RepositoryMetadataException e ) catch ( RepositoryMetadataException e )
{ {
log.warn( "Unable to update metadata {}:{}", localFile.getAbsolutePath(), e.getMessage(), e ); log.warn( "Unable to update metadata {}:{}", localFile.toAbsolutePath(), e.getMessage(), e );
} }
} }
@ -543,9 +547,9 @@ public class DefaultRepositoryProxyConnectors
* @throws NotModifiedException * @throws NotModifiedException
* @throws org.apache.archiva.admin.model.RepositoryAdminException * @throws org.apache.archiva.admin.model.RepositoryAdminException
*/ */
protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, File tmpMd5, protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5,
File tmpSha1, File tmpResource, String url, String remotePath, File resource, Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource,
File workingDirectory, ManagedRepositoryContent repository ) Path workingDirectory, ManagedRepositoryContent repository )
throws ProxyException, NotModifiedException, RepositoryAdminException throws ProxyException, NotModifiedException, RepositoryAdminException
{ {
Wagon wagon = null; Wagon wagon = null;
@ -623,26 +627,34 @@ public class DefaultRepositoryProxyConnectors
} }
private void transferArtifact( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private void transferArtifact( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File resource, File tmpDirectory, ManagedRepositoryContent repository, Path resource, Path tmpDirectory,
File destFile ) Path destFile )
throws ProxyException throws ProxyException
{ {
transferSimpleFile( wagon, remoteRepository, remotePath, repository, resource, destFile ); transferSimpleFile( wagon, remoteRepository, remotePath, repository, resource, destFile );
} }
private long getLastModified( File file ) private long getLastModified( Path file )
{ {
if ( !file.exists() || !file.isFile() ) if ( !Files.exists(file) || !Files.isRegularFile(file) )
{ {
return 0; return 0;
} }
return file.lastModified(); try
{
return Files.getLastModifiedTime(file).toMillis();
}
catch ( IOException e )
{
log.error("Could get the modified time of file {}", file.toAbsolutePath());
return 0;
}
} }
private boolean hasBeenUpdated( File file, long originalLastModified ) private boolean hasBeenUpdated( Path file, long originalLastModified )
{ {
if ( !file.exists() || !file.isFile() ) if ( !Files.exists(file) || !Files.isRegularFile(file) )
{ {
return false; return false;
} }
@ -651,11 +663,11 @@ public class DefaultRepositoryProxyConnectors
return ( currentLastModified > originalLastModified ); return ( currentLastModified > originalLastModified );
} }
private File toLocalRepoFile( ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository, private Path toLocalRepoFile( ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository,
String targetPath ) String targetPath )
{ {
String repoPath = metadataTools.getRepositorySpecificName( targetRepository, targetPath ); String repoPath = metadataTools.getRepositorySpecificName( targetRepository, targetPath );
return new File( repository.getRepoRoot(), repoPath ); return Paths.get( repository.getRepoRoot(), repoPath );
} }
/** /**
@ -670,9 +682,9 @@ public class DefaultRepositoryProxyConnectors
} }
} }
private File toLocalFile( ManagedRepositoryContent repository, ArtifactReference artifact ) private Path toLocalFile( ManagedRepositoryContent repository, ArtifactReference artifact )
{ {
return repository.toFile( artifact ).toFile(); return repository.toFile( artifact );
} }
/** /**
@ -681,19 +693,19 @@ public class DefaultRepositoryProxyConnectors
* @param file the file to test. (may be null) * @param file the file to test. (may be null)
* @return true if file exists. false if the file param is null, doesn't exist, or is not of type File. * @return true if file exists. false if the file param is null, doesn't exist, or is not of type File.
*/ */
private boolean fileExists( File file ) private boolean fileExists( Path file )
{ {
if ( file == null ) if ( file == null )
{ {
return false; return false;
} }
if ( !file.exists() ) if ( !Files.exists(file))
{ {
return false; return false;
} }
return file.isFile(); return Files.isRegularFile(file);
} }
/** /**
@ -712,8 +724,8 @@ public class DefaultRepositoryProxyConnectors
* the remote resource is not newer than the local File. * the remote resource is not newer than the local File.
* @throws ProxyException if transfer was unsuccessful. * @throws ProxyException if transfer was unsuccessful.
*/ */
private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, private Path transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File resource, Properties requestProperties, ManagedRepositoryContent repository, Path resource, Properties requestProperties,
boolean executeConsumers ) boolean executeConsumers )
throws ProxyException, NotModifiedException, RepositoryAdminException throws ProxyException, NotModifiedException, RepositoryAdminException
{ {
@ -763,10 +775,10 @@ public class DefaultRepositoryProxyConnectors
return null; return null;
} }
File workingDirectory = createWorkingDirectory( repository ); Path workingDirectory = createWorkingDirectory( repository );
File tmpResource = new File( workingDirectory, resource.getName() ); Path tmpResource = workingDirectory.resolve(resource.getFileName());
File tmpMd5 = new File( workingDirectory, resource.getName() + ".md5" ); Path tmpMd5 = workingDirectory.resolve(resource.getFileName().toString() + ".md5" );
File tmpSha1 = new File( workingDirectory, resource.getName() + ".sha1" ); Path tmpSha1 = workingDirectory.resolve( resource.getFileName().toString() + ".sha1" );
try try
{ {
@ -791,9 +803,9 @@ public class DefaultRepositoryProxyConnectors
if ( resource != null ) if ( resource != null )
{ {
synchronized ( resource.getAbsolutePath().intern() ) synchronized ( resource.toAbsolutePath().toString().intern() )
{ {
File directory = resource.getParentFile(); Path directory = resource.getParent();
moveFileIfExists( tmpMd5, directory ); moveFileIfExists( tmpMd5, directory );
moveFileIfExists( tmpSha1, directory ); moveFileIfExists( tmpSha1, directory );
moveFileIfExists( tmpResource, directory ); moveFileIfExists( tmpResource, directory );
@ -802,7 +814,7 @@ public class DefaultRepositoryProxyConnectors
} }
finally finally
{ {
FileUtils.deleteQuietly( workingDirectory ); org.apache.archiva.common.utils.FileUtils.deleteQuietly( workingDirectory );
} }
if ( executeConsumers ) if ( executeConsumers )
@ -815,11 +827,11 @@ public class DefaultRepositoryProxyConnectors
return resource; return resource;
} }
private void queueRepositoryTask( String repositoryId, File localFile ) private void queueRepositoryTask( String repositoryId, Path localFile )
{ {
RepositoryTask task = new RepositoryTask(); RepositoryTask task = new RepositoryTask();
task.setRepositoryId( repositoryId ); task.setRepositoryId( repositoryId );
task.setResourceFile( localFile ); task.setResourceFile( localFile.toFile() );
task.setUpdateRelatedArtifacts( true ); task.setUpdateRelatedArtifacts( true );
task.setScanAll( true ); task.setScanAll( true );
@ -830,7 +842,7 @@ public class DefaultRepositoryProxyConnectors
catch ( TaskQueueException e ) catch ( TaskQueueException e )
{ {
log.error( "Unable to queue repository task to execute consumers on resource file ['{}" log.error( "Unable to queue repository task to execute consumers on resource file ['{}"
+ "'].", localFile.getName() ); + "'].", localFile.getFileName() );
} }
} }
@ -840,12 +852,12 @@ public class DefaultRepositoryProxyConnectors
* @param fileToMove this could be either the main artifact, sha1 or md5 checksum file. * @param fileToMove this could be either the main artifact, sha1 or md5 checksum file.
* @param directory directory to write files to * @param directory directory to write files to
*/ */
private void moveFileIfExists( File fileToMove, File directory ) private void moveFileIfExists( Path fileToMove, Path directory )
throws ProxyException throws ProxyException
{ {
if ( fileToMove != null && fileToMove.exists() ) if ( fileToMove != null && Files.exists(fileToMove) )
{ {
File newLocation = new File( directory, fileToMove.getName() ); Path newLocation = directory.resolve(fileToMove.getFileName());
moveTempToTarget( fileToMove, newLocation ); moveTempToTarget( fileToMove, newLocation );
} }
} }
@ -865,8 +877,8 @@ public class DefaultRepositoryProxyConnectors
* @throws ProxyException if copying the downloaded file into place did not succeed. * @throws ProxyException if copying the downloaded file into place did not succeed.
*/ */
private void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File resource, File tmpDirectory, String ext, ManagedRepositoryContent repository, Path resource, Path tmpDirectory, String ext,
File destFile ) Path destFile )
throws ProxyException throws ProxyException
{ {
String url = remoteRepository.getURL().getUrl() + remotePath + ext; String url = remoteRepository.getURL().getUrl() + remotePath + ext;
@ -913,7 +925,7 @@ public class DefaultRepositoryProxyConnectors
* @throws ProxyException if there was a problem moving the downloaded file into place. * @throws ProxyException if there was a problem moving the downloaded file into place.
*/ */
private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
ManagedRepositoryContent repository, File origFile, File destFile ) ManagedRepositoryContent repository, Path origFile, Path destFile )
throws ProxyException throws ProxyException
{ {
assert ( remotePath != null ); assert ( remotePath != null );
@ -923,10 +935,10 @@ public class DefaultRepositoryProxyConnectors
{ {
boolean success = false; boolean success = false;
if ( !origFile.exists() ) if ( !Files.exists(origFile))
{ {
log.debug( "Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName() ); log.debug( "Retrieving {} from {}", remotePath, remoteRepository.getRepository().getName() );
wagon.get( addParameters( remotePath, remoteRepository.getRepository() ), destFile ); wagon.get( addParameters( remotePath, remoteRepository.getRepository() ), destFile.toFile() );
success = true; success = true;
// You wouldn't get here on failure, a WagonException would have been thrown. // You wouldn't get here on failure, a WagonException would have been thrown.
@ -935,15 +947,22 @@ public class DefaultRepositoryProxyConnectors
else else
{ {
log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() ); log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() );
success = wagon.getIfNewer( addParameters( remotePath, remoteRepository.getRepository() ), destFile, try
origFile.lastModified() ); {
success = wagon.getIfNewer( addParameters( remotePath, remoteRepository.getRepository() ), destFile.toFile(),
Files.getLastModifiedTime(origFile).toMillis());
}
catch ( IOException e )
{
throw new ProxyException( "Failed to the modification time of "+origFile.toAbsolutePath() );
}
if ( !success ) if ( !success )
{ {
throw new NotModifiedException( throw new NotModifiedException(
"Not downloaded, as local file is newer than remote side: " + origFile.getAbsolutePath() ); "Not downloaded, as local file is newer than remote side: " + origFile.toAbsolutePath() );
} }
if ( destFile.exists() ) if ( Files.exists(destFile))
{ {
log.debug( "Downloaded successfully." ); log.debug( "Downloaded successfully." );
} }
@ -981,7 +1000,7 @@ public class DefaultRepositoryProxyConnectors
* @throws PolicyViolationException * @throws PolicyViolationException
*/ */
private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings, private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
Properties request, File localFile ) Properties request, Path localFile )
throws PolicyViolationException throws PolicyViolationException
{ {
for ( Entry<String, ? extends DownloadPolicy> entry : policies.entrySet() ) for ( Entry<String, ? extends DownloadPolicy> entry : policies.entrySet() )
@ -997,7 +1016,7 @@ public class DefaultRepositoryProxyConnectors
log.debug( "Applying [{}] policy with [{}]", key, setting ); log.debug( "Applying [{}] policy with [{}]", key, setting );
try try
{ {
policy.applyPolicy( setting, request, localFile ); policy.applyPolicy( setting, request, localFile.toFile() );
} }
catch ( PolicyConfigurationException e ) catch ( PolicyConfigurationException e )
{ {
@ -1008,7 +1027,7 @@ public class DefaultRepositoryProxyConnectors
private void validatePolicies( Map<String, DownloadErrorPolicy> policies, Map<String, String> settings, private void validatePolicies( Map<String, DownloadErrorPolicy> policies, Map<String, String> settings,
Properties request, ArtifactReference artifact, RemoteRepositoryContent content, Properties request, ArtifactReference artifact, RemoteRepositoryContent content,
File localFile, Exception exception, Map<String, Exception> previousExceptions ) Path localFile, Exception exception, Map<String, Exception> previousExceptions )
throws ProxyDownloadException throws ProxyDownloadException
{ {
boolean process = true; boolean process = true;
@ -1026,7 +1045,7 @@ public class DefaultRepositoryProxyConnectors
try try
{ {
// all policies must approve the exception, any can cancel // all policies must approve the exception, any can cancel
process = policy.applyPolicy( setting, request, localFile, exception, previousExceptions ); process = policy.applyPolicy( setting, request, localFile.toFile(), exception, previousExceptions );
if ( !process ) if ( !process )
{ {
break; break;
@ -1066,11 +1085,11 @@ public class DefaultRepositoryProxyConnectors
* @param repository * @param repository
* @return file location of working directory * @return file location of working directory
*/ */
private File createWorkingDirectory( ManagedRepositoryContent repository ) private Path createWorkingDirectory( ManagedRepositoryContent repository )
{ {
try try
{ {
return Files.createTempDirectory( "temp" ).toFile(); return Files.createTempDirectory( "temp" );
} }
catch ( IOException e ) catch ( IOException e )
{ {
@ -1087,47 +1106,52 @@ public class DefaultRepositoryProxyConnectors
* @param target The final location of the downloaded file * @param target The final location of the downloaded file
* @throws ProxyException when the temp file cannot replace the target file * @throws ProxyException when the temp file cannot replace the target file
*/ */
private void moveTempToTarget( File temp, File target ) private void moveTempToTarget( Path temp, Path target )
throws ProxyException throws ProxyException
{ {
Lock lock; Lock lock;
try try
{ {
lock = fileLockManager.writeFileLock( target ); lock = fileLockManager.writeFileLock( target.toFile() );
if ( lock.getFile().exists() && !lock.getFile().delete() ) if ( lock.getFile().exists() && !lock.getFile().delete() )
{ {
throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() ); throw new ProxyException( "Unable to overwrite existing target file: " + target.toAbsolutePath() );
} }
lock.getFile().getParentFile().mkdirs(); lock.getFile().getParentFile().mkdirs();
if ( !temp.renameTo( lock.getFile() ) ) try
{
Files.move(temp, lock.getFile().toPath() );
}
catch ( IOException e )
{ {
log.warn( "Unable to rename tmp file to its final name... resorting to copy command." ); log.warn( "Unable to rename tmp file to its final name... resorting to copy command." );
try try
{ {
FileUtils.copyFile( temp, lock.getFile() ); Files.copy( temp, lock.getFile().toPath() );
} }
catch ( IOException e ) catch ( IOException e2 )
{ {
if ( lock.getFile().exists() ) if ( lock.getFile().exists() )
{ {
log.debug( "Tried to copy file {} to {} but file with this name already exists.", log.debug( "Tried to copy file {} to {} but file with this name already exists.",
temp.getName(), lock.getFile().getAbsolutePath() ); temp.getFileName(), lock.getFile().getAbsolutePath() );
} }
else else
{ {
throw new ProxyException( throw new ProxyException(
"Cannot copy tmp file " + temp.getAbsolutePath() + " to its final location", e ); "Cannot copy tmp file " + temp.toAbsolutePath() + " to its final location", e2 );
} }
} }
finally finally
{ {
FileUtils.deleteQuietly( temp ); org.apache.archiva.common.utils.FileUtils.deleteQuietly( temp );
} }
} }
} }
catch ( FileLockException | FileLockTimeoutException e ) catch ( FileLockException | FileLockTimeoutException e )
{ {

View File

@ -57,6 +57,10 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -64,6 +68,7 @@ import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -108,7 +113,7 @@ public abstract class AbstractProxyTestCase
protected ManagedRepositoryContent managedDefaultRepository; protected ManagedRepositoryContent managedDefaultRepository;
protected File managedDefaultDir; protected Path managedDefaultDir;
protected MockConfiguration config; protected MockConfiguration config;
@ -140,7 +145,7 @@ public abstract class AbstractProxyTestCase
managedDefaultRepository = managedDefaultRepository =
createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" ); createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" );
managedDefaultDir = new File( managedDefaultRepository.getRepoRoot() ); managedDefaultDir = Paths.get( managedDefaultRepository.getRepoRoot() );
ManagedRepository repoConfig = managedDefaultRepository.getRepository(); ManagedRepository repoConfig = managedDefaultRepository.getRepository();
@ -205,127 +210,72 @@ public abstract class AbstractProxyTestCase
} }
} }
/*
protected static final ArgumentsMatcher customWagonGetIfNewerMatcher = new ArgumentsMatcher()
{
public boolean matches( Object[] expected, Object[] actual ) protected void assertChecksums( Path expectedFile, String expectedSha1Contents, String expectedMd5Contents )
{
if ( expected.length < 1 || actual.length < 1 )
{
return false;
}
return MockControl.ARRAY_MATCHER.matches( ArrayUtils.remove( expected, 1 ),
ArrayUtils.remove( actual, 1 ) );
}
public String toString( Object[] arguments )
{
return ArrayUtils.toString( arguments );
}
};
protected static final ArgumentsMatcher customWagonGetMatcher = new ArgumentsMatcher()
{
public boolean matches( Object[] expected, Object[] actual )
{
if ( expected.length == 2 && actual.length == 2 )
{
if ( expected[0] == null && actual[0] == null )
{
return true;
}
if ( expected[0] == null )
{
return actual[0] == null;
}
if ( actual[0] == null )
{
return expected[0] == null;
}
return expected[0].equals( actual[0] );
}
return false;
}
public String toString( Object[] arguments )
{
return ArrayUtils.toString( arguments );
}
};
*/
protected void assertChecksums( File expectedFile, String expectedSha1Contents, String expectedMd5Contents )
throws Exception throws Exception
{ {
File sha1File = new File( expectedFile.getAbsolutePath() + ".sha1" ); Path sha1File = expectedFile.toAbsolutePath().resolveSibling( expectedFile.getFileName().toString()+ ".sha1" );
File md5File = new File( expectedFile.getAbsolutePath() + ".md5" ); Path md5File = expectedFile.toAbsolutePath().resolveSibling( expectedFile.getFileName().toString() + ".md5" );
if ( expectedSha1Contents == null ) if ( expectedSha1Contents == null )
{ {
assertFalse( "SHA1 File should NOT exist: " + sha1File.getPath(), sha1File.exists() ); assertFalse( "SHA1 File should NOT exist: " + sha1File.toAbsolutePath(), Files.exists(sha1File) );
} }
else else
{ {
assertTrue( "SHA1 File should exist: " + sha1File.getPath(), sha1File.exists() ); assertTrue( "SHA1 File should exist: " + sha1File.toAbsolutePath(), Files.exists(sha1File) );
String actualSha1Contents = readChecksumFile( sha1File ); String actualSha1Contents = readChecksumFile( sha1File );
assertEquals( "SHA1 File contents: " + sha1File.getPath(), expectedSha1Contents, actualSha1Contents ); assertEquals( "SHA1 File contents: " + sha1File.toAbsolutePath(), expectedSha1Contents, actualSha1Contents );
} }
if ( expectedMd5Contents == null ) if ( expectedMd5Contents == null )
{ {
assertFalse( "MD5 File should NOT exist: " + md5File.getPath(), md5File.exists() ); assertFalse( "MD5 File should NOT exist: " + md5File.toAbsolutePath(), Files.exists(md5File) );
} }
else else
{ {
assertTrue( "MD5 File should exist: " + md5File.getPath(), md5File.exists() ); assertTrue( "MD5 File should exist: " + md5File.toAbsolutePath(), Files.exists(md5File) );
String actualMd5Contents = readChecksumFile( md5File ); String actualMd5Contents = readChecksumFile( md5File );
assertEquals( "MD5 File contents: " + md5File.getPath(), expectedMd5Contents, actualMd5Contents ); assertEquals( "MD5 File contents: " + md5File.toAbsolutePath(), expectedMd5Contents, actualMd5Contents );
} }
} }
protected void assertFileEquals( File expectedFile, File actualFile, File sourceFile ) protected void assertFileEquals( Path expectedFile, Path actualFile, Path sourceFile )
throws Exception throws Exception
{ {
assertNotNull( "Expected File should not be null.", expectedFile ); assertNotNull( "Expected File should not be null.", expectedFile );
assertNotNull( "Actual File should not be null.", actualFile ); assertNotNull( "Actual File should not be null.", actualFile );
assertTrue( "Check actual file exists.", actualFile.exists() ); assertTrue( "Check actual file exists.", Files.exists(actualFile) );
assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), assertTrue( "Check file is the same.", Files.isSameFile( expectedFile,
actualFile.getCanonicalPath() ); actualFile));
assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() );
String expectedContents = String expectedContents =
org.apache.commons.io.FileUtils.readFileToString( sourceFile, Charset.defaultCharset() ); org.apache.commons.io.FileUtils.readFileToString( sourceFile.toFile(), Charset.defaultCharset() );
String actualContents = String actualContents =
org.apache.commons.io.FileUtils.readFileToString( actualFile, Charset.defaultCharset() ); org.apache.commons.io.FileUtils.readFileToString( actualFile.toFile(), Charset.defaultCharset() );
assertEquals( "Check file contents.", expectedContents, actualContents ); assertEquals( "Check file contents.", expectedContents, actualContents );
} }
protected void assertNotDownloaded( File downloadedFile ) protected void assertNotDownloaded( Path downloadedFile )
{ {
assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile ); assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile );
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
protected void assertNoTempFiles( File expectedFile ) protected void assertNoTempFiles( Path expectedFile )
{ {
File workingDir = expectedFile.getParentFile(); Path workingDir = expectedFile.getParent();
if ( ( workingDir == null ) || !workingDir.isDirectory() ) if ( ( workingDir == null ) || !Files.isDirectory( workingDir) )
{ {
return; return;
} }
Collection<File> tmpFiles = Collection<File> tmpFiles =
org.apache.commons.io.FileUtils.listFiles( workingDir, new String[]{ "tmp" }, false ); org.apache.commons.io.FileUtils.listFiles( workingDir.toFile(), new String[]{ "tmp" }, false );
if ( !tmpFiles.isEmpty() ) if ( !tmpFiles.isEmpty() )
{ {
StringBuilder emsg = new StringBuilder(); StringBuilder emsg = new StringBuilder();
emsg.append( "Found Temp Files in dir: " ).append( workingDir.getPath() ); emsg.append( "Found Temp Files in dir: " ).append( workingDir.toString() );
for ( File tfile : tmpFiles ) for ( File tfile : tmpFiles )
{ {
emsg.append( "\n " ).append( tfile.getName() ); emsg.append( "\n " ).append( tfile.getName() );
@ -342,17 +292,17 @@ public abstract class AbstractProxyTestCase
* @throws java.io.IOException if there is a copying problem * @throws java.io.IOException if there is a copying problem
* @todo get back into plexus-utils, share with converter module * @todo get back into plexus-utils, share with converter module
*/ */
protected void copyDirectoryStructure( File sourceDirectory, File destDirectory ) protected void copyDirectoryStructure( Path sourceDirectory, Path destDirectory )
throws IOException throws IOException
{ {
if ( !sourceDirectory.exists() ) if ( !Files.exists(sourceDirectory) )
{ {
throw new IOException( "Source directory doesn't exists (" + sourceDirectory.getAbsolutePath() + ")." ); throw new IOException( "Source directory doesn't exists (" + sourceDirectory.toAbsolutePath() + ")." );
} }
File[] files = sourceDirectory.listFiles(); File[] files = sourceDirectory.toFile().listFiles();
String sourcePath = sourceDirectory.getAbsolutePath(); String sourcePath = sourceDirectory.toAbsolutePath().toString();
for ( int i = 0; i < files.length; i++ ) for ( int i = 0; i < files.length; i++ )
{ {
@ -362,7 +312,7 @@ public abstract class AbstractProxyTestCase
dest = dest.substring( sourcePath.length() + 1 ); dest = dest.substring( sourcePath.length() + 1 );
File destination = new File( destDirectory, dest ); File destination = new File( destDirectory.toFile(), dest );
if ( file.isFile() ) if ( file.isFile() )
{ {
@ -382,7 +332,7 @@ public abstract class AbstractProxyTestCase
"Could not create destination directory '" + destination.getAbsolutePath() + "'." ); "Could not create destination directory '" + destination.getAbsolutePath() + "'." );
} }
copyDirectoryStructure( file, destination ); copyDirectoryStructure( file.toPath(), destination.toPath() );
} }
} }
else else
@ -411,7 +361,7 @@ public abstract class AbstractProxyTestCase
/** /**
* Read the first line from the checksum file, and return it (trimmed). * Read the first line from the checksum file, and return it (trimmed).
*/ */
protected String readChecksumFile( File checksumFile ) protected String readChecksumFile( Path checksumFile )
throws Exception throws Exception
{ {
FileReader freader = null; FileReader freader = null;
@ -419,7 +369,7 @@ public abstract class AbstractProxyTestCase
try try
{ {
freader = new FileReader( checksumFile ); freader = new FileReader( checksumFile.toFile() );
buf = new BufferedReader( freader ); buf = new BufferedReader( freader );
return buf.readLine(); return buf.readLine();
} }
@ -530,12 +480,12 @@ public abstract class AbstractProxyTestCase
config.triggerChange( prefix + ".layout", repoConfig.getLayout() ); config.triggerChange( prefix + ".layout", repoConfig.getLayout() );
} }
protected File saveTargetedRepositoryConfig( String id, String originalPath, String targetPath, String layout ) protected Path saveTargetedRepositoryConfig( String id, String originalPath, String targetPath, String layout )
throws IOException throws IOException
{ {
File repoLocation = new File( targetPath ); Path repoLocation = Paths.get( targetPath );
FileUtils.deleteDirectory( repoLocation ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoLocation );
copyDirectoryStructure( new File( originalPath ), repoLocation ); copyDirectoryStructure( Paths.get(originalPath) , repoLocation );
saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout );
@ -561,23 +511,23 @@ public abstract class AbstractProxyTestCase
resourceDir = resourcePath.substring( 0, idx ); resourceDir = resourcePath.substring( 0, idx );
} }
File sourceRepoDir = new File( REPOPATH_DEFAULT_MANAGED ); Path sourceRepoDir = Paths.get( REPOPATH_DEFAULT_MANAGED );
File sourceDir = new File( sourceRepoDir, resourceDir ); Path sourceDir = sourceRepoDir.resolve(resourceDir );
File destRepoDir = managedDefaultDir; Path destRepoDir = managedDefaultDir;
File destDir = new File( destRepoDir, resourceDir ); Path destDir = destRepoDir.resolve(resourceDir );
// Cleanout destination dirs. // Cleanout destination dirs.
if ( destDir.exists() ) if ( Files.exists(destDir))
{ {
FileUtils.deleteDirectory( destDir ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( destDir );
} }
// Make the destination dir. // Make the destination dir.
destDir.mkdirs(); Files.createDirectories(destDir);
// Test the source dir. // Test the source dir.
if ( !sourceDir.exists() ) if ( !Files.exists(sourceDir) )
{ {
// This is just a warning. // This is just a warning.
log.error( "[WARN] Skipping setup of testable managed repository, source dir does not exist: {}", // log.error( "[WARN] Skipping setup of testable managed repository, source dir does not exist: {}", //
@ -587,7 +537,7 @@ public abstract class AbstractProxyTestCase
{ {
// Test that the source is a dir. // Test that the source is a dir.
if ( !sourceDir.isDirectory() ) if ( !Files.isDirectory( sourceDir) )
{ {
fail( "Unable to setup testable managed repository, source is not a directory: " + sourceDir ); fail( "Unable to setup testable managed repository, source is not a directory: " + sourceDir );
} }
@ -597,55 +547,91 @@ public abstract class AbstractProxyTestCase
} }
} }
protected void setManagedNewerThanRemote( File managedFile, File remoteFile ) protected void setManagedNewerThanRemote( Path managedFile, Path remoteFile )
{ {
setManagedNewerThanRemote( managedFile, remoteFile, 55000 ); setManagedNewerThanRemote( managedFile, remoteFile, 55000 );
} }
protected void setManagedNewerThanRemote( File managedFile, File remoteFile, long time ) protected void setManagedNewerThanRemote( Path managedFile, Path remoteFile, long time )
{ {
assertTrue( "Managed File should exist: ", managedFile.exists() ); assertTrue( "Managed File should exist: ", Files.exists(managedFile) );
assertTrue( "Remote File should exist: ", remoteFile.exists() ); assertTrue( "Remote File should exist: ", Files.exists(remoteFile) );
managedFile.setLastModified( remoteFile.lastModified() + time ); try
{
Files.setLastModifiedTime( managedFile,
FileTime.from(Files.getLastModifiedTime( remoteFile ).toMillis() + time, TimeUnit.MILLISECONDS ));
}
catch ( IOException e )
{
e.printStackTrace( );
}
assertTrue( managedFile.lastModified() > remoteFile.lastModified() ); try
{
assertTrue( Files.getLastModifiedTime( managedFile).compareTo( Files.getLastModifiedTime( remoteFile )) > 0);
}
catch ( IOException e )
{
e.printStackTrace( );
}
} }
protected void setManagedOlderThanRemote( File managedFile, File remoteFile ) protected void setManagedOlderThanRemote( Path managedFile, Path remoteFile )
{ {
setManagedOlderThanRemote( managedFile, remoteFile, 55000 ); setManagedOlderThanRemote( managedFile, remoteFile, 55000 );
} }
protected void setManagedOlderThanRemote( File managedFile, File remoteFile, long time ) protected void setManagedOlderThanRemote( Path managedFile, Path remoteFile, long time )
{ {
assertTrue( "Managed File should exist: ", managedFile.exists() ); assertTrue( "Managed File should exist: ", Files.exists(managedFile) );
assertTrue( "Remote File should exist: ", remoteFile.exists() ); assertTrue( "Remote File should exist: ", Files.exists(remoteFile) );
managedFile.setLastModified( remoteFile.lastModified() - time ); try
{
Files.setLastModifiedTime( managedFile,
FileTime.from(Files.getLastModifiedTime( remoteFile ).toMillis() - time, TimeUnit.MILLISECONDS ));
}
catch ( IOException e )
{
e.printStackTrace( );
}
assertTrue( managedFile.lastModified() < remoteFile.lastModified() ); try
{
assertTrue( Files.getLastModifiedTime( managedFile ).compareTo(Files.getLastModifiedTime( remoteFile )) < 0 );
}
catch ( IOException e )
{
e.printStackTrace( );
}
} }
protected void assertNotModified( File file, long expectedModificationTime ) protected void assertNotModified( Path file, long expectedModificationTime )
{ {
assertEquals( "File <" + file.getAbsolutePath() + "> not have been modified.", expectedModificationTime, try
file.lastModified() ); {
assertEquals( "File <" + file.toAbsolutePath() + "> not have been modified.", expectedModificationTime,
Files.getLastModifiedTime( file ).toMillis());
}
catch ( IOException e )
{
e.printStackTrace( );
}
} }
protected void assertNotExistsInManagedDefaultRepo( File file ) protected void assertNotExistsInManagedDefaultRepo( Path testFile )
throws Exception throws Exception
{ {
String managedDefaultPath = managedDefaultDir.getCanonicalPath(); Path managedDefaultPath = managedDefaultDir;
String testFile = file.getCanonicalPath();
assertTrue( "Unit Test Failure: File <" + testFile assertTrue( "Unit Test Failure: File <" + testFile
+ "> should be have been defined within the managed default path of <" + managedDefaultPath + "> should be have been defined within the managed default path of <" + managedDefaultPath
+ ">", testFile.startsWith( managedDefaultPath ) ); + ">", testFile.startsWith( managedDefaultPath ) );
assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() ); assertFalse( "File < " + testFile + "> should not exist in managed default repository.", Files.exists(testFile) );
} }
protected static Date getFutureDate() protected static Date getFutureDate()

View File

@ -31,6 +31,9 @@ import org.easymock.EasyMock;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.inject.Inject; import javax.inject.Inject;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -55,7 +58,7 @@ public class CacheFailuresTransferTest
throws Exception throws Exception
{ {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path ); Path expectedFile = managedDefaultDir.resolve( path );
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -79,7 +82,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay(); wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify(); wagonMockControl.verify();
@ -89,7 +92,7 @@ public class CacheFailuresTransferTest
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify(); wagonMockControl.verify();
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile);
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -98,7 +101,7 @@ public class CacheFailuresTransferTest
throws Exception throws Exception
{ {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path ); Path expectedFile = managedDefaultDir.resolve( path );
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -120,7 +123,7 @@ public class CacheFailuresTransferTest
wagonMockControl.replay(); wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify(); wagonMockControl.verify();
@ -146,11 +149,11 @@ public class CacheFailuresTransferTest
{ {
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
expectedFile.delete(); Files.deleteIfExists(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path ); String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path );
@ -164,10 +167,10 @@ public class CacheFailuresTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Validate that file actually came from proxied2 (as intended). // Validate that file actually came from proxied2 (as intended).
File proxied2File = new File( REPOPATH_PROXIED2, path ); Path proxied2File = Paths.get( REPOPATH_PROXIED2, path );
assertFileEquals( expectedFile, downloadedFile, proxied2File ); assertFileEquals( expectedFile, downloadedFile, proxied2File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }

View File

@ -19,7 +19,7 @@ package org.apache.archiva.proxy;
* under the License. * under the License.
*/ */
import org.apache.commons.io.FileUtils; import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.CachedFailuresPolicy; import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ChecksumPolicy;
@ -30,6 +30,11 @@ import org.easymock.EasyMock;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -49,17 +54,17 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( downloadedFile ); assertNull( downloadedFile );
} }
@ -71,19 +76,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar"; String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar", assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
@ -97,19 +102,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
@ -123,19 +128,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" ); assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
@ -148,19 +153,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, null ); assertChecksums( expectedFile, null, null );
@ -173,19 +178,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" ); assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
@ -198,17 +203,17 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null ); assertChecksums( expectedFile, null, null );
@ -221,19 +226,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar"; String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar", assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56 get-checksum-both-bad-1.0.jar",
@ -247,17 +252,17 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null ); assertChecksums( expectedFile, null, null );
@ -270,20 +275,20 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// This is a success situation. No SHA1 with a Good MD5. // This is a success situation. No SHA1 with a Good MD5.
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" ); assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
@ -296,17 +301,17 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertChecksums( expectedFile, null, null ); assertChecksums( expectedFile, null, null );
@ -319,19 +324,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
@ -345,19 +350,20 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar"; String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar", assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
@ -371,19 +377,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar"; String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar", assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb get-checksum-md5-only-1.0.jar",
@ -397,19 +403,19 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar", assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486 get-default-layout-1.0.jar",
@ -423,12 +429,12 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar"; String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
FileUtils.deleteDirectory( expectedFile.getParentFile() ); FileUtils.deleteDirectory( expectedFile.getParent() );
assertFalse( expectedFile.getParentFile().exists() ); assertFalse( Files.exists(expectedFile.getParent()) );
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
@ -447,18 +453,19 @@ public class ChecksumTransferTest
wagonMockControl.replay(); wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify(); wagonMockControl.verify();
// Do what the mock doesn't do. // Do what the mock doesn't do.
String proxyPath = new File( REPOPATH_PROXIED1, path ).getAbsolutePath(); Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath();
String localPath = new File( managedDefaultDir, path ).getAbsolutePath(); Path localPath = managedDefaultDir.resolve( path ).toAbsolutePath();
FileUtils.copyFile( new File( proxyPath ), new File( localPath ) ); Files.copy( proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING);
FileUtils.copyFile( new File( proxyPath + ".sha1" ), new File( localPath + ".sha1" ) ); Files.copy( proxyPath.resolveSibling( proxyPath.getFileName() + ".sha1" ),
localPath.resolveSibling( localPath.getFileName() + ".sha1" ), StandardCopyOption.REPLACE_EXISTING );
// Test results. // Test results.
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar", assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
@ -472,8 +479,8 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
setManagedOlderThanRemote( expectedFile, remoteFile ); setManagedOlderThanRemote( expectedFile, remoteFile );
@ -483,9 +490,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get( REPOPATH_PROXIED1, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
// There are no hashcodes on the proxy side to download, hence the local ones should remain invalid. // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
@ -499,8 +506,8 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve( path );
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get( REPOPATH_PROXIED1, path );
setManagedOlderThanRemote( expectedFile, remoteFile ); setManagedOlderThanRemote( expectedFile, remoteFile );
@ -510,7 +517,7 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
@ -527,8 +534,8 @@ public class ChecksumTransferTest
String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar"; String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedOlderThanRemote( expectedFile, remoteFile ); setManagedOlderThanRemote( expectedFile, remoteFile );
@ -538,9 +545,9 @@ public class ChecksumTransferTest
saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar", assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar",

View File

@ -33,7 +33,12 @@ import org.apache.maven.wagon.authorization.AuthorizationException;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -64,7 +69,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
@ -79,7 +84,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP ); createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
@ -96,7 +101,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
@ -110,7 +115,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
@ -126,7 +131,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
@ -142,7 +147,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
@ -156,7 +161,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
@ -174,7 +179,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
@ -192,7 +197,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
@ -210,7 +215,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
@ -226,7 +231,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
@ -242,7 +247,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
@ -256,7 +261,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
@ -274,7 +279,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
@ -292,7 +297,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE ); createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
@ -310,7 +315,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -327,7 +332,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -344,7 +349,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -362,7 +367,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -380,7 +385,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -398,7 +403,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
@ -409,7 +414,7 @@ public class ErrorHandlingTest
simulateGetIfNewerError( path, expectedFile, createTransferException() ); simulateGetIfNewerError( path, expectedFile, createTransferException() );
confirmNotDownloadedNoError( path ); confirmNotDownloadedNoError( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
} }
@Test @Test
@ -417,7 +422,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -434,7 +439,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -444,7 +449,7 @@ public class ErrorHandlingTest
simulateGetIfNewerError( path, expectedFile, createTransferException() ); simulateGetIfNewerError( path, expectedFile, createTransferException() );
confirmNotDownloadedNoError( path ); confirmNotDownloadedNoError( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
} }
@Test @Test
@ -452,7 +457,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -470,7 +475,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -481,7 +486,7 @@ public class ErrorHandlingTest
simulateGetIfNewerError( path, expectedFile, createTransferException() ); simulateGetIfNewerError( path, expectedFile, createTransferException() );
confirmNotDownloadedNoError( path ); confirmNotDownloadedNoError( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile));
} }
@Test @Test
@ -489,7 +494,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -507,7 +512,7 @@ public class ErrorHandlingTest
throws Exception throws Exception
{ {
String path = PATH_IN_BOTH_REMOTES_AND_LOCAL; String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
File expectedFile = setupRepositoriesWithLocalFilePresent( path ); Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE, createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
@ -518,7 +523,7 @@ public class ErrorHandlingTest
simulateGetIfNewerError( path, expectedFile, createTransferException() ); simulateGetIfNewerError( path, expectedFile, createTransferException() );
confirmNotDownloadedNoError( path ); confirmNotDownloadedNoError( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile));
} }
// ------------------------------------------ // ------------------------------------------
@ -539,47 +544,47 @@ public class ErrorHandlingTest
CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false ); CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
} }
private File setupRepositoriesWithLocalFileNotPresent( String path ) private Path setupRepositoriesWithLocalFileNotPresent( String path )
throws Exception throws Exception
{ {
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File file = new File( managedDefaultDir, path ); Path file = managedDefaultDir.resolve( path );
assertNotExistsInManagedDefaultRepo( file ); assertNotExistsInManagedDefaultRepo( file );
return file; return file;
} }
private File setupRepositoriesWithLocalFilePresent( String path ) private Path setupRepositoriesWithLocalFilePresent( String path )
throws Exception throws Exception
{ {
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File file = new File( managedDefaultDir, path ); Path file = managedDefaultDir.resolve( path );
assertTrue( file.exists() ); assertTrue( Files.exists(file) );
return file; return file;
} }
private void simulateGetError( String path, File expectedFile, Exception throwable ) private void simulateGetError( String path, Path expectedFile, Exception throwable )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{ {
wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
EasyMock.expectLastCall().andThrow(throwable ); EasyMock.expectLastCall().andThrow(throwable );
} }
private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception ) private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
{ {
wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( expectedFile.lastModified() )); wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
EasyMock.expectLastCall().andThrow( exception ); EasyMock.expectLastCall().andThrow( exception );
} }
private File createExpectedTempFile( File expectedFile ) private Path createExpectedTempFile( Path expectedFile )
{ {
return new File( managedDefaultDir, expectedFile.getName() + ".tmp" ).getAbsoluteFile(); return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
} }
private void confirmSingleFailure( String path, String id ) private void confirmSingleFailure( String path, String id )
@ -594,7 +599,7 @@ public class ErrorHandlingTest
wagonMockControl.replay(); wagonMockControl.replay();
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = null; Path downloadedFile = null;
try try
{ {
downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
@ -615,30 +620,30 @@ public class ErrorHandlingTest
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
} }
private void confirmSuccess( String path, File expectedFile, String basedir ) private void confirmSuccess( String path, Path expectedFile, String basedir )
throws Exception throws Exception
{ {
File downloadedFile = performDownload( path ); Path downloadedFile = performDownload( path );
File proxied1File = new File( basedir, path ); Path proxied1File = Paths.get( basedir, path );
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
} }
private void confirmNotDownloadedNoError( String path ) private void confirmNotDownloadedNoError( String path )
throws Exception throws Exception
{ {
File downloadedFile = performDownload( path ); Path downloadedFile = performDownload( path );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
} }
private File performDownload( String path ) private Path performDownload( String path )
throws ProxyDownloadException, LayoutException throws ProxyDownloadException, LayoutException
{ {
wagonMockControl.replay(); wagonMockControl.replay();
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
managedDefaultRepository.toArtifactReference( path ) ); managedDefaultRepository.toArtifactReference( path ) );
wagonMockControl.verify(); wagonMockControl.verify();

View File

@ -54,9 +54,11 @@ import javax.inject.Inject;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@ -105,16 +107,16 @@ public class HttpProxyTransferTest
// Setup source repository (using default layout) // Setup source repository (using default layout)
String repoPath = "target/test-repository/managed/" + getClass().getSimpleName(); String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
File destRepoDir = new File( repoPath ); Path destRepoDir = Paths.get( repoPath );
// Cleanout destination dirs. // Cleanout destination dirs.
if ( destRepoDir.exists() ) if ( Files.exists(destRepoDir))
{ {
FileUtils.deleteDirectory( destRepoDir ); FileUtils.deleteDirectory( destRepoDir.toFile() );
} }
// Make the destination dir. // Make the destination dir.
destRepoDir.mkdirs(); Files.createDirectories(destRepoDir);
ManagedRepository repo = new ManagedRepository(); ManagedRepository repo = new ManagedRepository();
repo.setId( MANAGED_ID ); repo.setId( MANAGED_ID );
@ -212,23 +214,22 @@ public class HttpProxyTransferTest
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
addConnector(); addConnector();
File expectedFile = new File( new File( managedDefaultRepository.getRepoRoot() ), path ); Path expectedFile = Paths.get( managedDefaultRepository.getRepoRoot() ).resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File sourceFile = new File( PROXIED_BASEDIR, path ); Path sourceFile = Paths.get( PROXIED_BASEDIR, path );
assertNotNull( "Expected File should not be null.", expectedFile ); assertNotNull( "Expected File should not be null.", expectedFile );
assertNotNull( "Actual File should not be null.", downloadedFile ); assertNotNull( "Actual File should not be null.", downloadedFile );
assertTrue( "Check actual file exists.", downloadedFile.exists() ); assertTrue( "Check actual file exists.", Files.exists(downloadedFile));
assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), assertTrue( "Check filename path is appropriate.", Files.isSameFile( expectedFile, downloadedFile));
downloadedFile.getCanonicalPath() ); assertTrue( "Check file path matches.", Files.isSameFile( expectedFile, downloadedFile));
assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), downloadedFile.getAbsolutePath() );
String expectedContents = FileUtils.readFileToString( sourceFile, Charset.defaultCharset() ); String expectedContents = FileUtils.readFileToString( sourceFile.toFile(), Charset.defaultCharset() );
String actualContents = FileUtils.readFileToString( downloadedFile, Charset.defaultCharset() ); String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() );
assertEquals( "Check file contents.", expectedContents, actualContents ); assertEquals( "Check file contents.", expectedContents, actualContents );
Assertions.assertThat( System.getProperty( "http.proxyHost" ) ).isEmpty(); Assertions.assertThat( System.getProperty( "http.proxyHost" ) ).isEmpty();

View File

@ -32,6 +32,11 @@ import org.junit.Test;
import java.io.File; import java.io.File;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -48,7 +53,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Ensure file isn't present first. // Ensure file isn't present first.
@ -59,7 +64,7 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, true ); CachedFailuresPolicy.NO, true );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( "File should not have been downloaded", downloadedFile ); assertNull( "File should not have been downloaded", downloadedFile );
} }
@ -70,7 +75,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Ensure file isn't present first. // Ensure file isn't present first.
@ -81,9 +86,9 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false ); CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File sourceFile = new File( REPOPATH_PROXIED1, path ); Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, sourceFile ); assertFileEquals( expectedFile, downloadedFile, sourceFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -95,7 +100,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc"; String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar.asc";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
// Ensure file isn't present first. // Ensure file isn't present first.
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -105,13 +110,13 @@ public class ManagedDefaultTransferTest
CachedFailuresPolicy.NO, false ); CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
File sourceFile = new File( REPOPATH_PROXIED1, path ); Path sourceFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, sourceFile ); assertFileEquals( expectedFile, downloadedFile, sourceFile );
assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".sha1" ).exists() ); assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".sha1" )) );
assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".md5" ).exists() ); assertFalse( Files.exists(downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".md5" ) ));
assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".asc" ).exists() ); assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".asc" ) ));
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -129,18 +134,18 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
CachedFailuresPolicy.NO, false ); CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertFileEquals( expectedFile, downloadedFile, expectedFile ); assertFileEquals( expectedFile, downloadedFile, expectedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
@ -160,21 +165,21 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar.asc";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
// Set the managed File to be newer than local. // Set the managed File to be newer than local.
setManagedOlderThanRemote( expectedFile, remoteFile ); setManagedOlderThanRemote( expectedFile, remoteFile );
long originalModificationTime = expectedFile.lastModified(); long originalModificationTime = Files.getLastModifiedTime(expectedFile).toMillis();
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE,
CachedFailuresPolicy.NO, false ); CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, originalModificationTime ); assertNotModified( expectedFile, originalModificationTime );
@ -204,23 +209,23 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
// Set the managed File to be newer than local. // Set the managed File to be newer than local.
setManagedNewerThanRemote( expectedFile, remoteFile ); setManagedNewerThanRemote( expectedFile, remoteFile );
long originalModificationTime = expectedFile.lastModified(); long originalModificationTime = Files.getLastModifiedTime( expectedFile).toMillis();
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, originalModificationTime ); assertNotModified( expectedFile, originalModificationTime );
@ -250,24 +255,24 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
// Set the managed file to be newer than remote file. // Set the managed file to be newer than remote file.
setManagedOlderThanRemote( expectedFile, remoteFile ); setManagedOlderThanRemote( expectedFile, remoteFile );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -286,20 +291,20 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar"; String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
expectedFile.setLastModified( getPastDate().getTime() ); Files.setLastModifiedTime( expectedFile, FileTime.from(getPastDate().getTime(), TimeUnit.MILLISECONDS ));
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY,
CachedFailuresPolicy.NO, false ); CachedFailuresPolicy.NO, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -311,7 +316,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar"; String path = "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -321,16 +326,16 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied1File = new File( REPOPATH_PROXIED1, path ); Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
File proxied2File = new File( REPOPATH_PROXIED2, path ); Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertFileEquals( expectedFile, downloadedFile, proxied1File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
// TODO: is this check even needed if it passes above? // TODO: is this check even needed if it passes above?
String actualContents = FileUtils.readFileToString( downloadedFile, Charset.defaultCharset() ); String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() );
String badContents = FileUtils.readFileToString( proxied2File, Charset.defaultCharset() ); String badContents = FileUtils.readFileToString( proxied2File.toFile(), Charset.defaultCharset() );
assertFalse( "Downloaded file contents should not be that of proxy 2", assertFalse( "Downloaded file contents should not be that of proxy 2",
StringUtils.equals( actualContents, badContents ) ); StringUtils.equals( actualContents, badContents ) );
} }
@ -342,7 +347,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -352,9 +357,9 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxied2File = new File( REPOPATH_PROXIED2, path ); Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile, proxied2File ); assertFileEquals( expectedFile, downloadedFile, proxied2File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -366,7 +371,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar"; String path = "org/apache/maven/test/does-not-exist/1.0/does-not-exist-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -376,7 +381,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception", assertNull( "File returned was: " + downloadedFile + "; should have got a not found exception",
downloadedFile ); downloadedFile );
@ -390,7 +395,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -407,11 +412,11 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
// Attempt the proxy fetch. // Attempt the proxy fetch.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
wagonMockControl.verify(); wagonMockControl.verify();
File proxied2File = new File( REPOPATH_PROXIED2, path ); Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile, proxied2File ); assertFileEquals( expectedFile, downloadedFile, proxied2File );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -423,7 +428,7 @@ public class ManagedDefaultTransferTest
String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar"; String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path ); Path expectedFile = managedDefaultDir.resolve( path );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertNotExistsInManagedDefaultRepo( expectedFile ); assertNotExistsInManagedDefaultRepo( expectedFile );
@ -436,7 +441,7 @@ public class ManagedDefaultTransferTest
saveConnector( ID_DEFAULT_MANAGED, "badproxied1", false ); saveConnector( ID_DEFAULT_MANAGED, "badproxied1", false );
saveConnector( ID_DEFAULT_MANAGED, "badproxied2", false ); saveConnector( ID_DEFAULT_MANAGED, "badproxied2", false );
File tmpFile = new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ); Path tmpFile = expectedFile.getParent().resolve(expectedFile.getFileName() + ".tmp" );
wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) ); wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) ); EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) );
@ -446,7 +451,7 @@ public class ManagedDefaultTransferTest
wagonMockControl.replay(); wagonMockControl.replay();
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );

View File

@ -47,6 +47,8 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.io.File; import java.io.File;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -121,11 +123,11 @@ public class MetadataTransferTest
assertResourceNotFound( requestedResource ); assertResourceNotFound( requestedResource );
assertNoRepoMetadata( ID_PROXIED1, requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource );
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
ProjectReference metadata = createProjectReference( requestedResource ); ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath( managedDefaultRepository.toMetadataPath(
metadata ) ).getFile(); metadata ) ).getFile();
@ -155,7 +157,7 @@ public class MetadataTransferTest
assertNoRepoMetadata( ID_PROXIED2, requestedResource ); assertNoRepoMetadata( ID_PROXIED2, requestedResource );
// ensure that a hard failure in the first proxy connector is skipped and the second repository checked // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), Path expectedFile = managedDefaultDir.resolve(
metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) ); metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class )); wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
@ -984,11 +986,11 @@ public class MetadataTransferTest
private void assertFetchProjectOrGroup( String requestedResource ) private void assertFetchProjectOrGroup( String requestedResource )
throws Exception throws Exception
{ {
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
ProjectReference metadata = createProjectReference( requestedResource ); ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath( managedDefaultRepository.toMetadataPath(
metadata ) ).getFile(); metadata ) ).getFile();
@ -1011,10 +1013,10 @@ public class MetadataTransferTest
private void assertFetchProjectOrGroupFailed( String requestedResource ) private void assertFetchProjectOrGroupFailed( String requestedResource )
throws Exception throws Exception
{ {
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
ProjectReference metadata = createProjectReference( requestedResource ); ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath( managedDefaultRepository.toMetadataPath(
metadata ) ).getFile(); metadata ) ).getFile();
@ -1031,11 +1033,11 @@ public class MetadataTransferTest
private void assertFetchVersioned( String requestedResource ) private void assertFetchVersioned( String requestedResource )
throws Exception throws Exception
{ {
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
VersionedReference metadata = createVersionedReference( requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath( managedDefaultRepository.toMetadataPath(
metadata ) ).getFile(); metadata ) ).getFile();
@ -1058,10 +1060,10 @@ public class MetadataTransferTest
private void assertFetchVersionedFailed( String requestedResource ) private void assertFetchVersionedFailed( String requestedResource )
throws Exception throws Exception
{ {
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
VersionedReference metadata = createVersionedReference( requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath( managedDefaultRepository.toMetadataPath(
metadata ) ).getFile(); metadata ) ).getFile();
@ -1078,19 +1080,19 @@ public class MetadataTransferTest
private void assertResourceExists( String requestedResource ) private void assertResourceExists( String requestedResource )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
} }
private void assertMetadataEquals( String expectedMetadataXml, File actualFile ) private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
throws Exception throws Exception
{ {
assertNotNull( "Actual File should not be null.", actualFile ); assertNotNull( "Actual File should not be null.", actualFile );
assertTrue( "Actual file exists.", actualFile.exists() ); assertTrue( "Actual file exists.", Files.exists(actualFile) );
StringWriter actualContents = new StringWriter(); StringWriter actualContents = new StringWriter();
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile ); ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile.toFile() );
RepositoryMetadataWriter.write( metadata, actualContents ); RepositoryMetadataWriter.write( metadata, actualContents );
DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) ); DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
@ -1111,8 +1113,8 @@ public class MetadataTransferTest
private void assertNoMetadata( String requestedResource ) private void assertNoMetadata( String requestedResource )
throws Exception throws Exception
{ {
File expectedFile = new File( managedDefaultDir, requestedResource ); Path expectedFile = managedDefaultDir.resolve(requestedResource);
assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() ); assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
} }
/** /**
@ -1126,15 +1128,15 @@ public class MetadataTransferTest
{ {
String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
File actualFile = new File( managedDefaultDir, proxiedFile ); Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() ); assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
} }
private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] ) private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
ProjectReference actualMetadata = createGroupReference( requestedResource ); ProjectReference actualMetadata = createGroupReference( requestedResource );
@ -1156,15 +1158,15 @@ public class MetadataTransferTest
{ {
String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
File actualFile = new File( managedDefaultDir, proxiedFile ); Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
ProjectReference actualMetadata = createGroupReference( requestedResource ); ProjectReference actualMetadata = createGroupReference( requestedResource );
assertGroupMetadata( actualFile, actualMetadata, expectedPlugins ); assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
} }
private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] ) private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
throws Exception throws Exception
{ {
// Build expected metadata XML // Build expected metadata XML
@ -1198,8 +1200,8 @@ public class MetadataTransferTest
String latestVersion, String releaseVersion ) String latestVersion, String releaseVersion )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( actualFile.exists() ); assertTrue( Files.exists(actualFile) );
ProjectReference metadata = createProjectReference( requestedResource ); ProjectReference metadata = createProjectReference( requestedResource );
@ -1232,8 +1234,8 @@ public class MetadataTransferTest
private void assertReleaseMetadataContents( String requestedResource ) private void assertReleaseMetadataContents( String requestedResource )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
VersionedReference metadata = createVersionedReference( requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource );
@ -1263,8 +1265,8 @@ public class MetadataTransferTest
int expectedBuildnumber ) int expectedBuildnumber )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
VersionedReference actualMetadata = createVersionedReference( requestedResource ); VersionedReference actualMetadata = createVersionedReference( requestedResource );
@ -1288,15 +1290,15 @@ public class MetadataTransferTest
{ {
String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
File actualFile = new File( managedDefaultDir, proxiedFile ); Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
VersionedReference actualMetadata = createVersionedReference( requestedResource ); VersionedReference actualMetadata = createVersionedReference( requestedResource );
assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber ); assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
} }
private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate, private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
String expectedTime, int expectedBuildnumber ) String expectedTime, int expectedBuildnumber )
throws RepositoryMetadataException, Exception throws RepositoryMetadataException, Exception
{ {
@ -1338,8 +1340,8 @@ public class MetadataTransferTest
{ {
String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
File actualFile = new File( managedDefaultDir, proxiedFile ); Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( actualFile.exists() ); assertTrue( Files.exists(actualFile) );
ProjectReference metadata = createProjectReference( requestedResource ); ProjectReference metadata = createProjectReference( requestedResource );
@ -1372,8 +1374,8 @@ public class MetadataTransferTest
{ {
String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
File actualFile = new File( managedDefaultDir, proxiedFile ); Path actualFile = managedDefaultDir.resolve(proxiedFile);
assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() ); assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
VersionedReference metadata = createVersionedReference( requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource );
@ -1398,8 +1400,8 @@ public class MetadataTransferTest
private void assertResourceNotFound( String requestedResource ) private void assertResourceNotFound( String requestedResource )
throws Exception throws Exception
{ {
File actualFile = new File( managedDefaultDir, requestedResource ); Path actualFile = managedDefaultDir.resolve(requestedResource);
assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() ); assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );
} }
} }

View File

@ -26,7 +26,11 @@ import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy; import org.apache.archiva.policies.SnapshotsPolicy;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -46,16 +50,16 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/does-not-exist/1.0-SNAPSHOT/does-not-exist-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
expectedFile.delete(); Files.deleteIfExists(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -67,18 +71,18 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
expectedFile.delete(); Files.deleteIfExists(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -90,18 +94,18 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
expectedFile.setLastModified( getPastDate().getTime() ); Files.setLastModifiedTime( expectedFile, FileTime.from( getPastDate().getTime(), TimeUnit.MILLISECONDS ));
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -113,8 +117,8 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedNewerThanRemote( expectedFile, remoteFile ); setManagedNewerThanRemote( expectedFile, remoteFile );
@ -124,7 +128,7 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
// Attempt to download. // Attempt to download.
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Should not have downloaded as managed is newer than remote. // Should not have downloaded as managed is newer than remote.
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
@ -141,11 +145,11 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = createArtifactReference( "default", path ); ArtifactReference artifact = createArtifactReference( "default", path );
expectedFile.delete(); Files.delete(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Create customized proxy / target repository // Create customized proxy / target repository
File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1, File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1,
@ -162,7 +166,7 @@ public class SnapshotTransferTest
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
// Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version. // Should have downloaded the content from proxy2, as proxy1 has an old (by file.lastModified check) version.
File proxiedFile = new File( REPOPATH_PROXIED2, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED2, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -173,11 +177,11 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/get-timestamped-snapshot-in-both-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = createArtifactReference( "default", path ); ArtifactReference artifact = createArtifactReference( "default", path );
expectedFile.delete(); Files.delete(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Create customized proxy / target repository // Create customized proxy / target repository
File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2, File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED2_TARGET, REPOPATH_PROXIED2,
@ -205,18 +209,18 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
proxiedFile.setLastModified( getFutureDate().getTime() ); Files.setLastModifiedTime( proxiedFile, FileTime.from( getFutureDate().getTime(), TimeUnit.MILLISECONDS ));
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
@ -229,18 +233,18 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-present-timestamped-snapshot/1.0-SNAPSHOT/get-present-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
File remoteFile = new File( REPOPATH_PROXIED1, path ); Path remoteFile = Paths.get(REPOPATH_PROXIED1, path);
setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 ); setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 );
long expectedTimestamp = expectedFile.lastModified(); long expectedTimestamp = Files.getLastModifiedTime( expectedFile ).toMillis();
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
assertNotDownloaded( downloadedFile ); assertNotDownloaded( downloadedFile );
assertNotModified( expectedFile, expectedTimestamp ); assertNotModified( expectedFile, expectedTimestamp );
@ -254,11 +258,11 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar"; String path = "org/apache/maven/test/get-timestamped-snapshot/1.0-SNAPSHOT/get-timestamped-snapshot-1.0-SNAPSHOT.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
expectedFile.delete(); Files.deleteIfExists(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
@ -266,9 +270,9 @@ public class SnapshotTransferTest
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false); SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES , false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -280,18 +284,18 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar"; String path = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/get-metadata-snapshot-1.0-20050831.101112-1.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
expectedFile.delete(); Files.deleteIfExists(expectedFile);
assertFalse( expectedFile.exists() ); assertFalse( Files.exists(expectedFile) );
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }
@ -306,19 +310,19 @@ public class SnapshotTransferTest
String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar"; String path = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/get-present-metadata-snapshot-1.0-20050831.101112-1.jar";
setupTestableManagedRepository( path ); setupTestableManagedRepository( path );
File expectedFile = new File( managedDefaultDir, path ); Path expectedFile = managedDefaultDir.resolve(path);
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
assertTrue( expectedFile.exists() ); assertTrue( Files.exists(expectedFile) );
expectedFile.setLastModified( getPastDate().getTime() ); Files.setLastModifiedTime( expectedFile, FileTime.from( getPastDate().getTime(), TimeUnit.MILLISECONDS ));
// Configure Connector (usually done within archiva.xml configuration) // Configure Connector (usually done within archiva.xml configuration)
saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false);
File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
File proxiedFile = new File( REPOPATH_PROXIED1, path ); Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
assertFileEquals( expectedFile, downloadedFile, proxiedFile ); assertFileEquals( expectedFile, downloadedFile, proxiedFile );
assertNoTempFiles( expectedFile ); assertNoTempFiles( expectedFile );
} }

View File

@ -905,7 +905,7 @@ public class DefaultBrowseService
String path = managedRepositoryContent.toPath( archivaArtifact ); String path = managedRepositoryContent.toPath( archivaArtifact );
file = connectors.fetchFromProxies( managedRepositoryContent, path ).toPath(); file = connectors.fetchFromProxies( managedRepositoryContent, path );
if ( file != null && Files.exists(file) ) if ( file != null && Files.exists(file) )
{ {

View File

@ -105,6 +105,7 @@ import javax.servlet.http.HttpSession;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -781,7 +782,7 @@ public class ArchivaDavResourceFactory
String path = resource.getPath(); String path = resource.getPath();
if ( repositoryRequest.isSupportFile( path ) ) if ( repositoryRequest.isSupportFile( path ) )
{ {
File proxiedFile = connectors.fetchFromProxies( managedRepository, path ); Path proxiedFile = connectors.fetchFromProxies( managedRepository, path );
return ( proxiedFile != null ); return ( proxiedFile != null );
} }
@ -796,7 +797,7 @@ public class ArchivaDavResourceFactory
if ( repositoryRequest.isArchetypeCatalog( path ) ) if ( repositoryRequest.isArchetypeCatalog( path ) )
{ {
// FIXME we must implement a merge of remote archetype catalog from remote servers. // FIXME we must implement a merge of remote archetype catalog from remote servers.
File proxiedFile = connectors.fetchFromProxies( managedRepository, path ); Path proxiedFile = connectors.fetchFromProxies( managedRepository, path );
return ( proxiedFile != null ); return ( proxiedFile != null );
} }
@ -815,7 +816,7 @@ public class ArchivaDavResourceFactory
this.applicationContext.getBean( "repositoryStorage#" + repositoryLayout, RepositoryStorage.class ); this.applicationContext.getBean( "repositoryStorage#" + repositoryLayout, RepositoryStorage.class );
repositoryStorage.applyServerSideRelocation( managedRepository, artifact ); repositoryStorage.applyServerSideRelocation( managedRepository, artifact );
File proxiedFile = connectors.fetchFromProxies( managedRepository, artifact ); Path proxiedFile = connectors.fetchFromProxies( managedRepository, artifact );
resource.setPath( managedRepository.toPath( artifact ) ); resource.setPath( managedRepository.toPath( artifact ) );

View File

@ -657,7 +657,7 @@ public class ArchivaDavResourceFactoryTest
} }
return new ProxyFetchResult( target, true ); return new ProxyFetchResult( target.toPath(), true );
} }
} }
} }