From 9f98af73ec59629415926374cfe4f6ff3b198e45 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Fri, 14 May 2021 08:39:58 +0200 Subject: [PATCH] [MJAVADOC-592] detectJavaApiLink should also respect maven.compiler.source property --- .../invoker.properties | 17 ++++++ .../MJAVADOC-592_detectApiLink/pom.xml | 54 +++++++++++++++++++ .../src/main/java/foo/Bar.java | 30 +++++++++++ .../MJAVADOC-592_detectApiLink/verify.groovy | 21 ++++++++ .../plugins/javadoc/AbstractJavadocMojo.java | 36 ++++++++++--- 5 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 src/it/projects/MJAVADOC-592_detectApiLink/invoker.properties create mode 100644 src/it/projects/MJAVADOC-592_detectApiLink/pom.xml create mode 100644 src/it/projects/MJAVADOC-592_detectApiLink/src/main/java/foo/Bar.java create mode 100644 src/it/projects/MJAVADOC-592_detectApiLink/verify.groovy diff --git a/src/it/projects/MJAVADOC-592_detectApiLink/invoker.properties b/src/it/projects/MJAVADOC-592_detectApiLink/invoker.properties new file mode 100644 index 000000000..3a8a7389c --- /dev/null +++ b/src/it/projects/MJAVADOC-592_detectApiLink/invoker.properties @@ -0,0 +1,17 @@ +# 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=javadoc:javadoc diff --git a/src/it/projects/MJAVADOC-592_detectApiLink/pom.xml b/src/it/projects/MJAVADOC-592_detectApiLink/pom.xml new file mode 100644 index 000000000..78ecd47df --- /dev/null +++ b/src/it/projects/MJAVADOC-592_detectApiLink/pom.xml @@ -0,0 +1,54 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.javadoc.it + mjavadoc592 + 1.0-SNAPSHOT + + https://issues.apache.org/jira/browse/MJAVADOC-592 + + + UTF-8 + 7 + 7 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-javadoc-plugin + @project.version@ + + + + + + diff --git a/src/it/projects/MJAVADOC-592_detectApiLink/src/main/java/foo/Bar.java b/src/it/projects/MJAVADOC-592_detectApiLink/src/main/java/foo/Bar.java new file mode 100644 index 000000000..d9304f514 --- /dev/null +++ b/src/it/projects/MJAVADOC-592_detectApiLink/src/main/java/foo/Bar.java @@ -0,0 +1,30 @@ +package foo; + +/* + * 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. + */ + +import java.io.IOException; + +public class Bar { + + public static void main( String[] args ) + { + System.out.println( "Hello Bar" ); + } +} diff --git a/src/it/projects/MJAVADOC-592_detectApiLink/verify.groovy b/src/it/projects/MJAVADOC-592_detectApiLink/verify.groovy new file mode 100644 index 000000000..674ad5c27 --- /dev/null +++ b/src/it/projects/MJAVADOC-592_detectApiLink/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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 options = new File(basedir,'target/site/apidocs/options') +assert options.readLines().dropWhile{it!='-linkoffline'}.get(1).startsWith("'https://docs.oracle.com/javase/7/docs/api'") 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 2d4318210..0655f8a13 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -869,7 +869,7 @@ public abstract class AbstractJavadocMojo * Since Java * 1.4. */ - @Parameter( property = "source" ) + @Parameter( property = "source", defaultValue = "${maven.compiler.source}" ) private String source; /** @@ -2317,6 +2317,20 @@ protected Map> getFiles( Collection sourcePaths ) if ( StringUtils.isEmpty( subpackages ) ) { Collection excludedPackages = getExcludedPackages(); + + final boolean autoExclude; + if ( release != null ) + { + autoExclude = JavaVersion.parse( release ).isBefore( "9" ); + } + else if ( source != null ) + { + autoExclude = JavaVersion.parse( source ).isBefore( "9" ); + } + else + { + autoExclude = false; + } for ( Path sourcePath : sourcePaths ) { @@ -2325,8 +2339,7 @@ protected Map> getFiles( Collection sourcePaths ) sourceFileIncludes, sourceFileExcludes, excludedPackages ) ); - if ( source != null && JavaVersion.parse( source ).isBefore( "9" ) - && files.remove( "module-info.java" ) ) + if ( autoExclude && files.remove( "module-info.java" ) ) { getLog().debug( "Auto exclude module-info.java due to source value" ); } @@ -5107,9 +5120,16 @@ private void addJavadocOptions( File javadocOutputDirectory, Map allModuleDescriptors = new HashMap<>(); - boolean supportModulePath = javadocRuntimeVersion.isAtLeast( "9" ) - && ( source == null || JavaVersion.parse( source ).isAtLeast( "9" ) ) - && ( release == null || JavaVersion.parse( release ).isAtLeast( "9" ) ); + + boolean supportModulePath = javadocRuntimeVersion.isAtLeast( "9" ); + if ( release != null ) + { + supportModulePath &= JavaVersion.parse( release ).isAtLeast( "9" ); + } + else if ( source != null ) + { + supportModulePath &= JavaVersion.parse( source ).isAtLeast( "9" ); + } if ( supportModulePath ) { @@ -6511,6 +6531,10 @@ protected final OfflineLink getDefaultJavadocApiLink() { javaApiversion = JavaVersion.parse( release ); } + else if ( source != null && !source.isEmpty() ) + { + javaApiversion = JavaVersion.parse( source ); + } else { final String pluginId = "org.apache.maven.plugins:maven-compiler-plugin";