Skip to content

Commit 9f98af7

Browse files
committed
[MJAVADOC-592] detectJavaApiLink should also respect maven.compiler.source property
1 parent 1028afc commit 9f98af7

File tree

5 files changed

+152
-6
lines changed

5 files changed

+152
-6
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
invoker.goals=javadoc:javadoc
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
26+
<artifactId>mjavadoc592</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
29+
<url>https://issues.apache.org/jira/browse/MJAVADOC-592</url>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
<maven.compiler.source>7</maven.compiler.source>
34+
<maven.compiler.target>7</maven.compiler.target>
35+
</properties>
36+
37+
<build>
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<version>3.8.1</version>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-javadoc-plugin</artifactId>
48+
<version>@project.version@</version>
49+
</plugin>
50+
</plugins>
51+
</pluginManagement>
52+
</build>
53+
54+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package foo;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import java.io.IOException;
23+
24+
public class Bar {
25+
26+
public static void main( String[] args )
27+
{
28+
System.out.println( "Hello Bar" );
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 options = new File(basedir,'target/site/apidocs/options')
21+
assert options.readLines().dropWhile{it!='-linkoffline'}.get(1).startsWith("'https://docs.oracle.com/javase/7/docs/api'")

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public abstract class AbstractJavadocMojo
869869
* Since <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#summary">Java
870870
* 1.4</a>.
871871
*/
872-
@Parameter( property = "source" )
872+
@Parameter( property = "source", defaultValue = "${maven.compiler.source}" )
873873
private String source;
874874

875875
/**
@@ -2317,6 +2317,20 @@ protected Map<Path, Collection<String>> getFiles( Collection<Path> sourcePaths )
23172317
if ( StringUtils.isEmpty( subpackages ) )
23182318
{
23192319
Collection<String> excludedPackages = getExcludedPackages();
2320+
2321+
final boolean autoExclude;
2322+
if ( release != null )
2323+
{
2324+
autoExclude = JavaVersion.parse( release ).isBefore( "9" );
2325+
}
2326+
else if ( source != null )
2327+
{
2328+
autoExclude = JavaVersion.parse( source ).isBefore( "9" );
2329+
}
2330+
else
2331+
{
2332+
autoExclude = false;
2333+
}
23202334

23212335
for ( Path sourcePath : sourcePaths )
23222336
{
@@ -2325,8 +2339,7 @@ protected Map<Path, Collection<String>> getFiles( Collection<Path> sourcePaths )
23252339
sourceFileIncludes, sourceFileExcludes,
23262340
excludedPackages ) );
23272341

2328-
if ( source != null && JavaVersion.parse( source ).isBefore( "9" )
2329-
&& files.remove( "module-info.java" ) )
2342+
if ( autoExclude && files.remove( "module-info.java" ) )
23302343
{
23312344
getLog().debug( "Auto exclude module-info.java due to source value" );
23322345
}
@@ -5107,9 +5120,16 @@ private void addJavadocOptions( File javadocOutputDirectory,
51075120

51085121
Map<String, JavaModuleDescriptor> allModuleDescriptors = new HashMap<>();
51095122

5110-
boolean supportModulePath = javadocRuntimeVersion.isAtLeast( "9" )
5111-
&& ( source == null || JavaVersion.parse( source ).isAtLeast( "9" ) )
5112-
&& ( release == null || JavaVersion.parse( release ).isAtLeast( "9" ) );
5123+
5124+
boolean supportModulePath = javadocRuntimeVersion.isAtLeast( "9" );
5125+
if ( release != null )
5126+
{
5127+
supportModulePath &= JavaVersion.parse( release ).isAtLeast( "9" );
5128+
}
5129+
else if ( source != null )
5130+
{
5131+
supportModulePath &= JavaVersion.parse( source ).isAtLeast( "9" );
5132+
}
51135133

51145134
if ( supportModulePath )
51155135
{
@@ -6511,6 +6531,10 @@ protected final OfflineLink getDefaultJavadocApiLink()
65116531
{
65126532
javaApiversion = JavaVersion.parse( release );
65136533
}
6534+
else if ( source != null && !source.isEmpty() )
6535+
{
6536+
javaApiversion = JavaVersion.parse( source );
6537+
}
65146538
else
65156539
{
65166540
final String pluginId = "org.apache.maven.plugins:maven-compiler-plugin";

0 commit comments

Comments
 (0)