Skip to content

Commit d37a6d4

Browse files
committed
Try
1 parent 6c5fdc0 commit d37a6d4

File tree

4 files changed

+55
-46
lines changed

4 files changed

+55
-46
lines changed

src/it/projects/MJAVADOC-528/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<version>@project.version@</version>
4040
<configuration>
4141
<detectLinks>true</detectLinks>
42+
<validateLinks>true</validateLinks>
4243
</configuration>
4344
</plugin>
4445
</plugins>

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -3769,13 +3769,14 @@ private void addLinkofflineArguments(List<String> arguments, Set<OfflineLink> of
37693769
if (location == null || location.isEmpty()) {
37703770
continue;
37713771
}
3772-
if (isValidJavadocLink(location, false)) {
3773-
addArgIfNotEmpty(
3774-
arguments,
3775-
"-linkoffline",
3776-
JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
3777-
true);
3772+
if (validateLinks && !isValidJavadocLink(location, false)) {
3773+
continue;
37783774
}
3775+
addArgIfNotEmpty(
3776+
arguments,
3777+
"-linkoffline",
3778+
JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
3779+
true);
37793780
}
37803781
}
37813782

@@ -5571,7 +5572,11 @@ private List<String> getDependenciesLinks() {
55715572
}
55725573
}
55735574

5574-
if (url != null && isValidJavadocLink(url, detected)) {
5575+
if (url != null) {
5576+
if (validateLinks && !isValidJavadocLink(url, detected)) {
5577+
continue;
5578+
}
5579+
55755580
getLog().debug("Added Javadoc link: " + url + " for " + artifact.getId());
55765581

55775582
dependenciesLinks.add(url);
@@ -5768,14 +5773,14 @@ protected boolean isValidJavadocLink(String link, boolean detecting) {
57685773
}
57695774

57705775
try {
5771-
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings, validateLinks)) {
5776+
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings)) {
57725777
return true;
57735778
}
57745779
} catch (IOException e) {
57755780
// ignore this because it is optional
57765781
}
57775782

5778-
if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings, validateLinks)) {
5783+
if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings)) {
57795784
return true;
57805785
}
57815786

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

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

13431343
/**
1344-
* Validates an <code>URL</code> to point to a valid <code>package-list</code> resource.
1344+
* Validates the <code>URL</code> (content) to point to a valid <code>package-list</code> resource.
13451345
*
1346-
* @param url The URL to validate.
1346+
* @param url The URL (content) to validate.
13471347
* @param settings The user settings used to configure the connection to the URL or {@code null}.
1348-
* @param validateContent <code>true</code> to validate the content of the <code>package-list</code> resource;
1349-
* <code>false</code> to only check the existence of the <code>package-list</code> resource.
13501348
* @return <code>true</code> if <code>url</code> points to a valid <code>package-list</code> resource;
13511349
* <code>false</code> else.
13521350
* @throws IOException if reading the resource fails.
13531351
* @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
13541352
* @since 2.8
13551353
*/
1356-
protected static boolean isValidPackageList(URL url, Settings settings, boolean validateContent)
1357-
throws IOException {
1354+
protected static boolean isValidPackageList(URL url, Settings settings) throws IOException {
13581355
if (url == null) {
1359-
throw new IllegalArgumentException("The url is null");
1356+
throw new NullPointerException("The url is null");
13601357
}
13611358

13621359
try (BufferedReader reader = getReader(url, settings)) {
1363-
if (validateContent) {
1364-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1365-
if (!isValidPackageName(line)) {
1366-
return false;
1367-
}
1360+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1361+
if (!isValidPackageName(line)) {
1362+
return false;
13681363
}
13691364
}
13701365
return true;
13711366
}
13721367
}
13731368

1374-
protected static boolean isValidElementList(URL url, Settings settings, boolean validateContent)
1375-
throws IOException {
1369+
/**
1370+
* Validates the <code>URL</code> (content) to point to a valid <code>element-list</code> resource.
1371+
*
1372+
* @param url The URL (content) to validate.
1373+
* @param settings The user settings used to configure the connection to the URL or {@code null}.
1374+
* @return <code>true</code> if <code>url</code> points to a valid <code>element-list</code> resource;
1375+
* <code>false</code> else.
1376+
* @throws IOException if reading the resource fails.
1377+
* @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
1378+
* @since 3.1.0
1379+
*/
1380+
protected static boolean isValidElementList(URL url, Settings settings) throws IOException {
13761381
if (url == null) {
1377-
throw new IllegalArgumentException("The url is null");
1382+
throw new NullPointerException("The url is null");
13781383
}
13791384

13801385
try (BufferedReader reader = getReader(url, settings)) {
1381-
if (validateContent) {
1382-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1383-
if (line.startsWith("module:")) {
1384-
continue;
1385-
}
1386+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
1387+
if (line.startsWith("module:")) {
1388+
continue;
1389+
}
13861390

1387-
if (!isValidPackageName(line)) {
1388-
return false;
1389-
}
1391+
if (!isValidPackageName(line)) {
1392+
return false;
13901393
}
13911394
}
13921395
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)