summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2015-03-23 13:32:46 +1100
committerOlivier Lamy <olamy@apache.org>2015-03-23 14:31:58 +1100
commitf5022a27218c62310e82b62e53de0c5dee78abf2 (patch)
treeba025c1cb7e502bca5e2df8e3b7bd012f474b8a1 /archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers
parentf766714024cfc3ec7615e886887e0cc12ca92622 (diff)
downloadarchiva-f5022a27218c62310e82b62e53de0c5dee78abf2.tar.gz
archiva-f5022a27218c62310e82b62e53de0c5dee78abf2.zip
use 1.7 features for files
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml5
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java14
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java54
3 files changed, 47 insertions, 26 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
index 6bf6066e4..8c12f3fc3 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
@@ -145,6 +145,11 @@
<artifactId>xercesImpl</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<pluginManagement>
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java
index 70fb11933..3bc13fa41 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumer.java
@@ -141,8 +141,8 @@ public class ArtifactMissingChecksumsConsumer
public void processFile( String path )
throws ConsumerException
{
- createFixChecksum( path, new ChecksumAlgorithm[]{ ChecksumAlgorithm.SHA1 } );
- createFixChecksum( path, new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5 } );
+ createFixChecksum( path, ChecksumAlgorithm.SHA1 );
+ createFixChecksum( path, ChecksumAlgorithm.MD5 );
}
@Override
@@ -152,19 +152,19 @@ public class ArtifactMissingChecksumsConsumer
processFile( path );
}
- private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm[] )
+ private void createFixChecksum( String path, ChecksumAlgorithm checksumAlgorithm )
{
File artifactFile = new File( this.repositoryDir, path );
- File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm[0].getExt() );
+ File checksumFile = new File( this.repositoryDir, path + checksumAlgorithm.getExt() );
if ( checksumFile.exists() )
{
checksum = new ChecksummedFile( artifactFile );
try
{
- if ( !checksum.isValidChecksum( checksumAlgorithm[0] ) )
+ if ( !checksum.isValidChecksum( checksumAlgorithm ) )
{
- checksum.fixChecksums( checksumAlgorithm );
+ checksum.fixChecksums( new ChecksumAlgorithm[]{ checksumAlgorithm } );
log.info( "Fixed checksum file {}", checksumFile.getAbsolutePath() );
triggerConsumerInfo( "Fixed checksum file " + checksumFile.getAbsolutePath() );
}
@@ -181,7 +181,7 @@ public class ArtifactMissingChecksumsConsumer
checksum = new ChecksummedFile( artifactFile );
try
{
- checksum.createChecksum( checksumAlgorithm[0] );
+ checksum.createChecksum( checksumAlgorithm );
log.info( "Created missing checksum file {}", checksumFile.getAbsolutePath() );
triggerConsumerInfo( "Created missing checksum file " + checksumFile.getAbsolutePath() );
}
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java
index 41e64910a..8645ab01d 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/ArtifactMissingChecksumsConsumerTest.java
@@ -1,16 +1,20 @@
package org.apache.archiva.consumers.core;
-import java.io.File;
-import java.util.Calendar;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.commons.io.FileUtils;
-import static org.junit.Assert.*;
+import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Calendar;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -58,21 +62,26 @@ public class ArtifactMissingChecksumsConsumerTest
{
String path = "/no-checksums-artifact/1.0/no-checksums-artifact-1.0.jar";
- File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
- File md5File = new File( repoConfig.getLocation(), path + ".md5" );
+ Path sha1Path = Paths.get( repoConfig.getLocation(),
+ path + ".sha1" );// new File( repoConfig.getLocation(), path + ".sha1" );
+ Path md5FilePath =
+ Paths.get( repoConfig.getLocation(), path + ".md5" );// new File( repoConfig.getLocation(), path + ".md5" );
+
+ Files.deleteIfExists( sha1Path );
+ Files.deleteIfExists( md5FilePath );
- sha1File.delete();
- md5File.delete();
+ //sha1File.delete();
+ //md5File.delete();
- assertFalse( sha1File.exists() );
- assertFalse( md5File.exists() );
+ Assertions.assertThat( sha1Path.toFile() ).doesNotExist();// assertFalse( sha1File.exists() );
+ Assertions.assertThat( md5FilePath.toFile() ).doesNotExist();// assertFalse( md5File.exists() );
consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
consumer.processFile( path );
- assertTrue( sha1File.exists() );
- assertTrue( md5File.exists() );
+ Assertions.assertThat( sha1Path.toFile() ).exists();// assertTrue( sha1File.exists() );
+ Assertions.assertThat( md5FilePath.toFile() ).exists();//assertTrue( md5File.exists() );
}
@Test
@@ -86,21 +95,28 @@ public class ArtifactMissingChecksumsConsumerTest
String path = "/incorrect-checksums/1.0/incorrect-checksums-1.0.jar";
- File sha1File = new File( repoConfig.getLocation(), path + ".sha1" );
- File md5File = new File( repoConfig.getLocation(), path + ".md5" );
+ // new File( repoConfig.getLocation(), path + ".sha1" );
+ Path sha1Path = Paths.get( repoConfig.getLocation(), path + ".sha1" );
+
+ //new File( repoConfig.getLocation(), path + ".md5" );
+ Path md5Path = Paths.get( repoConfig.getLocation(), path + ".md5" );
ChecksummedFile checksum = new ChecksummedFile( new File( repoConfig.getLocation(), path ) );
- assertTrue( sha1File.exists() );
- assertTrue( md5File.exists() );
- assertFalse( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );
+ Assertions.assertThat( sha1Path.toFile() ).exists();
+ Assertions.assertThat( md5Path.toFile() ).exists();
+ Assertions.assertThat(
+ checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) //
+ .isFalse();
consumer.beginScan( repoConfig, Calendar.getInstance().getTime() );
consumer.processFile( path );
- assertTrue( sha1File.exists() );
- assertTrue( md5File.exists() );
- assertTrue( checksum.isValidChecksums( new ChecksumAlgorithm[] { ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) );
+ Assertions.assertThat( sha1Path.toFile() ).exists();
+ Assertions.assertThat( md5Path.toFile() ).exists();
+ Assertions.assertThat(
+ checksum.isValidChecksums( new ChecksumAlgorithm[]{ ChecksumAlgorithm.MD5, ChecksumAlgorithm.SHA1 } ) ) //
+ .isTrue();
}
}