Skip to content

Commit 98fd758

Browse files
committed
cleanup for the pom tests
1 parent 311ca86 commit 98fd758

2 files changed

Lines changed: 23 additions & 73 deletions

File tree

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
<!-- selenium -->
5555
<htmlunitdriver.version>4.40.0-SNAPSHOT</htmlunitdriver.version>
56-
<selenium.version>4.39.0</selenium.version>
56+
<selenium.version>4.40.0</selenium.version>
5757
<selenium.devtools.artifactId>selenium-devtools-v143</selenium.devtools.artifactId>
5858

5959
<!-- test dependencies -->
@@ -69,6 +69,7 @@
6969
<imageio-batik.version>3.13.0</imageio-batik.version>
7070
<jfreechart.version>1.5.6</jfreechart.version>
7171
<maven-model.version>3.9.12</maven-model.version>
72+
<maven-artifact.version>3.9.12</maven-artifact.version>
7273

7374
<!-- quality -->
7475
<checkstyle.version>12.3.1</checkstyle.version>
@@ -1559,6 +1560,11 @@
15591560
<artifactId>maven-model</artifactId>
15601561
<version>${maven-model.version}</version>
15611562
</dependency>
1563+
<dependency>
1564+
<groupId>org.apache.maven</groupId>
1565+
<artifactId>maven-artifact</artifactId>
1566+
<version>${maven-artifact.version}</version>
1567+
</dependency>
15621568
<!-- Jetty -->
15631569
<dependency>
15641570
<groupId>org.eclipse.jetty.ee10</groupId>

src/test/java/org/htmlunit/ExternalTest.java

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.regex.Matcher;
2828
import java.util.regex.Pattern;
2929

30+
import org.apache.maven.artifact.versioning.ComparableVersion;
3031
import org.apache.maven.model.Model;
3132
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
3233
import org.htmlunit.html.DomNode;
@@ -85,14 +86,16 @@ public void pom() throws Exception {
8586
try (FileReader fileReader = new FileReader(pomFile)) {
8687
final Model model = reader.read(fileReader);
8788

89+
final Pattern ignorePattern = Pattern.compile("" + model.getProperties().get("maven.version.ignore"));
90+
8891
final List<String> wrongVersions = new LinkedList<>();
8992
for (var dep : model.getDependencies()) {
9093
String version = dep.getVersion();
9194
if (version.startsWith("${")) {
9295
version = "" + model.getProperties().get(version.substring(2, version.length() - 1));
9396
}
9497
try {
95-
assertVersion(dep.getGroupId(), dep.getArtifactId(), version);
98+
assertVersion(dep.getGroupId(), dep.getArtifactId(), version, ignorePattern);
9699
}
97100
catch (final AssertionError e) {
98101
wrongVersions.add(e.getMessage());
@@ -102,8 +105,6 @@ public void pom() throws Exception {
102105
Assertions.fail(String.join("\n ", wrongVersions));
103106
}
104107
}
105-
106-
assertVersion("org.sonatype.oss", "oss-parent", "9");
107108
}
108109

109110
/**
@@ -215,7 +216,8 @@ public void snapshot() throws Exception {
215216
}
216217
}
217218

218-
private static void assertVersion(final String groupId, final String artifactId, final String pomVersion)
219+
private static void assertVersion(final String groupId, final String artifactId,
220+
final String pomVersion, final Pattern ignorePattern)
219221
throws Exception {
220222
String latestMavenCentralVersion = null;
221223
String url = MAVEN_REPO_URL_
@@ -232,7 +234,7 @@ private static void assertVersion(final String groupId, final String artifactId,
232234
for (final HtmlAnchor anchor : page.getAnchors()) {
233235
String mavenCentralVersion = anchor.getTextContent();
234236
mavenCentralVersion = mavenCentralVersion.substring(0, mavenCentralVersion.length() - 1);
235-
if (!isIgnored(groupId, artifactId, mavenCentralVersion)) {
237+
if (!isIgnored(groupId, artifactId, mavenCentralVersion, ignorePattern)) {
236238
if (isVersionAfter(mavenCentralVersion, latestMavenCentralVersion)) {
237239
latestMavenCentralVersion = mavenCentralVersion;
238240
}
@@ -243,6 +245,7 @@ private static void assertVersion(final String groupId, final String artifactId,
243245
// ignore because our ci machine sometimes fails
244246
}
245247
}
248+
246249
if (!pomVersion.endsWith("-SNAPSHOT")
247250
|| !isVersionAfter(
248251
pomVersion.substring(0, pomVersion.length() - "-SNAPSHOT".length()),
@@ -259,81 +262,18 @@ private static boolean isVersionAfter(final String pomVersion, final String cent
259262
if (centralVersion == null) {
260263
return true;
261264
}
262-
final String[] pomValues = pomVersion.split("\\.");
263-
final String[] centralValues = centralVersion.split("\\.");
264-
for (int i = 0; i < pomValues.length; i++) {
265-
if (pomValues[i].startsWith("v")) {
266-
pomValues[i] = pomValues[i].substring(1);
267-
}
268-
try {
269-
Integer.parseInt(pomValues[i]);
270-
}
271-
catch (final NumberFormatException e) {
272-
return false;
273-
}
274-
}
275-
for (int i = 0; i < centralValues.length; i++) {
276-
if (centralValues[i].startsWith("v")) {
277-
centralValues[i] = centralValues[i].substring(1);
278-
}
279-
try {
280-
Integer.parseInt(centralValues[i]);
281-
}
282-
catch (final NumberFormatException e) {
283-
return true;
284-
}
285-
}
286-
for (int i = 0; i < pomValues.length; i++) {
287-
if (i == centralValues.length) {
288-
return true;
289-
}
290-
final int pomValuePart = Integer.parseInt(pomValues[i]);
291-
final int centralValuePart = Integer.parseInt(centralValues[i]);
292-
if (pomValuePart < centralValuePart) {
293-
return false;
294-
}
295-
if (pomValuePart > centralValuePart) {
296-
return true;
297-
}
298-
}
299-
return false;
300-
}
301265

302-
private static boolean isIgnored(@SuppressWarnings("unused") final String groupId,
303-
@SuppressWarnings("unused") final String artifactId, @SuppressWarnings("unused") final String version) {
304-
if (groupId.startsWith("org.eclipse.jetty")
305-
&& (version.startsWith("11.") || version.startsWith("10."))) {
306-
return true;
307-
}
266+
return new ComparableVersion(pomVersion).compareTo(new ComparableVersion(centralVersion)) > 0;
267+
}
308268

269+
private static boolean isIgnored(final String groupId, final String artifactId,
270+
final String version, final Pattern ignorePattern) {
309271
// version > 3.12.0 does not work with our site.xml and also not with a refactored one
310272
if ("maven-site-plugin".equals(artifactId)
311273
&& (version.startsWith("3.12.1") || version.startsWith("3.20.") || version.startsWith("3.21."))) {
312274
return true;
313275
}
314276

315-
// >= 11.x requires java11
316-
if ("org.owasp".equals(groupId)
317-
&& (version.startsWith("11.") || version.startsWith("12."))) {
318-
return true;
319-
}
320-
321-
// 6.x requires java11
322-
if ("org.apache.felix".equals(groupId)
323-
&& version.startsWith("6.")) {
324-
return true;
325-
}
326-
327-
// 6.x requires java17
328-
if ("org.junit.jupiter".equals(groupId)
329-
&& version.startsWith("6.")) {
330-
return true;
331-
}
332-
if ("org.junit.platform".equals(groupId)
333-
&& version.startsWith("6.")) {
334-
return true;
335-
}
336-
337277
// ancient common versions
338278
if ("commons-io".equals(artifactId) && (version.startsWith("2003"))) {
339279
return true;
@@ -342,6 +282,10 @@ private static boolean isIgnored(@SuppressWarnings("unused") final String groupI
342282
return true;
343283
}
344284

285+
if (ignorePattern.matcher(version).matches()) {
286+
return true;
287+
}
288+
345289
return false;
346290
}
347291
}

0 commit comments

Comments
 (0)