MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / assertVersion

Method assertVersion

src/test/java/org/htmlunit/ExternalTest.java:219–259  ·  view source on GitHub ↗
(final String groupId, final String artifactId,
                            final String pomVersion, final Pattern ignorePattern)

Source from the content-addressed store, hash-verified

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) {

Callers 1

pomMethod · 0.95

Calls 12

getAnchorsMethod · 0.95
isIgnoredMethod · 0.95
isVersionAfterMethod · 0.95
endsWithMethod · 0.80
substringMethod · 0.80
getPageMethod · 0.65
lengthMethod · 0.65
replaceMethod · 0.45
getOptionsMethod · 0.45
getTextContentMethod · 0.45
assertEqualsMethod · 0.45

Tested by

no test coverage detected