Skip to content

Commit ea3d9fa

Browse files
committed
Try
1 parent 2e3f738 commit ea3d9fa

File tree

3 files changed

+54
-46
lines changed

3 files changed

+54
-46
lines changed

src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -3759,13 +3759,14 @@ private void addLinkofflineArguments(List<String> arguments, Set<OfflineLink> of
37593759
if (location == null || location.isEmpty()) {
37603760
continue;
37613761
}
3762-
if (isValidJavadocLink(location, false)) {
3763-
addArgIfNotEmpty(
3764-
arguments,
3765-
"-linkoffline",
3766-
JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
3767-
true);
3762+
if (validateLinks && !isValidJavadocLink(location, false)) {
3763+
continue;
37683764
}
3765+
addArgIfNotEmpty(
3766+
arguments,
3767+
"-linkoffline",
3768+
JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
3769+
true);
37693770
}
37703771
}
37713772

@@ -5617,7 +5618,11 @@ private List<String> getDependenciesLinks() {
56175618
}
56185619
}
56195620

5620-
if (url != null && isValidJavadocLink(url, detected)) {
5621+
if (url != null) {
5622+
if (validateLinks && !isValidJavadocLink(url, detected)) {
5623+
continue;
5624+
}
5625+
56215626
getLog().debug("Added Javadoc link: " + url + " for " + artifact.getId());
56225627

56235628
dependenciesLinks.add(url);
@@ -5814,13 +5819,13 @@ protected boolean isValidJavadocLink(String link, boolean detecting) {
58145819
}
58155820

58165821
try {
5817-
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings, validateLinks)) {
5822+
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings)) {
58185823
return true;
58195824
}
58205825
} catch (IOException e) {
58215826
}
58225827

5823-
if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings, validateLinks)) {
5828+
if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings)) {
58245829
return true;
58255830
}
58265831

src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java

+26-23
Original file line numberDiff line numberDiff line change
@@ -1333,52 +1333,55 @@ protected static URL getRedirectUrl(URL url, Settings settings) throws IOExcepti
13331333
}
13341334

13351335
/**
1336-
* Validates an <code>URL</code> to point to a valid <code>package-list</code> resource.
1336+
* Validates the <code>URL</code> (content) to point to a valid <code>package-list</code> resource.
13371337
*
1338-
* @param url The URL to validate.
1338+
* @param url The URL (content) to validate.
13391339
* @param settings The user settings used to configure the connection to the URL or {@code null}.
1340-
* @param validateContent <code>true</code> to validate the content of the <code>package-list</code> resource;
1341-
* <code>false</code> to only check the existence of the <code>package-list</code> resource.
13421340
* @return <code>true</code> if <code>url</code> points to a valid <code>package-list</code> resource;
13431341
* <code>false</code> else.
13441342
* @throws IOException if reading the resource fails.
13451343
* @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
13461344
* @since 2.8
13471345
*/
1348-
protected static boolean isValidPackageList(URL url, Settings settings, boolean validateContent)
1349-
throws IOException {
1346+
protected static boolean isValidPackageList(URL url, Settings settings) throws IOException {
13501347
if (url == null) {
1351-
throw new IllegalArgumentException("The url is null");
1348+
throw new NullPointerException("The url is null");
13521349
}
13531350

13541351
try (BufferedReader reader = getReader(url, settings)) {
1355-
if (validateContent) {
1356-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1357-
if (!isValidPackageName(line)) {
1358-
return false;
1359-
}
1352+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1353+
if (!isValidPackageName(line)) {
1354+
return false;
13601355
}
13611356
}
13621357
return true;
13631358
}
13641359
}
13651360

1366-
protected static boolean isValidElementList(URL url, Settings settings, boolean validateContent)
1367-
throws IOException {
1361+
/**
1362+
* Validates the <code>URL</code> (content) to point to a valid <code>element-list</code> resource.
1363+
*
1364+
* @param url The URL (content) to validate.
1365+
* @param settings The user settings used to configure the connection to the URL or {@code null}.
1366+
* @return <code>true</code> if <code>url</code> points to a valid <code>element-list</code> resource;
1367+
* <code>false</code> else.
1368+
* @throws IOException if reading the resource fails.
1369+
* @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
1370+
* @since 3.1.0
1371+
*/
1372+
protected static boolean isValidElementList(URL url, Settings settings) throws IOException {
13681373
if (url == null) {
1369-
throw new IllegalArgumentException("The url is null");
1374+
throw new NullPointerException("The url is null");
13701375
}
13711376

13721377
try (BufferedReader reader = getReader(url, settings)) {
1373-
if (validateContent) {
1374-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1375-
if (line.startsWith("module:")) {
1376-
continue;
1377-
}
1378+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1379+
if (line.startsWith("module:")) {
1380+
continue;
1381+
}
13781382

1379-
if (!isValidPackageName(line)) {
1380-
return false;
1381-
}
1383+
if (!isValidPackageName(line)) {
1384+
return false;
13821385
}
13831386
}
13841387
return true;

src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ public void testIsValidPackageList() throws Exception {
249249
URL url = null;
250250
URL wrongUrl;
251251
try {
252-
JavadocUtil.isValidPackageList(url, settings, false);
252+
JavadocUtil.isValidPackageList(url, settings);
253253
fail();
254-
} catch (IllegalArgumentException e) {
254+
} catch (NullPointerException e) {
255255
assertTrue(true);
256256
}
257257

258258
url = new File(getBasedir(), "/pom.xml").toURI().toURL();
259-
assertTrue(JavadocUtil.isValidPackageList(url, settings, false));
259+
assertFalse(JavadocUtil.isValidPackageList(url, settings));
260260

261261
try {
262-
assertFalse(JavadocUtil.isValidPackageList(url, settings, true));
262+
assertFalse(JavadocUtil.isValidPackageList(url, settings));
263263
} catch (IOException e) {
264264
assertTrue(true);
265265
}
@@ -268,14 +268,14 @@ public void testIsValidPackageList() throws Exception {
268268
.getResource("/JavadocUtilTest-package-list.txt")
269269
.toURI()
270270
.toURL();
271-
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
271+
assertTrue(JavadocUtil.isValidPackageList(url, settings));
272272

273273
url = new URL("http://maven.apache.org/plugins-archives/maven-javadoc-plugin-3.5.0/apidocs/package-list");
274-
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
274+
assertTrue(JavadocUtil.isValidPackageList(url, settings));
275275

276276
wrongUrl = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list2");
277277
try {
278-
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
278+
JavadocUtil.isValidPackageList(wrongUrl, settings);
279279
fail();
280280
} catch (IOException e) {
281281
assertTrue(true);
@@ -291,10 +291,10 @@ public void testIsValidPackageList() throws Exception {
291291

292292
settings = new Settings();
293293

294-
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
294+
assertTrue(JavadocUtil.isValidPackageList(url, settings));
295295

296296
try {
297-
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
297+
JavadocUtil.isValidPackageList(wrongUrl, settings);
298298
fail();
299299
} catch (IOException e) {
300300
assertTrue(true);
@@ -321,7 +321,7 @@ public void testIsValidPackageList() throws Exception {
321321
proxy.setProtocol("http");
322322
settings.addProxy(proxy);
323323

324-
JavadocUtil.isValidPackageList(url, settings, false);
324+
JavadocUtil.isValidPackageList(url, settings);
325325
fail();
326326
} catch (FileNotFoundException e) {
327327
assertTrue(true);
@@ -345,10 +345,10 @@ public void testIsValidPackageList() throws Exception {
345345
proxy.setPassword("bar");
346346
settings.addProxy(proxy);
347347

348-
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
348+
assertTrue(JavadocUtil.isValidPackageList(url, settings));
349349

350350
try {
351-
JavadocUtil.isValidPackageList(wrongUrl, settings, false);
351+
JavadocUtil.isValidPackageList(wrongUrl, settings);
352352
fail();
353353
} catch (IOException e) {
354354
assertTrue(true);
@@ -373,7 +373,7 @@ public void testIsValidPackageList() throws Exception {
373373
proxy.setPassword("bar");
374374
settings.addProxy(proxy);
375375

376-
JavadocUtil.isValidPackageList(url, settings, true);
376+
JavadocUtil.isValidPackageList(url, settings);
377377
fail();
378378
} catch (SocketTimeoutException e) {
379379
assertTrue(true);
@@ -398,7 +398,7 @@ public void testIsValidPackageList() throws Exception {
398398
proxy.setNonProxyHosts("maven.apache.org");
399399
settings.addProxy(proxy);
400400

401-
assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
401+
assertTrue(JavadocUtil.isValidPackageList(url, settings));
402402
} finally {
403403
proxyServer.stop();
404404
}

0 commit comments

Comments
 (0)