From: Martin Stockhammer Date: Tue, 5 Sep 2017 21:28:55 +0000 (+0200) Subject: Migrating policies module to java.nio X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5437dfd6de11e16815ca184c296d2eafdff6905b;p=archiva.git Migrating policies module to java.nio --- 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 9874fc75d..e2946ff00 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 @@ -47,7 +47,6 @@ import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; diff --git a/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java b/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java index ade5a1fc0..22eb836e9 100644 --- a/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java +++ b/archiva-modules/archiva-base/archiva-maven2-metadata/src/main/java/org/apache/archiva/maven2/metadata/MavenMetadataReader.java @@ -25,8 +25,12 @@ import org.apache.archiva.xml.XMLException; import org.apache.archiva.xml.XMLReader; import org.apache.commons.lang.math.NumberUtils; import org.dom4j.Element; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Date; /** @@ -58,6 +62,8 @@ public class MavenMetadataReader */ + private static final Logger log = LoggerFactory.getLogger( MavenMetadataReader.class ); + /** * Read and return the {@link org.apache.archiva.model.ArchivaRepositoryMetadata} object from the provided xml file. * @@ -65,11 +71,11 @@ public class MavenMetadataReader * @return the archiva repository metadata object that represents the provided file contents. * @throws XMLException */ - public static ArchivaRepositoryMetadata read( File metadataFile ) + public static ArchivaRepositoryMetadata read( Path metadataFile ) throws XMLException { - XMLReader xml = new XMLReader( "metadata", metadataFile ); + XMLReader xml = new XMLReader( "metadata", metadataFile.toFile() ); // invoke this to remove namespaces, see MRM-1136 xml.removeNamespaces(); @@ -78,8 +84,26 @@ public class MavenMetadataReader metadata.setGroupId( xml.getElementText( "//metadata/groupId" ) ); metadata.setArtifactId( xml.getElementText( "//metadata/artifactId" ) ); metadata.setVersion( xml.getElementText( "//metadata/version" ) ); - metadata.setFileLastModified( new Date( metadataFile.lastModified() ) ); - metadata.setFileSize( metadataFile.length() ); + Date modTime; + try + { + modTime = new Date(Files.getLastModifiedTime( metadataFile ).toMillis( )); + } + catch ( IOException e ) + { + modTime = new Date(); + log.error("Could not read modification time of {}", metadataFile); + } + metadata.setFileLastModified( modTime ); + try + { + metadata.setFileSize( Files.size( metadataFile ) ); + } + catch ( IOException e ) + { + metadata.setFileSize( 0 ); + log.error("Could not read file size of {}", metadataFile); + } metadata.setLastUpdated( xml.getElementText( "//metadata/versioning/lastUpdated" ) ); metadata.setLatestVersion( xml.getElementText( "//metadata/versioning/latest" ) ); diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java index 103c7a458..1fbbfece5 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/AbstractUpdatePolicy.java @@ -24,9 +24,12 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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.Calendar; +import java.util.Date; import java.util.List; import java.util.Properties; @@ -103,7 +106,7 @@ public abstract class AbstractUpdatePolicy } @Override - public void applyPolicy( String policySetting, Properties request, File localFile ) + public void applyPolicy( String policySetting, Properties request, Path localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !StringUtils.equals( request.getProperty( "filetype" ), "artifact" ) ) @@ -154,7 +157,7 @@ public abstract class AbstractUpdatePolicy throw new PolicyViolationException( "NO to update, " + getUpdateMode() + " policy set to NEVER." ); } - if ( !localFile.exists() ) + if ( !Files.exists(localFile) ) { // No file means it's ok. log.debug( "OK to update {}, local file does not exist.", getUpdateMode() ); @@ -173,7 +176,15 @@ public abstract class AbstractUpdatePolicy Calendar cal = Calendar.getInstance(); cal.add( Calendar.DAY_OF_MONTH, -1 ); Calendar fileCal = Calendar.getInstance(); - fileCal.setTimeInMillis( localFile.lastModified() ); + try + { + fileCal.setTimeInMillis( Files.getLastModifiedTime(localFile).toMillis() ); + } + catch ( IOException e ) + { + fileCal.setTimeInMillis( new Date().getTime() ); + log.error("Could not read modification time of {}", localFile); + } if ( cal.after( fileCal ) ) { @@ -192,7 +203,15 @@ public abstract class AbstractUpdatePolicy Calendar cal = Calendar.getInstance(); cal.add( Calendar.HOUR, -1 ); Calendar fileCal = Calendar.getInstance(); - fileCal.setTimeInMillis( localFile.lastModified() ); + try + { + fileCal.setTimeInMillis( Files.getLastModifiedTime(localFile).toMillis() ); + } + catch ( IOException e ) + { + fileCal.setTimeInMillis( new Date().getTime() ); + log.error("Could not read modification time of {}", localFile); + } if ( cal.after( fileCal ) ) { diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java index 62e76a4d6..e92858fe8 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/CachedFailuresPolicy.java @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.inject.Inject; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -64,7 +64,7 @@ public class CachedFailuresPolicy } @Override - public void applyPolicy( String policySetting, Properties request, File localFile ) + public void applyPolicy( String policySetting, Properties request, Path localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) 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 7c2193361..975139c65 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 @@ -26,7 +26,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -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.List; import java.util.Properties; @@ -76,7 +78,7 @@ public class ChecksumPolicy } @Override - public void applyPolicy( String policySetting, Properties request, File localFile ) + public void applyPolicy( String policySetting, Properties request, Path localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( "resource".equals( request.getProperty( "filetype" ) ) ) @@ -99,16 +101,16 @@ public class ChecksumPolicy return; } - if ( !localFile.exists() ) + if ( !Files.exists(localFile) ) { // Local File does not exist. throw new PolicyViolationException( - "Checksum policy failure, local file " + localFile.getAbsolutePath() + " does not exist to check." ); + "Checksum policy failure, local file " + localFile.toAbsolutePath() + " does not exist to check." ); } if ( FAIL.equals( policySetting ) ) { - ChecksummedFile checksum = new ChecksummedFile( localFile.toPath() ); + ChecksummedFile checksum = new ChecksummedFile( localFile ); if ( checksum.isValidChecksums( algorithms ) ) { return; @@ -116,22 +118,33 @@ public class ChecksumPolicy for ( ChecksumAlgorithm algorithm : algorithms ) { - File file = new File( localFile.getAbsolutePath() + "." + algorithm.getExt() ); - if ( file.exists() ) + Path file = localFile.toAbsolutePath().resolveSibling( localFile.getFileName() + "." + algorithm.getExt() ); + try { - file.delete(); + Files.deleteIfExists( file ); + } + catch ( IOException e ) + { + log.error("Could not delete file {}", file); } } - localFile.delete(); + try + { + Files.deleteIfExists( localFile ); + } + catch ( IOException e ) + { + log.error("Could not delete file {}", localFile); + } throw new PolicyViolationException( "Checksums do not match, policy set to FAIL, " + "deleting checksum files and local file " - + localFile.getAbsolutePath() + "." ); + + localFile.toAbsolutePath() + "." ); } if ( FIX.equals( policySetting ) ) { - ChecksummedFile checksum = new ChecksummedFile( localFile.toPath() ); + ChecksummedFile checksum = new ChecksummedFile( localFile ); if ( checksum.fixChecksums( algorithms ) ) { log.debug( "Checksum policy set to FIX, checksum files have been updated." ); @@ -141,7 +154,7 @@ public class ChecksumPolicy { throw new PolicyViolationException( "Checksum policy set to FIX, " + "yet unable to update checksums for local file " - + localFile.getAbsolutePath() + "." ); + + localFile.toAbsolutePath() + "." ); } } diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java index 971afc763..90261737e 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadErrorPolicy.java @@ -19,7 +19,7 @@ package org.apache.archiva.policies; * under the License. */ -import java.io.File; +import java.nio.file.Path; import java.util.Map; import java.util.Properties; @@ -43,7 +43,7 @@ public interface DownloadErrorPolicy * @return whether to process the exception or not * @throws PolicyConfigurationException if the policy is improperly configured */ - boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception, - Map previousExceptions ) + boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception, + Map previousExceptions ) throws PolicyConfigurationException; } diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java index 1a25043d6..8d149e619 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/DownloadPolicy.java @@ -19,7 +19,7 @@ package org.apache.archiva.policies; * under the License. */ -import java.io.File; +import java.nio.file.Path; import java.util.Properties; /** @@ -40,6 +40,6 @@ public interface DownloadPolicy * * @throws PolicyViolationException if the policy has been violated. */ - void applyPolicy( String policySetting, Properties request, File localFile ) + void applyPolicy( String policySetting, Properties request, Path localFile ) throws PolicyViolationException, PolicyConfigurationException; } diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java index 5813cd5ae..1fab1209a 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsDownloadPolicy.java @@ -24,7 +24,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -64,7 +64,7 @@ public class PropagateErrorsDownloadPolicy } @Override - public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception, + public boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception, Map previousExceptions ) throws PolicyConfigurationException { diff --git a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java index 14732f1ec..ec3289105 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java +++ b/archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/PropagateErrorsOnUpdateDownloadPolicy.java @@ -22,7 +22,8 @@ package org.apache.archiva.policies; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -54,7 +55,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy } @Override - public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception, + public boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception, Map previousExceptions ) throws PolicyConfigurationException { @@ -75,7 +76,7 @@ public class PropagateErrorsOnUpdateDownloadPolicy if ( NOT_PRESENT.equals( policySetting ) ) { // cancel the exception if the file exists - return !localFile.exists(); + return !Files.exists(localFile); } throw new PolicyConfigurationException( diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java index 6f46b6845..2c9995c0b 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java +++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/CachedFailuresPolicyTest.java @@ -21,15 +21,16 @@ package org.apache.archiva.policies; import junit.framework.TestCase; import org.apache.archiva.policies.urlcache.UrlFailureCache; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Properties; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; /** * CachedFailuresPolicyTest @@ -56,9 +57,9 @@ public class CachedFailuresPolicyTest return downloadPolicy; } - private File getFile() + private Path getFile() { - return new File( "target/cache-failures/" + getName() + ".txt" ); + return Paths.get( "target/cache-failures/" + getName() + ".txt" ); } private Properties createRequest() @@ -73,7 +74,7 @@ public class CachedFailuresPolicyTest throws Exception { DownloadPolicy policy = lookupPolicy(); - File localFile = getFile(); + Path localFile = getFile(); Properties request = createRequest(); request.setProperty( "url", "http://a.bad.hostname.maven.org/path/to/resource.txt" ); @@ -87,7 +88,7 @@ public class CachedFailuresPolicyTest { DownloadPolicy policy = lookupPolicy(); - File localFile = getFile(); + Path localFile = getFile(); Properties request = createRequest(); // make unique name String url = "http://a.bad.hostname.maven.org/path/to/resource"+ System.currentTimeMillis() +".txt"; 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 ec1cd2165..845074420 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 @@ -27,8 +27,10 @@ import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import java.io.BufferedReader; -import java.io.File; import java.io.FileReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Properties; import javax.inject.Inject; import javax.inject.Named; @@ -193,7 +195,7 @@ public class ChecksumPolicyTest throws Exception { PostDownloadPolicy policy = lookupPolicy(); - File localFile = createTestableFiles( null, null ); + Path localFile = createTestableFiles( null, null ); Properties request = createRequest(); policy.applyPolicy( ChecksumPolicy.IGNORE, request, localFile ); @@ -203,7 +205,7 @@ public class ChecksumPolicyTest throws Exception { PostDownloadPolicy policy = lookupPolicy(); - File localFile = createTestableFiles( md5State, sha1State ); + Path localFile = createTestableFiles( md5State, sha1State ); Properties request = createRequest(); boolean actualResult; @@ -218,11 +220,11 @@ public class ChecksumPolicyTest actualResult = false; String msg = createMessage( ChecksumPolicy.FAIL, md5State, sha1State ); - assertFalse( msg + " local file should not exist:", localFile.exists() ); - File md5File = new File( localFile.getAbsolutePath() + ".sha1" ); - File sha1File = new File( localFile.getAbsolutePath() + ".md5" ); - assertFalse( msg + " local md5 file should not exist:", md5File.exists() ); - assertFalse( msg + " local sha1 file should not exist:", sha1File.exists() ); + assertFalse( msg + " local file should not exist:", Files.exists(localFile) ); + Path md5File = localFile.toAbsolutePath().resolveSibling( localFile.getFileName() + ".sha1" ); + Path sha1File = localFile.toAbsolutePath().resolveSibling( localFile.getFileName() + ".md5" ); + assertFalse( msg + " local md5 file should not exist:", Files.exists(md5File) ); + assertFalse( msg + " local sha1 file should not exist:", Files.exists(sha1File) ); } assertEquals( createMessage( ChecksumPolicy.FAIL, md5State, sha1State ), expectedResult, actualResult ); @@ -232,7 +234,7 @@ public class ChecksumPolicyTest throws Exception { PostDownloadPolicy policy = lookupPolicy(); - File localFile = createTestableFiles( md5State, sha1State ); + Path localFile = createTestableFiles( md5State, sha1State ); Properties request = createRequest(); boolean actualResult; @@ -250,11 +252,11 @@ public class ChecksumPolicyTest assertEquals( createMessage( ChecksumPolicy.FIX, md5State, sha1State ), expectedResult, actualResult ); // End result should be legitimate SHA1 and MD5 files. - File md5File = new File( localFile.getAbsolutePath() + ".md5" ); - File sha1File = new File( localFile.getAbsolutePath() + ".sha1" ); + Path md5File = localFile.toAbsolutePath().resolveSibling( localFile.getFileName() + ".md5" ); + Path sha1File = localFile.toAbsolutePath().resolveSibling( localFile.getFileName() + ".sha1" ); - assertTrue( "ChecksumPolicy.apply(FIX) md5 should exist.", md5File.exists() && md5File.isFile() ); - assertTrue( "ChecksumPolicy.apply(FIX) sha1 should exist.", sha1File.exists() && sha1File.isFile() ); + assertTrue( "ChecksumPolicy.apply(FIX) md5 should exist.", Files.exists(md5File) && Files.isRegularFile(md5File) ); + assertTrue( "ChecksumPolicy.apply(FIX) sha1 should exist.", Files.exists(sha1File) && Files.isRegularFile(sha1File) ); String actualMd5Contents = readChecksumFile( md5File ); String actualSha1Contents = readChecksumFile( sha1File ); @@ -269,7 +271,7 @@ public class ChecksumPolicyTest /** * Read the first line from the checksum file, and return it (trimmed). */ - private String readChecksumFile( File checksumFile ) + private String readChecksumFile( Path checksumFile ) throws Exception { FileReader freader = null; @@ -277,7 +279,7 @@ public class ChecksumPolicyTest try { - freader = new FileReader( checksumFile ); + freader = new FileReader( checksumFile.toFile() ); buf = new BufferedReader( freader ); return buf.readLine(); } @@ -334,37 +336,37 @@ public class ChecksumPolicyTest return request; } - private File createTestableFiles( String md5State, String sha1State ) + private Path createTestableFiles( String md5State, String sha1State ) throws Exception { - File sourceDir = getTestFile( "src/test/resources/checksums/" ); - File destDir = getTestFile( "target/checksum-tests/" + name.getMethodName() + "/" ); + Path sourceDir = getTestFile( "src/test/resources/checksums/" ); + Path destDir = getTestFile( "target/checksum-tests/" + name.getMethodName() + "/" ); - FileUtils.copyFileToDirectory( new File( sourceDir, "artifact.jar" ), destDir ); + FileUtils.copyFileToDirectory( sourceDir.resolve("artifact.jar" ).toFile(), destDir.toFile() ); if ( md5State != null ) { - File md5File = new File( sourceDir, "artifact.jar.md5-" + md5State ); - assertTrue( "Testable file exists: " + md5File.getName() + ":", md5File.exists() && md5File.isFile() ); - File destFile = new File( destDir, "artifact.jar.md5" ); - FileUtils.copyFile( md5File, destFile ); + Path md5File = sourceDir.resolve("artifact.jar.md5-" + md5State ); + assertTrue( "Testable file exists: " + md5File.getFileName() + ":", Files.exists(md5File) && Files.isRegularFile(md5File) ); + Path destFile = destDir.resolve("artifact.jar.md5" ); + FileUtils.copyFile( md5File.toFile(), destFile.toFile() ); } if ( sha1State != null ) { - File sha1File = new File( sourceDir, "artifact.jar.sha1-" + sha1State ); - assertTrue( "Testable file exists: " + sha1File.getName() + ":", sha1File.exists() && sha1File.isFile() ); - File destFile = new File( destDir, "artifact.jar.sha1" ); - FileUtils.copyFile( sha1File, destFile ); + Path sha1File = sourceDir.resolve("artifact.jar.sha1-" + sha1State ); + assertTrue( "Testable file exists: " + sha1File.getFileName() + ":", Files.exists(sha1File) && Files.isRegularFile(sha1File) ); + Path destFile = destDir.resolve("artifact.jar.sha1" ); + FileUtils.copyFile( sha1File.toFile(), destFile.toFile() ); } - File localFile = new File( destDir, "artifact.jar" ); + Path localFile = destDir.resolve("artifact.jar" ); return localFile; } - public static File getTestFile( String path ) + public static Path getTestFile( String path ) { - return new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); + return Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), path ); } } diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java index 2a02605d0..4d45646d5 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java +++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/ReleasePolicyTest.java @@ -28,8 +28,13 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; -import java.io.File; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileTime; import java.util.Properties; +import java.util.concurrent.TimeUnit; + import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; /** @@ -42,6 +47,9 @@ import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; public class ReleasePolicyTest extends TestCase { + + private static final Charset FILE_ENCODING = Charset.forName( "UTF-8" ); + private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml"; private static final String PATH_PROJECT_METADATA = "org/apache/archiva/archiva-testable/maven-metadata.xml"; @@ -333,19 +341,17 @@ public class ReleasePolicyTest request.setProperty( "version", "2.0" ); } - File targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" ); - File localFile = new File( targetDir, path ); + Path targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" ); + Path localFile = targetDir.resolve( path ); - if ( localFile.exists() ) - { - localFile.delete(); - } + Files.deleteIfExists( localFile ); if ( createLocalFile ) { - localFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( localFile, "random-junk" ); - localFile.setLastModified( localFile.lastModified() - generatedLocalFileUpdateDelta ); + Files.createDirectories( localFile.getParent()); + org.apache.archiva.common.utils.FileUtils.writeStringToFile( localFile, FILE_ENCODING, "random-junk" ); + Files.setLastModifiedTime( localFile, + FileTime.fromMillis(Files.getLastModifiedTime(localFile).toMillis() - generatedLocalFileUpdateDelta)); } policy.applyPolicy( setting, request, localFile ); diff --git a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java index 50fec5799..5272777fe 100644 --- a/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java +++ b/archiva-modules/archiva-base/archiva-policies/src/test/java/org/apache/archiva/policies/SnapshotsPolicyTest.java @@ -20,7 +20,7 @@ package org.apache.archiva.policies; */ import junit.framework.TestCase; -import org.apache.commons.io.FileUtils; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,9 +28,11 @@ import org.springframework.test.context.ContextConfiguration; import javax.inject.Inject; import javax.inject.Named; -import java.io.File; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileTime; import java.util.Properties; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; /** * SnapshotsPolicyTest @@ -42,6 +44,8 @@ import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; public class SnapshotsPolicyTest extends TestCase { + private static final Charset FILE_ENCODING = Charset.forName( "UTF-8" ); + private static final String PATH_VERSION_METADATA = "org/apache/archiva/archiva-testable/1.0-SNAPSHOT/maven-metadata.xml"; private static final String PATH_PROJECT_METADATA = "org/apache/archiva/archiva-testable/maven-metadata.xml"; @@ -333,19 +337,17 @@ public class SnapshotsPolicyTest request.setProperty( "version", "2.0" ); } - File targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" ); - File localFile = new File( targetDir, path ); + Path targetDir = ChecksumPolicyTest.getTestFile( "target/test-policy/" ); + Path localFile = targetDir.resolve( path ); - if ( localFile.exists() ) - { - localFile.delete(); - } + Files.deleteIfExists( localFile ); if ( createLocalFile ) { - localFile.getParentFile().mkdirs(); - FileUtils.writeStringToFile( localFile, "random-junk" ); - localFile.setLastModified( localFile.lastModified() - generatedLocalFileUpdateDelta ); + Files.createDirectories( localFile.getParent()); + org.apache.archiva.common.utils.FileUtils.writeStringToFile( localFile, FILE_ENCODING, "random-junk" ); + Files.setLastModifiedTime( localFile, + FileTime.fromMillis( Files.getLastModifiedTime( localFile ).toMillis() - generatedLocalFileUpdateDelta )); } policy.applyPolicy( setting, request, localFile ); 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 5043594df..dc100f0ca 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 @@ -991,9 +991,9 @@ public class DefaultRepositoryProxyConnectors * @param policies the map of policies to execute. (Map of String policy keys, to {@link DownloadPolicy} objects) * @param settings the map of settings for the policies to execute. (Map of String policy keys, to String policy * setting) - * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)} + * @param request the request properties (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, Path)} * ) - * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, File)}) + * @param localFile the local file (utilized by the {@link DownloadPolicy#applyPolicy(String, Properties, Path)}) * @throws PolicyViolationException */ private void validatePolicies( Map policies, Map settings, @@ -1013,7 +1013,7 @@ public class DefaultRepositoryProxyConnectors log.debug( "Applying [{}] policy with [{}]", key, setting ); try { - policy.applyPolicy( setting, request, localFile.toFile() ); + policy.applyPolicy( setting, request, localFile ); } catch ( PolicyConfigurationException e ) { @@ -1042,7 +1042,7 @@ public class DefaultRepositoryProxyConnectors try { // all policies must approve the exception, any can cancel - process = policy.applyPolicy( setting, request, localFile.toFile(), exception, previousExceptions ); + process = policy.applyPolicy( setting, request, localFile, exception, previousExceptions ); if ( !process ) { break; 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 47fd97ee4..7d453540d 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 @@ -1092,7 +1092,7 @@ public class MetadataTransferTest assertTrue( "Actual file exists.", Files.exists(actualFile) ); StringWriter actualContents = new StringWriter(); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile.toFile() ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile ); RepositoryMetadataWriter.write( metadata, actualContents ); DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) ); 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 016f42a3d..7b6b95bd8 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 @@ -376,7 +376,7 @@ public class MetadataTools try { - return MavenMetadataReader.read( metadataFile.toFile() ); + return MavenMetadataReader.read( metadataFile ); } catch ( XMLException e ) { @@ -401,7 +401,7 @@ public class MetadataTools try { - return MavenMetadataReader.read( metadataFile.toFile() ); + return MavenMetadataReader.read( metadataFile ); } catch ( XMLException e ) { @@ -426,7 +426,7 @@ public class MetadataTools try { - return MavenMetadataReader.read( metadataFile.toFile() ); + return MavenMetadataReader.read( metadataFile ); } catch ( XMLException e ) { @@ -524,7 +524,7 @@ public class MetadataTools { try { - ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file.toFile() ); + ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file ); if ( existingMetadata != null ) { metadatas.add( existingMetadata ); @@ -594,7 +594,7 @@ public class MetadataTools { try { - allPlugins = new LinkedHashSet( MavenMetadataReader.read( metadataFile.toFile() ).getPlugins() ); + allPlugins = new LinkedHashSet( MavenMetadataReader.read( metadataFile ).getPlugins() ); } catch ( XMLException e ) { @@ -755,7 +755,7 @@ public class MetadataTools try { - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toFile() ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); return getLastUpdated( metadata ); } 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 f652d7f19..d497e2a97 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 @@ -878,7 +878,7 @@ public class DefaultBrowseService try { ArchivaRepositoryMetadata archivaRepositoryMetadata = - MavenMetadataReader.read( metadataFile.toFile() ); + MavenMetadataReader.read( metadataFile ); int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); // rebuild file name with timestamped version and build number 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 1f0fd73cb..0c57b3c5c 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 @@ -526,7 +526,7 @@ public class DefaultRepositoriesService { try { - metadata = MavenMetadataReader.read( metadataFile ); + metadata = MavenMetadataReader.read( metadataFile.toPath() ); } catch ( XMLException e ) { 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 d3b67064e..5d27b97e0 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 @@ -517,7 +517,7 @@ public class DefaultFileUploadService { try { - metadata = MavenMetadataReader.read( metadataFile ); + metadata = MavenMetadataReader.read( metadataFile.toPath() ); } catch ( XMLException e ) { 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 493856100..0b2edef88 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 @@ -383,7 +383,7 @@ public class ArchivaDavResourceFactory try { File metadataFile = new File( resourceAbsPath ); - ArchivaRepositoryMetadata repoMetadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata repoMetadata = MavenMetadataReader.read( metadataFile.toPath() ); mergedMetadata = RepositoryMetadataMerge.merge( mergedMetadata, repoMetadata ); } catch ( XMLException e ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletRepositoryGroupTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletRepositoryGroupTest.java index f237e6569..cd7dce94b 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletRepositoryGroupTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletRepositoryGroupTest.java @@ -264,7 +264,7 @@ public class RepositoryServletRepositoryGroupTest File returnedMetadata = new File( "target/test-classes/retrievedMetadataFile.xml" ); FileUtils.writeStringToFile( returnedMetadata, response.getContentAsString() ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( returnedMetadata ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( returnedMetadata.toPath() ); assertResponseOK( response ); diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java index adb1a875e..24982f21d 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/dependency/tree/maven2/Maven3DependencyTreeBuilder.java @@ -312,7 +312,7 @@ public class Maven3DependencyTreeBuilder { try { - ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( metadataFile.toPath() ); int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); // rebuild file name with timestamped version and build number 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 44a77e037..e1f45ced3 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 @@ -208,7 +208,7 @@ public class Maven2RepositoryStorage METADATA_FILENAME ); try { - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename SnapshotVersion snapshotVersion = metadata.getSnapshotVersion(); @@ -820,7 +820,7 @@ public class Maven2RepositoryStorage { return filePath; } - ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( metadataFile.toPath() ); int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber(); String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp(); @@ -967,7 +967,7 @@ public class Maven2RepositoryStorage { try { - metadata = MavenMetadataReader.read( metadataFile ); + metadata = MavenMetadataReader.read( metadataFile.toPath() ); } catch ( XMLException e ) { diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java index b84a859b9..cd6cc5514 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java @@ -169,7 +169,7 @@ public class RepositoryModelResolver { try { - ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata ); + ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata.toPath() ); SnapshotVersion snapshotVersion = archivaRepositoryMetadata.getSnapshotVersion(); if ( snapshotVersion != null ) { @@ -266,7 +266,7 @@ public class RepositoryModelResolver log.debug( "Successfully downloaded metadata." ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( tmpMetadataResource ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( tmpMetadataResource.toPath() ); // re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename SnapshotVersion snapshotVersion = metadata.getSnapshotVersion(); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java index ec2d7b00c..4d09032a9 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MavenRepositoryMetadataReaderTest.java @@ -49,7 +49,7 @@ public class MavenRepositoryMetadataReaderTest { File metadataFile = new File( defaultRepoDir, "org/apache/maven/plugins/maven-metadata.xml" ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); assertNotNull( metadata ); assertEquals( "org.apache.maven.plugins", metadata.getGroupId() ); @@ -84,7 +84,7 @@ public class MavenRepositoryMetadataReaderTest { File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); assertNotNull( metadata ); assertEquals( "org.apache.maven.shared", metadata.getGroupId() ); @@ -102,7 +102,7 @@ public class MavenRepositoryMetadataReaderTest { File metadataFile = new File( defaultRepoDir, "org/apache/apache/5-SNAPSHOT/maven-metadata.xml" ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); assertNotNull( metadata ); assertEquals( "org.apache", metadata.getGroupId() ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java index bff475680..319443ae5 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/RepositoryMetadataReaderTest.java @@ -45,7 +45,7 @@ public class RepositoryMetadataReaderTest File defaultRepoDir = new File( "src/test/repositories/default-repository" ); File metadataFile = new File( defaultRepoDir, "org/apache/maven/shared/maven-downloader/maven-metadata.xml" ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); assertNotNull( metadata ); assertEquals( "Group Id", "org.apache.maven.shared", metadata.getGroupId() ); @@ -63,7 +63,7 @@ public class RepositoryMetadataReaderTest File defaultRepoDir = new File( "src/test/repositories/default-repository" ); File metadataFile = new File( defaultRepoDir, "org/apache/maven/samplejar/maven-metadata.xml" ); - ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile ); + ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toPath() ); assertNotNull( metadata ); assertEquals( "Group Id", "org.apache.maven", metadata.getGroupId() ); diff --git a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java index d209098cf..5bea095cc 100644 --- a/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java +++ b/archiva-modules/plugins/stage-repository-merge/src/main/java/org/apache/archiva/stagerepository/merge/Maven2RepositoryMerger.java @@ -357,7 +357,7 @@ public class Maven2RepositoryMerger { try { - metadata = MavenMetadataReader.read( metadataFile ); + metadata = MavenMetadataReader.read( metadataFile.toPath() ); } catch ( XMLException e ) {