Skip to content

Commit

Permalink
[MJAVADOC-680] JDK 16+: Error fetching link: ...\target\javadoc-bundl…
Browse files Browse the repository at this point in the history
…e-options. Ignored it.
  • Loading branch information
rfscholte committed Aug 23, 2021
1 parent 292ebb7 commit d770460
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
14 changes: 12 additions & 2 deletions src/it/projects/MJAVADOC-580_detectLinks/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,15 @@
* under the License.
*/

def buildLog = new File(basedir,'build.log')
assert buildLog.readLines().any{ it ==~ /\[DEBUG\] Found Java API link: .*\/javase\/\d+\/docs\/api\// }
def javaVersion = System.getProperty( 'java.specification.version' )

if ( javaVersion.startsWith('1.') || Integer.parseInt(javaVersion) < 16 )
{
def buildLog = new File(basedir,'build.log')
assert buildLog.readLines().any{ it ==~ /\[DEBUG\] Found Java API link: .*\/javase\/\d+\/docs\/api\// }
}
else
{
def barHtml = new File(basedir,'target/site/apidocs/foo/Bar.html')
assert barHtml.text =~ /<a href="https:[^"]+Object.html"/
}
Original file line number Diff line number Diff line change
Expand Up @@ -6596,6 +6596,10 @@ else if ( source != null && !source.isEmpty() )
{
javaApiLink = javaApiLinks.getProperty( javaApiKey );
}
else if ( javaApiversion.isAtLeast( "16" ) )
{
javaApiLink = null; // JDK-8216497
}
else if ( javaApiversion.isAtLeast( "11" ) )
{
javaApiLink =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,35 +257,42 @@ public void testDefaultConfiguration()
Path generatedFile = apidocs.resolve( appHtml );
assertThat( generatedFile ).exists();

// only test when URL can be reached

String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
connection.setRequestMethod( "HEAD" );
try
if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "16" ) )
{
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
connection.setRequestMethod( "HEAD" );
try
{
try
// only test when URL can be reached
if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK )
{
assumeThat( connection.getURL().toString(), is( url ) );

// https://bugs.openjdk.java.net/browse/JDK-8216497
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
}
catch ( AssumptionViolatedException e )
{
LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
try
{
assumeThat( connection.getURL().toString(), is( url ) );

// https://bugs.openjdk.java.net/browse/JDK-8216497
MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
anyOf( containsString( "/docs/api/java/lang/Object.html" ),
containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
}
catch ( AssumptionViolatedException e )
{
LOGGER.warn( "ignoring defaultAPI check: {}", e.getMessage() );
}
}
}
catch (Exception e)
{
LOGGER.error("error connecting to javadoc URL: {}", url);
throw e;
}
}
catch (Exception e)
else
{
LOGGER.error("error connecting to javadoc URL: {}", url);
throw e;
MatcherAssert.assertThat( new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
containsString( "/docs/api/java.base/java/lang/Object.html" ) );
}

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

0 comments on commit d770460

Please sign in to comment.