Migrating policies module to java.nio

This commit is contained in:
Martin Stockhammer 2017-09-05 23:28:55 +02:00
parent c8b3346225
commit 5437dfd6de
27 changed files with 188 additions and 121 deletions

View File

@ -47,7 +47,6 @@
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;

View File

@ -25,8 +25,12 @@
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
</metadata>
*/
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 static ArchivaRepositoryMetadata read( File metadataFile )
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" ) );

View File

@ -24,9 +24,12 @@
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 List<String> getOptions()
}
@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 void applyPolicy( String policySetting, Properties request, File localFil
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 void applyPolicy( String policySetting, Properties request, File localFil
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 void applyPolicy( String policySetting, Properties request, File localFil
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 ) )
{

View File

@ -26,7 +26,7 @@
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 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 ) )

View File

@ -26,7 +26,9 @@
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 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 void applyPolicy( String policySetting, Properties request, File localFil
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 void applyPolicy( String policySetting, Properties request, File localFil
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 void applyPolicy( String policySetting, Properties request, File localFil
{
throw new PolicyViolationException(
"Checksum policy set to FIX, " + "yet unable to update checksums for local file "
+ localFile.getAbsolutePath() + "." );
+ localFile.toAbsolutePath() + "." );
}
}

View File

@ -19,7 +19,7 @@
* 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<String, Exception> previousExceptions )
boolean applyPolicy( String policySetting, Properties request, Path localFile, Exception exception,
Map<String, Exception> previousExceptions )
throws PolicyConfigurationException;
}

View File

@ -19,7 +19,7 @@
* 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;
}

View File

@ -24,7 +24,7 @@
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 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<String, Exception> previousExceptions )
throws PolicyConfigurationException
{

View File

@ -22,7 +22,8 @@
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 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<String, Exception> previousExceptions )
throws PolicyConfigurationException
{
@ -75,7 +76,7 @@ public boolean applyPolicy( String policySetting, Properties request, File local
if ( NOT_PRESENT.equals( policySetting ) )
{
// cancel the exception if the file exists
return !localFile.exists();
return !Files.exists(localFile);
}
throw new PolicyConfigurationException(

View File

@ -21,15 +21,16 @@
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 @@ private DownloadPolicy lookupPolicy()
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 void testPolicyNo()
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 void testPolicyYes()
{
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";

View File

@ -27,8 +27,10 @@
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 void testIgnore()
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 @@ private void assertFailSetting( boolean expectedResult, String md5State, String
throws Exception
{
PostDownloadPolicy policy = lookupPolicy();
File localFile = createTestableFiles( md5State, sha1State );
Path localFile = createTestableFiles( md5State, sha1State );
Properties request = createRequest();
boolean actualResult;
@ -218,11 +220,11 @@ private void assertFailSetting( boolean expectedResult, String md5State, String
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 @@ private void assertFixSetting( boolean expectedResult, String md5State, String s
throws Exception
{
PostDownloadPolicy policy = lookupPolicy();
File localFile = createTestableFiles( md5State, sha1State );
Path localFile = createTestableFiles( md5State, sha1State );
Properties request = createRequest();
boolean actualResult;
@ -250,11 +252,11 @@ private void assertFixSetting( boolean expectedResult, String md5State, String s
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 @@ private void assertFixSetting( boolean expectedResult, String md5State, String s
/**
* 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 @@ private String readChecksumFile( File checksumFile )
try
{
freader = new FileReader( checksumFile );
freader = new FileReader( checksumFile.toFile() );
buf = new BufferedReader( freader );
return buf.readLine();
}
@ -334,37 +336,37 @@ private Properties createRequest()
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 );
}
}

View File

@ -28,8 +28,13 @@
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 @@
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 @@ private void assertReleasesPolicy( String setting, String path, boolean createLo
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 );

View File

@ -20,7 +20,7 @@
*/
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 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 @@
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 @@ private void assertSnapshotPolicy( String setting, String path, boolean createLo
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 );

View File

@ -991,9 +991,9 @@ private void transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepo
* @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<String, ? extends DownloadPolicy> policies, Map<String, String> settings,
@ -1013,7 +1013,7 @@ private void validatePolicies( Map<String, ? extends DownloadPolicy> policies, M
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 @@ private void validatePolicies( Map<String, DownloadErrorPolicy> policies, Map<St
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;

View File

@ -1092,7 +1092,7 @@ private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
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() ) );

View File

@ -376,7 +376,7 @@ public ArchivaRepositoryMetadata readProxyMetadata( ManagedRepositoryContent man
try
{
return MavenMetadataReader.read( metadataFile.toFile() );
return MavenMetadataReader.read( metadataFile );
}
catch ( XMLException e )
{
@ -401,7 +401,7 @@ public ArchivaRepositoryMetadata readProxyMetadata( ManagedRepositoryContent man
try
{
return MavenMetadataReader.read( metadataFile.toFile() );
return MavenMetadataReader.read( metadataFile );
}
catch ( XMLException e )
{
@ -426,7 +426,7 @@ public ArchivaRepositoryMetadata readProxyMetadata( ManagedRepositoryContent man
try
{
return MavenMetadataReader.read( metadataFile.toFile() );
return MavenMetadataReader.read( metadataFile );
}
catch ( XMLException e )
{
@ -524,7 +524,7 @@ private List<ArchivaRepositoryMetadata> getMetadatasForManagedRepository(
{
try
{
ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file.toFile() );
ArchivaRepositoryMetadata existingMetadata = MavenMetadataReader.read( file );
if ( existingMetadata != null )
{
metadatas.add( existingMetadata );
@ -594,7 +594,7 @@ public void updateMetadata( ManagedRepositoryContent managedRepository, ProjectR
{
try
{
allPlugins = new LinkedHashSet<Plugin>( MavenMetadataReader.read( metadataFile.toFile() ).getPlugins() );
allPlugins = new LinkedHashSet<Plugin>( MavenMetadataReader.read( metadataFile ).getPlugins() );
}
catch ( XMLException e )
{
@ -755,7 +755,7 @@ private long getExistingLastUpdated( Path metadataFile )
try
{
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile.toFile() );
ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( metadataFile );
return getLastUpdated( metadata );
}

View File

@ -878,7 +878,7 @@ public Boolean artifactAvailable( String groupId, String artifactId, String vers
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

View File

@ -526,7 +526,7 @@ private ArchivaRepositoryMetadata getMetadata( File metadataFile )
{
try
{
metadata = MavenMetadataReader.read( metadataFile );
metadata = MavenMetadataReader.read( metadataFile.toPath() );
}
catch ( XMLException e )
{

View File

@ -517,7 +517,7 @@ private ArchivaRepositoryMetadata getMetadata( File metadataFile )
{
try
{
metadata = MavenMetadataReader.read( metadataFile );
metadata = MavenMetadataReader.read( metadataFile.toPath() );
}
catch ( XMLException e )
{

View File

@ -383,7 +383,7 @@ public DavResource createResource( final DavResourceLocator locator, final DavSe
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 )

View File

@ -264,7 +264,7 @@ public void testGetMergedMetadata()
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 );

View File

@ -312,7 +312,7 @@ private ManagedRepository findArtifactInRepositories( List<String> repositoryIds
{
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

View File

@ -208,7 +208,7 @@ public ProjectVersionMetadata readProjectVersionMetadata( ReadMetadataRequest re
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 String getFilePathWithVersion( final String requestPath, ManagedRepositor
{
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 @@ private ArchivaRepositoryMetadata readMetadata( File directory )
{
try
{
metadata = MavenMetadataReader.read( metadataFile );
metadata = MavenMetadataReader.read( metadataFile.toPath() );
}
catch ( XMLException e )
{

View File

@ -169,7 +169,7 @@ protected File findTimeStampedSnapshotPom( String groupId, String artifactId, St
{
try
{
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata );
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( mavenMetadata.toPath() );
SnapshotVersion snapshotVersion = archivaRepositoryMetadata.getSnapshotVersion();
if ( snapshotVersion != null )
{
@ -266,7 +266,7 @@ private boolean getModelFromProxy( RemoteRepository remoteRepository, String gro
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();

View File

@ -49,7 +49,7 @@ public void testGroupMetadata()
{
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 void testProjectMetadata()
{
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 void testProjectVersionMetadata()
{
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() );

View File

@ -45,7 +45,7 @@ public void testLoadSimple()
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 void testLoadComplex()
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() );

View File

@ -357,7 +357,7 @@ private ArchivaRepositoryMetadata getMetadata( File metadataFile )
{
try
{
metadata = MavenMetadataReader.read( metadataFile );
metadata = MavenMetadataReader.read( metadataFile.toPath() );
}
catch ( XMLException e )
{