aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-checksum
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2008-04-15 04:44:17 +0000
committerJoakim Erdfelt <joakime@apache.org>2008-04-15 04:44:17 +0000
commit92362e9ee3b5d2720dd12880ab7a3589f1f84a8d (patch)
tree21a07bd143c42d35cdfa2dd3f14d2fcd070ceb27 /archiva-modules/archiva-base/archiva-checksum
parent11e37d73c422e575be1d6f3fafeaf9658ffd9945 (diff)
downloadarchiva-92362e9ee3b5d2720dd12880ab7a3589f1f84a8d.tar.gz
archiva-92362e9ee3b5d2720dd12880ab7a3589f1f84a8d.zip
Replacing plexus-digest with archiva-checksum
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@648115 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-checksum')
-rw-r--r--archiva-modules/archiva-base/archiva-checksum/pom.xml10
-rw-r--r--archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java44
-rw-r--r--archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java2
3 files changed, 31 insertions, 25 deletions
diff --git a/archiva-modules/archiva-base/archiva-checksum/pom.xml b/archiva-modules/archiva-base/archiva-checksum/pom.xml
index fb23cc6bf..a80e3525c 100644
--- a/archiva-modules/archiva-base/archiva-checksum/pom.xml
+++ b/archiva-modules/archiva-base/archiva-checksum/pom.xml
@@ -18,12 +18,11 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.archiva</groupId>
- <artifactId>archiva-modules</artifactId>
+ <artifactId>archiva-base</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<artifactId>archiva-checksum</artifactId>
<name>Archiva Checksum</name>
- <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -47,19 +46,12 @@
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
- <version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
index 4f6b4276a..f1b510497 100644
--- a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
+++ b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
@@ -141,11 +141,9 @@ public class ChecksummedFile
* the to the checksum.
*
* @param algorithms the algorithms to check for.
- * @return true if the checksums report that the the reference file is valid.
- * @throws IOException if unable to validate the checksums.
+ * @return true if the checksums report that the the reference file is valid, false if invalid.
*/
public boolean isValidChecksums( ChecksumAlgorithm algorithms[] )
- throws IOException
{
FileInputStream fis = null;
try
@@ -166,30 +164,46 @@ public class ChecksummedFile
// Any checksums?
if ( checksums.isEmpty() )
{
- // No checksum objects, no checksum files, default to is valid.
- return true;
+ // No checksum objects, no checksum files, default to is invalid.
+ return false;
}
// Parse file once, for all checksums.
- fis = new FileInputStream( referenceFile );
- Checksum.update( checksums, fis );
+ try
+ {
+ fis = new FileInputStream( referenceFile );
+ Checksum.update( checksums, fis );
+ }
+ catch ( IOException e )
+ {
+ log.warn( "Unable to update checksum:" + e.getMessage() );
+ return false;
+ }
boolean valid = true;
// check the checksum files
- for ( Checksum checksum : checksums )
+ try
{
- ChecksumAlgorithm checksumAlgorithm = checksum.getAlgorithm();
- File checksumFile = getChecksumFile( checksumAlgorithm );
+ for ( Checksum checksum : checksums )
+ {
+ ChecksumAlgorithm checksumAlgorithm = checksum.getAlgorithm();
+ File checksumFile = getChecksumFile( checksumAlgorithm );
- String rawChecksum = FileUtils.readFileToString( checksumFile );
- String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getName() );
+ String rawChecksum = FileUtils.readFileToString( checksumFile );
+ String expectedChecksum = parseChecksum( rawChecksum, checksumAlgorithm, referenceFile.getName() );
- if ( StringUtils.equalsIgnoreCase( expectedChecksum, checksum.getChecksum() ) == false )
- {
- valid = false;
+ if ( StringUtils.equalsIgnoreCase( expectedChecksum, checksum.getChecksum() ) == false )
+ {
+ valid = false;
+ }
}
}
+ catch ( IOException e )
+ {
+ log.warn( "Unable to read / parse checksum: " + e.getMessage() );
+ return false;
+ }
return valid;
}
diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java
index 3b3c93512..733ffb7d3 100644
--- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java
+++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java
@@ -158,7 +158,7 @@ public class ChecksummedFileTest
File jarFile = createTestableJar( "examples/redback-authz-open.jar", false, false );
ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
- assertTrue( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( new ChecksumAlgorithm[] {
+ assertFalse( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums( new ChecksumAlgorithm[] {
ChecksumAlgorithm.SHA1,
ChecksumAlgorithm.MD5 } ) );