From cd1f4a9e79c91e11f1183045b6aeb8b93017d319 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sat, 2 Sep 2017 22:05:16 +0200 Subject: [PATCH] Switching the checksum module to java.nio --- .../archiva/checksum/ChecksummedFile.java | 54 ++++++------ .../checksum/AbstractChecksumTestCase.java | 31 ++++--- .../checksum/ChecksumAlgorithmTest.java | 5 +- .../apache/archiva/checksum/ChecksumTest.java | 9 +- .../archiva/checksum/ChecksummedFileTest.java | 84 ++++++++++--------- .../apache/archiva/common/utils/FileUtil.java | 36 -------- .../archiva/common/utils/FileUtils.java | 47 +++++++++++ .../ArchivaConfigurationMRM789Test.java | 12 +-- .../ArchivaConfigurationTest.java | 3 +- .../ArtifactMissingChecksumsConsumer.java | 4 +- .../ArtifactMissingChecksumsConsumerTest.java | 2 +- .../LegacyToDefaultConverterTest.java | 5 +- .../search/AbstractMavenRepositorySearch.java | 27 +++--- .../search/MavenRepositorySearchTest.java | 39 +++++---- .../archiva/policies/ChecksumPolicy.java | 4 +- .../archiva/policies/ChecksumPolicyTest.java | 3 +- .../DefaultRepositoryProxyConnectors.java | 3 - .../remote/DefaultRemoteRepositoryAdmin.java | 2 - .../repository/metadata/MetadataTools.java | 6 +- .../transaction/CopyFileEventTest.java | 7 +- .../transaction/CreateFileEventTest.java | 7 +- .../indexing/DownloadRemoteIndexTaskTest.java | 4 +- .../services/DefaultRepositoriesService.java | 4 +- .../services/AbstractArchivaRestTest.java | 4 +- .../services/RepositoriesServiceTest.java | 3 +- .../web/api/DefaultFileUploadService.java | 2 +- .../maven2/Maven2RepositoryStorage.java | 2 +- ...yMetadataResolverMRM1411RepoGroupTest.java | 13 ++- ...RepositoryMetadataResolverMRM1411Test.java | 13 ++- .../Maven2RepositoryMetadataResolverTest.java | 14 ++-- .../content/maven2/RepositoryRequestTest.java | 4 +- .../consumers/DuplicateArtifactsConsumer.java | 2 +- 32 files changed, 232 insertions(+), 223 deletions(-) delete mode 100644 archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtil.java diff --git a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java index 39a11c538..6459a1c97 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java @@ -19,15 +19,16 @@ package org.apache.archiva.checksum; * under the License. */ -import org.apache.commons.io.FileUtils; +import org.apache.archiva.common.utils.FileUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.List; @@ -49,18 +50,21 @@ import java.util.regex.Pattern; */ public class ChecksummedFile { + + private static Charset FILE_ENCODING = Charset.forName( "UTF-8" ); + private final Logger log = LoggerFactory.getLogger( ChecksummedFile.class ); private static final Pattern METADATA_PATTERN = Pattern.compile( "maven-metadata-\\S*.xml" ); - private final File referenceFile; + private final Path referenceFile; /** * Construct a ChecksummedFile object. * * @param referenceFile */ - public ChecksummedFile( final File referenceFile ) + public ChecksummedFile( final Path referenceFile ) { this.referenceFile = referenceFile; } @@ -76,7 +80,7 @@ public class ChecksummedFile throws IOException { - try (InputStream fis = Files.newInputStream( referenceFile.toPath() )) + try (InputStream fis = Files.newInputStream( referenceFile )) { Checksum checksum = new Checksum( checksumAlgorithm ); checksum.update( fis ); @@ -91,14 +95,14 @@ public class ChecksummedFile * @return the checksum File that was created. * @throws IOException if there was a problem either reading the referenceFile, or writing the checksum file. */ - public File createChecksum( ChecksumAlgorithm checksumAlgorithm ) + public Path createChecksum( ChecksumAlgorithm checksumAlgorithm ) throws IOException { - File checksumFile = new File( referenceFile.getAbsolutePath() + "." + checksumAlgorithm.getExt() ); - Files.deleteIfExists( checksumFile.toPath() ); + Path checksumFile = referenceFile.resolveSibling( referenceFile.getFileName() + "." + checksumAlgorithm.getExt() ); + Files.deleteIfExists( checksumFile ); String checksum = calculateChecksum( checksumAlgorithm ); - Files.write( checksumFile.toPath(), // - ( checksum + " " + referenceFile.getName() ).getBytes(), // + Files.write( checksumFile, // + ( checksum + " " + referenceFile.getFileName().toString() ).getBytes(), // StandardOpenOption.CREATE_NEW ); return checksumFile; } @@ -109,9 +113,9 @@ public class ChecksummedFile * @param checksumAlgorithm the hash that we are interested in. * @return the checksum file to return */ - public File getChecksumFile( ChecksumAlgorithm checksumAlgorithm ) + public Path getChecksumFile( ChecksumAlgorithm checksumAlgorithm ) { - return new File( referenceFile.getAbsolutePath() + "." + checksumAlgorithm.getExt() ); + return referenceFile.resolveSibling( referenceFile.getFileName() + "." + checksumAlgorithm.getExt() ); } /** @@ -142,16 +146,16 @@ public class ChecksummedFile public boolean isValidChecksums( ChecksumAlgorithm algorithms[] ) { - try (InputStream fis = Files.newInputStream( referenceFile.toPath() )) + try (InputStream fis = Files.newInputStream( referenceFile)) { List checksums = new ArrayList<>( algorithms.length ); // Create checksum object for each algorithm. for ( ChecksumAlgorithm checksumAlgorithm : algorithms ) { - File checksumFile = getChecksumFile( checksumAlgorithm ); + Path checksumFile = getChecksumFile( checksumAlgorithm ); // Only add algorithm if checksum file exists. - if ( checksumFile.exists() ) + if ( Files.exists(checksumFile) ) { checksums.add( new Checksum( checksumAlgorithm ) ); } @@ -183,10 +187,10 @@ public class ChecksummedFile for ( Checksum checksum : checksums ) { ChecksumAlgorithm checksumAlgorithm = checksum.getAlgorithm(); - File checksumFile = getChecksumFile( checksumAlgorithm ); + Path checksumFile = getChecksumFile( checksumAlgorithm ); - String rawChecksum = FileUtils.readFileToString( checksumFile ); - String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getName() ); + String rawChecksum = FileUtils.readFileToString( checksumFile , FILE_ENCODING ); + String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getFileName().toString() ); if ( !StringUtils.equalsIgnoreCase( expectedChecksum, checksum.getChecksum() ) ) { @@ -231,7 +235,7 @@ public class ChecksummedFile return true; } - try (InputStream fis = Files.newInputStream( referenceFile.toPath() )) + try (InputStream fis = Files.newInputStream( referenceFile )) { // Parse file once, for all checksums. Checksum.update( checksums, fis ); @@ -250,23 +254,23 @@ public class ChecksummedFile ChecksumAlgorithm checksumAlgorithm = checksum.getAlgorithm(); try { - File checksumFile = getChecksumFile( checksumAlgorithm ); + Path checksumFile = getChecksumFile( checksumAlgorithm ); String actualChecksum = checksum.getChecksum(); - if ( checksumFile.exists() ) + if ( Files.exists(checksumFile) ) { - String rawChecksum = FileUtils.readFileToString( checksumFile ); - String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getName() ); + String rawChecksum = FileUtils.readFileToString( checksumFile, FILE_ENCODING); + String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getFileName().toString() ); if ( !StringUtils.equalsIgnoreCase( expectedChecksum, actualChecksum ) ) { // create checksum (again) - FileUtils.writeStringToFile( checksumFile, actualChecksum + " " + referenceFile.getName() ); + FileUtils.writeStringToFile( checksumFile, FILE_ENCODING, actualChecksum + " " + referenceFile.getFileName().toString()); } } else { - FileUtils.writeStringToFile( checksumFile, actualChecksum + " " + referenceFile.getName() ); + FileUtils.writeStringToFile( checksumFile, FILE_ENCODING, actualChecksum + " " + referenceFile.getFileName().toString() ); } } catch ( IOException e ) diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/AbstractChecksumTestCase.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/AbstractChecksumTestCase.java index 93b9cbeb1..fafa10319 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/AbstractChecksumTestCase.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/AbstractChecksumTestCase.java @@ -20,11 +20,14 @@ package org.apache.archiva.checksum; */ import junit.framework.TestCase; -import org.apache.archiva.common.utils.FileUtil; +import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.junit.runner.RunWith; -import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; /** * AbstractChecksumTestCase @@ -35,26 +38,30 @@ import java.io.File; public abstract class AbstractChecksumTestCase extends TestCase { - public File getTestOutputDir() + public Path getTestOutputDir() { - File dir = new File( FileUtil.getBasedir(), "target/test-output/" + getName() ); - if ( dir.exists() == false ) + Path dir = Paths.get( FileUtils.getBasedir(), "target/test-output/" + getName() ); + if ( !Files.exists(dir)) { - if ( dir.mkdirs() == false ) + try { - fail( "Unable to create test output directory: " + dir.getAbsolutePath() ); + Files.createDirectories( dir ); + } + catch ( IOException e ) + { + fail( "Unable to create test output directory: " + dir.toAbsolutePath() ); } } return dir; } - public File getTestResource( String filename ) + public Path getTestResource( String filename ) { - File dir = new File( FileUtil.getBasedir(), "src/test/resources" ); - File file = new File( dir, filename ); - if ( file.exists() == false ) + Path dir = Paths.get( FileUtils.getBasedir(), "src/test/resources" ); + Path file = dir.resolve(filename ); + if ( !Files.exists(file)) { - fail( "Test Resource does not exist: " + file.getAbsolutePath() ); + fail( "Test Resource does not exist: " + file.toAbsolutePath() ); } return file; } diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java index 39719ccbd..56fc5ad49 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java @@ -19,14 +19,13 @@ package org.apache.archiva.checksum; * under the License. */ -import java.io.File; -import java.nio.file.Paths; - import junit.framework.TestCase; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.junit.Test; import org.junit.runner.RunWith; +import java.nio.file.Paths; + /** * ChecksumAlgorithmTest * diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumTest.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumTest.java index 11df7b9b5..bc7f0b274 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumTest.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumTest.java @@ -19,15 +19,16 @@ package org.apache.archiva.checksum; * under the License. */ -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import junit.framework.TestCase; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + /** * ChecksumTest * diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java index 69d34f28d..04c63912c 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java @@ -19,14 +19,18 @@ package org.apache.archiva.checksum; * under the License. */ -import org.apache.commons.io.FileUtils; +import org.apache.archiva.common.utils.FileUtils; import org.apache.commons.lang.StringUtils; import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; -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 java.nio.file.StandardCopyOption; /** * ChecksummedFileTest @@ -46,6 +50,8 @@ public class ChecksummedFileTest private static final String REMOTE_METADATA_MD5 = "d41d8cd98f00b204e9800998ecf8427e"; + private static final Charset FILE_ENCODING = Charset.forName( "UTF-8" ); + @Before public void cleanTestDir() @@ -60,36 +66,36 @@ public class ChecksummedFileTest } } - private File createTestableJar( String filename ) + private Path createTestableJar( String filename ) throws IOException { - File srcFile = getTestResource( filename ); - File destFile = new File( getTestOutputDir(), srcFile.getName() ); - FileUtils.copyFile( srcFile, destFile ); + Path srcFile = getTestResource( filename ); + Path destFile = getTestOutputDir( ).resolve( srcFile.getFileName()); + Files.copy( srcFile, destFile, StandardCopyOption.REPLACE_EXISTING ); return destFile; } - private File createTestableJar( String filename, boolean copySha1, boolean copyMd5 ) + private Path createTestableJar( String filename, boolean copySha1, boolean copyMd5 ) throws IOException { - File srcFile = getTestResource( filename ); - File jarFile = new File( getTestOutputDir(), srcFile.getName() ); - FileUtils.copyFile( srcFile, jarFile ); + Path srcFile = getTestResource( filename ); + Path jarFile = getTestOutputDir().resolve(srcFile.getFileName() ); + Files.copy( srcFile, jarFile, StandardCopyOption.REPLACE_EXISTING ); if ( copySha1 ) { - File srcSha1 = new File( srcFile.getAbsolutePath() + ".sha1" ); - File sha1File = new File( jarFile.getAbsolutePath() + ".sha1" ); + Path srcSha1 = srcFile.resolveSibling( srcFile.getFileName() + ".sha1" ); + Path sha1File = jarFile.resolveSibling( jarFile.getFileName() + ".sha1" ); - FileUtils.copyFile( srcSha1, sha1File ); + Files.copy( srcSha1, sha1File, StandardCopyOption.REPLACE_EXISTING ); } if ( copyMd5 ) { - File srcMd5 = new File( srcFile.getAbsolutePath() + ".md5" ); - File md5File = new File( jarFile.getAbsolutePath() + ".md5" ); + Path srcMd5 = srcFile.resolveSibling( srcFile.getFileName() + ".md5" ); + Path md5File = jarFile.resolveSibling( jarFile.getFileName() + ".md5" ); - FileUtils.copyFile( srcMd5, md5File ); + Files.copy( srcMd5, md5File, StandardCopyOption.REPLACE_EXISTING ); } return jarFile; @@ -99,7 +105,7 @@ public class ChecksummedFileTest public void testCalculateChecksumMd5() throws IOException { - File testfile = getTestResource( "examples/redback-authz-open.jar" ); + Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String expectedChecksum = "f42047fe2e177ac04d0df7aa44d408be"; String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ); @@ -110,7 +116,7 @@ public class ChecksummedFileTest public void testCalculateChecksumSha1() throws IOException { - File testfile = getTestResource( "examples/redback-authz-open.jar" ); + Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String expectedChecksum = "2bb14b388973351b0a4dfe11d171965f59cc61a1"; String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ); @@ -121,12 +127,12 @@ public class ChecksummedFileTest public void testCreateChecksum() throws IOException { - File testableJar = createTestableJar( "examples/redback-authz-open.jar" ); + Path testableJar = createTestableJar( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testableJar ); checksummedFile.createChecksum( ChecksumAlgorithm.SHA1 ); - File hashFile = checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ); - assertTrue( "ChecksumAlgorithm file should exist.", hashFile.exists() ); - String hashContents = FileUtils.readFileToString( hashFile ); + Path hashFile = checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ); + assertTrue( "ChecksumAlgorithm file should exist.", Files.exists(hashFile) ); + String hashContents = org.apache.commons.io.FileUtils.readFileToString( hashFile.toFile() ); hashContents = StringUtils.trim( hashContents ); assertEquals( "2bb14b388973351b0a4dfe11d171965f59cc61a1 redback-authz-open.jar", hashContents ); } @@ -135,11 +141,11 @@ public class ChecksummedFileTest public void testFixChecksum() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar" ); - File sha1File = new File( jarFile.getAbsolutePath() + ".sha1" ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar" ); + Path sha1File = jarFile.resolveSibling( jarFile.getFileName()+ ".sha1" ); // A typical scenario seen in the wild. - FileUtils.writeStringToFile( sha1File, "sha1sum: redback-authz-open.jar: No such file or directory" ); + org.apache.commons.io.FileUtils.writeStringToFile( sha1File.toFile(), "sha1sum: redback-authz-open.jar: No such file or directory" ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertFalse( "ChecksummedFile.isValid(SHA1) == false", @@ -155,15 +161,15 @@ public class ChecksummedFileTest @Test public void testGetChecksumFile() { - ChecksummedFile checksummedFile = new ChecksummedFile( new File( "test.jar" ) ); - assertEquals( "test.jar.sha1", checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ).getName() ); + ChecksummedFile checksummedFile = new ChecksummedFile( Paths.get( "test.jar" ) ); + assertEquals( "test.jar.sha1", checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ).getFileName().toString() ); } @Test public void testIsValidChecksum() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) ); @@ -173,11 +179,11 @@ public class ChecksummedFileTest public void testIsValidChecksumInvalidSha1Format() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar" ); - File sha1File = new File( jarFile.getAbsolutePath() + ".sha1" ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar" ); + Path sha1File = jarFile.resolveSibling( jarFile.getFileName() + ".sha1" ); // A typical scenario seen in the wild. - FileUtils.writeStringToFile( sha1File, "sha1sum: redback-authz-open.jar: No such file or directory" ); + FileUtils.writeStringToFile( sha1File, FILE_ENCODING, "sha1sum: redback-authz-open.jar: No such file or directory" ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertFalse( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) ); @@ -188,7 +194,7 @@ public class ChecksummedFileTest public void testIsValidChecksumNoChecksumFiles() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar", false, false ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar", false, false ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertFalse( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( @@ -200,7 +206,7 @@ public class ChecksummedFileTest public void testIsValidChecksumSha1AndMd5() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar", true, true ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, true ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertTrue( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( @@ -211,7 +217,7 @@ public class ChecksummedFileTest public void testIsValidChecksumSha1NoMd5() throws IOException { - File jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false ); + Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false ); ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksums( @@ -226,7 +232,7 @@ public class ChecksummedFileTest String expected = SERVLETAPI_SHA1 + " /home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom"; - File testfile = getTestResource( "examples/redback-authz-open.jar" ); + Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String s = checksummedFile.parseChecksum( expected, ChecksumAlgorithm.SHA1, "servletapi/servletapi/2.4/servletapi-2.4.pom" ); @@ -239,7 +245,7 @@ public class ChecksummedFileTest throws IOException { String expected = SERVLETAPI_SHA1 + " -"; - File testfile = getTestResource( "examples/redback-authz-open.jar" ); + Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String s = checksummedFile.parseChecksum( expected, ChecksumAlgorithm.SHA1, "servletapi/servletapi/2.4/servletapi-2.4.pom" ); @@ -251,7 +257,7 @@ public class ChecksummedFileTest throws IOException { String expected = "SHA1(-)=" + SERVLETAPI_SHA1; - File testfile = getTestResource( "examples/redback-authz-open.jar" ); + Path testfile = getTestResource( "examples/redback-authz-open.jar" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); String s = checksummedFile.parseChecksum( expected, ChecksumAlgorithm.SHA1, "servletapi/servletapi/2.4/servletapi-2.4.pom" ); @@ -263,7 +269,7 @@ public class ChecksummedFileTest throws IOException { String expected = REMOTE_METADATA_SHA1 + " /home/test/repository/examples/metadata/maven-metadata.xml"; - File testfile = getTestResource( "examples/metadata/maven-metadata-remote.xml" ); + Path testfile = getTestResource( "examples/metadata/maven-metadata-remote.xml" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); try @@ -283,7 +289,7 @@ public class ChecksummedFileTest throws IOException { String expected = REMOTE_METADATA_MD5 + " ./examples/metadata/maven-metadata.xml"; - File testfile = getTestResource( "examples/metadata/maven-metadata-remote.xml" ); + Path testfile = getTestResource( "examples/metadata/maven-metadata-remote.xml" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); try diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtil.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtil.java deleted file mode 100644 index d60a3a53d..000000000 --- a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/common/utils/FileUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -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 java.io.File; - -public class FileUtil -{ - public static String getBasedir() - { - String basedir = System.getProperty( "basedir" ); - if ( basedir == null ) - { - basedir = new File( "" ).getAbsolutePath(); - } - - return basedir; - } -} \ No newline at end of file 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 0c8683d98..71dcb8da1 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 @@ -18,9 +18,15 @@ package org.apache.archiva.common.utils; * under the License. */ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + 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.StandardOpenOption; import java.util.Comparator; import java.util.Optional; @@ -32,6 +38,7 @@ import java.util.Optional; */ public class FileUtils { + private static final Logger log = LoggerFactory.getLogger( FileUtils.class ); /** * Deletes the directory recursively and quietly. * @@ -85,4 +92,44 @@ public class FileUtils throw new IOException("Error during recursive delete of "+dir.toAbsolutePath()); } } + + public static String readFileToString( Path file, Charset encoding) + { + try + { + return new String(Files.readAllBytes( file ), encoding ); + } + catch ( IOException e ) + { + log.error("Could not read from file {}", file); + return ""; + } + } + + public static void writeStringToFile( Path file, Charset encoding, String value ) + { + try + { + Files.write( file, value.getBytes( encoding ), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + } + catch ( IOException e ) + { + log.error("Could not write to file {}", file); + } + } + + /** + * Return the base directory + * @return + */ + public static String getBasedir() + { + String basedir = System.getProperty( "basedir" ); + if ( basedir == null ) + { + basedir = Paths.get("").toAbsolutePath().toString(); + } + + return basedir; + } } diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationMRM789Test.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationMRM789Test.java index 7811bdfc6..c91d2f841 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationMRM789Test.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationMRM789Test.java @@ -25,7 +25,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import javax.inject.Inject; -import org.apache.archiva.common.utils.FileUtil; + import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -53,7 +53,7 @@ public class ArchivaConfigurationMRM789Test public static Path getTestFile( String path ) { - return Paths.get( FileUtil.getBasedir(), path ); + return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); } protected T lookup( Class clazz, String hint ) @@ -66,18 +66,18 @@ public class ArchivaConfigurationMRM789Test public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting() throws Exception { - Path repo = Paths.get( FileUtil.getBasedir(), "target/test-classes/existing_snapshots" ); + Path repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_snapshots" ); Files.createDirectories(repo); - repo = Paths.get( FileUtil.getBasedir(), "target/test-classes/existing_internal" ); + repo = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_internal" ); Files.createDirectories(repo); String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString( getTestFile( "target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml" ).toFile(), FILE_ENCODING ); existingTestDefaultArchivaConfigFile = - StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", FileUtil.getBasedir() ); + StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", org.apache.archiva.common.utils.FileUtils.getBasedir() ); - Path generatedTestDefaultArchivaConfigFile = Paths.get( FileUtil.getBasedir(), + Path generatedTestDefaultArchivaConfigFile = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/org/apache/archiva/configuration/default-archiva.xml" ); FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile.toFile(), existingTestDefaultArchivaConfigFile, diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java index 1cc64ccd2..ca4312cf6 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java @@ -19,7 +19,6 @@ package org.apache.archiva.configuration; * under the License. */ -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; @@ -63,7 +62,7 @@ public class ArchivaConfigurationTest public static Path getTestFile( String path ) { - return Paths.get( FileUtil.getBasedir(), path ); + return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); } protected T lookup( Class clazz, String hint ) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java index 9984b0b06..58e93b5dd 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java @@ -157,7 +157,7 @@ public class ArtifactMissingChecksumsConsumer if ( checksumFile.exists( ) ) { - checksum = new ChecksummedFile( artifactFile ); + checksum = new ChecksummedFile( artifactFile.toPath() ); try { if ( !checksum.isValidChecksum( checksumAlgorithm ) ) @@ -176,7 +176,7 @@ public class ArtifactMissingChecksumsConsumer } else if ( !checksumFile.exists( ) ) { - checksum = new ChecksummedFile( artifactFile ); + checksum = new ChecksummedFile( artifactFile.toPath() ); try { checksum.createChecksum( checksumAlgorithm ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java index bf4f85b24..824e7678d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java @@ -105,7 +105,7 @@ public class ArtifactMissingChecksumsConsumerTest Path md5Path = Paths.get( repoConfig.getLocation(), path + ".md5" ); - ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) ); + ChecksummedFile checksum = new ChecksummedFile( Paths.get(repoConfig.getLocation(), path ) ); Assertions.assertThat( sha1Path.toFile() ).exists(); Assertions.assertThat( md5Path.toFile() ).exists(); diff --git a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverterTest.java b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverterTest.java index a737e845e..8d79bd682 100644 --- a/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverterTest.java +++ b/archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverterTest.java @@ -21,7 +21,6 @@ package org.apache.archiva.converter.artifact; import junit.framework.TestCase; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.artifact.Artifact; @@ -108,7 +107,7 @@ public class LegacyToDefaultConverterTest public static File getTestFile( String path ) { - return new File( FileUtil.getBasedir(), path ); + return new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); } private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory ) @@ -429,7 +428,7 @@ public class LegacyToDefaultConverterTest Artifact artifact = createArtifact( "org.apache.maven.plugins", "maven-foo-plugin", "1.0", "1.0", "maven-plugin" ); artifact.setFile( - new File( FileUtil.getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) ); + new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/source-repository/test/plugins/maven-foo-plugin-1.0.jar" ) ); artifactConverter.convert( artifact, targetRepository ); // There is a warning but I can't figure out how to look at it. Eyeballing the results it appears // the plugin is being coverted correctly. diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java index e3b96f043..f9e2cf301 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractMavenRepositorySearch.java @@ -23,7 +23,6 @@ import junit.framework.TestCase; import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; @@ -99,11 +98,11 @@ public abstract class AbstractMavenRepositorySearch { super.setUp(); - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ).exists() ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ) ); + assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer" ).exists() ); - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ).exists() ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) ); + assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ).exists() ); archivaConfigControl = EasyMock.createControl(); @@ -137,11 +136,11 @@ public abstract class AbstractMavenRepositorySearch nexusIndexer.removeIndexingContext( indexingContext, true ); } - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_1 ).exists() ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 ) ); + assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 ).exists() ); - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 ) ); - assertFalse( new File( FileUtil.getBasedir(), "/target/repos/" + TEST_REPO_2 ).exists() ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 ) ); + assertFalse( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 ).exists() ); super.tearDown(); } @@ -150,7 +149,7 @@ public abstract class AbstractMavenRepositorySearch { ManagedRepositoryConfiguration repositoryConfig = new ManagedRepositoryConfiguration(); repositoryConfig.setId( repository ); - repositoryConfig.setLocation( FileUtil.getBasedir() + "/target/repos/" + repository ); + repositoryConfig.setLocation( org.apache.archiva.common.utils.FileUtils.getBasedir() + "/target/repos/" + repository ); File f = new File( repositoryConfig.getLocation() ); if ( !f.exists() ) { @@ -176,7 +175,7 @@ public abstract class AbstractMavenRepositorySearch nexusIndexer.removeIndexingContext( context, true ); } - File indexerDirectory = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" ); + File indexerDirectory = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer" ); if ( indexerDirectory.exists() ) { @@ -185,7 +184,7 @@ public abstract class AbstractMavenRepositorySearch assertFalse( indexerDirectory.exists() ); - File lockFile = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" ); + File lockFile = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" ); if ( lockFile.exists() ) { lockFile.delete(); @@ -193,10 +192,10 @@ public abstract class AbstractMavenRepositorySearch assertFalse( lockFile.exists() ); - File repo = new File( FileUtil.getBasedir(), "src/test/" + repository ); + File repo = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository ); assertTrue( repo.exists() ); File indexDirectory = - new File( FileUtil.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) ); + new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) ); indexDirectory.deleteOnExit(); FileUtils.deleteDirectory( indexDirectory ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java index 6d4f6acab..596851362 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/MavenRepositorySearchTest.java @@ -19,7 +19,6 @@ package org.apache.archiva.indexer.search; * under the License. */ -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.indexer.util.SearchUtil; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index_shaded.lucene.index.IndexUpgrader; @@ -49,11 +48,11 @@ public class MavenRepositorySearchTest throws Exception { List files = new ArrayList<>(); - files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1, "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ).toFile() ); - files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1, "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ).toFile() ); - files.add( Paths.get( FileUtil.getBasedir(), "src/test", TEST_REPO_1, + files.add( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test", TEST_REPO_1, "org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ).toFile() ); createIndex( TEST_REPO_1, files, scan ); @@ -63,19 +62,19 @@ public class MavenRepositorySearchTest throws Exception { List files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-webapp/1.0/archiva-webapp-1.0.war" ) ); - files.add( new File( FileUtil.getBasedir(), + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/classname-search/1.0/classname-search-1.0.jar" ) ); createIndex( TEST_REPO_1, files, scan ); @@ -86,13 +85,13 @@ public class MavenRepositorySearchTest { List files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.pom" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) ); createIndex( TEST_REPO_1, files, scan ); @@ -327,9 +326,9 @@ public class MavenRepositorySearchTest createSimpleIndex( true ); List files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) ); createIndex( TEST_REPO_2, files, false ); @@ -458,9 +457,9 @@ public class MavenRepositorySearchTest throws Exception { List files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_2 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_2 + "/org/apache/archiva/archiva-search/1.1/archiva-search-1.1.jar" ) ); createIndex( TEST_REPO_2, files, false ); @@ -544,9 +543,9 @@ public class MavenRepositorySearchTest throws Exception { List files = new ArrayList<>(); - files.add( new File( FileUtil.getBasedir(), + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric/1.0/artifactid-numeric-1.0.jar" ) ); - files.add( new File( FileUtil.getBasedir(), "src/test/" + TEST_REPO_1 + files.add( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + TEST_REPO_1 + "/com/artifactid-numeric123/1.0/artifactid-numeric123-1.0.jar" ) ); createIndex( TEST_REPO_1, files, true ); diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java index 00e37a839..7c2193361 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java @@ -108,7 +108,7 @@ public class ChecksumPolicy if ( FAIL.equals( policySetting ) ) { - ChecksummedFile checksum = new ChecksummedFile( localFile ); + ChecksummedFile checksum = new ChecksummedFile( localFile.toPath() ); if ( checksum.isValidChecksums( algorithms ) ) { return; @@ -131,7 +131,7 @@ public class ChecksumPolicy if ( FIX.equals( policySetting ) ) { - ChecksummedFile checksum = new ChecksummedFile( localFile ); + ChecksummedFile checksum = new ChecksummedFile( localFile.toPath() ); if ( checksum.fixChecksums( algorithms ) ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java index 0ecce463a..ec1cd2165 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java +++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ChecksumPolicyTest.java @@ -20,7 +20,6 @@ package org.apache.archiva.policies; */ import org.apache.commons.io.FileUtils; -import org.apache.archiva.common.utils.FileUtil; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -365,7 +364,7 @@ public class ChecksumPolicyTest public static File getTestFile( String path ) { - return new File( FileUtil.getBasedir(), path ); + return new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); } } 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 5869f6730..5043594df 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,7 +28,6 @@ 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; @@ -65,7 +64,6 @@ import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.scheduler.ArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.model.RepositoryTask; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.SystemUtils; @@ -88,7 +86,6 @@ 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; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 01f733767..d54c797b0 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -23,7 +23,6 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ProxyConnectorConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; @@ -43,7 +42,6 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java index 71258fc08..d04de274d 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java @@ -477,7 +477,7 @@ public class MetadataTools RepositoryMetadataWriter.write( metadata, metadataFile ); - ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() ); + ChecksummedFile checksum = new ChecksummedFile( metadataFile ); checksum.fixChecksums( algorithms ); } @@ -650,7 +650,7 @@ public class MetadataTools // Save the metadata model to disk. RepositoryMetadataWriter.write( metadata, metadataFile ); - ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() ); + ChecksummedFile checksum = new ChecksummedFile( metadataFile ); checksum.fixChecksums( algorithms ); } @@ -890,7 +890,7 @@ public class MetadataTools // Save the metadata model to disk. RepositoryMetadataWriter.write( metadata, metadataFile ); - ChecksummedFile checksum = new ChecksummedFile( metadataFile.toFile() ); + ChecksummedFile checksum = new ChecksummedFile( metadataFile ); checksum.fixChecksums( algorithms ); } diff --git a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java index 360f64df8..6a707ab9a 100644 --- a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java +++ b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java @@ -20,7 +20,6 @@ package org.apache.archiva.transaction; */ import org.apache.commons.io.FileUtils; -import org.apache.archiva.common.utils.FileUtil; import java.io.File; import java.io.IOException; @@ -33,11 +32,11 @@ import org.junit.Test; public class CopyFileEventTest extends AbstractFileEventTest { - private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/copy-file" ); + private File testDir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests/copy-file" ); private File testDest = new File( testDir, "test-file.txt" ); - private File testSource = new File( FileUtil.getBasedir(), "target/transaction-tests/test-file.txt" ); + private File testSource = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests/test-file.txt" ); private File testDestChecksum; @@ -163,7 +162,7 @@ public class CopyFileEventTest { super.tearDown(); - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests" ) ); } @Override diff --git a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java index 42b2f6245..0f8695220 100644 --- a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java +++ b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java @@ -22,7 +22,6 @@ package org.apache.archiva.transaction; import java.io.File; import org.apache.commons.io.FileUtils; -import org.apache.archiva.common.utils.FileUtil; import org.junit.After; import org.junit.Test; @@ -31,7 +30,7 @@ import org.junit.Test; public class CreateFileEventTest extends AbstractFileEventTest { - private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/create-file" ); + private File testDir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests/create-file" ); @Test public void testCreateCommitRollback() @@ -56,7 +55,7 @@ public class CreateFileEventTest assertChecksumRollback( testFile ); assertFalse( "Test file parent directories has been rolledback too", testDir.exists() ); - assertTrue( "target directory still exists", new File( FileUtil.getBasedir(), "target" ).exists() ); + assertTrue( "target directory still exists", new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target" ).exists() ); } @Test @@ -122,6 +121,6 @@ public class CreateFileEventTest { super.tearDown(); - FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) ); + FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests" ) ); } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java index ef0dd86ed..b7e630e1e 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/DownloadRemoteIndexTaskTest.java @@ -20,7 +20,7 @@ package org.apache.archiva.scheduler.indexing; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; -import org.apache.archiva.common.utils.FileUtil; +import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.maven.index.FlatSearchRequest; import org.apache.maven.index.FlatSearchResponse; @@ -145,7 +145,7 @@ public class DownloadRemoteIndexTaskTest { RemoteRepository remoteRepository = new RemoteRepository(); File indexDirectory = - new File( FileUtil.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) ); + new File( FileUtils.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) ); indexDirectory.mkdirs(); indexDirectory.deleteOnExit(); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 629a44d6c..1f0fd73cb 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -557,7 +557,7 @@ public class DefaultRepositoriesService private void fixChecksums( File file ) { - ChecksummedFile checksum = new ChecksummedFile( file ); + ChecksummedFile checksum = new ChecksummedFile( file.toPath() ); checksum.fixChecksums( algorithms ); } @@ -1188,7 +1188,7 @@ public class DefaultRepositoriesService metadata.setAvailableVersions( availableVersions ); RepositoryMetadataWriter.write( metadata, metadataFile.toPath() ); - ChecksummedFile checksum = new ChecksummedFile( metadataFile ); + ChecksummedFile checksum = new ChecksummedFile( metadataFile.toPath() ); checksum.fixChecksums( algorithms ); } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java index bc1b545ab..cce73ba2b 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java @@ -21,7 +21,6 @@ package org.apache.archiva.rest.services; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.redback.rest.api.services.RedbackServiceException; import org.apache.archiva.redback.rest.services.AbstractRestServicesTest; import org.apache.archiva.rest.api.services.ArchivaAdministrationService; @@ -45,7 +44,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; -import org.junit.After; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; @@ -334,7 +332,7 @@ public abstract class AbstractArchivaRestTest protected ManagedRepository getTestManagedRepository() { - String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath(); + String location = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repo" ).getAbsolutePath(); return new ManagedRepository( "TEST", "test", location, "default", true, true, false, "2 * * * * ?", null, false, 2, 3, true, false, "my nice repo", false ); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java index f745c043d..aab1ea962 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java @@ -20,7 +20,6 @@ package org.apache.archiva.rest.services; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; @@ -542,7 +541,7 @@ public class RepositoriesServiceTest protected ManagedRepository getTestManagedRepository( String id, String path ) { - String location = new File( FileUtil.getBasedir(), "target/" + path ).getAbsolutePath(); + String location = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/" + path ).getAbsolutePath(); return new ManagedRepository( id, id, location, "default", true, true, true, "2 * * * * ?", null, false, 80, 80, true, false ); } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java index b272489c1..d3b67064e 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java @@ -551,7 +551,7 @@ public class DefaultFileUploadService private void fixChecksums( File file ) { - ChecksummedFile checksum = new ChecksummedFile( file ); + ChecksummedFile checksum = new ChecksummedFile( file.toPath() ); checksum.fixChecksums( algorithms ); } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java index 37c1b9186..44a77e037 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java @@ -883,7 +883,7 @@ public class Maven2RepositoryStorage { metadata.setWhenGathered( new Date() ); metadata.setFileLastModified( file.lastModified() ); - ChecksummedFile checksummedFile = new ChecksummedFile( file ); + ChecksummedFile checksummedFile = new ChecksummedFile( file.toPath() ); try { metadata.setMd5( checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 ) ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java index dcc05ea11..ed630ad66 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411RepoGroupTest.java @@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository.storage.maven2; */ import junit.framework.TestCase; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; @@ -494,15 +493,15 @@ public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest { for ( String path : pathsToBeDeleted ) { - File dir = new File( FileUtil.getBasedir(), path ); + File dir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); FileUtils.deleteDirectory( dir ); assertFalse( dir.exists() ); } - File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); File parentPom = - new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); - File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); + new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); + File rootPom = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); FileUtils.deleteDirectory( dest ); FileUtils.deleteDirectory( parentPom ); @@ -516,8 +515,8 @@ public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest private File copyTestArtifactWithParent( String srcPath, String destPath ) throws IOException { - File src = new File( FileUtil.getBasedir(), srcPath ); - File dest = new File( FileUtil.getBasedir(), destPath ); + File src = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath ); FileUtils.copyDirectory( src, dest ); assertTrue( dest.exists() ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java index 0b2f65071..5242414ba 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java @@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository.storage.maven2; */ import junit.framework.TestCase; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; @@ -398,15 +397,15 @@ public class Maven2RepositoryMetadataResolverMRM1411Test { for ( String path : pathsToBeDeleted ) { - File dir = new File( FileUtil.getBasedir(), path ); + File dir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); FileUtils.deleteDirectory( dir ); assertFalse( dir.exists() ); } - File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); File parentPom = - new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); - File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); + new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); + File rootPom = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); FileUtils.deleteDirectory( dest ); FileUtils.deleteDirectory( parentPom ); @@ -420,8 +419,8 @@ public class Maven2RepositoryMetadataResolverMRM1411Test private File copyTestArtifactWithParent( String srcPath, String destPath ) throws IOException { - File src = new File( FileUtil.getBasedir(), srcPath ); - File dest = new File( FileUtil.getBasedir(), destPath ); + File src = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath ); FileUtils.copyDirectory( src, dest ); assertTrue( dest.exists() ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index 24e9b2609..46ef5ac54 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository.storage.maven2; */ import junit.framework.TestCase; -import org.apache.archiva.common.utils.FileUtil; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; @@ -53,7 +52,6 @@ import javax.inject.Named; import java.io.File; import java.io.IOException; import java.net.URL; -import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -773,15 +771,15 @@ public class Maven2RepositoryMetadataResolverTest { for ( String path : pathsToBeDeleted ) { - File dir = new File( FileUtil.getBasedir(), path ); + File dir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); FileUtils.deleteDirectory( dir ); assertFalse( dir.exists() ); } - File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" ); File parentPom = - new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); - File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); + new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" ); + File rootPom = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" ); FileUtils.deleteDirectory( dest ); FileUtils.deleteDirectory( parentPom ); @@ -795,8 +793,8 @@ public class Maven2RepositoryMetadataResolverTest private File copyTestArtifactWithParent( String srcPath, String destPath ) throws IOException { - File src = new File( FileUtil.getBasedir(), srcPath ); - File dest = new File( FileUtil.getBasedir(), destPath ); + File src = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), srcPath ); + File dest = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), destPath ); FileUtils.copyDirectory( src, dest ); assertTrue( dest.exists() ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java index 7a81e13c6..54ff2e947 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/content/maven2/RepositoryRequestTest.java @@ -20,7 +20,7 @@ package org.apache.archiva.repository.content.maven2; */ import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.common.utils.FileUtil; +import org.apache.archiva.common.utils.FileUtils; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.repository.ManagedRepositoryContent; @@ -368,7 +368,7 @@ public class RepositoryRequestTest private ManagedRepositoryContent createManagedRepo( String layout ) throws Exception { - File repoRoot = new File( FileUtil.getBasedir() + "/target/test-repo" ); + File repoRoot = new File( FileUtils.getBasedir() + "/target/test-repo" ); return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout ); } diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java index 498300404..5fcb71731 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java @@ -149,7 +149,7 @@ public class DuplicateArtifactsConsumer // alternatively this could come straight from the storage resolver, which could populate the artifact metadata // in the later parse call with the desired checksum and use that String checksumSha1; - ChecksummedFile checksummedFile = new ChecksummedFile( artifactFile ); + ChecksummedFile checksummedFile = new ChecksummedFile( artifactFile.toPath() ); try { checksumSha1 = checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 ); -- 2.39.5