Skip to content

Commit b225096

Browse files
committed
[MJAVADOC-642] Make offline mode configurable
expose the offline flag as a property (and a setting).
1 parent c22c8fe commit b225096

File tree

10 files changed

+264
-5
lines changed

10 files changed

+264
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals= package

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed under the Apache License, Version 2.0 (the "License");
4+
~ you may not use this file except in compliance with the License.
5+
~ You may obtain a copy of the License at
6+
~
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~
9+
~ Unless required by applicable law or agreed to in writing, software
10+
~ distributed under the License is distributed on an "AS IS" BASIS,
11+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
~ See the License for the specific language governing permissions and
13+
~ limitations under the License.
14+
-->
15+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
19+
<artifactId>mjavadoc642</artifactId>
20+
<version>1.0-SNAPSHOT</version>
21+
<packaging>jar</packaging>
22+
23+
<url>https://issues.apache.org/jira/browse/MJAVADOC-642</url>
24+
25+
<properties>
26+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27+
</properties>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-javadoc-plugin</artifactId>
33+
<version>@project.version@</version>
34+
<executions>
35+
<execution>
36+
<id>javadoc</id>
37+
<goals>
38+
<goal>jar</goal>
39+
</goals>
40+
<phase>package</phase>
41+
<configuration>
42+
<offline>true</offline>
43+
<skip>false</skip>
44+
<detectJavaApiLink>false</detectJavaApiLink>
45+
<detectOfflineLinks>false</detectOfflineLinks>
46+
<failOnWarnings>true</failOnWarnings>
47+
</configuration>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package mjavadoc642;
21+
22+
/**
23+
* This is the main class.
24+
*/
25+
public final class Main {
26+
/**
27+
* This is the main method.
28+
*
29+
* @param args The arguments
30+
* @throws Exception if something goes wrong
31+
*/
32+
public static final void main(String ... args) throws Exception {
33+
System.out.println("Hello, World!");
34+
}
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def log = new File( basedir, 'build.log').text
21+
22+
assert log.count("[DEBUG] (f) offline = false") == 0
23+
assert log.count("[DEBUG] (f) offline = true") == 1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals= -Dmaven.javadoc.offline=true package
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed under the Apache License, Version 2.0 (the "License");
4+
~ you may not use this file except in compliance with the License.
5+
~ You may obtain a copy of the License at
6+
~
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~
9+
~ Unless required by applicable law or agreed to in writing, software
10+
~ distributed under the License is distributed on an "AS IS" BASIS,
11+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
~ See the License for the specific language governing permissions and
13+
~ limitations under the License.
14+
-->
15+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
18+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
19+
<artifactId>mjavadoc642</artifactId>
20+
<version>1.0-SNAPSHOT</version>
21+
<packaging>jar</packaging>
22+
23+
<url>https://issues.apache.org/jira/browse/MJAVADOC-642</url>
24+
25+
<properties>
26+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27+
</properties>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>maven-javadoc-plugin</artifactId>
33+
<version>@project.version@</version>
34+
<executions>
35+
<execution>
36+
<id>javadoc</id>
37+
<goals>
38+
<goal>jar</goal>
39+
</goals>
40+
<phase>package</phase>
41+
<configuration>
42+
<skip>false</skip>
43+
<detectJavaApiLink>false</detectJavaApiLink>
44+
<detectOfflineLinks>false</detectOfflineLinks>
45+
<failOnWarnings>true</failOnWarnings>
46+
</configuration>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package mjavadoc642;
21+
22+
/**
23+
* This is the main class.
24+
*/
25+
public final class Main {
26+
/**
27+
* This is the main method.
28+
*
29+
* @param args The arguments
30+
* @throws Exception if something goes wrong
31+
*/
32+
public static final void main(String ... args) throws Exception {
33+
System.out.println("Hello, World!");
34+
}
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def log = new File( basedir, 'build.log').text
21+
22+
assert log.count("[DEBUG] (f) offline = false") == 0
23+
assert log.count("[DEBUG] (f) offline = true") == 1

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,11 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
334334

335335
/**
336336
* Specify if the Javadoc should operate in offline mode.
337+
*
338+
* @since 3.6.0
337339
*/
338-
@Parameter(defaultValue = "${settings.offline}", required = true, readonly = true)
339-
private boolean isOffline;
340+
@Parameter(property = "maven.javadoc.offline", defaultValue = "false")
341+
private boolean offline;
340342

341343
/**
342344
* Specifies the Javadoc resources directory to be included in the Javadoc (i.e. package.html, images...).
@@ -1033,7 +1035,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
10331035
*
10341036
* <b>Notes</b>:
10351037
* <ol>
1036-
* <li>only used if {@code isOffline} is set to <code>false</code>.</li>
1038+
* <li>only used if the plugin is not run in offline mode.</li>
10371039
* <li>all given links should have a fetchable <code>/package-list</code> or <code>/element-list</code>
10381040
* (since Java 10). For instance:
10391041
* <pre>
@@ -3781,7 +3783,7 @@ private void addLinkArguments(List<String> arguments) throws MavenReportExceptio
37813783
continue;
37823784
}
37833785

3784-
if (isOffline && !link.startsWith("file:")) {
3786+
if ((settings.isOffline() || offline) && !link.startsWith("file:")) {
37853787
continue;
37863788
}
37873789

src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ under the License.
9898
<header>MAVEN JAVADOC PLUGIN TEST</header>
9999
<footer>MAVEN JAVADOC PLUGIN TEST FOOTER</footer>
100100
<locale>en_US</locale>
101-
<isOffline>true</isOffline>
101+
<offline>true</offline>
102102
<excludePackageNames>*.exclude2:custom.configuration.exclude1.*</excludePackageNames>
103103
<debug>true</debug>
104104
<failOnError>true</failOnError>

0 commit comments

Comments
 (0)