]> source.dussan.org Git - archiva.git/commitdiff
Changing the event system to use the checksum module
authorMartin Stockhammer <martin_s@apache.org>
Sun, 1 Apr 2018 07:54:30 +0000 (09:54 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 1 Apr 2018 07:54:30 +0000 (09:54 +0200)
20 files changed:
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumValidationException.java
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java
archiva-modules/archiva-base/archiva-converter/pom.xml
archiva-modules/archiva-base/archiva-converter/src/main/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverter.java
archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/artifact/LegacyToDefaultConverterTest.java
archiva-modules/archiva-base/archiva-policies/src/main/java/org/apache/archiva/policies/ChecksumPolicy.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/metadata/MetadataTools.java
archiva-modules/archiva-base/archiva-transaction/pom.xml
archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java
archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java
archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java
archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java
archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java
archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java
archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java

index 1123e6afa976605efd1fe05a776848c0ced36f77..280dc8b2d453e661d648971482bd08c9206c8add 100644 (file)
@@ -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;
index 53a3d4658b45ed1d9206d8e1071120057e0041a0..b8ff4e33873708141db245282b1b750c8047e676 100644 (file)
@@ -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( );
     }
index d458d82a739de463a3276782458dbf9684584f95..963cd87bc3e7c9ae933999a8bc34547ada77392c 100644 (file)
@@ -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 ) ) );
 
     }
 
index ca45bb6176785f4f8d01f28e9e2b0a8492eca2fc..f90fb10c62aa13d5acff7d5ba0d5a7a6c7685458 100644 (file)
@@ -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( ) );
             }
index 5851e677075846fef57bea29df327c31691b1ed8..0cd2488aea052c72b8e61012f8ffddf176cf9d19 100644 (file)
@@ -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();
     }
 }
index 8d729fbc5ef1c0515a32a8e364f83d22ff69e040..98a7abe0408c893c232acf578e88c72ac3842cae 100644 (file)
       <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>
index f6a17a661dc196b1703a39ce0c65168a5414a3b9..1404b0ca4f878bd2712a37c84007ee648876fb0a 100644 (file)
@@ -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}&lt;{@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;
     }
index 5084bffa9978800e573c08cc153a49af0740d457..b6fdbf1407355c35b4e187cc8e7d13be5fcbbc23 100644 (file)
@@ -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" );
index 146ea8809d3db594b7011f13cceba7c0a945b70b..c2004d139550ac41d4fd15dfaa07d81f44e00d24 100644 (file)
@@ -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 );
 
index af5b4ea1a31d2a53c4841cb4e9d027e81aa5159b..9bfcc2676f4c01f7b7f50727bdcee8762e17b305 100644 (file)
@@ -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;
 
index f15b31f09613c0941b32095b0bd44810a211cc1d..12143296f7d9063cbb1b4cdd16c810f550e5e218 100644 (file)
       <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>
index 2df01e66849f43fd5c90c2b08710f2ae1da4742d..0082517d89e7c62cddd13f86a6a6b706a57e811d 100644 (file)
@@ -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}&lt;{@link Digester}&gt;
      */
-    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);
     }
 
 }
index 2ef4a90939b29f3e6f28342a27c645b8704eaf9b..b168dfbcff4b5a1b92e59f66c8eb933af33ba2b4 100644 (file)
@@ -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}&lt;{@link Digester}&gt; 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 ) );
         }
     }
 
index 6cb6126b73e595916c4a71b92ad734f29964791f..2be9706578caa54fe2f12317279d50192b10af23 100644 (file)
@@ -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}&lt;{@link Digester}&gt; digesters to use for checksumming 
+     * @param checksumAlgorithms {@link List}&lt;{@link Digester}&gt; 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;
     }
index 8b4a5dd3abf81b55c4734f18a13e3daae4eb286b..1c93667aca65cf3c99eade36e2cd0169ff219deb 100644 (file)
@@ -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}&lt;{@link org.codehaus.plexus.digest.Digester}&gt; 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}&lt;{@link org.codehaus.plexus.digest.Digester}&gt; 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 ) );
     }
 }
index 80b9ca924218a9c24b0b9fd0902d5d28a26c4e64..0905c477c1554aff19d64c064b3a0b0087226cda 100644 (file)
@@ -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 )
index 164b5e6db7fc14e5444d8664f8a2b8f203f20d94..4ecf4437798aa96ac9c19e19f40be46ec90a87eb 100644 (file)
@@ -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) );
 
index 30164eb77dc5dbf05d6ff6b099fcc00e09cd5714..36924574d0712818ba9d56ae2402428e6a55c4f0 100644 (file)
@@ -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) );
 
index d3da9bb6242e4cd332709bf3250cb9c6a4f3e2ee..c8ae783f196605ad49b2a9c42c73b17cd9dd4745 100644 (file)
@@ -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 )
index 937470af222643bec48452dff5098ca29da3e671..5e1c69ac94a284ad64298a324b96cbe36d4f29a2 100644 (file)
@@ -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")