]> source.dussan.org Git - archiva.git/commitdiff
Moved checksum module to java.nio
authorMartin Stockhammer <martin_s@apache.org>
Sat, 2 Sep 2017 18:37:52 +0000 (20:37 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sat, 2 Sep 2017 18:37:52 +0000 (20:37 +0200)
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java

index 71f051f724147c34ff8daab29d7eceb80f104760..8d20239a6ecfabd2c4da35f8cc370c05a2c4e1b8 100644 (file)
@@ -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." );
     }
 
     /**
index bfaa06bc193e34baa77a3ed190db6b4a3e9c835b..39719ccbd40eec40e615b090bed037935a7e4d65 100644 (file)
@@ -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 )