@Test public void resolve() { assertNull(Version.resolve(null, null, null)); String version = "1.0"; assertEquals(version, Version.resolve(version, null, null)); version = "1.0-SNAPSHOT"; assertEquals(version, Version.resolve(version, null, null)); version = "3.0.5.RELEASE"; assertEquals(version, Version.resolve(version, null, null)); version = "[, 1.0 ]"; assertEquals("1.0", Version.resolve(version, null, null)); version = "(,1.0]"; assertEquals("1.0", Version.resolve(version, null, null)); version = "[0.1,1.0]"; assertEquals("1.0", Version.resolve(version, null, null)); version = "(0.1,1.0]"; assertEquals("1.0", Version.resolve(version, null, null)); version = "[,1.0-SNAPSHOT]"; assertEquals("1.0-SNAPSHOT", Version.resolve(version, null, null)); version = "(,1.0-SNAPSHOT]"; assertEquals("1.0-SNAPSHOT", Version.resolve(version, null, null)); version = "[0.1,1.0-SNAPSHOT]"; assertEquals("1.0-SNAPSHOT", Version.resolve(version, null, null)); version = "(0.1,1.0-SNAPSHOT]"; assertEquals("1.0-SNAPSHOT", Version.resolve(version, null, null)); version = "[1.10.1]"; assertEquals("1.10.1", Version.resolve(version, null, null)); version = "(1.10.1)"; assertNull("1.10.1", Version.resolve(version, null, null)); version = "[,1.4.3)"; assertEquals("1.4.3-rc1", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(,1.4.3)"; assertEquals("1.4.3-rc1", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.3-rc1,1.4.3)"; assertEquals("1.4.3-rc1", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "( 1.4.3-rc1 ,1.4.3)"; assertNull(Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[,1.4.4-rc1)"; assertEquals("1.4.3", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(,1.4.4-rc1)"; assertEquals("1.4.3", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.4-rc1,1.4.4)"; assertEquals("1.4.4-rc1", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.4,1.4.4)"; assertNull(Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.2,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.2,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.3-rc1,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.3-rc1,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.3,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.3,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.4-rc1,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.4-rc1,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.4.4,)"; assertEquals("1.4.4", Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "(1.4.4,)"; assertNull(Version.resolve(version, "classpath:mock-mvn-repo/javax/mail/mail", null)); version = "[1.0,2.0),[3.0,)"; try { Version.resolve(version, null, null); fail("Expecting a Version.UnsupportedRangeSet exception"); } catch (Version.UnsupportedRangeSet vurs) { } version = "(1.0,2.0],(3.0,]"; try { Version.resolve(version, null, null); fail("Expecting a Version.UnsupportedRangeSet exception"); } catch (Version.UnsupportedRangeSet vurs) { } version = "(,1.0],[1.2,)"; try { Version.resolve(version, null, null); fail("Expecting a Version.UnsupportedRangeSet exception"); } catch (Version.UnsupportedRangeSet vurs) { } version = "(,1.1),(1.1,)"; try { Version.resolve(version, null, null); fail("Expecting a Version.UnsupportedRangeSet exception"); } catch (Version.UnsupportedRangeSet vurs) { } version = "(,)"; try { Version.resolve(version, null, null); fail("Expecting a Version.Invalid exception"); } catch (Version.Invalid vurs) { } version = "(,]"; try { Version.resolve(version, null, null); fail("Expecting a Version.Invalid exception"); } catch (Version.Invalid vurs) { } version = "[,)"; try { Version.resolve(version, null, null); fail("Expecting a Version.Invalid exception"); } catch (Version.Invalid vurs) { } version = "[,]"; try { Version.resolve(version, null, null); fail("Expecting a Version.Invalid exception"); } catch (Version.Invalid vurs) { } }
public static String resolve(String version, String baseResource, Map<String, String> headers) throws Invalid, UnsupportedRangeSet { if ((version == null) || (!version.startsWith("[") && !version.startsWith("("))) { return version; } boolean inclusiveStart = version.startsWith("["), inclusiveEnd = version.endsWith("]"); String lower, upper; int index = 0; while (index < version.length()) { if (version.charAt(index) == ',') { break; } index++; } if (index == version.length()) { index -= 1; } lower = version.substring(1, index); char cur; int lowerEnd = index + 1; if (index == (version.length() - 1)) { upper = lower; } else { while ((cur = version.charAt(++index)) != ')' && (cur != ']')) { } upper = version.substring(lowerEnd, index); if (version.length() != (index + 1)) { throw new UnsupportedRangeSet(); } } lower = lower.trim(); upper = upper.trim(); if (lower.isEmpty() && upper.isEmpty()) { throw new Invalid(); } if (inclusiveEnd && !upper.isEmpty()) { return upper; } MavenMetadataParser parser = new MavenMetadataParser(); MavenMetadataParser.Metadata metadata = parser.parseMetadata(baseResource, headers); if ((metadata == null) || ((metadata.latest == null) && (metadata.versions == null))) { Output.print("^warn^ Could not resolve the 'maven-metadata.xml' file from the repository at %s", baseResource); return null; } String latest = (metadata.latest == null ? metadata.versions.get(metadata.versions.size() - 1) : metadata.latest); if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ Version ^b^%s^r^ falls outside of lower bound restriction: ^b^%s%s^r^", latest, (inclusiveStart ? "[" :"("), lower); return null; } if (upper.isEmpty()) { return latest; } else { int compare = MAVEN_VERSION_COMPARATOR.compare(upper, latest); if (compare <= 0) { if (metadata.versions != null) { for (int i = metadata.versions.size() - 1; i > -1; i--) { latest = metadata.versions.get(i); if (MAVEN_VERSION_COMPARATOR.compare(upper, latest) > 0) { if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ All available versions fall outside of lower bound restriction: ^b^%s%s^r^", (inclusiveStart ? "[" :"("), lower); return null; } return latest; } } } Output.print("^warn^ All available versions fall outside of upper bound restriction: ^b^%s%s^r^", upper, (inclusiveEnd ? "[" : "(")); return null; } return latest; } }
Version { public static String resolve(String version, String baseResource, Map<String, String> headers) throws Invalid, UnsupportedRangeSet { if ((version == null) || (!version.startsWith("[") && !version.startsWith("("))) { return version; } boolean inclusiveStart = version.startsWith("["), inclusiveEnd = version.endsWith("]"); String lower, upper; int index = 0; while (index < version.length()) { if (version.charAt(index) == ',') { break; } index++; } if (index == version.length()) { index -= 1; } lower = version.substring(1, index); char cur; int lowerEnd = index + 1; if (index == (version.length() - 1)) { upper = lower; } else { while ((cur = version.charAt(++index)) != ')' && (cur != ']')) { } upper = version.substring(lowerEnd, index); if (version.length() != (index + 1)) { throw new UnsupportedRangeSet(); } } lower = lower.trim(); upper = upper.trim(); if (lower.isEmpty() && upper.isEmpty()) { throw new Invalid(); } if (inclusiveEnd && !upper.isEmpty()) { return upper; } MavenMetadataParser parser = new MavenMetadataParser(); MavenMetadataParser.Metadata metadata = parser.parseMetadata(baseResource, headers); if ((metadata == null) || ((metadata.latest == null) && (metadata.versions == null))) { Output.print("^warn^ Could not resolve the 'maven-metadata.xml' file from the repository at %s", baseResource); return null; } String latest = (metadata.latest == null ? metadata.versions.get(metadata.versions.size() - 1) : metadata.latest); if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ Version ^b^%s^r^ falls outside of lower bound restriction: ^b^%s%s^r^", latest, (inclusiveStart ? "[" :"("), lower); return null; } if (upper.isEmpty()) { return latest; } else { int compare = MAVEN_VERSION_COMPARATOR.compare(upper, latest); if (compare <= 0) { if (metadata.versions != null) { for (int i = metadata.versions.size() - 1; i > -1; i--) { latest = metadata.versions.get(i); if (MAVEN_VERSION_COMPARATOR.compare(upper, latest) > 0) { if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ All available versions fall outside of lower bound restriction: ^b^%s%s^r^", (inclusiveStart ? "[" :"("), lower); return null; } return latest; } } } Output.print("^warn^ All available versions fall outside of upper bound restriction: ^b^%s%s^r^", upper, (inclusiveEnd ? "[" : "(")); return null; } return latest; } } }
Version { public static String resolve(String version, String baseResource, Map<String, String> headers) throws Invalid, UnsupportedRangeSet { if ((version == null) || (!version.startsWith("[") && !version.startsWith("("))) { return version; } boolean inclusiveStart = version.startsWith("["), inclusiveEnd = version.endsWith("]"); String lower, upper; int index = 0; while (index < version.length()) { if (version.charAt(index) == ',') { break; } index++; } if (index == version.length()) { index -= 1; } lower = version.substring(1, index); char cur; int lowerEnd = index + 1; if (index == (version.length() - 1)) { upper = lower; } else { while ((cur = version.charAt(++index)) != ')' && (cur != ']')) { } upper = version.substring(lowerEnd, index); if (version.length() != (index + 1)) { throw new UnsupportedRangeSet(); } } lower = lower.trim(); upper = upper.trim(); if (lower.isEmpty() && upper.isEmpty()) { throw new Invalid(); } if (inclusiveEnd && !upper.isEmpty()) { return upper; } MavenMetadataParser parser = new MavenMetadataParser(); MavenMetadataParser.Metadata metadata = parser.parseMetadata(baseResource, headers); if ((metadata == null) || ((metadata.latest == null) && (metadata.versions == null))) { Output.print("^warn^ Could not resolve the 'maven-metadata.xml' file from the repository at %s", baseResource); return null; } String latest = (metadata.latest == null ? metadata.versions.get(metadata.versions.size() - 1) : metadata.latest); if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ Version ^b^%s^r^ falls outside of lower bound restriction: ^b^%s%s^r^", latest, (inclusiveStart ? "[" :"("), lower); return null; } if (upper.isEmpty()) { return latest; } else { int compare = MAVEN_VERSION_COMPARATOR.compare(upper, latest); if (compare <= 0) { if (metadata.versions != null) { for (int i = metadata.versions.size() - 1; i > -1; i--) { latest = metadata.versions.get(i); if (MAVEN_VERSION_COMPARATOR.compare(upper, latest) > 0) { if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ All available versions fall outside of lower bound restriction: ^b^%s%s^r^", (inclusiveStart ? "[" :"("), lower); return null; } return latest; } } } Output.print("^warn^ All available versions fall outside of upper bound restriction: ^b^%s%s^r^", upper, (inclusiveEnd ? "[" : "(")); return null; } return latest; } } private  Version(); }
Version { public static String resolve(String version, String baseResource, Map<String, String> headers) throws Invalid, UnsupportedRangeSet { if ((version == null) || (!version.startsWith("[") && !version.startsWith("("))) { return version; } boolean inclusiveStart = version.startsWith("["), inclusiveEnd = version.endsWith("]"); String lower, upper; int index = 0; while (index < version.length()) { if (version.charAt(index) == ',') { break; } index++; } if (index == version.length()) { index -= 1; } lower = version.substring(1, index); char cur; int lowerEnd = index + 1; if (index == (version.length() - 1)) { upper = lower; } else { while ((cur = version.charAt(++index)) != ')' && (cur != ']')) { } upper = version.substring(lowerEnd, index); if (version.length() != (index + 1)) { throw new UnsupportedRangeSet(); } } lower = lower.trim(); upper = upper.trim(); if (lower.isEmpty() && upper.isEmpty()) { throw new Invalid(); } if (inclusiveEnd && !upper.isEmpty()) { return upper; } MavenMetadataParser parser = new MavenMetadataParser(); MavenMetadataParser.Metadata metadata = parser.parseMetadata(baseResource, headers); if ((metadata == null) || ((metadata.latest == null) && (metadata.versions == null))) { Output.print("^warn^ Could not resolve the 'maven-metadata.xml' file from the repository at %s", baseResource); return null; } String latest = (metadata.latest == null ? metadata.versions.get(metadata.versions.size() - 1) : metadata.latest); if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ Version ^b^%s^r^ falls outside of lower bound restriction: ^b^%s%s^r^", latest, (inclusiveStart ? "[" :"("), lower); return null; } if (upper.isEmpty()) { return latest; } else { int compare = MAVEN_VERSION_COMPARATOR.compare(upper, latest); if (compare <= 0) { if (metadata.versions != null) { for (int i = metadata.versions.size() - 1; i > -1; i--) { latest = metadata.versions.get(i); if (MAVEN_VERSION_COMPARATOR.compare(upper, latest) > 0) { if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ All available versions fall outside of lower bound restriction: ^b^%s%s^r^", (inclusiveStart ? "[" :"("), lower); return null; } return latest; } } } Output.print("^warn^ All available versions fall outside of upper bound restriction: ^b^%s%s^r^", upper, (inclusiveEnd ? "[" : "(")); return null; } return latest; } } private  Version(); static String resolve(String version, String baseResource, Map<String, String> headers); }
Version { public static String resolve(String version, String baseResource, Map<String, String> headers) throws Invalid, UnsupportedRangeSet { if ((version == null) || (!version.startsWith("[") && !version.startsWith("("))) { return version; } boolean inclusiveStart = version.startsWith("["), inclusiveEnd = version.endsWith("]"); String lower, upper; int index = 0; while (index < version.length()) { if (version.charAt(index) == ',') { break; } index++; } if (index == version.length()) { index -= 1; } lower = version.substring(1, index); char cur; int lowerEnd = index + 1; if (index == (version.length() - 1)) { upper = lower; } else { while ((cur = version.charAt(++index)) != ')' && (cur != ']')) { } upper = version.substring(lowerEnd, index); if (version.length() != (index + 1)) { throw new UnsupportedRangeSet(); } } lower = lower.trim(); upper = upper.trim(); if (lower.isEmpty() && upper.isEmpty()) { throw new Invalid(); } if (inclusiveEnd && !upper.isEmpty()) { return upper; } MavenMetadataParser parser = new MavenMetadataParser(); MavenMetadataParser.Metadata metadata = parser.parseMetadata(baseResource, headers); if ((metadata == null) || ((metadata.latest == null) && (metadata.versions == null))) { Output.print("^warn^ Could not resolve the 'maven-metadata.xml' file from the repository at %s", baseResource); return null; } String latest = (metadata.latest == null ? metadata.versions.get(metadata.versions.size() - 1) : metadata.latest); if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ Version ^b^%s^r^ falls outside of lower bound restriction: ^b^%s%s^r^", latest, (inclusiveStart ? "[" :"("), lower); return null; } if (upper.isEmpty()) { return latest; } else { int compare = MAVEN_VERSION_COMPARATOR.compare(upper, latest); if (compare <= 0) { if (metadata.versions != null) { for (int i = metadata.versions.size() - 1; i > -1; i--) { latest = metadata.versions.get(i); if (MAVEN_VERSION_COMPARATOR.compare(upper, latest) > 0) { if (!lower.isEmpty() && !withinLowerBound(inclusiveStart, lower, latest)) { Output.print("^warn^ All available versions fall outside of lower bound restriction: ^b^%s%s^r^", (inclusiveStart ? "[" :"("), lower); return null; } return latest; } } } Output.print("^warn^ All available versions fall outside of upper bound restriction: ^b^%s%s^r^", upper, (inclusiveEnd ? "[" : "(")); return null; } return latest; } } private  Version(); static String resolve(String version, String baseResource, Map<String, String> headers); static final Comparator<String> MAVEN_VERSION_COMPARATOR; }