aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-transaction
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2018-04-01 09:54:30 +0200
committerMartin Stockhammer <martin_s@apache.org>2018-04-01 09:54:30 +0200
commitf8a9bc1640ddbe2748eb7bc8e68b4dd3dd84fa51 (patch)
tree1721e44ab24c19e5ebb4a02982942a3e5e28f4b5 /archiva-modules/archiva-base/archiva-transaction
parentfbf5e991b3cbe86b6a60aae4f127e07b30bb374a (diff)
downloadarchiva-f8a9bc1640ddbe2748eb7bc8e68b4dd3dd84fa51.tar.gz
archiva-f8a9bc1640ddbe2748eb7bc8e68b4dd3dd84fa51.zip
Changing the event system to use the checksum module
Diffstat (limited to 'archiva-modules/archiva-base/archiva-transaction')
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/pom.xml4
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java36
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java12
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java7
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java13
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java8
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java6
-rw-r--r--archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java6
8 files changed, 45 insertions, 47 deletions
diff --git a/archiva-modules/archiva-base/archiva-transaction/pom.xml b/archiva-modules/archiva-base/archiva-transaction/pom.xml
index f15b31f09..12143296f 100644
--- a/archiva-modules/archiva-base/archiva-transaction/pom.xml
+++ b/archiva-modules/archiva-base/archiva-transaction/pom.xml
@@ -34,6 +34,10 @@
<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>
</dependency>
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java
index 2df01e668..0082517d8 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/AbstractTransactionEvent.java
@@ -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);
}
}
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java
index 2ef4a9093..b168dfbcf 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CopyFileEvent.java
@@ -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 ) );
}
}
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java
index 6cb6126b7..2be970657 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/CreateFileEvent.java
@@ -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;
}
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java
index 8b4a5dd3a..1c93667ac 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/main/java/org/apache/archiva/transaction/FileTransaction.java
@@ -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 ) );
}
}
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java
index 80b9ca924..0905c477c 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/AbstractFileEventTest.java
@@ -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 )
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java
index 164b5e6db..4ecf44377 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CopyFileEventTest.java
@@ -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) );
diff --git a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java
index 30164eb77..36924574d 100644
--- a/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java
+++ b/archiva-modules/archiva-base/archiva-transaction/src/test/java/org/apache/archiva/transaction/CreateFileEventTest.java
@@ -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) );