This is an automated email from the ASF dual-hosted git repository. rfscholte pushed a commit to branch pre-MJAVADOC-592 in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/pre-MJAVADOC-592 by this push: new 9f98af7 [MJAVADOC-592] detectJavaApiLink should also respect maven.compiler.source property 9f98af7 is described below commit 9f98af73ec59629415926374cfe4f6ff3b198e45 Author: rfscholte <rfscho...@apache.org> AuthorDate: Fri May 14 08:39:58 2021 +0200 [MJAVADOC-592] detectJavaApiLink should also respect maven.compiler.source property --- .../MJAVADOC-592_detectApiLink/invoker.properties | 17 +++++++ src/it/projects/MJAVADOC-592_detectApiLink/pom.xml | 54 ++++++++++++++++++++++ .../src/main/java/foo/Bar.java | 30 ++++++++++++ .../MJAVADOC-592_detectApiLink/verify.groovy | 21 +++++++++ .../maven/plugins/javadoc/AbstractJavadocMojo.java | 36 ++++++++++++--- 5 files changed, 152 insertions(+), 6 deletions(-) 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 0000000..3a8a738 --- /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 0000000..78ecd47 --- /dev/null +++ b/src/it/projects/MJAVADOC-592_detectApiLink/pom.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.javadoc.it</groupId> + <artifactId>mjavadoc592</artifactId> + <version>1.0-SNAPSHOT</version> + + <url>https://issues.apache.org/jira/browse/MJAVADOC-592</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>7</maven.compiler.source> + <maven.compiler.target>7</maven.compiler.target> + </properties> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>@project.version@</version> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project> 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 0000000..d9304f5 --- /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 0000000..674ad5c --- /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 2d43182..0655f8a 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 <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#summary">Java * 1.4</a>. */ - @Parameter( property = "source" ) + @Parameter( property = "source", defaultValue = "${maven.compiler.source}" ) private String source; /** @@ -2317,6 +2317,20 @@ public abstract class AbstractJavadocMojo if ( StringUtils.isEmpty( subpackages ) ) { Collection<String> 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 @@ public abstract class AbstractJavadocMojo 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 @@ public abstract class AbstractJavadocMojo Map<String, JavaModuleDescriptor> 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 @@ public abstract class AbstractJavadocMojo { 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";