ManifestUtils { public static String findMavenVersion( String bundleVersion ) { String result = bundleVersion; if( bundleVersion != null ) { result = bundleVersion.replaceAll( "(?i:(\\.|-)SNAPSHOT$)", "-SNAPSHOT" ); Pattern pattern = Pattern.compile( "(\\d+\\.\\d+)\\.0(-SNAPSHOT)?$" ); Matcher m = pattern.matcher( result ); if( m.find()) result = m.replaceFirst( "$1$2" ); } return result; } private  ManifestUtils(); static String findMavenVersion( String bundleVersion ); static String findBundleVersion(); static String findManifestProperty( String propertyName ); static String findManifestProperty( Properties props, String propertyName );  }
@Test public void testFindMavenVersion() { Assert.assertEquals( "0.4", ManifestUtils.findMavenVersion( "0.4" )); Assert.assertEquals( "0.4", ManifestUtils.findMavenVersion( "0.4.0" )); Assert.assertEquals( "0.4.1", ManifestUtils.findMavenVersion( "0.4.1" )); Assert.assertEquals( "0.4-SNAPSHOT", ManifestUtils.findMavenVersion( "0.4.0-SNAPSHOT" )); Assert.assertEquals( "0.4.1-SNAPSHOT", ManifestUtils.findMavenVersion( "0.4.1-SNAPSHOT" )); Assert.assertEquals( "0.4-SNAPSHOT", ManifestUtils.findMavenVersion( "0.4.SNAPSHOT" )); Assert.assertEquals( "0.4-SNAPSHOT", ManifestUtils.findMavenVersion( "0.4.0.SNAPSHOT" )); Assert.assertEquals( "0.4.1-SNAPSHOT", ManifestUtils.findMavenVersion( "0.4.1.SNAPSHOT" )); Assert.assertEquals( "12.52", ManifestUtils.findMavenVersion( "12.52.0" )); Assert.assertEquals( "12.52-SNAPSHOT", ManifestUtils.findMavenVersion( "12.52.0-SNAPSHOT" )); Assert.assertEquals( "12.52.1-SNAPSHOT", ManifestUtils.findMavenVersion( "12.52.1-SNAPSHOT" )); Assert.assertEquals( "12.52.1-SNAPSHOT", ManifestUtils.findMavenVersion( "12.52.1-snapshoT" )); Assert.assertEquals( "0.4.0.1", ManifestUtils.findMavenVersion( "0.4.0.1" )); Assert.assertEquals( "whatever", ManifestUtils.findMavenVersion( "whatever" )); Assert.assertEquals( "", ManifestUtils.findMavenVersion( "" )); Assert.assertNull( ManifestUtils.findMavenVersion( null )); }