From 478115559621e6ca27cd51835363b246824c6d4d Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 2 Sep 2017 18:18:56 +0200 Subject: [PATCH] Next part for moving to java.nio --- .../archiva/common/utils/FileUtils.java | 30 +++ .../archiva/common/utils/FileUtilsTest.java | 113 +++++++++ .../archiva/proxy/model/ProxyFetchResult.java | 9 +- .../model/RepositoryProxyConnectors.java | 6 +- .../DefaultRepositoryProxyConnectors.java | 162 +++++++------ .../archiva/proxy/AbstractProxyTestCase.java | 224 ++++++++---------- .../proxy/CacheFailuresTransferTest.java | 23 +- .../archiva/proxy/ChecksumTransferTest.java | 193 +++++++-------- .../archiva/proxy/ErrorHandlingTest.java | 103 ++++---- .../archiva/proxy/HttpProxyTransferTest.java | 29 +-- .../proxy/ManagedDefaultTransferTest.java | 107 +++++---- .../archiva/proxy/MetadataTransferTest.java | 82 +++---- .../archiva/proxy/SnapshotTransferTest.java | 102 ++++---- .../rest/services/DefaultBrowseService.java | 2 +- .../webdav/ArchivaDavResourceFactory.java | 7 +- .../webdav/ArchivaDavResourceFactoryTest.java | 2 +- 16 files changed, 688 insertions(+), 506 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/common/utils/FileUtilsTest.java diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java index 45a68ec7f..0c8683d98 100644 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtils.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Comparator; +import java.util.Optional; /** * @@ -31,6 +32,11 @@ import java.util.Comparator; */ public class FileUtils { + /** + * Deletes the directory recursively and quietly. + * + * @param dir + */ public static void deleteQuietly(Path dir) { 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()); + } + } } diff --git a/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/common/utils/FileUtilsTest.java b/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/common/utils/FileUtilsTest.java new file mode 100644 index 000000000..d165cbdaa --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/test/java/org/apache/archiva/common/utils/FileUtilsTest.java @@ -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 + */ +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 ); + } + +} diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java index 94df725bf..28e8cb9b1 100644 --- a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java +++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java @@ -19,7 +19,8 @@ package org.apache.archiva.proxy.model; * under the License. */ -import java.io.File; + +import java.nio.file.Path; /** * A result from a proxy fetch operation. @@ -30,18 +31,18 @@ public class ProxyFetchResult { //The file returned - private File file; + private Path file; //Was the local file modified by the fetch? private boolean modified; - public ProxyFetchResult( File file, boolean modified ) + public ProxyFetchResult( Path file, boolean modified ) { this.file = file; this.modified = modified; } - public File getFile() + public Path getFile() { return file; } diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java index e63f62393..1216fe253 100644 --- a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java @@ -23,7 +23,7 @@ import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.repository.ManagedRepositoryContent; -import java.io.File; +import java.nio.file.Path; import java.util.List; /** @@ -45,7 +45,7 @@ public interface RepositoryProxyConnectors * @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. */ - File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) + Path fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) throws ProxyDownloadException; /** @@ -69,7 +69,7 @@ public interface RepositoryProxyConnectors * @param path the path of the resource to fetch * @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. diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index 3e8aab8c5..5869f6730 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -28,6 +28,7 @@ import org.apache.archiva.common.filelock.FileLockException; import org.apache.archiva.common.filelock.FileLockManager; import org.apache.archiva.common.filelock.FileLockTimeoutException; 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.Configuration; import org.apache.archiva.configuration.ConfigurationNames; @@ -87,7 +88,10 @@ import javax.inject.Inject; import javax.inject.Named; import java.io.File; import java.io.IOException; +import java.lang.reflect.Proxy; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -302,10 +306,10 @@ public class DefaultRepositoryProxyConnectors } @Override - public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) + public Path fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) throws ProxyDownloadException { - File localFile = toLocalFile( repository, artifact ); + Path localFile = toLocalFile( repository, artifact ); Properties requestProperties = new Properties(); requestProperties.setProperty( "filetype", "artifact" ); @@ -334,13 +338,13 @@ public class DefaultRepositoryProxyConnectors try { - File downloadedFile = + Path downloadedFile = transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, true ); if ( fileExists( downloadedFile ) ) { - log.debug( "Successfully transferred: {}", downloadedFile.getAbsolutePath() ); + log.debug( "Successfully transferred: {}", downloadedFile.toAbsolutePath() ); return downloadedFile; } } @@ -373,12 +377,12 @@ public class DefaultRepositoryProxyConnectors } @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 - if ( localFile.exists() ) + if ( Files.exists(localFile) ) { return null; } @@ -402,13 +406,13 @@ public class DefaultRepositoryProxyConnectors try { - File downloadedFile = + Path downloadedFile = transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties, false ); if ( fileExists( downloadedFile ) ) { - log.debug( "Successfully transferred: {}", downloadedFile.getAbsolutePath() ); + log.debug( "Successfully transferred: {}", downloadedFile.toAbsolutePath() ); return downloadedFile; } } @@ -449,7 +453,7 @@ public class DefaultRepositoryProxyConnectors @Override 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(); requestProperties.setProperty( "filetype", "metadata" ); @@ -466,7 +470,7 @@ public class DefaultRepositoryProxyConnectors RemoteRepositoryContent targetRepository = connector.getTargetRepository(); - File localRepoFile = toLocalRepoFile( repository, targetRepository, logicalPath ); + Path localRepoFile = toLocalRepoFile( repository, targetRepository, logicalPath ); long originalMetadataTimestamp = getLastModified( localRepoFile ); try @@ -507,7 +511,7 @@ public class DefaultRepositoryProxyConnectors metadataNeedsUpdating = true; } - if ( metadataNeedsUpdating || !localFile.exists() ) + if ( metadataNeedsUpdating || !Files.exists(localFile)) { try { @@ -515,7 +519,7 @@ public class DefaultRepositoryProxyConnectors } 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 org.apache.archiva.admin.model.RepositoryAdminException */ - protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, File tmpMd5, - File tmpSha1, File tmpResource, String url, String remotePath, File resource, - File workingDirectory, ManagedRepositoryContent repository ) + protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, Path tmpMd5, + Path tmpSha1, Path tmpResource, String url, String remotePath, Path resource, + Path workingDirectory, ManagedRepositoryContent repository ) throws ProxyException, NotModifiedException, RepositoryAdminException { Wagon wagon = null; @@ -623,26 +627,34 @@ public class DefaultRepositoryProxyConnectors } private void transferArtifact( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File resource, File tmpDirectory, - File destFile ) + ManagedRepositoryContent repository, Path resource, Path tmpDirectory, + Path destFile ) throws ProxyException { 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 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; } @@ -651,11 +663,11 @@ public class DefaultRepositoryProxyConnectors return ( currentLastModified > originalLastModified ); } - private File toLocalRepoFile( ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository, + private Path toLocalRepoFile( ManagedRepositoryContent repository, RemoteRepositoryContent targetRepository, String 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) * @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 ) { return false; } - if ( !file.exists() ) + if ( !Files.exists(file)) { 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. * @throws ProxyException if transfer was unsuccessful. */ - private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File resource, Properties requestProperties, + private Path transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath, + ManagedRepositoryContent repository, Path resource, Properties requestProperties, boolean executeConsumers ) throws ProxyException, NotModifiedException, RepositoryAdminException { @@ -763,10 +775,10 @@ public class DefaultRepositoryProxyConnectors return null; } - File workingDirectory = createWorkingDirectory( repository ); - File tmpResource = new File( workingDirectory, resource.getName() ); - File tmpMd5 = new File( workingDirectory, resource.getName() + ".md5" ); - File tmpSha1 = new File( workingDirectory, resource.getName() + ".sha1" ); + Path workingDirectory = createWorkingDirectory( repository ); + Path tmpResource = workingDirectory.resolve(resource.getFileName()); + Path tmpMd5 = workingDirectory.resolve(resource.getFileName().toString() + ".md5" ); + Path tmpSha1 = workingDirectory.resolve( resource.getFileName().toString() + ".sha1" ); try { @@ -791,9 +803,9 @@ public class DefaultRepositoryProxyConnectors if ( resource != null ) { - synchronized ( resource.getAbsolutePath().intern() ) + synchronized ( resource.toAbsolutePath().toString().intern() ) { - File directory = resource.getParentFile(); + Path directory = resource.getParent(); moveFileIfExists( tmpMd5, directory ); moveFileIfExists( tmpSha1, directory ); moveFileIfExists( tmpResource, directory ); @@ -802,7 +814,7 @@ public class DefaultRepositoryProxyConnectors } finally { - FileUtils.deleteQuietly( workingDirectory ); + org.apache.archiva.common.utils.FileUtils.deleteQuietly( workingDirectory ); } if ( executeConsumers ) @@ -815,11 +827,11 @@ public class DefaultRepositoryProxyConnectors return resource; } - private void queueRepositoryTask( String repositoryId, File localFile ) + private void queueRepositoryTask( String repositoryId, Path localFile ) { RepositoryTask task = new RepositoryTask(); task.setRepositoryId( repositoryId ); - task.setResourceFile( localFile ); + task.setResourceFile( localFile.toFile() ); task.setUpdateRelatedArtifacts( true ); task.setScanAll( true ); @@ -830,7 +842,7 @@ public class DefaultRepositoryProxyConnectors catch ( TaskQueueException e ) { 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 directory directory to write files to */ - private void moveFileIfExists( File fileToMove, File directory ) + private void moveFileIfExists( Path fileToMove, Path directory ) 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 ); } } @@ -865,8 +877,8 @@ public class DefaultRepositoryProxyConnectors * @throws ProxyException if copying the downloaded file into place did not succeed. */ private void transferChecksum( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File resource, File tmpDirectory, String ext, - File destFile ) + ManagedRepositoryContent repository, Path resource, Path tmpDirectory, String ext, + Path destFile ) throws ProxyException { 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. */ private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath, - ManagedRepositoryContent repository, File origFile, File destFile ) + ManagedRepositoryContent repository, Path origFile, Path destFile ) throws ProxyException { assert ( remotePath != null ); @@ -923,10 +935,10 @@ public class DefaultRepositoryProxyConnectors { boolean success = false; - if ( !origFile.exists() ) + if ( !Files.exists(origFile)) { 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; // You wouldn't get here on failure, a WagonException would have been thrown. @@ -935,15 +947,22 @@ public class DefaultRepositoryProxyConnectors else { log.debug( "Retrieving {} from {} if updated", remotePath, remoteRepository.getRepository().getName() ); - success = wagon.getIfNewer( addParameters( remotePath, remoteRepository.getRepository() ), destFile, - origFile.lastModified() ); + try + { + 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 ) { 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." ); } @@ -981,7 +1000,7 @@ public class DefaultRepositoryProxyConnectors * @throws PolicyViolationException */ private void validatePolicies( Map policies, Map settings, - Properties request, File localFile ) + Properties request, Path localFile ) throws PolicyViolationException { for ( Entry entry : policies.entrySet() ) @@ -997,7 +1016,7 @@ public class DefaultRepositoryProxyConnectors log.debug( "Applying [{}] policy with [{}]", key, setting ); try { - policy.applyPolicy( setting, request, localFile ); + policy.applyPolicy( setting, request, localFile.toFile() ); } catch ( PolicyConfigurationException e ) { @@ -1008,7 +1027,7 @@ public class DefaultRepositoryProxyConnectors private void validatePolicies( Map policies, Map settings, Properties request, ArtifactReference artifact, RemoteRepositoryContent content, - File localFile, Exception exception, Map previousExceptions ) + Path localFile, Exception exception, Map previousExceptions ) throws ProxyDownloadException { boolean process = true; @@ -1026,7 +1045,7 @@ public class DefaultRepositoryProxyConnectors try { // 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 ) { break; @@ -1066,11 +1085,11 @@ public class DefaultRepositoryProxyConnectors * @param repository * @return file location of working directory */ - private File createWorkingDirectory( ManagedRepositoryContent repository ) + private Path createWorkingDirectory( ManagedRepositoryContent repository ) { try { - return Files.createTempDirectory( "temp" ).toFile(); + return Files.createTempDirectory( "temp" ); } catch ( IOException e ) { @@ -1087,47 +1106,52 @@ public class DefaultRepositoryProxyConnectors * @param target The final location of the downloaded file * @throws ProxyException when the temp file cannot replace the target file */ - private void moveTempToTarget( File temp, File target ) + private void moveTempToTarget( Path temp, Path target ) throws ProxyException { Lock lock; try { - lock = fileLockManager.writeFileLock( target ); + lock = fileLockManager.writeFileLock( target.toFile() ); 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(); - 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." ); try { - FileUtils.copyFile( temp, lock.getFile() ); + Files.copy( temp, lock.getFile().toPath() ); } - catch ( IOException e ) + catch ( IOException e2 ) { if ( lock.getFile().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 { 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 { - FileUtils.deleteQuietly( temp ); + org.apache.archiva.common.utils.FileUtils.deleteQuietly( temp ); } } + } catch ( FileLockException | FileLockTimeoutException e ) { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index 4d0a9a810..124e7a58b 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -57,6 +57,10 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; 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.SimpleDateFormat; import java.util.ArrayList; @@ -64,6 +68,7 @@ import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.Locale; +import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; @@ -108,7 +113,7 @@ public abstract class AbstractProxyTestCase protected ManagedRepositoryContent managedDefaultRepository; - protected File managedDefaultDir; + protected Path managedDefaultDir; protected MockConfiguration config; @@ -140,7 +145,7 @@ public abstract class AbstractProxyTestCase managedDefaultRepository = createRepository( ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath, "default" ); - managedDefaultDir = new File( managedDefaultRepository.getRepoRoot() ); + managedDefaultDir = Paths.get( managedDefaultRepository.getRepoRoot() ); 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 ) - { - 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 ) + protected void assertChecksums( Path expectedFile, String expectedSha1Contents, String expectedMd5Contents ) throws Exception { - File sha1File = new File( expectedFile.getAbsolutePath() + ".sha1" ); - File md5File = new File( expectedFile.getAbsolutePath() + ".md5" ); + Path sha1File = expectedFile.toAbsolutePath().resolveSibling( expectedFile.getFileName().toString()+ ".sha1" ); + Path md5File = expectedFile.toAbsolutePath().resolveSibling( expectedFile.getFileName().toString() + ".md5" ); 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 { - assertTrue( "SHA1 File should exist: " + sha1File.getPath(), sha1File.exists() ); + assertTrue( "SHA1 File should exist: " + sha1File.toAbsolutePath(), Files.exists(sha1File) ); String actualSha1Contents = readChecksumFile( sha1File ); - assertEquals( "SHA1 File contents: " + sha1File.getPath(), expectedSha1Contents, actualSha1Contents ); + assertEquals( "SHA1 File contents: " + sha1File.toAbsolutePath(), expectedSha1Contents, actualSha1Contents ); } 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 { - assertTrue( "MD5 File should exist: " + md5File.getPath(), md5File.exists() ); + assertTrue( "MD5 File should exist: " + md5File.toAbsolutePath(), Files.exists(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 { assertNotNull( "Expected File should not be null.", expectedFile ); assertNotNull( "Actual File should not be null.", actualFile ); - assertTrue( "Check actual file exists.", actualFile.exists() ); - assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), - actualFile.getCanonicalPath() ); - assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), actualFile.getAbsolutePath() ); - + assertTrue( "Check actual file exists.", Files.exists(actualFile) ); + assertTrue( "Check file is the same.", Files.isSameFile( expectedFile, + actualFile)); String expectedContents = - org.apache.commons.io.FileUtils.readFileToString( sourceFile, Charset.defaultCharset() ); + org.apache.commons.io.FileUtils.readFileToString( sourceFile.toFile(), Charset.defaultCharset() ); 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 ); } - protected void assertNotDownloaded( File downloadedFile ) + protected void assertNotDownloaded( Path downloadedFile ) { assertNull( "Found file: " + downloadedFile + "; but was expecting a failure", downloadedFile ); } @SuppressWarnings( "unchecked" ) - protected void assertNoTempFiles( File expectedFile ) + protected void assertNoTempFiles( Path expectedFile ) { - File workingDir = expectedFile.getParentFile(); - if ( ( workingDir == null ) || !workingDir.isDirectory() ) + Path workingDir = expectedFile.getParent(); + if ( ( workingDir == null ) || !Files.isDirectory( workingDir) ) { return; } Collection 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() ) { 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 ) { emsg.append( "\n " ).append( tfile.getName() ); @@ -342,17 +292,17 @@ public abstract class AbstractProxyTestCase * @throws java.io.IOException if there is a copying problem * @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 { - 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++ ) { @@ -362,7 +312,7 @@ public abstract class AbstractProxyTestCase dest = dest.substring( sourcePath.length() + 1 ); - File destination = new File( destDirectory, dest ); + File destination = new File( destDirectory.toFile(), dest ); if ( file.isFile() ) { @@ -382,7 +332,7 @@ public abstract class AbstractProxyTestCase "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } - copyDirectoryStructure( file, destination ); + copyDirectoryStructure( file.toPath(), destination.toPath() ); } } else @@ -411,7 +361,7 @@ public abstract class AbstractProxyTestCase /** * Read the first line from the checksum file, and return it (trimmed). */ - protected String readChecksumFile( File checksumFile ) + protected String readChecksumFile( Path checksumFile ) throws Exception { FileReader freader = null; @@ -419,7 +369,7 @@ public abstract class AbstractProxyTestCase try { - freader = new FileReader( checksumFile ); + freader = new FileReader( checksumFile.toFile() ); buf = new BufferedReader( freader ); return buf.readLine(); } @@ -530,12 +480,12 @@ public abstract class AbstractProxyTestCase 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 { - File repoLocation = new File( targetPath ); - FileUtils.deleteDirectory( repoLocation ); - copyDirectoryStructure( new File( originalPath ), repoLocation ); + Path repoLocation = Paths.get( targetPath ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoLocation ); + copyDirectoryStructure( Paths.get(originalPath) , repoLocation ); saveRemoteRepositoryConfig( id, "Target Repo-" + id, targetPath, layout ); @@ -561,23 +511,23 @@ public abstract class AbstractProxyTestCase resourceDir = resourcePath.substring( 0, idx ); } - File sourceRepoDir = new File( REPOPATH_DEFAULT_MANAGED ); - File sourceDir = new File( sourceRepoDir, resourceDir ); + Path sourceRepoDir = Paths.get( REPOPATH_DEFAULT_MANAGED ); + Path sourceDir = sourceRepoDir.resolve(resourceDir ); - File destRepoDir = managedDefaultDir; - File destDir = new File( destRepoDir, resourceDir ); + Path destRepoDir = managedDefaultDir; + Path destDir = destRepoDir.resolve(resourceDir ); // 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. - destDir.mkdirs(); + Files.createDirectories(destDir); // Test the source dir. - if ( !sourceDir.exists() ) + if ( !Files.exists(sourceDir) ) { // This is just a warning. 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. - if ( !sourceDir.isDirectory() ) + if ( !Files.isDirectory( 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 ); } - 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( "Remote File should exist: ", remoteFile.exists() ); + assertTrue( "Managed File should exist: ", Files.exists(managedFile) ); + 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 ); } - 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( "Remote File should exist: ", remoteFile.exists() ); + assertTrue( "Managed File should exist: ", Files.exists(managedFile) ); + 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, - file.lastModified() ); + try + { + 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 { - String managedDefaultPath = managedDefaultDir.getCanonicalPath(); - String testFile = file.getCanonicalPath(); + Path managedDefaultPath = managedDefaultDir; assertTrue( "Unit Test Failure: File <" + testFile + "> should be have been defined within the managed default path of <" + managedDefaultPath + ">", testFile.startsWith( managedDefaultPath ) ); - assertFalse( "File < " + testFile + "> should not exist in managed default repository.", file.exists() ); + assertFalse( "File < " + testFile + "> should not exist in managed default repository.", Files.exists(testFile) ); } protected static Date getFutureDate() diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java index e668db8eb..f1857fb1f 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/CacheFailuresTransferTest.java @@ -31,6 +31,9 @@ import org.easymock.EasyMock; import org.junit.Test; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import javax.inject.Inject; import static org.junit.Assert.assertFalse; @@ -55,7 +58,7 @@ public class CacheFailuresTransferTest throws Exception { 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 ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -79,7 +82,7 @@ public class CacheFailuresTransferTest wagonMockControl.replay(); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); wagonMockControl.verify(); @@ -89,7 +92,7 @@ public class CacheFailuresTransferTest downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); wagonMockControl.verify(); - assertNotDownloaded( downloadedFile ); + assertNotDownloaded( downloadedFile); assertNoTempFiles( expectedFile ); } @@ -98,7 +101,7 @@ public class CacheFailuresTransferTest throws Exception { 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 ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -120,7 +123,7 @@ public class CacheFailuresTransferTest wagonMockControl.replay(); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.deleteIfExists(expectedFile); + assertFalse( Files.exists(expectedFile) ); String url = PathUtil.toUrl( REPOPATH_PROXIED1 + "/" + path ); @@ -164,10 +167,10 @@ public class CacheFailuresTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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). - File proxied2File = new File( REPOPATH_PROXIED2, path ); + Path proxied2File = Paths.get( REPOPATH_PROXIED2, path ); assertFileEquals( expectedFile, downloadedFile, proxied2File ); assertNoTempFiles( expectedFile ); } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java index c1ebf9cf4..51e53e765 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ChecksumTransferTest.java @@ -19,7 +19,7 @@ package org.apache.archiva.proxy; * 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.policies.CachedFailuresPolicy; import org.apache.archiva.policies.ChecksumPolicy; @@ -30,6 +30,11 @@ import org.easymock.EasyMock; import org.junit.Test; 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.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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + org.apache.archiva.common.utils.FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, 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. - File proxied1File = new File( REPOPATH_PROXIED1, path ); + Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - FileUtils.deleteDirectory( expectedFile.getParentFile() ); - assertFalse( expectedFile.getParentFile().exists() ); - assertFalse( expectedFile.exists() ); + FileUtils.deleteDirectory( expectedFile.getParent() ); + assertFalse( Files.exists(expectedFile.getParent()) ); + assertFalse( Files.exists(expectedFile) ); saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" ); @@ -447,18 +453,19 @@ public class ChecksumTransferTest wagonMockControl.replay(); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); wagonMockControl.verify(); // Do what the mock doesn't do. - String proxyPath = new File( REPOPATH_PROXIED1, path ).getAbsolutePath(); - String localPath = new File( managedDefaultDir, path ).getAbsolutePath(); - FileUtils.copyFile( new File( proxyPath ), new File( localPath ) ); - FileUtils.copyFile( new File( proxyPath + ".sha1" ), new File( localPath + ".sha1" ) ); + Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath(); + Path localPath = managedDefaultDir.resolve( path ).toAbsolutePath(); + Files.copy( proxyPath, localPath, StandardCopyOption.REPLACE_EXISTING); + Files.copy( proxyPath.resolveSibling( proxyPath.getFileName() + ".sha1" ), + localPath.resolveSibling( localPath.getFileName() + ".sha1" ), StandardCopyOption.REPLACE_EXISTING ); // Test results. - File proxied1File = new File( REPOPATH_PROXIED1, path ); + Path proxied1File = Paths.get( REPOPATH_PROXIED1, path ); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve( path ); + Path remoteFile = Paths.get( REPOPATH_PROXIED1, path ); setManagedOlderThanRemote( expectedFile, remoteFile ); @@ -483,9 +490,9 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); // 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve( path ); + Path remoteFile = Paths.get( REPOPATH_PROXIED1, path ); setManagedOlderThanRemote( expectedFile, remoteFile ); @@ -510,7 +517,7 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); setManagedOlderThanRemote( expectedFile, remoteFile ); @@ -538,9 +545,9 @@ public class ChecksumTransferTest saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, 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 ); assertNoTempFiles( expectedFile ); assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4 get-bad-local-checksum-1.0.jar", diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java index 69c5c3a72..614a5fbd8 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ErrorHandlingTest.java @@ -33,7 +33,12 @@ import org.apache.maven.wagon.authorization.AuthorizationException; import org.easymock.EasyMock; import org.junit.Test; + 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.*; @@ -64,7 +69,7 @@ public class ErrorHandlingTest throws Exception { 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 ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); @@ -79,7 +84,7 @@ public class ErrorHandlingTest throws Exception { 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_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP ); @@ -96,7 +101,7 @@ public class ErrorHandlingTest throws Exception { String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; - File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); + Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); @@ -110,7 +115,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -126,7 +131,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -142,7 +147,7 @@ public class ErrorHandlingTest throws Exception { String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; - File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); + Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); @@ -156,7 +161,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -174,7 +179,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -192,7 +197,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -210,7 +215,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -226,7 +231,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -242,7 +247,7 @@ public class ErrorHandlingTest throws Exception { String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL; - File expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); + Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path ); saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); @@ -256,7 +261,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -274,7 +279,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -292,7 +297,7 @@ public class ErrorHandlingTest throws Exception { 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 ); @@ -310,7 +315,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -327,7 +332,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -344,7 +349,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -362,7 +367,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -380,7 +385,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -398,7 +403,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.ALWAYS ); @@ -409,7 +414,7 @@ public class ErrorHandlingTest simulateGetIfNewerError( path, expectedFile, createTransferException() ); confirmNotDownloadedNoError( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); } @Test @@ -417,7 +422,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -434,7 +439,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -444,7 +449,7 @@ public class ErrorHandlingTest simulateGetIfNewerError( path, expectedFile, createTransferException() ); confirmNotDownloadedNoError( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); } @Test @@ -452,7 +457,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -470,7 +475,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -481,7 +486,7 @@ public class ErrorHandlingTest simulateGetIfNewerError( path, expectedFile, createTransferException() ); confirmNotDownloadedNoError( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile)); } @Test @@ -489,7 +494,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -507,7 +512,7 @@ public class ErrorHandlingTest throws Exception { 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, PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT ); @@ -518,7 +523,7 @@ public class ErrorHandlingTest simulateGetIfNewerError( path, expectedFile, createTransferException() ); confirmNotDownloadedNoError( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile)); } // ------------------------------------------ @@ -539,47 +544,47 @@ public class ErrorHandlingTest CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false ); } - private File setupRepositoriesWithLocalFileNotPresent( String path ) + private Path setupRepositoriesWithLocalFileNotPresent( String path ) throws Exception { setupTestableManagedRepository( path ); - File file = new File( managedDefaultDir, path ); + Path file = managedDefaultDir.resolve( path ); assertNotExistsInManagedDefaultRepo( file ); return file; } - private File setupRepositoriesWithLocalFilePresent( String path ) + private Path setupRepositoriesWithLocalFilePresent( String path ) throws Exception { setupTestableManagedRepository( path ); - File file = new File( managedDefaultDir, path ); + Path file = managedDefaultDir.resolve( path ); - assertTrue( file.exists() ); + assertTrue( Files.exists(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 { wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class )); EasyMock.expectLastCall().andThrow(throwable ); } - private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception ) - throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException + private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception ) + 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 ); } - 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 ) @@ -594,7 +599,7 @@ public class ErrorHandlingTest wagonMockControl.replay(); // Attempt the proxy fetch. - File downloadedFile = null; + Path downloadedFile = null; try { downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, @@ -615,30 +620,30 @@ public class ErrorHandlingTest assertNotDownloaded( downloadedFile ); } - private void confirmSuccess( String path, File expectedFile, String basedir ) + private void confirmSuccess( String path, Path expectedFile, String basedir ) 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 ); } private void confirmNotDownloadedNoError( String path ) throws Exception { - File downloadedFile = performDownload( path ); + Path downloadedFile = performDownload( path ); assertNotDownloaded( downloadedFile ); } - private File performDownload( String path ) + private Path performDownload( String path ) throws ProxyDownloadException, LayoutException { wagonMockControl.replay(); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, managedDefaultRepository.toArtifactReference( path ) ); wagonMockControl.verify(); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index d85d5016e..fad03d802 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -54,9 +54,11 @@ import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; import java.io.IOException; 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; @@ -105,16 +107,16 @@ public class HttpProxyTransferTest // Setup source repository (using default layout) String repoPath = "target/test-repository/managed/" + getClass().getSimpleName(); - File destRepoDir = new File( repoPath ); + Path destRepoDir = Paths.get( repoPath ); // Cleanout destination dirs. - if ( destRepoDir.exists() ) + if ( Files.exists(destRepoDir)) { - FileUtils.deleteDirectory( destRepoDir ); + FileUtils.deleteDirectory( destRepoDir.toFile() ); } // Make the destination dir. - destRepoDir.mkdirs(); + Files.createDirectories(destRepoDir); ManagedRepository repo = new ManagedRepository(); repo.setId( MANAGED_ID ); @@ -212,23 +214,22 @@ public class HttpProxyTransferTest // Configure Connector (usually done within archiva.xml configuration) addConnector(); - File expectedFile = new File( new File( managedDefaultRepository.getRepoRoot() ), path ); + Path expectedFile = Paths.get( managedDefaultRepository.getRepoRoot() ).resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // 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( "Actual File should not be null.", downloadedFile ); - assertTrue( "Check actual file exists.", downloadedFile.exists() ); - assertEquals( "Check filename path is appropriate.", expectedFile.getCanonicalPath(), - downloadedFile.getCanonicalPath() ); - assertEquals( "Check file path matches.", expectedFile.getAbsolutePath(), downloadedFile.getAbsolutePath() ); + assertTrue( "Check actual file exists.", Files.exists(downloadedFile)); + assertTrue( "Check filename path is appropriate.", Files.isSameFile( expectedFile, downloadedFile)); + assertTrue( "Check file path matches.", Files.isSameFile( expectedFile, downloadedFile)); - String expectedContents = FileUtils.readFileToString( sourceFile, Charset.defaultCharset() ); - String actualContents = FileUtils.readFileToString( downloadedFile, Charset.defaultCharset() ); + String expectedContents = FileUtils.readFileToString( sourceFile.toFile(), Charset.defaultCharset() ); + String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() ); assertEquals( "Check file contents.", expectedContents, actualContents ); Assertions.assertThat( System.getProperty( "http.proxyHost" ) ).isEmpty(); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java index 1dcb8ec83..017594374 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/ManagedDefaultTransferTest.java @@ -32,6 +32,11 @@ import org.junit.Test; import java.io.File; 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.*; @@ -48,7 +53,7 @@ public class ManagedDefaultTransferTest String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Ensure file isn't present first. @@ -59,7 +64,7 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, true ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Ensure file isn't present first. @@ -81,9 +86,9 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); // Ensure file isn't present first. assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -105,13 +110,13 @@ public class ManagedDefaultTransferTest CachedFailuresPolicy.NO, false ); // 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 ); - assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".sha1" ).exists() ); - assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".md5" ).exists() ); - assertFalse( new File( downloadedFile.getParentFile(), downloadedFile.getName() + ".asc" ).exists() ); + assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".sha1" )) ); + assertFalse( Files.exists(downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".md5" ) )); + assertFalse( Files.exists( downloadedFile.getParent().resolve(downloadedFile.getFileName() + ".asc" ) )); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertFileEquals( expectedFile, downloadedFile, 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); // Set the managed File to be newer than local. setManagedOlderThanRemote( expectedFile, remoteFile ); - long originalModificationTime = expectedFile.lastModified(); + long originalModificationTime = Files.getLastModifiedTime(expectedFile).toMillis(); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ONCE, SnapshotsPolicy.ONCE, CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, path ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); // Set the managed File to be newer than local. setManagedNewerThanRemote( expectedFile, remoteFile ); - long originalModificationTime = expectedFile.lastModified(); + long originalModificationTime = Files.getLastModifiedTime( expectedFile).toMillis(); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); // Set the managed file to be newer than remote file. setManagedOlderThanRemote( expectedFile, remoteFile ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false ); // 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); - expectedFile.setLastModified( getPastDate().getTime() ); + assertTrue( Files.exists(expectedFile) ); + Files.setLastModifiedTime( expectedFile, FileTime.from(getPastDate().getTime(), TimeUnit.MILLISECONDS )); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.DAILY, SnapshotsPolicy.DAILY, CachedFailuresPolicy.NO, false ); // 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -321,16 +326,16 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); - File proxied1File = new File( REPOPATH_PROXIED1, path ); - File proxied2File = new File( REPOPATH_PROXIED2, path ); + Path proxied1File = Paths.get(REPOPATH_PROXIED1, path); + Path proxied2File = Paths.get(REPOPATH_PROXIED2, path); assertFileEquals( expectedFile, downloadedFile, proxied1File ); assertNoTempFiles( expectedFile ); // TODO: is this check even needed if it passes above? - String actualContents = FileUtils.readFileToString( downloadedFile, Charset.defaultCharset() ); - String badContents = FileUtils.readFileToString( proxied2File, Charset.defaultCharset() ); + String actualContents = FileUtils.readFileToString( downloadedFile.toFile(), Charset.defaultCharset() ); + String badContents = FileUtils.readFileToString( proxied2File.toFile(), Charset.defaultCharset() ); assertFalse( "Downloaded file contents should not be that of proxy 2", 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -352,9 +357,9 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -376,7 +381,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // 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", 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -407,11 +412,11 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false ); // Attempt the proxy fetch. - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); wagonMockControl.verify(); - File proxied2File = new File( REPOPATH_PROXIED2, path ); + Path proxied2File = Paths.get(REPOPATH_PROXIED2, path); assertFileEquals( expectedFile, downloadedFile, proxied2File ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir.getAbsoluteFile(), path ); + Path expectedFile = managedDefaultDir.resolve( path ); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); assertNotExistsInManagedDefaultRepo( expectedFile ); @@ -436,7 +441,7 @@ public class ManagedDefaultTransferTest saveConnector( ID_DEFAULT_MANAGED, "badproxied1", 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 ) ); EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) ); @@ -446,7 +451,7 @@ public class ManagedDefaultTransferTest wagonMockControl.replay(); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java index 8ed576788..47fd97ee4 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java @@ -47,6 +47,8 @@ import javax.inject.Inject; import javax.inject.Named; import java.io.File; import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -121,11 +123,11 @@ public class MetadataTransferTest assertResourceNotFound( requestedResource ); assertNoRepoMetadata( ID_PROXIED1, requestedResource ); - File expectedFile = new File( managedDefaultDir, requestedResource ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -155,7 +157,7 @@ public class MetadataTransferTest assertNoRepoMetadata( ID_PROXIED2, requestedResource ); // 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 ) ); wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class )); @@ -984,11 +986,11 @@ public class MetadataTransferTest private void assertFetchProjectOrGroup( String requestedResource ) throws Exception { - File expectedFile = new File( managedDefaultDir, requestedResource ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1011,10 +1013,10 @@ public class MetadataTransferTest private void assertFetchProjectOrGroupFailed( String requestedResource ) throws Exception { - File expectedFile = new File( managedDefaultDir, requestedResource ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1031,11 +1033,11 @@ public class MetadataTransferTest private void assertFetchVersioned( String requestedResource ) throws Exception { - File expectedFile = new File( managedDefaultDir, requestedResource ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1058,10 +1060,10 @@ public class MetadataTransferTest private void assertFetchVersionedFailed( String requestedResource ) throws Exception { - File expectedFile = new File( managedDefaultDir, requestedResource ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, + Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( metadata ) ).getFile(); @@ -1078,19 +1080,19 @@ public class MetadataTransferTest private void assertResourceExists( String requestedResource ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) ); } - private void assertMetadataEquals( String expectedMetadataXml, File actualFile ) + private void assertMetadataEquals( String expectedMetadataXml, Path actualFile ) throws Exception { 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(); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile.toFile() ); RepositoryMetadataWriter.write( metadata, actualContents ); DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) ); @@ -1111,8 +1113,8 @@ public class MetadataTransferTest private void assertNoMetadata( String requestedResource ) throws Exception { - File expectedFile = new File( managedDefaultDir, requestedResource ); - assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() ); + Path expectedFile = managedDefaultDir.resolve(requestedResource); + assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) ); } /** @@ -1126,15 +1128,15 @@ public class MetadataTransferTest { String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); - File actualFile = new File( managedDefaultDir, proxiedFile ); - assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(proxiedFile); + assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) ); } private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) ); ProjectReference actualMetadata = createGroupReference( requestedResource ); @@ -1156,15 +1158,15 @@ public class MetadataTransferTest { String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); - File actualFile = new File( managedDefaultDir, proxiedFile ); - assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(proxiedFile); + assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) ); ProjectReference actualMetadata = createGroupReference( requestedResource ); assertGroupMetadata( actualFile, actualMetadata, expectedPlugins ); } - private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] ) + private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] ) throws Exception { // Build expected metadata XML @@ -1198,8 +1200,8 @@ public class MetadataTransferTest String latestVersion, String releaseVersion ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertTrue( actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertTrue( Files.exists(actualFile) ); ProjectReference metadata = createProjectReference( requestedResource ); @@ -1232,8 +1234,8 @@ public class MetadataTransferTest private void assertReleaseMetadataContents( String requestedResource ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) ); VersionedReference metadata = createVersionedReference( requestedResource ); @@ -1263,8 +1265,8 @@ public class MetadataTransferTest int expectedBuildnumber ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) ); VersionedReference actualMetadata = createVersionedReference( requestedResource ); @@ -1288,15 +1290,15 @@ public class MetadataTransferTest { String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); - File actualFile = new File( managedDefaultDir, proxiedFile ); - assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(proxiedFile); + assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) ); VersionedReference actualMetadata = createVersionedReference( requestedResource ); 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 ) throws RepositoryMetadataException, Exception { @@ -1338,8 +1340,8 @@ public class MetadataTransferTest { String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); - File actualFile = new File( managedDefaultDir, proxiedFile ); - assertTrue( actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(proxiedFile); + assertTrue( Files.exists(actualFile) ); ProjectReference metadata = createProjectReference( requestedResource ); @@ -1372,8 +1374,8 @@ public class MetadataTransferTest { String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource ); - File actualFile = new File( managedDefaultDir, proxiedFile ); - assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(proxiedFile); + assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) ); VersionedReference metadata = createVersionedReference( requestedResource ); @@ -1398,8 +1400,8 @@ public class MetadataTransferTest private void assertResourceNotFound( String requestedResource ) throws Exception { - File actualFile = new File( managedDefaultDir, requestedResource ); - assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() ); + Path actualFile = managedDefaultDir.resolve(requestedResource); + assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) ); } } diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java index 097a3a3c8..9ab0585bf 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/SnapshotTransferTest.java @@ -26,7 +26,11 @@ import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; 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.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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.deleteIfExists(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.deleteIfExists(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); - expectedFile.setLastModified( getPastDate().getTime() ); + assertTrue( Files.exists(expectedFile) ); + Files.setLastModifiedTime( expectedFile, FileTime.from( getPastDate().getTime(), TimeUnit.MILLISECONDS )); // Configure Connector (usually done within archiva.xml configuration) 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); setManagedNewerThanRemote( expectedFile, remoteFile ); @@ -124,7 +128,7 @@ public class SnapshotTransferTest saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false ); // 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. 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = createArtifactReference( "default", path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.delete(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Create customized proxy / target repository File targetProxyDir = saveTargetedRepositoryConfig( ID_PROXIED1_TARGET, REPOPATH_PROXIED1, @@ -162,7 +166,7 @@ public class SnapshotTransferTest File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); // 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = createArtifactReference( "default", path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.delete(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Create customized proxy / target repository 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - assertTrue( expectedFile.exists() ); + assertTrue( Files.exists(expectedFile) ); - File proxiedFile = new File( REPOPATH_PROXIED1, path ); - proxiedFile.setLastModified( getFutureDate().getTime() ); + Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path); + Files.setLastModifiedTime( proxiedFile, FileTime.from( getFutureDate().getTime(), TimeUnit.MILLISECONDS )); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertFileEquals( expectedFile, downloadedFile, proxiedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); - File remoteFile = new File( REPOPATH_PROXIED1, path ); + Path expectedFile = managedDefaultDir.resolve(path); + Path remoteFile = Paths.get(REPOPATH_PROXIED1, path); setManagedNewerThanRemote( expectedFile, remoteFile, 12000000 ); - long expectedTimestamp = expectedFile.lastModified(); + long expectedTimestamp = Files.getLastModifiedTime( expectedFile ).toMillis(); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); // Configure Connector (usually done within archiva.xml configuration) saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false); - File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); + Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact ); assertNotDownloaded( downloadedFile ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.deleteIfExists(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) 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, 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(path); ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path ); - expectedFile.delete(); - assertFalse( expectedFile.exists() ); + Files.deleteIfExists(expectedFile); + assertFalse( Files.exists(expectedFile) ); // Configure Connector (usually done within archiva.xml configuration) 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 ); 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"; setupTestableManagedRepository( path ); - File expectedFile = new File( managedDefaultDir, path ); + Path expectedFile = managedDefaultDir.resolve(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) 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 ); assertNoTempFiles( expectedFile ); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 4fc786fbb..f652d7f19 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -905,7 +905,7 @@ public class DefaultBrowseService String path = managedRepositoryContent.toPath( archivaArtifact ); - file = connectors.fetchFromProxies( managedRepositoryContent, path ).toPath(); + file = connectors.fetchFromProxies( managedRepositoryContent, path ); if ( file != null && Files.exists(file) ) { diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 3f4aeecfc..ecf26209f 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -105,6 +105,7 @@ import javax.servlet.http.HttpSession; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -781,7 +782,7 @@ public class ArchivaDavResourceFactory String path = resource.getPath(); if ( repositoryRequest.isSupportFile( path ) ) { - File proxiedFile = connectors.fetchFromProxies( managedRepository, path ); + Path proxiedFile = connectors.fetchFromProxies( managedRepository, path ); return ( proxiedFile != null ); } @@ -796,7 +797,7 @@ public class ArchivaDavResourceFactory if ( repositoryRequest.isArchetypeCatalog( path ) ) { // 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 ); } @@ -815,7 +816,7 @@ public class ArchivaDavResourceFactory this.applicationContext.getBean( "repositoryStorage#" + repositoryLayout, RepositoryStorage.class ); repositoryStorage.applyServerSideRelocation( managedRepository, artifact ); - File proxiedFile = connectors.fetchFromProxies( managedRepository, artifact ); + Path proxiedFile = connectors.fetchFromProxies( managedRepository, artifact ); resource.setPath( managedRepository.toPath( artifact ) ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index 7b3870d23..331cd588e 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -657,7 +657,7 @@ public class ArchivaDavResourceFactoryTest } - return new ProxyFetchResult( target, true ); + return new ProxyFetchResult( target.toPath(), true ); } } } -- 2.39.5