(final String groupId, final String artifactId,
final String pomVersion, final Pattern ignorePattern)
| 217 | } |
| 218 | |
| 219 | private static void assertVersion(final String groupId, final String artifactId, |
| 220 | final String pomVersion, final Pattern ignorePattern) |
| 221 | throws Exception { |
| 222 | String latestMavenCentralVersion = null; |
| 223 | String url = MAVEN_REPO_URL_ |
| 224 | + groupId.replace('.', '/') + '/' |
| 225 | + artifactId.replace('.', '/'); |
| 226 | if (!url.endsWith("/")) { |
| 227 | url += "/"; |
| 228 | } |
| 229 | try (WebClient webClient = new WebClient(BrowserVersion.FIREFOX, false, null, -1)) { |
| 230 | webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); |
| 231 | |
| 232 | try { |
| 233 | final HtmlPage page = webClient.getPage(url); |
| 234 | for (final HtmlAnchor anchor : page.getAnchors()) { |
| 235 | String mavenCentralVersion = anchor.getTextContent(); |
| 236 | mavenCentralVersion = mavenCentralVersion.substring(0, mavenCentralVersion.length() - 1); |
| 237 | if (!isIgnored(groupId, artifactId, mavenCentralVersion, ignorePattern)) { |
| 238 | if (isVersionAfter(mavenCentralVersion, latestMavenCentralVersion)) { |
| 239 | latestMavenCentralVersion = mavenCentralVersion; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | catch (final UnknownHostException e) { |
| 245 | // ignore because our ci machine sometimes fails |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | if (!pomVersion.endsWith("-SNAPSHOT") |
| 250 | || !isVersionAfter( |
| 251 | pomVersion.substring(0, pomVersion.length() - "-SNAPSHOT".length()), |
| 252 | latestMavenCentralVersion)) { |
| 253 | |
| 254 | // it is ok if the pom uses a more recent version |
| 255 | if (!isVersionAfter(pomVersion, latestMavenCentralVersion)) { |
| 256 | Assertions.assertEquals(latestMavenCentralVersion, pomVersion, groupId + ":" + artifactId); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | private static boolean isVersionAfter(final String pomVersion, final String centralVersion) { |
| 262 | if (centralVersion == null) { |
no test coverage detected