@@ -30,7 +30,7 @@ public class ChecksumValidationException extends RuntimeException | |||
{ | |||
public enum ValidationError { | |||
INVALID_FORMAT, DIGEST_ERROR, READ_ERROR, FILE_NOT_FOUND, BAD_CHECKSUM_FILE_REF | |||
INVALID_FORMAT, DIGEST_ERROR, READ_ERROR, FILE_NOT_FOUND, BAD_CHECKSUM_FILE_REF, BAD_CHECKSUM_FILE | |||
}; | |||
final private ValidationError errorType; |
@@ -30,10 +30,12 @@ import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.StandardOpenOption; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.regex.Matcher; | |||
import java.util.regex.Pattern; | |||
import static org.apache.archiva.checksum.ChecksumValidationException.ValidationError.BAD_CHECKSUM_FILE; | |||
import static org.apache.archiva.checksum.ChecksumValidationException.ValidationError.BAD_CHECKSUM_FILE_REF; | |||
/** | |||
@@ -157,7 +159,7 @@ public class ChecksummedFile | |||
public boolean isValidChecksum( ChecksumAlgorithm algorithm, boolean throwExceptions ) | |||
throws ChecksumValidationException | |||
{ | |||
return isValidChecksums( new ChecksumAlgorithm[]{algorithm} ); | |||
return isValidChecksums( Arrays.asList( algorithm ), throwExceptions ); | |||
} | |||
/** | |||
@@ -167,7 +169,7 @@ public class ChecksummedFile | |||
* @param algorithms the algorithms to check for. | |||
* @return true if the checksums report that the the reference file is valid, false if invalid. | |||
*/ | |||
public boolean isValidChecksums( ChecksumAlgorithm algorithms[]) throws ChecksumValidationException | |||
public boolean isValidChecksums( List<ChecksumAlgorithm> algorithms) throws ChecksumValidationException | |||
{ | |||
return isValidChecksums( algorithms, false ); | |||
} | |||
@@ -180,10 +182,10 @@ public class ChecksummedFile | |||
* @return True, if it is valid, otherwise false. | |||
* @throws ChecksumValidationException | |||
*/ | |||
public boolean isValidChecksums( ChecksumAlgorithm algorithms[], boolean throwExceptions) throws ChecksumValidationException | |||
public boolean isValidChecksums( List<ChecksumAlgorithm> algorithms, boolean throwExceptions) throws ChecksumValidationException | |||
{ | |||
List<Checksum> checksums = new ArrayList<>( algorithms.length ); | |||
List<Checksum> checksums = new ArrayList<>( algorithms.size() ); | |||
// Create checksum object for each algorithm. | |||
for ( ChecksumAlgorithm checksumAlgorithm : algorithms ) | |||
{ | |||
@@ -255,15 +257,20 @@ public class ChecksummedFile | |||
return referenceFile; | |||
} | |||
public boolean fixChecksum(ChecksumAlgorithm algorithm) { | |||
return fixChecksums( Arrays.asList(algorithm) ); | |||
} | |||
/** | |||
* Fix or create checksum files for the reference file. | |||
* | |||
* @param algorithms the hashes to check for. | |||
* @return true if checksums were created successfully. | |||
*/ | |||
public boolean fixChecksums( ChecksumAlgorithm[] algorithms ) | |||
public boolean fixChecksums( List<ChecksumAlgorithm> algorithms ) | |||
{ | |||
List<Checksum> checksums = new ArrayList<>( algorithms.length ); | |||
List<Checksum> checksums = new ArrayList<>( algorithms.size() ); | |||
// Create checksum object for each algorithm. | |||
for ( ChecksumAlgorithm checksumAlgorithm : algorithms ) | |||
{ | |||
@@ -299,7 +306,13 @@ public class ChecksummedFile | |||
Path checksumFile = getChecksumFile( checksumAlgorithm ); | |||
if ( Files.exists( checksumFile ) ) | |||
{ | |||
String expectedChecksum = parseChecksum( checksumFile, checksumAlgorithm, referenceFile.getFileName( ).toString( ), FILE_ENCODING ); | |||
String expectedChecksum; | |||
try | |||
{ | |||
expectedChecksum = parseChecksum( checksumFile, checksumAlgorithm, referenceFile.getFileName( ).toString( ), FILE_ENCODING ); | |||
} catch (ChecksumValidationException ex) { | |||
expectedChecksum = ""; | |||
} | |||
if ( !checksum.compare( expectedChecksum ) ) | |||
{ | |||
@@ -362,6 +375,8 @@ public class ChecksummedFile | |||
{ | |||
throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, | |||
"The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + expectedPath + "'" ); | |||
} else if (!fc.isFormatMatch()) { | |||
throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); | |||
} | |||
return fc.getChecksum( ); | |||
} |
@@ -25,13 +25,13 @@ 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; | |||
import java.util.Arrays; | |||
/** | |||
* ChecksummedFileTest | |||
@@ -152,7 +152,7 @@ public class ChecksummedFileTest | |||
assertFalse( "ChecksummedFile.isValid(SHA1) == false", | |||
checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) ); | |||
boolean fixed = checksummedFile.fixChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1 } ); | |||
boolean fixed = checksummedFile.fixChecksums( Arrays.asList( ChecksumAlgorithm.SHA1 ) ); | |||
assertTrue( "ChecksummedFile.fixChecksums() == true", fixed ); | |||
assertTrue( "ChecksummedFile.isValid(SHA1) == true", | |||
@@ -199,7 +199,7 @@ public class ChecksummedFileTest | |||
ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); | |||
assertFalse( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( | |||
new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 } ) ); | |||
Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) ); | |||
} | |||
@@ -211,7 +211,7 @@ public class ChecksummedFileTest | |||
ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); | |||
assertTrue( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( | |||
new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 } ) ); | |||
Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) ); | |||
} | |||
@Test | |||
@@ -222,7 +222,7 @@ public class ChecksummedFileTest | |||
ChecksummedFile checksummedFile = new ChecksummedFile( jarFile ); | |||
assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksums( | |||
new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 } ) ); | |||
Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) ); | |||
} | |||
@@ -162,7 +162,7 @@ public class ArtifactMissingChecksumsConsumer | |||
checksum = new ChecksummedFile( artifactFile); | |||
if ( !checksum.isValidChecksum( checksumAlgorithm ) ) | |||
{ | |||
checksum.fixChecksums( new ChecksumAlgorithm[]{checksumAlgorithm} ); | |||
checksum.fixChecksum( checksumAlgorithm ); | |||
log.info( "Fixed checksum file {}", checksumFile.toAbsolutePath( ) ); | |||
triggerConsumerInfo( "Fixed checksum file " + checksumFile.toAbsolutePath( ) ); | |||
} |
@@ -14,6 +14,7 @@ import org.junit.Test; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
/* | |||
@@ -112,7 +113,7 @@ public class ArtifactMissingChecksumsConsumerTest | |||
Assertions.assertThat( sha1Path.toFile() ).exists(); | |||
Assertions.assertThat( md5Path.toFile() ).exists(); | |||
Assertions.assertThat( | |||
checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) // | |||
checksum.isValidChecksums( Arrays.asList(ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 ) ) ) // | |||
.isFalse(); | |||
consumer.beginScan( repoConfig, Calendar.getInstance().getTime() ); | |||
@@ -122,7 +123,7 @@ public class ArtifactMissingChecksumsConsumerTest | |||
Assertions.assertThat( sha1Path.toFile() ).exists(); | |||
Assertions.assertThat( md5Path.toFile() ).exists(); | |||
Assertions.assertThat( | |||
checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) // | |||
checksum.isValidChecksums( Arrays.asList(ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 )) ) // | |||
.isTrue(); | |||
} | |||
} |
@@ -41,6 +41,10 @@ | |||
<groupId>org.apache.maven.shared</groupId> | |||
<artifactId>maven-model-converter</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-checksum</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-repository-layer</artifactId> |
@@ -19,6 +19,9 @@ package org.apache.archiva.converter.artifact; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.apache.archiva.checksum.ChecksumValidationException; | |||
import org.apache.archiva.checksum.ChecksummedFile; | |||
import org.apache.archiva.common.plexusbridge.DigesterUtils; | |||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; | |||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; | |||
@@ -59,6 +62,7 @@ import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
@@ -75,14 +79,11 @@ public class LegacyToDefaultConverter | |||
/** | |||
* {@link List}<{@link Digester} | |||
*/ | |||
private List<? extends Digester> digesters; | |||
private List<ChecksumAlgorithm> digesters; | |||
@Inject | |||
private PlexusSisuBridge plexusSisuBridge; | |||
@Inject | |||
private DigesterUtils digesterUtils; | |||
private ModelConverter translator; | |||
private ArtifactFactory artifactFactory; | |||
@@ -99,7 +100,8 @@ public class LegacyToDefaultConverter | |||
public void initialize() | |||
throws PlexusSisuBridgeException | |||
{ | |||
this.digesters = digesterUtils.getAllDigesters(); | |||
// TODO: Should be configurable! | |||
this.digesters = Arrays.asList(ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5); | |||
translator = plexusSisuBridge.lookup( ModelConverter.class ); | |||
artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class ); | |||
artifactHandlerManager = plexusSisuBridge.lookup( ArtifactHandlerManager.class ); | |||
@@ -287,7 +289,7 @@ public class LegacyToDefaultConverter | |||
throws IOException | |||
{ | |||
boolean result = true; | |||
for ( Digester digester : digesters ) | |||
for ( ChecksumAlgorithm digester : digesters ) | |||
{ | |||
result &= verifyChecksum( file, file.getFileName() + "." + getDigesterFileExtension( digester ), digester, | |||
//$NON-NLS-1$ | |||
@@ -297,24 +299,22 @@ public class LegacyToDefaultConverter | |||
return result; | |||
} | |||
private boolean verifyChecksum( Path file, String fileName, Digester digester, Artifact artifact, String key ) | |||
private boolean verifyChecksum( Path file, String fileName, ChecksumAlgorithm digester, Artifact artifact, String key ) | |||
throws IOException | |||
{ | |||
boolean result = true; | |||
boolean result; | |||
Path checksumFile = file.resolveSibling( fileName ); | |||
if ( Files.exists(checksumFile) ) | |||
// We ignore the check, if the checksum file does not exist | |||
if (!Files.exists(checksumFile)) { | |||
return true; | |||
} | |||
ChecksummedFile csFile = new ChecksummedFile( file ); | |||
try | |||
{ | |||
String checksum = org.apache.archiva.common.utils.FileUtils.readFileToString( checksumFile, Charset.defaultCharset() ); | |||
try | |||
{ | |||
digester.verify( file.toFile(), checksum ); | |||
} | |||
catch ( DigesterException e ) | |||
{ | |||
addWarning( artifact, Messages.getString( key ) ); | |||
result = false; | |||
} | |||
result = csFile.isValidChecksum( digester, true ); | |||
} catch (ChecksumValidationException e ) { | |||
addWarning( artifact, Messages.getString( key ) ); | |||
result = false; | |||
} | |||
return result; | |||
} | |||
@@ -323,9 +323,9 @@ public class LegacyToDefaultConverter | |||
* File extension for checksums | |||
* TODO should be moved to plexus-digester ? | |||
*/ | |||
private String getDigesterFileExtension( Digester digester ) | |||
private String getDigesterFileExtension( ChecksumAlgorithm checksumAlgorithm ) | |||
{ | |||
return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); //$NON-NLS-1$ //$NON-NLS-2$ | |||
return checksumAlgorithm.getExt().get(0); | |||
} | |||
private boolean copyArtifact( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction ) | |||
@@ -672,12 +672,12 @@ public class LegacyToDefaultConverter | |||
} | |||
public List<? extends Digester> getDigesters() | |||
public List<ChecksumAlgorithm> getDigesters() | |||
{ | |||
return digesters; | |||
} | |||
public void setDigesters( List<Digester> digesters ) | |||
public void setDigesters( List<ChecksumAlgorithm> digesters ) | |||
{ | |||
this.digesters = digesters; | |||
} |
@@ -84,10 +84,6 @@ public class LegacyToDefaultConverterTest | |||
ArtifactRepositoryFactory factory = plexusSisuBridge.lookup( ArtifactRepositoryFactory.class ); | |||
Map<String, ArtifactRepositoryLayout> layoutsMap = plexusSisuBridge.lookupMap( ArtifactRepositoryLayout.class ); | |||
System.out.println( "hints " + layoutsMap.keySet().toString() ); | |||
ArtifactRepositoryLayout layout = plexusSisuBridge.lookup( ArtifactRepositoryLayout.class, "legacy" ); | |||
Path sourceBase = getTestFile( "src/test/source-repository" ); |
@@ -30,6 +30,7 @@ import java.io.IOException; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Properties; | |||
@@ -66,7 +67,7 @@ public class ChecksumPolicy | |||
*/ | |||
public static final String FIX = "fix"; | |||
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; | |||
private List<ChecksumAlgorithm> algorithms = Arrays.asList( ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); | |||
private List<String> options = new ArrayList<>( 3 ); | |||
@@ -61,6 +61,7 @@ import java.nio.file.Paths; | |||
import java.text.ParseException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
@@ -108,7 +109,7 @@ public class MetadataTools | |||
@Named( value = "fileTypes" ) | |||
private FileTypes filetypes; | |||
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; | |||
private List<ChecksumAlgorithm> algorithms = Arrays.asList(ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); | |||
private List<String> artifactPatterns; | |||
@@ -33,6 +33,10 @@ | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-common</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-checksum</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>commons-io</groupId> | |||
<artifactId>commons-io</artifactId> |
@@ -19,9 +19,10 @@ package org.apache.archiva.transaction; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.apache.archiva.checksum.ChecksummedFile; | |||
import org.apache.commons.io.FileUtils; | |||
import org.codehaus.plexus.digest.Digester; | |||
import org.codehaus.plexus.digest.DigesterException; | |||
import java.io.IOException; | |||
import java.nio.charset.Charset; | |||
@@ -53,21 +54,21 @@ public abstract class AbstractTransactionEvent | |||
/** | |||
* {@link List}<{@link Digester}> | |||
*/ | |||
private List<? extends Digester> digesters; | |||
private List<ChecksumAlgorithm> checksumAlgorithms; | |||
protected AbstractTransactionEvent() | |||
{ | |||
this( new ArrayList<Digester>( 0 ) ); | |||
this( new ArrayList<ChecksumAlgorithm>( 0 ) ); | |||
} | |||
protected AbstractTransactionEvent( List<? extends Digester> digesters ) | |||
protected AbstractTransactionEvent( List<ChecksumAlgorithm> checksumAlgorithms) | |||
{ | |||
this.digesters = digesters; | |||
this.checksumAlgorithms = checksumAlgorithms; | |||
} | |||
protected List<? extends Digester> getDigesters() | |||
protected List<ChecksumAlgorithm> getChecksumAlgorithms() | |||
{ | |||
return digesters; | |||
return checksumAlgorithms; | |||
} | |||
/** | |||
@@ -181,10 +182,10 @@ public abstract class AbstractTransactionEvent | |||
protected void createChecksums( Path file, boolean force ) | |||
throws IOException | |||
{ | |||
for ( Digester digester : getDigesters() ) | |||
for ( ChecksumAlgorithm checksumAlgorithm : getChecksumAlgorithms() ) | |||
{ | |||
Path checksumFile = Paths.get(file.toAbsolutePath() + "." + getDigesterFileExtension( digester ) ); | |||
if ( Files.exists(checksumFile) ) | |||
Path checksumFile = Paths.get( file.toAbsolutePath( ) + "." + getChecksumFileExtension( checksumAlgorithm ) ); | |||
if ( Files.exists( checksumFile ) ) | |||
{ | |||
if ( !force ) | |||
{ | |||
@@ -196,16 +197,9 @@ public abstract class AbstractTransactionEvent | |||
{ | |||
createdFiles.add( checksumFile ); | |||
} | |||
try | |||
{ | |||
writeStringToFile( checksumFile, digester.calc( file.toFile() ) ); | |||
} | |||
catch ( DigesterException e ) | |||
{ | |||
throw (IOException) e.getCause(); | |||
} | |||
} | |||
ChecksummedFile csFile = new ChecksummedFile( file ); | |||
csFile.fixChecksums( getChecksumAlgorithms() ); | |||
} | |||
/** | |||
@@ -221,9 +215,9 @@ public abstract class AbstractTransactionEvent | |||
* File extension for checksums | |||
* TODO should be moved to plexus-digester ? | |||
*/ | |||
protected String getDigesterFileExtension( Digester digester ) | |||
protected String getChecksumFileExtension( ChecksumAlgorithm algorithm ) | |||
{ | |||
return digester.getAlgorithm().toLowerCase().replaceAll( "-", "" ); | |||
return algorithm.getExt().get(0); | |||
} | |||
} |
@@ -19,8 +19,8 @@ package org.apache.archiva.transaction; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.apache.commons.io.FileUtils; | |||
import org.codehaus.plexus.digest.Digester; | |||
import java.io.IOException; | |||
import java.nio.file.Files; | |||
@@ -44,11 +44,11 @@ public class CopyFileEvent | |||
* | |||
* @param source | |||
* @param destination | |||
* @param digesters {@link List}<{@link Digester}> digesters to use for checksumming | |||
* @param checksumAlgorithms The checksum algorithms | |||
*/ | |||
public CopyFileEvent( Path source, Path destination, List<? extends Digester> digesters ) | |||
public CopyFileEvent( Path source, Path destination, List<ChecksumAlgorithm> checksumAlgorithms ) | |||
{ | |||
super( digesters ); | |||
super( checksumAlgorithms ); | |||
this.source = source; | |||
this.destination = destination; | |||
} | |||
@@ -77,9 +77,9 @@ public class CopyFileEvent | |||
private void copyChecksums() | |||
throws IOException | |||
{ | |||
for ( Digester digester : getDigesters() ) | |||
for ( ChecksumAlgorithm checksumAlgorithm : getChecksumAlgorithms() ) | |||
{ | |||
copyChecksum( getDigesterFileExtension( digester ) ); | |||
copyChecksum( getChecksumFileExtension( checksumAlgorithm ) ); | |||
} | |||
} | |||
@@ -19,6 +19,7 @@ package org.apache.archiva.transaction; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.codehaus.plexus.digest.Digester; | |||
import java.io.IOException; | |||
@@ -42,11 +43,11 @@ public class CreateFileEvent | |||
* | |||
* @param content | |||
* @param destination | |||
* @param digesters {@link List}<{@link Digester}> digesters to use for checksumming | |||
* @param checksumAlgorithms {@link List}<{@link Digester}> digesters to use for checksumming | |||
*/ | |||
public CreateFileEvent( String content, Path destination, List<? extends Digester> digesters ) | |||
public CreateFileEvent( String content, Path destination, List<ChecksumAlgorithm> checksumAlgorithms ) | |||
{ | |||
super( digesters ); | |||
super( checksumAlgorithms ); | |||
this.content = content; | |||
this.destination = destination; | |||
} |
@@ -19,6 +19,7 @@ package org.apache.archiva.transaction; | |||
* under the License. | |||
*/ | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.codehaus.plexus.digest.Digester; | |||
import java.io.IOException; | |||
@@ -77,20 +78,20 @@ public class FileTransaction | |||
/** | |||
* @param source | |||
* @param destination | |||
* @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming | |||
* @param checksumAlgorithms The checksum algorithms | |||
*/ | |||
public void copyFile(Path source, Path destination, List<? extends Digester> digesters ) | |||
public void copyFile(Path source, Path destination, List<ChecksumAlgorithm> checksumAlgorithms ) | |||
{ | |||
events.add( new CopyFileEvent( source, destination, digesters ) ); | |||
events.add( new CopyFileEvent( source, destination, checksumAlgorithms ) ); | |||
} | |||
/** | |||
* @param content | |||
* @param destination | |||
* @param digesters {@link List}<{@link org.codehaus.plexus.digest.Digester}> digesters to use for checksumming | |||
* @param checksumAlgorithms Checksum algorithms | |||
*/ | |||
public void createFile( String content, Path destination, List<? extends Digester> digesters ) | |||
public void createFile( String content, Path destination, List<ChecksumAlgorithm> checksumAlgorithms ) | |||
{ | |||
events.add( new CreateFileEvent( content, destination, digesters ) ); | |||
events.add( new CreateFileEvent( content, destination, checksumAlgorithms ) ); | |||
} | |||
} |
@@ -20,11 +20,9 @@ package org.apache.archiva.transaction; | |||
*/ | |||
import junit.framework.TestCase; | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; | |||
import org.apache.commons.io.FileUtils; | |||
import org.codehaus.plexus.digest.Digester; | |||
import org.codehaus.plexus.digest.Md5Digester; | |||
import org.codehaus.plexus.digest.Sha1Digester; | |||
import org.junit.Before; | |||
import org.junit.runner.RunWith; | |||
@@ -43,7 +41,7 @@ import java.util.List; | |||
public abstract class AbstractFileEventTest | |||
extends TestCase | |||
{ | |||
protected List<Digester> digesters; | |||
protected List<ChecksumAlgorithm> checksumAlgorithms; | |||
@SuppressWarnings( "unchecked" ) | |||
@Before | |||
@@ -53,7 +51,7 @@ public abstract class AbstractFileEventTest | |||
{ | |||
super.setUp(); | |||
digesters = Arrays.asList( (Digester) new Md5Digester(), (Digester) new Sha1Digester() ); | |||
checksumAlgorithms = Arrays.asList( ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); | |||
} | |||
protected void assertChecksumExists(Path file, String algorithm ) |
@@ -77,7 +77,7 @@ public class CopyFileEventTest | |||
public void testCopyCommitRollback() | |||
throws Exception | |||
{ | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters ); | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, checksumAlgorithms ); | |||
assertFalse( "Test that the destination is not yet created", Files.exists(testDest) ); | |||
@@ -110,7 +110,7 @@ public class CopyFileEventTest | |||
assertTrue( "Test that the destination exists", Files.exists(testDest) ); | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters ); | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, checksumAlgorithms ); | |||
String target = readFile( testDest ); | |||
@@ -137,7 +137,7 @@ public class CopyFileEventTest | |||
public void testCreateRollbackCommit() | |||
throws Exception | |||
{ | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, digesters ); | |||
CopyFileEvent event = new CopyFileEvent( testSource, testDest, checksumAlgorithms ); | |||
assertFalse( "Test that the destination is not yet created", Files.exists(testDest) ); | |||
@@ -40,7 +40,7 @@ public class CreateFileEventTest | |||
{ | |||
Path testFile = testDir.resolve("test-file.txt" ); | |||
CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters ); | |||
CreateFileEvent event = new CreateFileEvent( "file contents", testFile, checksumAlgorithms ); | |||
assertFalse( "Test file is not yet created", Files.exists(testFile) ); | |||
@@ -72,7 +72,7 @@ public class CreateFileEventTest | |||
writeFile( testFile, "original contents" ); | |||
CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters ); | |||
CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, checksumAlgorithms ); | |||
String contents = readFile( testFile ); | |||
@@ -101,7 +101,7 @@ public class CreateFileEventTest | |||
{ | |||
Path testFile = testDir.resolve( "test-file.txt" ); | |||
CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters ); | |||
CreateFileEvent event = new CreateFileEvent( "file contents", testFile, checksumAlgorithms ); | |||
assertFalse( "Test file is not yet created", Files.exists(testFile) ); | |||
@@ -25,7 +25,6 @@ import org.apache.archiva.admin.model.beans.ManagedRepository; | |||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; | |||
import org.apache.archiva.checksum.ChecksumAlgorithm; | |||
import org.apache.archiva.checksum.ChecksummedFile; | |||
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; | |||
import org.apache.archiva.common.utils.VersionComparator; | |||
import org.apache.archiva.common.utils.VersionUtil; | |||
import org.apache.archiva.maven2.metadata.MavenMetadataReader; | |||
@@ -96,6 +95,7 @@ import java.nio.file.StandardCopyOption; | |||
import java.text.DateFormat; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
@@ -125,8 +125,6 @@ public class DefaultRepositoriesService | |||
@Inject | |||
private ManagedRepositoryAdmin managedRepositoryAdmin; | |||
@Inject | |||
private PlexusSisuBridge plexusSisuBridge; | |||
@Inject | |||
private SecuritySystem securitySystem; | |||
@@ -156,7 +154,7 @@ public class DefaultRepositoriesService | |||
@Named(value = "cache#namespaces") | |||
private Cache<String, Collection<String>> namespacesCache; | |||
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; | |||
private List<ChecksumAlgorithm> algorithms = Arrays.asList(ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); | |||
@Override | |||
public Boolean scanRepository( String repositoryId, boolean fullScan ) |
@@ -75,6 +75,7 @@ import java.nio.file.StandardCopyOption; | |||
import java.text.DateFormat; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
@@ -105,7 +106,7 @@ public class DefaultFileUploadService | |||
@Inject | |||
private ArchivaAdministration archivaAdministration; | |||
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; | |||
private List<ChecksumAlgorithm> algorithms = Arrays.asList( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); | |||
@Inject | |||
@Named(value = "archivaTaskScheduler#repository") |