Skip to content

Commit

Permalink
Improve external link checker, swapping the number of the latest rele…
Browse files Browse the repository at this point in the history
…ase using a regex
  • Loading branch information
nizarbenalla committed Dec 20, 2024
1 parent b6ccb57 commit 0857f83
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 71 deletions.
119 changes: 64 additions & 55 deletions test/docs/jdk/javadoc/doccheck/ExtLinksJdk.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# This file is used to check external links in the JDK generated documentation
# to prevent broken links from backsliding into the JDK source.
#
# The file serves as a "whitelist" of links that have been checked to be working as intended
# and JDK developers should add external links to this file whenever they add them to their documentation.
#
#
# The links in this file are checked before every release.
#
#
#
http://cldr.unicode.org/
http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf
http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
http://docs.oracle.com/javase/feedback.html
http://docs.oracle.com/javase/jndi/tutorial/index.html
http://docs.oracle.com/javase/specs/jls/se25/html/jls-12.html
http://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-12.html
http://docs.oracle.com/javase/tutorial/collections/index.html
http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html
Expand Down Expand Up @@ -98,8 +109,6 @@ http://www.ietf.org/rfc/rfc3491.txt
http://www.ietf.org/rfc/rfc3492.txt
http://www.ietf.org/rfc/rfc3530.txt
http://www.ietf.org/rfc/rfc3720.txt
key = http://www.ietf.org/rfc/rfc3720.txt"
value = {LinkedHashSet@1761} size = 2
http://www.ietf.org/rfc/rfc3720.txt.pdf
http://www.ietf.org/rfc/rfc3758.txt
http://www.ietf.org/rfc/rfc3810.txt
Expand Down Expand Up @@ -264,9 +273,9 @@ https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/Double.ht
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/math/BigDecimal.html
https://docs.oracle.com/en/java/javase/23/docs/specs/man/java.html
https://docs.oracle.com/en/java/javase/24/docs/specs/man/java.html
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html
https://docs.oracle.com/en/java/javase/25/docs/specs/javadoc/javadoc-search-spec.html
https://docs.oracle.com/en/java/javase/25/docs/specs/man/javadoc.html
https://docs.oracle.com/en/java/javase/@@JAVASE_VERSION@@/docs/api/java.base/java/lang/String.html
https://docs.oracle.com/en/java/javase/@@JAVASE_VERSION@@/docs/specs/javadoc/javadoc-search-spec.html
https://docs.oracle.com/en/java/javase/@@JAVASE_VERSION@@/docs/specs/man/javadoc.html
https://docs.oracle.com/en/java/javase/index.html
https://docs.oracle.com/javase/10/tools/java.htm
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
Expand Down Expand Up @@ -315,24 +324,24 @@ https://docs.oracle.com/javase/specs/jls/se23/html/jls-8.html
https://docs.oracle.com/javase/specs/jls/se23/html/jls-9.html
https://docs.oracle.com/javase/specs/jls/se24/html/index.html
https://docs.oracle.com/javase/specs/jls/se24/html/jls-9.html
https://docs.oracle.com/javase/specs/jls/se25/html/
https://docs.oracle.com/javase/specs/jls/se25/html/index.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-10.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-11.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-12.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-13.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-14.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-17.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-18.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-3.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-4.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-5.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-6.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-7.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-8.html
https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html
https://docs.oracle.com/javase/specs/jls/se25/jls25.pdf
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/index.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-10.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-11.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-12.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-13.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-14.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-15.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-17.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-18.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-3.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-4.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-5.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-6.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-7.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-8.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/html/jls-9.html
https://docs.oracle.com/javase/specs/jls/se@@JAVASE_VERSION@@/jls@@JAVASE_VERSION@@.pdf
https://docs.oracle.com/javase/specs/jls/se6/html/j3TOC.html
https://docs.oracle.com/javase/specs/jls/se7/html/index.html
https://docs.oracle.com/javase/specs/jls/se8/html/index.html
Expand All @@ -355,14 +364,14 @@ https://docs.oracle.com/javase/specs/jvms/se23/html/index.html
https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-5.html
https://docs.oracle.com/javase/specs/jvms/se24/html/index.html
https://docs.oracle.com/javase/specs/jvms/se24/html/jvms-4.html
https://docs.oracle.com/javase/specs/jvms/se25/html/index.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-1.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-2.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-3.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-5.html
https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-6.html
https://docs.oracle.com/javase/specs/jvms/se25/jvms25.pdf
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/index.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-1.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-2.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-3.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-4.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-5.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/html/jvms-6.html
https://docs.oracle.com/javase/specs/jvms/se@@JAVASE_VERSION@@/jvms@@JAVASE_VERSION@@.pdf
https://docs.oracle.com/javase/specs/jvms/se7/html/index.html
https://docs.oracle.com/javase/specs/jvms/se8/html/index.html
https://docs.oracle.com/javase/specs/jvms/se9/html/index.html
Expand Down Expand Up @@ -430,28 +439,28 @@ https://docs.oracle.com/javase/tutorial/uiswing/misc/action.html
https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html
https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html
https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=GUID-FE2D2E28-C991-4EF9-9DBE-2A4982726313
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=homepage
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=i18n_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=imf_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=jndi_ldap_gl_prop
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=jndi_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=logging_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=monitoring_and_management_using_jmx_technology
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=rmi_guide
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=secure_coding_guidelines_javase
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_impl_provider
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_jca
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_jca_provider
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_jdk_providers
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_jgss_tutorial
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_pki
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_sasl
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=security_guide_tools
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=serialization_filter_guide
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=serialver_tool_reference
https://docs.oracle.com/pls/topic/lookup?ctx=javase25&id=using_jconsole
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=GUID-FE2D2E28-C991-4EF9-9DBE-2A4982726313
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=homepage
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=i18n_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=imf_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=jndi_ldap_gl_prop
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=jndi_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=logging_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=monitoring_and_management_using_jmx_technology
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=rmi_guide
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=secure_coding_guidelines_javase
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_impl_provider
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_jca
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_jca_provider
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_jdk_providers
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_jgss_tutorial
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_overview
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_pki
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_sasl
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=security_guide_tools
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=serialization_filter_guide
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=serialver_tool_reference
https://docs.oracle.com/pls/topic/lookup?ctx=javase@@JAVASE_VERSION@@&id=using_jconsole
https://ftp.pwg.org/pub/pwg/candidates/cs-ippoutputbin10-20010207-5100.2.pdf
https://ftp.pwg.org/pub/pwg/standards/temp_archive/pwg5100.3.pdf
https://github.github.com/gfm/
Expand Down Expand Up @@ -625,7 +634,7 @@ https://www.itu.int/rec/T-REC-X.509/en
https://www.netlib.org/fdlibm/
https://www.oasis-open.org
https://www.oasis-open.org/committees/download.php/14809/xml-catalogs.html
https://www.oracle.com/java/javase/terms/license/java25speclicense.html
https://www.oracle.com/java/javase/terms/license/java@@JAVASE_VERSION@@speclicense.html
https://www.oracle.com/java/technologies/a-swing-architecture.html
https://www.oracle.com/java/technologies/javase/seccodeguide.html
https://www.oracle.com/java/technologies/javase/training-support.html
Expand Down
6 changes: 0 additions & 6 deletions test/docs/jdk/javadoc/doccheck/checks/jdkCheckExtlinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@
* @build DocTester toolbox.TestRunner
* @run main/othervm -Ddoccheck.checks=extlinks DocCheck
*/


public class jdkCheckExtlinks
{
void main(){};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -49,7 +50,10 @@ public class ExtLinkChecker implements HtmlChecker, AutoCloseable {
} catch (IOException e) {
throw new RuntimeException(e);
}
extLinks.addAll(input.lines().collect(Collectors.toUnmodifiableSet()));
extLinks.addAll(input.lines()
.map(line -> line.replaceAll("\\@\\@JAVASE_VERSION\\@\\@", String.valueOf(Runtime.version().feature())))
.filter(line -> !line.startsWith("#"))
.collect(Collectors.toUnmodifiableSet()));
}

private final Log log;
Expand Down Expand Up @@ -99,14 +103,34 @@ public void endElement(int line, String name) {

private void foundReference(int line, String ref) {
try {
URI uri = new URI(ref);
String uriPath = ref;
String fragment = null;

// The checker runs into a problem with links that have more than one hash character.
// You cannot create a URI unless you convert the second hash character into

int firstHashIndex = ref.indexOf('#');
int lastHashIndex = ref.lastIndexOf('#');
if (firstHashIndex != -1 && firstHashIndex != lastHashIndex) {
uriPath = ref.substring(0, firstHashIndex);
fragment = ref.substring(firstHashIndex + 1).replace("#", "%23");
} else if (firstHashIndex != -1) {
uriPath = ref.substring(0, firstHashIndex);
fragment = ref.substring(firstHashIndex + 1);
}

URI uri = new URI(uriPath);
if (fragment != null) {
uri = new URI(uri + "#" + fragment);
}

if (uri.isAbsolute()) {
if (Objects.equals(uri.getScheme(), "javascript")) {
// ignore JavaScript URIs
return;
}
String fragment = uri.getRawFragment();
URI noFrag = new URI(uri.toString().replaceAll("#\\Q" + fragment + "\\E$", ""));
String rawFragment = uri.getRawFragment();
URI noFrag = new URI(uri.toString().replaceAll("#\\Q" + rawFragment + "\\E$", ""));
allURIs.computeIfAbsent(noFrag, _ -> new LinkedHashSet<>()).add(currFile);
}
} catch (URISyntaxException e) {
Expand Down Expand Up @@ -153,11 +177,13 @@ private void checkURI(URI uri, Set<Path> files) {
}

private void isVettedLink(URI uri, Set<Path> files) {
if (!uri.toString().contains("docs.oracle.com/") && !extLinks.contains(uri.toString())) {
System.err.println("The external link " + uri + "\n" + "needs to be added to the whitelist " +
"test/docs/jdk/javadoc/doccheck/ExtLinksJdk.txt in order to be checked regularly ");
System.err.println("The link is present in:");
files.forEach(System.err::println);
if (!extLinks.contains(uri.toString())) {
System.err.println(MessageFormat.format("""
The external link {0} needs to be added to the whitelist test/docs/jdk/javadoc/doccheck/ExtLinksJdk.txt in order to be checked regularly\s
The link is present in:
{1}
""", uri, files.stream().map(Path::toString).collect(Collectors.joining("\n "))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ private void foundReference(int line, String ref) {
}
}
} catch (URISyntaxException e) {
log.log(currFile, line, "invalid URI: " + e);
System.err.println("Failed to create URI: " + ref);
log.log(currFile, line, "invalid URI: " + e);
}
}

Expand Down

0 comments on commit 0857f83

Please sign in to comment.