2727import java .util .regex .Matcher ;
2828import java .util .regex .Pattern ;
2929
30+ import org .apache .maven .artifact .versioning .ComparableVersion ;
3031import org .apache .maven .model .Model ;
3132import org .apache .maven .model .io .xpp3 .MavenXpp3Reader ;
3233import 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