Skip to content

Commit d770460

Browse files
committed
[MJAVADOC-680] JDK 16+: Error fetching link: ...\target\javadoc-bundle-options. Ignored it.
1 parent 292ebb7 commit d770460

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

src/it/projects/MJAVADOC-580_detectLinks/verify.groovy

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@
1717
* under the License.
1818
*/
1919

20-
def buildLog = new File(basedir,'build.log')
21-
assert buildLog.readLines().any{ it ==~ /\[DEBUG\] Found Java API link: .*\/javase\/\d+\/docs\/api\// }
20+
def javaVersion = System.getProperty( 'java.specification.version' )
21+
22+
if ( javaVersion.startsWith('1.') || Integer.parseInt(javaVersion) < 16 )
23+
{
24+
def buildLog = new File(basedir,'build.log')
25+
assert buildLog.readLines().any{ it ==~ /\[DEBUG\] Found Java API link: .*\/javase\/\d+\/docs\/api\// }
26+
}
27+
else
28+
{
29+
def barHtml = new File(basedir,'target/site/apidocs/foo/Bar.html')
30+
assert barHtml.text =~ /<a href="https:[^"]+Object.html"/
31+
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -6596,6 +6596,10 @@ else if ( source != null && !source.isEmpty() )
65966596
{
65976597
javaApiLink = javaApiLinks.getProperty( javaApiKey );
65986598
}
6599+
else if ( javaApiversion.isAtLeast( "16" ) )
6600+
{
6601+
javaApiLink = null; // JDK-8216497
6602+
}
65996603
else if ( javaApiversion.isAtLeast( "11" ) )
66006604
{
66016605
javaApiLink =

src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java

+29-22
Original file line numberDiff line numberDiff line change
@@ -257,35 +257,42 @@ public void testDefaultConfiguration()
257257
Path generatedFile = apidocs.resolve( appHtml );
258258
assertThat( generatedFile ).exists();
259259

260-
// only test when URL can be reached
261-
262-
String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
263-
HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
264-
connection.setRequestMethod( "HEAD" );
265-
try
260+
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "16" ) )
266261
{
267-
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
262+
String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
263+
HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
264+
connection.setRequestMethod( "HEAD" );
265+
try
268266
{
269-
try
267+
// only test when URL can be reached
268+
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
270269
{
271-
assumeThat( connection.getURL().toString(), is( url ) );
272-
273-
// https://bugs.openjdk.java.net/browse/JDK-8216497
274-
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
275-
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
276-
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
277-
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
278-
}
279-
catch ( AssumptionViolatedException e )
280-
{
281-
LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
270+
try
271+
{
272+
assumeThat( connection.getURL().toString(), is( url ) );
273+
274+
// https://bugs.openjdk.java.net/browse/JDK-8216497
275+
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
276+
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
277+
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
278+
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
279+
}
280+
catch ( AssumptionViolatedException e )
281+
{
282+
LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
283+
}
282284
}
283285
}
286+
catch (Exception e)
287+
{
288+
LOGGER.error("error connecting to javadoc URL: {}", url);
289+
throw e;
290+
}
284291
}
285-
catch (Exception e)
292+
else
286293
{
287-
LOGGER.error("error connecting to javadoc URL: {}", url);
288-
throw e;
294+
MatcherAssert.assertThat( new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
295+
containsString( "/docs/api/java.base/java/lang/Object.html" ) );
289296
}
290297

291298
assertThat( apidocs.resolve( "def/configuration/AppSample.html" )).exists();

0 commit comments

Comments
 (0)