From: Martin Stockhammer Date: Sat, 2 Sep 2017 18:37:52 +0000 (+0200) Subject: Moved checksum module to java.nio X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=faceef262c3521c1f27bfc49c7ab74c1b41a57ec;p=archiva.git Moved checksum module to java.nio --- diff --git a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java index 71f051f72..8d20239a6 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java @@ -19,10 +19,11 @@ package org.apache.archiva.checksum; * under the License. */ -import java.io.File; import org.apache.commons.io.FilenameUtils; +import java.nio.file.Path; + /** * Enumeration of available ChecksumAlgorithm techniques. * @@ -32,9 +33,9 @@ public enum ChecksumAlgorithm { SHA1("SHA-1", "sha1", "SHA1"), MD5("MD5", "md5", "MD5"); - public static ChecksumAlgorithm getByExtension( File file ) + public static ChecksumAlgorithm getByExtension( Path file ) { - String ext = FilenameUtils.getExtension( file.getName() ).toLowerCase(); + String ext = FilenameUtils.getExtension( file.getFileName().toString() ).toLowerCase(); if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) ) { return ChecksumAlgorithm.SHA1; @@ -44,7 +45,7 @@ public enum ChecksumAlgorithm { return ChecksumAlgorithm.MD5; } - throw new IllegalArgumentException( "Filename " + file.getName() + " has no associated extension." ); + throw new IllegalArgumentException( "Filename " + file.getFileName() + " has no associated extension." ); } /** diff --git a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java index bfaa06bc1..39719ccbd 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java @@ -20,6 +20,7 @@ package org.apache.archiva.checksum; */ import java.io.File; +import java.nio.file.Paths; import junit.framework.TestCase; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; @@ -38,15 +39,15 @@ public class ChecksumAlgorithmTest @Test public void testGetHashByExtensionSha1() { - assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( new File( "something.jar.sha1" ) ) ); - assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( new File( "OTHER.JAR.SHA1" ) ) ); + assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.sha1" ) ) ); + assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.SHA1" ) ) ); } @Test public void testGetHashByExtensionMd5() { - assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( new File( "something.jar.md5" ) ) ); - assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( new File( "OTHER.JAR.MD5" ) ) ); + assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.md5" ) ) ); + assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.MD5" ) ) ); } @Test @@ -54,7 +55,7 @@ public class ChecksumAlgorithmTest { try { - ChecksumAlgorithm.getByExtension( new File( "something.jar" ) ); + ChecksumAlgorithm.getByExtension( Paths.get( "something.jar" ) ); fail( "Expected " + IllegalArgumentException.class.getName() ); } catch ( IllegalArgumentException e )