You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2024/08/14 17:39:42 UTC
(maven-javadoc-plugin) branch MJAVADOC-792-alternative created (now ea3d9fa0)
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a change to branch MJAVADOC-792-alternative
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
at ea3d9fa0 Try
This branch includes the following new commits:
new ea3d9fa0 Try
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-javadoc-plugin) 01/01: Try
Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MJAVADOC-792-alternative
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit ea3d9fa055f59ac251a45436a93cf60447ffe982
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed Aug 14 19:39:08 2024 +0200
Try
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 23 ++++++----
.../apache/maven/plugins/javadoc/JavadocUtil.java | 49 ++++++++++++----------
.../maven/plugins/javadoc/JavadocUtilTest.java | 28 ++++++-------
3 files changed, 54 insertions(+), 46 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index 9310370f..0a291dd9 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -3759,13 +3759,14 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
if (location == null || location.isEmpty()) {
continue;
}
- if (isValidJavadocLink(location, false)) {
- addArgIfNotEmpty(
- arguments,
- "-linkoffline",
- JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
- true);
+ if (validateLinks && !isValidJavadocLink(location, false)) {
+ continue;
}
+ addArgIfNotEmpty(
+ arguments,
+ "-linkoffline",
+ JavadocUtil.quotedPathArgument(url) + " " + JavadocUtil.quotedPathArgument(location),
+ true);
}
}
@@ -5617,7 +5618,11 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
}
}
- if (url != null && isValidJavadocLink(url, detected)) {
+ if (url != null) {
+ if (validateLinks && !isValidJavadocLink(url, detected)) {
+ continue;
+ }
+
getLog().debug("Added Javadoc link: " + url + " for " + artifact.getId());
dependenciesLinks.add(url);
@@ -5814,13 +5819,13 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
}
try {
- if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings, validateLinks)) {
+ if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings)) {
return true;
}
} catch (IOException e) {
}
- if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings, validateLinks)) {
+ if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings)) {
return true;
}
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index 5bd3fb7a..f5710ad8 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -1333,52 +1333,55 @@ public class JavadocUtil {
}
/**
- * Validates an <code>URL</code> to point to a valid <code>package-list</code> resource.
+ * Validates the <code>URL</code> (content) to point to a valid <code>package-list</code> resource.
*
- * @param url The URL to validate.
+ * @param url The URL (content) to validate.
* @param settings The user settings used to configure the connection to the URL or {@code null}.
- * @param validateContent <code>true</code> to validate the content of the <code>package-list</code> resource;
- * <code>false</code> to only check the existence of the <code>package-list</code> resource.
* @return <code>true</code> if <code>url</code> points to a valid <code>package-list</code> resource;
* <code>false</code> else.
* @throws IOException if reading the resource fails.
* @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
* @since 2.8
*/
- protected static boolean isValidPackageList(URL url, Settings settings, boolean validateContent)
- throws IOException {
+ protected static boolean isValidPackageList(URL url, Settings settings) throws IOException {
if (url == null) {
- throw new IllegalArgumentException("The url is null");
+ throw new NullPointerException("The url is null");
}
try (BufferedReader reader = getReader(url, settings)) {
- if (validateContent) {
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- if (!isValidPackageName(line)) {
- return false;
- }
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ if (!isValidPackageName(line)) {
+ return false;
}
}
return true;
}
}
- protected static boolean isValidElementList(URL url, Settings settings, boolean validateContent)
- throws IOException {
+ /**
+ * Validates the <code>URL</code> (content) to point to a valid <code>element-list</code> resource.
+ *
+ * @param url The URL (content) to validate.
+ * @param settings The user settings used to configure the connection to the URL or {@code null}.
+ * @return <code>true</code> if <code>url</code> points to a valid <code>element-list</code> resource;
+ * <code>false</code> else.
+ * @throws IOException if reading the resource fails.
+ * @see #createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
+ * @since 3.1.0
+ */
+ protected static boolean isValidElementList(URL url, Settings settings) throws IOException {
if (url == null) {
- throw new IllegalArgumentException("The url is null");
+ throw new NullPointerException("The url is null");
}
try (BufferedReader reader = getReader(url, settings)) {
- if (validateContent) {
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- if (line.startsWith("module:")) {
- continue;
- }
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ if (line.startsWith("module:")) {
+ continue;
+ }
- if (!isValidPackageName(line)) {
- return false;
- }
+ if (!isValidPackageName(line)) {
+ return false;
}
}
return true;
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
index a421706f..5516c308 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
@@ -249,17 +249,17 @@ public class JavadocUtilTest extends PlexusTestCase {
URL url = null;
URL wrongUrl;
try {
- JavadocUtil.isValidPackageList(url, settings, false);
+ JavadocUtil.isValidPackageList(url, settings);
fail();
- } catch (IllegalArgumentException e) {
+ } catch (NullPointerException e) {
assertTrue(true);
}
url = new File(getBasedir(), "/pom.xml").toURI().toURL();
- assertTrue(JavadocUtil.isValidPackageList(url, settings, false));
+ assertFalse(JavadocUtil.isValidPackageList(url, settings));
try {
- assertFalse(JavadocUtil.isValidPackageList(url, settings, true));
+ assertFalse(JavadocUtil.isValidPackageList(url, settings));
} catch (IOException e) {
assertTrue(true);
}
@@ -268,14 +268,14 @@ public class JavadocUtilTest extends PlexusTestCase {
.getResource("/JavadocUtilTest-package-list.txt")
.toURI()
.toURL();
- assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
+ assertTrue(JavadocUtil.isValidPackageList(url, settings));
url = new URL("http://maven.apache.org/plugins-archives/maven-javadoc-plugin-3.5.0/apidocs/package-list");
- assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
+ assertTrue(JavadocUtil.isValidPackageList(url, settings));
wrongUrl = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list2");
try {
- JavadocUtil.isValidPackageList(wrongUrl, settings, false);
+ JavadocUtil.isValidPackageList(wrongUrl, settings);
fail();
} catch (IOException e) {
assertTrue(true);
@@ -291,10 +291,10 @@ public class JavadocUtilTest extends PlexusTestCase {
settings = new Settings();
- assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
+ assertTrue(JavadocUtil.isValidPackageList(url, settings));
try {
- JavadocUtil.isValidPackageList(wrongUrl, settings, false);
+ JavadocUtil.isValidPackageList(wrongUrl, settings);
fail();
} catch (IOException e) {
assertTrue(true);
@@ -321,7 +321,7 @@ public class JavadocUtilTest extends PlexusTestCase {
proxy.setProtocol("http");
settings.addProxy(proxy);
- JavadocUtil.isValidPackageList(url, settings, false);
+ JavadocUtil.isValidPackageList(url, settings);
fail();
} catch (FileNotFoundException e) {
assertTrue(true);
@@ -345,10 +345,10 @@ public class JavadocUtilTest extends PlexusTestCase {
proxy.setPassword("bar");
settings.addProxy(proxy);
- assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
+ assertTrue(JavadocUtil.isValidPackageList(url, settings));
try {
- JavadocUtil.isValidPackageList(wrongUrl, settings, false);
+ JavadocUtil.isValidPackageList(wrongUrl, settings);
fail();
} catch (IOException e) {
assertTrue(true);
@@ -373,7 +373,7 @@ public class JavadocUtilTest extends PlexusTestCase {
proxy.setPassword("bar");
settings.addProxy(proxy);
- JavadocUtil.isValidPackageList(url, settings, true);
+ JavadocUtil.isValidPackageList(url, settings);
fail();
} catch (SocketTimeoutException e) {
assertTrue(true);
@@ -398,7 +398,7 @@ public class JavadocUtilTest extends PlexusTestCase {
proxy.setNonProxyHosts("maven.apache.org");
settings.addProxy(proxy);
- assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
+ assertTrue(JavadocUtil.isValidPackageList(url, settings));
} finally {
proxyServer.stop();
}