From b2250960f9c7a04a1822cadd5d1cbf0a1ffc6ebb Mon Sep 17 00:00:00 2001 From: "Henning P. Schmiedehausen" Date: Fri, 8 Sep 2023 12:58:52 -0700 Subject: [PATCH] [MJAVADOC-642] Make offline mode configurable expose the offline flag as a property (and a setting). --- .../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 ++++++++++++ .../MJAVADOC-642_cmdline/verify.groovy | 23 ++++++++ .../plugins/javadoc/AbstractJavadocMojo.java | 10 ++-- .../custom-configuration-plugin-config.xml | 2 +- 10 files changed, 264 insertions(+), 5 deletions(-) create mode 100644 src/it/projects/MJAVADOC-642/invoker.properties create mode 100644 src/it/projects/MJAVADOC-642/pom.xml create mode 100644 src/it/projects/MJAVADOC-642/src/main/java/mjavadoc642/Main.java create mode 100644 src/it/projects/MJAVADOC-642/verify.groovy create mode 100644 src/it/projects/MJAVADOC-642_cmdline/invoker.properties create mode 100644 src/it/projects/MJAVADOC-642_cmdline/pom.xml create mode 100644 src/it/projects/MJAVADOC-642_cmdline/src/main/java/mjavadoc642/Main.java create mode 100644 src/it/projects/MJAVADOC-642_cmdline/verify.groovy 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 @@ + + + + 4.0.0 + + org.apache.maven.plugins.javadoc.it + mjavadoc642 + 1.0-SNAPSHOT + jar + + https://issues.apache.org/jira/browse/MJAVADOC-642 + + + UTF-8 + + + + + + maven-javadoc-plugin + @project.version@ + + + javadoc + + jar + + package + + true + false + false + false + true + + + + + + + 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 @@ + + + + 4.0.0 + + org.apache.maven.plugins.javadoc.it + mjavadoc642 + 1.0-SNAPSHOT + jar + + https://issues.apache.org/jira/browse/MJAVADOC-642 + + + UTF-8 + + + + + + maven-javadoc-plugin + @project.version@ + + + javadoc + + jar + + package + + false + false + false + true + + + + + + + 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 b0d401c7..f353e3d8 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -334,9 +334,11 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { /** * Specify if the Javadoc should operate 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 +1035,7 @@ public abstract class AbstractJavadocMojo extends AbstractMojo { * * Notes: *
    - *
  1. only used if {@code isOffline} is set to false.
  2. + *
  3. only used if the plugin is not run in offline mode.
  4. *
  5. all given links should have a fetchable /package-list or /element-list * (since Java 10). For instance: *
    @@ -3781,7 +3783,7 @@ private void addLinkArguments(List arguments) throws MavenReportExceptio
                     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.
               
    MAVEN JAVADOC PLUGIN TEST
    MAVEN JAVADOC PLUGIN TEST FOOTER
    en_US - true + true *.exclude2:custom.configuration.exclude1.* true true