mirror of https://github.com/apache/archiva.git
Moved checksum module to java.nio
This commit is contained in:
parent
90250dc304
commit
faceef262c
|
@ -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." );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in New Issue