IVY-1665: verify version is greater before reporting on available update

This commit is contained in:
Eric Milles 2026-06-11 15:40:08 -05:00
parent 8ca1d8895e
commit e6a9db4456
Failed to extract signature
7 changed files with 135 additions and 3 deletions

View File

@ -127,9 +127,9 @@ public class IvyDependencyUpdateChecker extends IvyPostResolveTask {
boolean dependencyUpdateDetected = false;
for (IvyNode latest : latestReport.getDependencies()) {
for (IvyNode originalDependency : originalReport.getDependencies()) {
if (originalDependency.getModuleId().equals(latest.getModuleId())) {
if (!originalDependency.getResolvedId().getRevision()
.equals(latest.getResolvedId().getRevision())) {
if (latest.getModuleId().equals(originalDependency.getModuleId())) {
if (isGreater(latest.getResolvedId().getRevision(),
originalDependency.getResolvedId().getRevision())) {
// is this dependency a transitive or a direct dependency?
// (unfortunately .isTransitive() methods do not have the same meaning)
boolean isTransitiveDependency = latest.getDependencyDescriptor(latest
@ -195,4 +195,42 @@ public class IvyDependencyUpdateChecker extends IvyPostResolveTask {
}
}
}
//--------------------------------------------------------------------------
private static boolean isGreater(String string1, String string2) {
String[] tokens1 = string1.split("[\\._\\-\\+]");
String[] tokens2 = string2.split("[\\._\\-\\+]");
int i = 0;
for (final int n = Math.min(tokens1.length, tokens2.length); i < n; i += 1) {
if (!tokens1[i].equals(tokens2[i])) {
boolean is1Number = isNumeric(tokens1[i]);
boolean is2Number = isNumeric(tokens2[i]);
if (is1Number && is2Number) {
return Long.valueOf(tokens1[i]).compareTo(Long.valueOf(tokens2[i])) > 0;
} else if (is1Number && !is2Number) {
return true;
} else if (!is1Number && is2Number) {
return false;
}
return true; // special meanings accounted for by resolve
}
}
if (i < tokens1.length) {
return isNumeric(tokens1[i]);
}
if (i < tokens2.length) {
return !isNumeric(tokens2[i]);
}
return false;
}
private static boolean isNumeric(String string) {
for (int i = 0, n = string.length(); i < n; ++i) {
if (!Character.isDigit(string.charAt(i))) {
return false;
}
}
return true;
}
}

View File

@ -220,6 +220,26 @@ public class IvyDependencyUpdateCheckerTest extends AntTaskTestCase {
assertLogContaining("org1#mod1.2\t2.0 -> 2.2");
}
/**
* Test case for IVY-1665.
*
* @see <a href="https://issues.apache.org/jira/browse/IVY-1665">IVY-1665</a>
*/
@Test
public void testLatestRelease() {
dependencyUpdateChecker.getProject().setProperty("ivy.settings.file", "test/repositories/IVY-1665/ivysettings.xml");
dependencyUpdateChecker.setRevisionToCheck("latest.release"); // exclude milestone (2.0-M1)
dependencyUpdateChecker.setOrganisation("bar");
dependencyUpdateChecker.setModule("foo");
dependencyUpdateChecker.setRevision("2.0-M1");
dependencyUpdateChecker.setInline(true);
dependencyUpdateChecker.execute();
assertLogNotContaining("bar#foo\t2.0-M1 -> 1.0");
// expect listing for 2.0 when it comes available
assertLogContaining("All dependencies are up to date");
}
@Test
public void testSimpleExtends() {
dependencyUpdateChecker.setFile(new File("test/java/org/apache/ivy/ant/ivy-extends-multiconf.xml"));

View File

@ -0,0 +1 @@
.

View File

@ -0,0 +1 @@
.

View File

@ -0,0 +1,22 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<ivy-module version="2.0">
<info organisation="bar" module="foo" revision="1.0" status="release"/>
</ivy-module>

View File

@ -0,0 +1,22 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<ivy-module version="2.0">
<info organisation="bar" module="foo" revision="2.0-M1" status="integration"/>
</ivy-module>

View File

@ -0,0 +1,28 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<ivysettings>
<settings defaultResolver="local"/>
<resolvers>
<filesystem name="local">
<ivy pattern="${ivy.settings.dir}/[organisation]/[module]/ivy-[revision].xml"/>
<artifact pattern="${ivy.settings.dir}/[organisation]/[module]/[artifact]-[revision].[ext]"/>
</filesystem>
</resolvers>
</ivysettings>