@Test public void getMinimumVersion() { DependencyAtom left = DependencyAtom.parse("foo:foo:1.0", new AtomicReference<String>()); DependencyAtom right = DependencyAtom.parse("foo:foo:1.0", new AtomicReference<String>()); DependencyAtom result = Deps.getMinimumVersion(left, right); assertNull(result); left = DependencyAtom.parse("foo:foo:1.0.0", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:1.0", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(right, result); left = DependencyAtom.parse("foo:foo:1.0.0", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:1.0.1", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.0.0", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:1.0.1", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(right, result); left = DependencyAtom.parse("foo:foo:2.9", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.9-rc", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.10-rc", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.10", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10-SNAPSHOT", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(right, result); left = DependencyAtom.parse("foo:foo:2.10.v20150330", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10.v20150331", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.10.v20150330", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10.V20150401", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(left, result); left = DependencyAtom.parse("foo:foo:2.10.V20150509", new AtomicReference<String>()); right = DependencyAtom.parse("foo:foo:2.10.V20150401", new AtomicReference<String>()); result = Deps.getMinimumVersion(left, right); assertSame(right, result); }
public static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right) { String leftVersion = left.getPropertyValue(); String rightVersion = right.getPropertyValue(); if ((leftVersion == null) || (rightVersion == null) || leftVersion.equals(rightVersion)) { return null; } String[] leftVersions = leftVersion.split("\\."); String[] rightVersions = rightVersion.split("\\."); for (int i = 0; i < leftVersions.length; i++) { String leftCandidate = leftVersions[i]; String rightCandidate = null; if (rightVersions.length > i) { rightCandidate = rightVersions[i]; } if (rightCandidate == null) { return right; } if (leftCandidate.startsWith("v") || leftCandidate.startsWith("V")) { leftCandidate = leftCandidate.substring(1); } if (rightCandidate.startsWith("v") || rightCandidate.startsWith("V")) { rightCandidate = rightCandidate.substring(1); } boolean leftRc = false, rightRc = false; if (leftCandidate.endsWith("-rc")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 3); leftRc = true; } if (rightCandidate.endsWith("-rc")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 3); rightRc = true; } boolean leftSnapshot = false, rightSnapshot = false; if (leftCandidate.endsWith("-SNAPSHOT")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 9); leftSnapshot = true; } if (rightCandidate.endsWith("-SNAPSHOT")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 9); rightSnapshot = true; } try { Long leftPortion = Long.valueOf(leftCandidate); Long rightPortion = Long.valueOf(rightCandidate); if (leftPortion > rightPortion) { return right; } else if (rightPortion > leftPortion) { return left; } if ((leftRc && !rightRc) || (leftSnapshot && !rightSnapshot)) { return left; } if ((rightRc && !leftRc) || (rightSnapshot && !leftSnapshot)) { return right; } } catch (NumberFormatException nfe) { return null; } } return (rightVersions.length > leftVersion.length() ? left : null); }
Deps { public static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right) { String leftVersion = left.getPropertyValue(); String rightVersion = right.getPropertyValue(); if ((leftVersion == null) || (rightVersion == null) || leftVersion.equals(rightVersion)) { return null; } String[] leftVersions = leftVersion.split("\\."); String[] rightVersions = rightVersion.split("\\."); for (int i = 0; i < leftVersions.length; i++) { String leftCandidate = leftVersions[i]; String rightCandidate = null; if (rightVersions.length > i) { rightCandidate = rightVersions[i]; } if (rightCandidate == null) { return right; } if (leftCandidate.startsWith("v") || leftCandidate.startsWith("V")) { leftCandidate = leftCandidate.substring(1); } if (rightCandidate.startsWith("v") || rightCandidate.startsWith("V")) { rightCandidate = rightCandidate.substring(1); } boolean leftRc = false, rightRc = false; if (leftCandidate.endsWith("-rc")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 3); leftRc = true; } if (rightCandidate.endsWith("-rc")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 3); rightRc = true; } boolean leftSnapshot = false, rightSnapshot = false; if (leftCandidate.endsWith("-SNAPSHOT")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 9); leftSnapshot = true; } if (rightCandidate.endsWith("-SNAPSHOT")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 9); rightSnapshot = true; } try { Long leftPortion = Long.valueOf(leftCandidate); Long rightPortion = Long.valueOf(rightCandidate); if (leftPortion > rightPortion) { return right; } else if (rightPortion > leftPortion) { return left; } if ((leftRc && !rightRc) || (leftSnapshot && !rightSnapshot)) { return left; } if ((rightRc && !leftRc) || (rightSnapshot && !leftSnapshot)) { return right; } } catch (NumberFormatException nfe) { return null; } } return (rightVersions.length > leftVersion.length() ? left : null); } }
Deps { public static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right) { String leftVersion = left.getPropertyValue(); String rightVersion = right.getPropertyValue(); if ((leftVersion == null) || (rightVersion == null) || leftVersion.equals(rightVersion)) { return null; } String[] leftVersions = leftVersion.split("\\."); String[] rightVersions = rightVersion.split("\\."); for (int i = 0; i < leftVersions.length; i++) { String leftCandidate = leftVersions[i]; String rightCandidate = null; if (rightVersions.length > i) { rightCandidate = rightVersions[i]; } if (rightCandidate == null) { return right; } if (leftCandidate.startsWith("v") || leftCandidate.startsWith("V")) { leftCandidate = leftCandidate.substring(1); } if (rightCandidate.startsWith("v") || rightCandidate.startsWith("V")) { rightCandidate = rightCandidate.substring(1); } boolean leftRc = false, rightRc = false; if (leftCandidate.endsWith("-rc")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 3); leftRc = true; } if (rightCandidate.endsWith("-rc")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 3); rightRc = true; } boolean leftSnapshot = false, rightSnapshot = false; if (leftCandidate.endsWith("-SNAPSHOT")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 9); leftSnapshot = true; } if (rightCandidate.endsWith("-SNAPSHOT")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 9); rightSnapshot = true; } try { Long leftPortion = Long.valueOf(leftCandidate); Long rightPortion = Long.valueOf(rightCandidate); if (leftPortion > rightPortion) { return right; } else if (rightPortion > leftPortion) { return left; } if ((leftRc && !rightRc) || (leftSnapshot && !rightSnapshot)) { return left; } if ((rightRc && !leftRc) || (rightSnapshot && !leftSnapshot)) { return right; } } catch (NumberFormatException nfe) { return null; } } return (rightVersions.length > leftVersion.length() ? left : null); } private  Deps(); }
Deps { public static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right) { String leftVersion = left.getPropertyValue(); String rightVersion = right.getPropertyValue(); if ((leftVersion == null) || (rightVersion == null) || leftVersion.equals(rightVersion)) { return null; } String[] leftVersions = leftVersion.split("\\."); String[] rightVersions = rightVersion.split("\\."); for (int i = 0; i < leftVersions.length; i++) { String leftCandidate = leftVersions[i]; String rightCandidate = null; if (rightVersions.length > i) { rightCandidate = rightVersions[i]; } if (rightCandidate == null) { return right; } if (leftCandidate.startsWith("v") || leftCandidate.startsWith("V")) { leftCandidate = leftCandidate.substring(1); } if (rightCandidate.startsWith("v") || rightCandidate.startsWith("V")) { rightCandidate = rightCandidate.substring(1); } boolean leftRc = false, rightRc = false; if (leftCandidate.endsWith("-rc")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 3); leftRc = true; } if (rightCandidate.endsWith("-rc")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 3); rightRc = true; } boolean leftSnapshot = false, rightSnapshot = false; if (leftCandidate.endsWith("-SNAPSHOT")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 9); leftSnapshot = true; } if (rightCandidate.endsWith("-SNAPSHOT")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 9); rightSnapshot = true; } try { Long leftPortion = Long.valueOf(leftCandidate); Long rightPortion = Long.valueOf(rightCandidate); if (leftPortion > rightPortion) { return right; } else if (rightPortion > leftPortion) { return left; } if ((leftRc && !rightRc) || (leftSnapshot && !rightSnapshot)) { return left; } if ((rightRc && !leftRc) || (rightSnapshot && !leftSnapshot)) { return right; } } catch (NumberFormatException nfe) { return null; } } return (rightVersions.length > leftVersion.length() ? left : null); } private  Deps(); static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry,
                                                               String classifier,
                                                               boolean failMissingDependency); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry,
                                                               String classifier, boolean failMissingDependency,
                                                               ConflictingVersionVisitor conflictingVersionVisitor); static String getPathAsString(Vertex<Dep> vertex, DependencyAtom dependencyAtom); static List<DependencyAtom> parse(PropFile dependencies, String classifier); static DependencyAtom parse(Prop dependencyProp); static List<DependencyAtom> parseExclusions(PropFile exclusions, String classifier); static PropFile convertToResolvedPropertiesFile(DirectedAcyclicGraph<Dep> graph); static PropFile getResolvedProperties(boolean nullOnFNF); static PropFile getResolvedProperties(File projectConfigDir, Scope scope, boolean nullOnFNF); static String getClasspath(PropFile resolvedDependencies, String ... supplemental); static DependencyAtom getProjectDep(); static DependencyAtom getDepFromParts(String namespace, String name, String version, String artifactName); static String getArtifactName(String name, String version, String classifier, String packaging); static String getDependencyDirectoryPathForRepo(DependencyAtom dependencyAtom, RepositoryAtom repositoryAtom); static String getDependencyArtifactPathForRepo(DependencyAtom dependencyAtom, RepositoryAtom repositoryAtom); static void addChangedDependency(Scope scope, DependencyAtom dependency); }
Deps { public static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right) { String leftVersion = left.getPropertyValue(); String rightVersion = right.getPropertyValue(); if ((leftVersion == null) || (rightVersion == null) || leftVersion.equals(rightVersion)) { return null; } String[] leftVersions = leftVersion.split("\\."); String[] rightVersions = rightVersion.split("\\."); for (int i = 0; i < leftVersions.length; i++) { String leftCandidate = leftVersions[i]; String rightCandidate = null; if (rightVersions.length > i) { rightCandidate = rightVersions[i]; } if (rightCandidate == null) { return right; } if (leftCandidate.startsWith("v") || leftCandidate.startsWith("V")) { leftCandidate = leftCandidate.substring(1); } if (rightCandidate.startsWith("v") || rightCandidate.startsWith("V")) { rightCandidate = rightCandidate.substring(1); } boolean leftRc = false, rightRc = false; if (leftCandidate.endsWith("-rc")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 3); leftRc = true; } if (rightCandidate.endsWith("-rc")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 3); rightRc = true; } boolean leftSnapshot = false, rightSnapshot = false; if (leftCandidate.endsWith("-SNAPSHOT")) { leftCandidate = leftCandidate.substring(0, leftCandidate.length() - 9); leftSnapshot = true; } if (rightCandidate.endsWith("-SNAPSHOT")) { rightCandidate = rightCandidate.substring(0, rightCandidate.length() - 9); rightSnapshot = true; } try { Long leftPortion = Long.valueOf(leftCandidate); Long rightPortion = Long.valueOf(rightCandidate); if (leftPortion > rightPortion) { return right; } else if (rightPortion > leftPortion) { return left; } if ((leftRc && !rightRc) || (leftSnapshot && !rightSnapshot)) { return left; } if ((rightRc && !leftRc) || (rightSnapshot && !leftSnapshot)) { return right; } } catch (NumberFormatException nfe) { return null; } } return (rightVersions.length > leftVersion.length() ? left : null); } private  Deps(); static DependencyAtom getMinimumVersion(DependencyAtom left, DependencyAtom right); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry,
                                                               String classifier,
                                                               boolean failMissingDependency); static DirectedAcyclicGraph<Dep> getDependencyGraph(List<DependencyAtom> dependencyAtoms,
                                                               Set<DependencyAtom> exclusionAtoms,
                                                               RepositoryRegistry repositoryRegistry,
                                                               String classifier, boolean failMissingDependency,
                                                               ConflictingVersionVisitor conflictingVersionVisitor); static String getPathAsString(Vertex<Dep> vertex, DependencyAtom dependencyAtom); static List<DependencyAtom> parse(PropFile dependencies, String classifier); static DependencyAtom parse(Prop dependencyProp); static List<DependencyAtom> parseExclusions(PropFile exclusions, String classifier); static PropFile convertToResolvedPropertiesFile(DirectedAcyclicGraph<Dep> graph); static PropFile getResolvedProperties(boolean nullOnFNF); static PropFile getResolvedProperties(File projectConfigDir, Scope scope, boolean nullOnFNF); static String getClasspath(PropFile resolvedDependencies, String ... supplemental); static DependencyAtom getProjectDep(); static DependencyAtom getDepFromParts(String namespace, String name, String version, String artifactName); static String getArtifactName(String name, String version, String classifier, String packaging); static String getDependencyDirectoryPathForRepo(DependencyAtom dependencyAtom, RepositoryAtom repositoryAtom); static String getDependencyArtifactPathForRepo(DependencyAtom dependencyAtom, RepositoryAtom repositoryAtom); static void addChangedDependency(Scope scope, DependencyAtom dependency);  }