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,7 +21,8 @@ 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()
@ -91,4 +92,10 @@ public class VersionUtilTest extends TestCase
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" ) );
}
} }