Versions { public static Version parseSemanticVersion(String version) { if(version.matches("\\d+\\.\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9-]+)?$")) { String[] toks = version.split("\\."); StringBuilder sb = new StringBuilder(); sb.append(toks[0]).append('.').append(toks[1]).append('.') .append(toks[2]); toks = toks[3].split("-"); if(toks.length > 1) { sb.append('-').append(AnyStrings.join("-", (Object[]) Arrays.copyOfRange(toks, 1, toks.length))); } sb.append('+').append(toks[0]); version = sb.toString(); } return Version.valueOf(version); } private  Versions(); static Version parseSemanticVersion(String version);  }
@Test public void testParseCinchapiSemanticVersion() { int major = Random.getScaleCount(); int minor = Random.getScaleCount(); int patch = Random.getScaleCount(); int build = Random.getScaleCount(); String snapshot = Random.getBoolean() ? "-SNAPSHOT" : ""; String cinchapiVersion = AnyStrings.format("{}.{}.{}.{}{}", major, minor, patch, build, snapshot); Version version = Versions.parseSemanticVersion(cinchapiVersion); Assert.assertEquals(major, version.getMajorVersion()); Assert.assertEquals(minor, version.getMinorVersion()); Assert.assertEquals(patch, version.getPatchVersion()); Assert.assertEquals(String.valueOf(build), version.getBuildMetadata()); }
@Test public void testParseCinchapiFeatureBranchSemanticVersion() { int major = 0; int minor = 5; int patch = 0; int build = 26; String snapshot = "-CON-512"; String cinchapiVersion = AnyStrings.format("{}.{}.{}.{}{}", major, minor, patch, build, snapshot); Version version = Versions.parseSemanticVersion(cinchapiVersion); Assert.assertEquals(major, version.getMajorVersion()); Assert.assertEquals(minor, version.getMinorVersion()); Assert.assertEquals(patch, version.getPatchVersion()); Assert.assertEquals(String.valueOf(build), version.getBuildMetadata()); }