add util method to extract version from generic snapshot version

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401074 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-10-22 20:51:46 +00:00
parent ede0480333
commit 725db7a105
2 changed files with 38 additions and 23 deletions

View File

@ -26,8 +26,6 @@ import java.util.regex.Pattern;
/** /**
* Version utility methods. * Version utility methods.
*
*
*/ */
public class VersionUtil public class VersionUtil
{ {
@ -191,4 +189,14 @@ public class VersionUtil
{ {
return version.endsWith( SNAPSHOT ); return version.endsWith( SNAPSHOT );
} }
public static String getVersionFromGenericSnapshot( String version )
{
Matcher m = GENERIC_SNAPSHOT_PATTERN.matcher( version );
if ( m.matches() )
{
return m.group( 1 );
}
return version;
}
} }

View File

@ -21,74 +21,81 @@ package org.apache.archiva.common.utils;
import junit.framework.TestCase; import junit.framework.TestCase;
public class VersionUtilTest extends TestCase public class VersionUtilTest
extends TestCase
{ {
public void testIsVersion() public void testIsVersion()
{ {
// 0% // 0%
assertFalse( VersionUtil.isVersion( "project" ) ); assertFalse( VersionUtil.isVersion( "project" ) );
// 0% // 0%
assertFalse( VersionUtil.isVersion( "project-not-version" ) ); assertFalse( VersionUtil.isVersion( "project-not-version" ) );
// 50% // 50%
assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) ); assertFalse( VersionUtil.isVersion( "project-ver-1.0-dev" ) );
// > 75% // > 75%
assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) ); assertTrue( VersionUtil.isVersion( "project-1.0-alpha" ) );
// 75% // 75%
assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) ); assertTrue( VersionUtil.isVersion( "project-1.0-latest-nightly" ) );
// >75% // >75%
assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) ); assertTrue( VersionUtil.isVersion( "1.0-project-unofficial-nightly-alpha-release" ) );
//only first token matches //only first token matches
assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) ); assertTrue( VersionUtil.isVersion( "1.0-project-my-own-version" ) );
} }
public void testIsSimpleVersionKeyword() public void testIsSimpleVersionKeyword()
{ {
assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) ); assertTrue( VersionUtil.isSimpleVersionKeyword( "rc4.34" ) );
assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) ); assertTrue( VersionUtil.isSimpleVersionKeyword( "beta" ) );
assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) ); assertFalse( VersionUtil.isSimpleVersionKeyword( "1.0-SNAPSHOT" ) );
} }
public void testIsSnapshot() public void testIsSnapshot()
{ {
assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) ); assertTrue( VersionUtil.isSnapshot( "1.0-20070113.163208-99" ) );
assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) ); assertTrue( VersionUtil.isSnapshot( "1.0-SNAPSHOT" ) );
assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) ); assertFalse( VersionUtil.isSnapshot( "1.0-beta1" ) );
} }
public void testGetBaseVersion() public void testGetBaseVersion()
{ {
assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" ); assertEquals( VersionUtil.getBaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2-SNAPSHOT" );
} }
public void testGetReleaseVersion() public void testGetReleaseVersion()
{ {
assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" ); assertEquals( VersionUtil.getReleaseVersion( "1.3.2-20090420.083501-3" ), "1.3.2" );
} }
public void testIsUniqueSnapshot() public void testIsUniqueSnapshot()
{ {
assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) ); assertTrue( VersionUtil.isUniqueSnapshot( "1.3.2-20090420.083501-3" ) );
assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) ); assertFalse( VersionUtil.isUniqueSnapshot( "1.3.2" ) );
} }
public void testIsGenericSnapshot() public void testIsGenericSnapshot()
{ {
assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) ); assertFalse( VersionUtil.isGenericSnapshot( "1.3.2-20090420.083501-3" ) );
assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) ); assertTrue( VersionUtil.isGenericSnapshot( "1.3.2-SNAPSHOT" ) );
} }
public void testGetVersionFromGenericSnapshot()
{
assertEquals( "3.0", VersionUtil.getVersionFromGenericSnapshot( "3.0-SNAPSHOT" ) );
}
} }