Skip to content

Commit

Permalink
[MJAVADOC-592] detectJavaApiLink should also respect maven.compiler.s…
Browse files Browse the repository at this point in the history
…ource property
  • Loading branch information
rfscholte committed May 14, 2021
1 parent 1028afc commit 9f98af7
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/it/projects/MJAVADOC-592_detectApiLink/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions src/it/projects/MJAVADOC-592_detectApiLink/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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" );
}
}
21 changes: 21 additions & 0 deletions src/it/projects/MJAVADOC-592_detectApiLink/verify.groovy
Original file line number Diff line number Diff line change
@@ -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'")
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -2317,6 +2317,20 @@ protected Map<Path, Collection<String>> getFiles( Collection<Path> sourcePaths )
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 )
{
Expand All @@ -2325,8 +2339,7 @@ protected Map<Path, Collection<String>> getFiles( Collection<Path> 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" );
}
Expand Down Expand Up @@ -5107,9 +5120,16 @@ private void addJavadocOptions( File javadocOutputDirectory,

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 )
{
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 9f98af7

Please sign in to comment.