Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen scope of validateLinks #308

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/it/projects/MJAVADOC-498_aggr_modulepath/baz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>javadoc-aggregate</id>
<phase>package</phase>
<goals>
<goal>javadoc-no-fork</goal>
</goals>
<configuration>
<includeDependencySources>true</includeDependencySources>
<includeTransitiveDependencySources>true</includeTransitiveDependencySources>
</configuration>
</execution>
</executions>
<configuration>
<includeDependencySources>true</includeDependencySources>
<includeTransitiveDependencySources>true</includeTransitiveDependencySources>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -58,4 +49,4 @@
</dependency>
</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -16,3 +16,4 @@
# under the License.

invoker.java.version = 9+
invoker.goals=clean compile javadoc:javadoc
9 changes: 0 additions & 9 deletions src/it/projects/MJAVADOC-498_aggr_modulepath/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
5 changes: 3 additions & 2 deletions src/it/projects/MJAVADOC-498_mm_modulepath/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -16,3 +16,4 @@
# under the License.

invoker.java.version = 9+
invoker.goals=clean compile javadoc:javadoc
9 changes: 0 additions & 9 deletions src/it/projects/MJAVADOC-498_mm_modulepath/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
1 change: 1 addition & 0 deletions src/it/projects/MJAVADOC-498_modulepath/invoker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
# under the License.

invoker.java.version = 9+
invoker.goals=clean compile javadoc:javadoc javadoc:test-javadoc
9 changes: 0 additions & 9 deletions src/it/projects/MJAVADOC-498_modulepath/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id></id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
5 changes: 3 additions & 2 deletions src/it/projects/MJAVADOC-498_modulepath/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
* under the License.
*/
def log = new File( basedir, 'build.log').text

assert log.count( " --module-path" ) == 3
def count = log.count( " --module-path" )
// depends on Maven version
assert count == 2 || count == 3
1 change: 1 addition & 0 deletions src/it/projects/MJAVADOC-528/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<version>@project.version@</version>
<configuration>
<detectLinks>true</detectLinks>
<validateLinks>true</validateLinks>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3759,13 +3759,14 @@ private void addLinkofflineArguments(List<String> arguments, Set<OfflineLink> of
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);
}
}

Expand Down Expand Up @@ -5617,7 +5618,11 @@ private List<String> getDependenciesLinks() {
}
}

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);
Expand Down Expand Up @@ -5814,14 +5819,14 @@ protected boolean isValidJavadocLink(String link, boolean detecting) {
}

try {
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings, validateLinks)) {
if (JavadocUtil.isValidElementList(elementListUri.toURL(), settings)) {
return true;
}
} catch (IOException e) {
// ignore this because it is optional
}

if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings, validateLinks)) {
if (JavadocUtil.isValidPackageList(packageListUri.toURL(), settings)) {
return true;
}

Expand Down
49 changes: 26 additions & 23 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1333,52 +1333,55 @@ protected static URL getRedirectUrl(URL url, Settings settings) throws IOExcepti
}

/**
* 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;
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ public void testIsValidPackageList() throws Exception {
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);
}
Expand All @@ -268,14 +268,14 @@ public void testIsValidPackageList() throws Exception {
.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);
Expand All @@ -291,10 +291,10 @@ public void testIsValidPackageList() throws Exception {

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);
Expand All @@ -321,7 +321,7 @@ public void testIsValidPackageList() throws Exception {
proxy.setProtocol("http");
settings.addProxy(proxy);

JavadocUtil.isValidPackageList(url, settings, false);
JavadocUtil.isValidPackageList(url, settings);
fail();
} catch (FileNotFoundException e) {
assertTrue(true);
Expand All @@ -345,10 +345,10 @@ public void testIsValidPackageList() throws Exception {
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);
Expand All @@ -373,7 +373,7 @@ public void testIsValidPackageList() throws Exception {
proxy.setPassword("bar");
settings.addProxy(proxy);

JavadocUtil.isValidPackageList(url, settings, true);
JavadocUtil.isValidPackageList(url, settings);
fail();
} catch (SocketTimeoutException e) {
assertTrue(true);
Expand All @@ -398,7 +398,7 @@ public void testIsValidPackageList() throws Exception {
proxy.setNonProxyHosts("maven.apache.org");
settings.addProxy(proxy);

assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
assertTrue(JavadocUtil.isValidPackageList(url, settings));
} finally {
proxyServer.stop();
}
Expand Down