This is an automated email from the ASF dual-hosted git repository. henning pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 6f30bed4 [MJAVADOC-642] Make offline mode configurable (#232) 6f30bed4 is described below commit 6f30bed49a05dc548b4a6c1cffde92204aca14c6 Author: Henning Schmiedehausen <henn...@schmiedehausen.org> AuthorDate: Sat Sep 9 10:04:24 2023 -0700 [MJAVADOC-642] Make offline mode configurable (#232) expose the offline flag as a property (and a setting). --- src/it/projects/MJAVADOC-642/invoker.properties | 18 ++++++++ src/it/projects/MJAVADOC-642/pom.xml | 53 ++++++++++++++++++++++ .../src/main/java/mjavadoc642/Main.java | 35 ++++++++++++++ src/it/projects/MJAVADOC-642/verify.groovy | 23 ++++++++++ .../MJAVADOC-642_cmdline/invoker.properties | 18 ++++++++ src/it/projects/MJAVADOC-642_cmdline/pom.xml | 52 +++++++++++++++++++++ .../src/main/java/mjavadoc642/Main.java | 35 ++++++++++++++ src/it/projects/MJAVADOC-642_cmdline/verify.groovy | 23 ++++++++++ .../maven/plugins/javadoc/AbstractJavadocMojo.java | 16 +++++-- .../custom-configuration-plugin-config.xml | 2 +- 10 files changed, 269 insertions(+), 6 deletions(-) diff --git a/src/it/projects/MJAVADOC-642/invoker.properties b/src/it/projects/MJAVADOC-642/invoker.properties new file mode 100644 index 00000000..4c251c07 --- /dev/null +++ b/src/it/projects/MJAVADOC-642/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# 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 +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals= package diff --git a/src/it/projects/MJAVADOC-642/pom.xml b/src/it/projects/MJAVADOC-642/pom.xml new file mode 100644 index 00000000..a086f869 --- /dev/null +++ b/src/it/projects/MJAVADOC-642/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +~ Licensed 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 KIND, either express or implied. +~ See the License for the specific language governing permissions and +~ limitations under the License. +--> +<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"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.javadoc.it</groupId> + <artifactId>mjavadoc642</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <url>https://issues.apache.org/jira/browse/MJAVADOC-642</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>javadoc</id> + <goals> + <goal>jar</goal> + </goals> + <phase>package</phase> + <configuration> + <offline>true</offline> + <skip>false</skip> + <detectJavaApiLink>false</detectJavaApiLink> + <detectOfflineLinks>false</detectOfflineLinks> + <failOnWarnings>true</failOnWarnings> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/it/projects/MJAVADOC-642/src/main/java/mjavadoc642/Main.java b/src/it/projects/MJAVADOC-642/src/main/java/mjavadoc642/Main.java new file mode 100644 index 00000000..088c2b3c --- /dev/null +++ b/src/it/projects/MJAVADOC-642/src/main/java/mjavadoc642/Main.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mjavadoc642; + +/** + * This is the main class. + */ +public final class Main { + /** + * This is the main method. + * + * @param args The arguments + * @throws Exception if something goes wrong + */ + public static final void main(String ... args) throws Exception { + System.out.println("Hello, World!"); + } +} diff --git a/src/it/projects/MJAVADOC-642/verify.groovy b/src/it/projects/MJAVADOC-642/verify.groovy new file mode 100644 index 00000000..05c87788 --- /dev/null +++ b/src/it/projects/MJAVADOC-642/verify.groovy @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def log = new File( basedir, 'build.log').text + +assert log.count("[DEBUG] (f) offline = false") == 0 +assert log.count("[DEBUG] (f) offline = true") == 1 diff --git a/src/it/projects/MJAVADOC-642_cmdline/invoker.properties b/src/it/projects/MJAVADOC-642_cmdline/invoker.properties new file mode 100644 index 00000000..0fe00967 --- /dev/null +++ b/src/it/projects/MJAVADOC-642_cmdline/invoker.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# 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 +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals= -Dmaven.javadoc.offline=true package diff --git a/src/it/projects/MJAVADOC-642_cmdline/pom.xml b/src/it/projects/MJAVADOC-642_cmdline/pom.xml new file mode 100644 index 00000000..3297e5f6 --- /dev/null +++ b/src/it/projects/MJAVADOC-642_cmdline/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +~ Licensed 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 KIND, either express or implied. +~ See the License for the specific language governing permissions and +~ limitations under the License. +--> +<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"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.javadoc.it</groupId> + <artifactId>mjavadoc642</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <url>https://issues.apache.org/jira/browse/MJAVADOC-642</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>javadoc</id> + <goals> + <goal>jar</goal> + </goals> + <phase>package</phase> + <configuration> + <skip>false</skip> + <detectJavaApiLink>false</detectJavaApiLink> + <detectOfflineLinks>false</detectOfflineLinks> + <failOnWarnings>true</failOnWarnings> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/src/it/projects/MJAVADOC-642_cmdline/src/main/java/mjavadoc642/Main.java b/src/it/projects/MJAVADOC-642_cmdline/src/main/java/mjavadoc642/Main.java new file mode 100644 index 00000000..088c2b3c --- /dev/null +++ b/src/it/projects/MJAVADOC-642_cmdline/src/main/java/mjavadoc642/Main.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package mjavadoc642; + +/** + * This is the main class. + */ +public final class Main { + /** + * This is the main method. + * + * @param args The arguments + * @throws Exception if something goes wrong + */ + public static final void main(String ... args) throws Exception { + System.out.println("Hello, World!"); + } +} diff --git a/src/it/projects/MJAVADOC-642_cmdline/verify.groovy b/src/it/projects/MJAVADOC-642_cmdline/verify.groovy new file mode 100644 index 00000000..05c87788 --- /dev/null +++ b/src/it/projects/MJAVADOC-642_cmdline/verify.groovy @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * 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 + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def log = new File( basedir, 'build.log').text + +assert log.count("[DEBUG] (f) offline = false") == 0 +assert log.count("[DEBUG] (f) offline = true") == 1 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 5f8c30fa..e812c17f 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -333,10 +333,14 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { private MojoExecution mojo; /** - * Specify if the Javadoc should operate in offline mode. + * Specify if the Javadoc plugin should operate in offline mode. If maven is run in offline + * mode (using {@code -o} or {@code --offline} on the command line), this option has no effect + * and the plugin is always in offline mode. + * + * @since 3.6.0 */ - @Parameter(defaultValue = "${settings.offline}", required = true, readonly = true) - private boolean isOffline; + @Parameter(property = "maven.javadoc.offline", defaultValue = "false") + private boolean offline; /** * Specifies the Javadoc resources directory to be included in the Javadoc (i.e. package.html, images...). @@ -1033,7 +1037,9 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { * * <b>Notes</b>: * <ol> - * <li>only used if {@code isOffline} is set to <code>false</code>.</li> + * <li>This option is ignored if the plugin is run in offline mode (using the {@code <offline>} + * setting or specifying {@code -o, --offline} or {@code -Dmaven.javadoc.offline=true} on the + * command line.</li> * <li>all given links should have a fetchable <code>/package-list</code> or <code>/element-list</code> * (since Java 10). For instance: * <pre> @@ -3781,7 +3787,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { continue; } - if (isOffline && !link.startsWith("file:")) { + if ((settings.isOffline() || offline) && !link.startsWith("file:")) { continue; } diff --git a/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml b/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml index d9d0ec17..6ed8ad0b 100644 --- a/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml +++ b/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml @@ -98,7 +98,7 @@ under the License. <header>MAVEN JAVADOC PLUGIN TEST</header> <footer>MAVEN JAVADOC PLUGIN TEST FOOTER</footer> <locale>en_US</locale> - <isOffline>true</isOffline> + <offline>true</offline> <excludePackageNames>*.exclude2:custom.configuration.exclude1.*</excludePackageNames> <debug>true</debug> <failOnError>true</failOnError>