From commits-return-5071-archive-asf-public=cust-asf.ponee.io@juneau.apache.org Sat Feb 3 18:15:23 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id DA5CF180621 for ; Sat, 3 Feb 2018 18:15:23 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CA296160C3B; Sat, 3 Feb 2018 17:15:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EBA81160C38 for ; Sat, 3 Feb 2018 18:15:22 +0100 (CET) Received: (qmail 22271 invoked by uid 500); 3 Feb 2018 17:15:22 -0000 Mailing-List: contact commits-help@juneau.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.apache.org Delivered-To: mailing list commits@juneau.apache.org Received: (qmail 22262 invoked by uid 99); 3 Feb 2018 17:15:22 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Feb 2018 17:15:22 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 0BCCD80F9C; Sat, 3 Feb 2018 17:15:21 +0000 (UTC) Date: Sat, 03 Feb 2018 17:15:21 +0000 To: "commits@juneau.apache.org" Subject: [juneau] branch master updated: Add Javadoc link tester utility. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151767812100.22630.7929214420688766723@gitbox.apache.org> From: jamesbognar@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: juneau X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: adf5be304cf886108a6db94d2817cb1662d603d2 X-Git-Newrev: 3f94b450d9836c0ac39220067abdc73feb2b0ee4 X-Git-Rev: 3f94b450d9836c0ac39220067abdc73feb2b0ee4 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. jamesbognar pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/juneau.git The following commit(s) were added to refs/heads/master by this push: new 3f94b45 Add Javadoc link tester utility. 3f94b45 is described below commit 3f94b450d9836c0ac39220067abdc73feb2b0ee4 Author: JamesBognar AuthorDate: Sat Feb 3 12:15:18 2018 -0500 Add Javadoc link tester utility. --- .../org/apache/juneau/utils/JavadocLinkTester.java | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/utils/JavadocLinkTester.java b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/utils/JavadocLinkTester.java new file mode 100644 index 0000000..da32647 --- /dev/null +++ b/juneau-core/juneau-core-test/src/test/java/org/apache/juneau/utils/JavadocLinkTester.java @@ -0,0 +1,123 @@ +// *************************************************************************************************************************** +// * 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. * +// *************************************************************************************************************************** +package org.apache.juneau.utils; + +import java.io.*; +import java.util.*; +import java.util.regex.*; + +import org.apache.juneau.internal.*; + +/** + * Javadoc link checker. + * + *

+ * Runs against the generated javadocs folder looking for any broken internal links (missing files, invalid anchor tags, etc...). + */ +public class JavadocLinkTester { + + static Pattern p = Pattern.compile("(href|src)\\=['\\\"]([^'\\\"]+)['\\\"]"); + static Pattern p2 = Pattern.compile("(name|id)\\=['\\\"]([^'\\\"]+)['\\\"]"); + static int errors, files, directories, links; + + public static void main(String[] args) { + try { + long startTime = System.currentTimeMillis(); + File root = new File("../../target/site/apidocs").getCanonicalFile(); + System.out.println("Checking " + root); + process(root); + System.out.println("Checked "+links+" links in " + files + " files in " + directories + " directories in "+(System.currentTimeMillis()-startTime)+"ms"); + if (errors == 0) + System.out.println("No errors"); + else { + System.out.flush(); + System.err.println(errors + " errors"); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + static Map> ANCHORS = new LinkedHashMap<>(); + + static Map> ERRORS = new TreeMap<>(); + + static void process(File f) throws Exception { + if (f.isDirectory()) { + for (File fc : f.listFiles()) { + if (fc.isFile() && fc.getName().endsWith(".html")) { + files++; + resolveLinks(fc); + } + } + for (File fc : f.listFiles()) { + if (fc.isDirectory() && ! fc.getName().equals("src-html")) { + directories++; + process(fc); + } + } + } + } + + private static boolean hasAnchor(File f, String anchor) throws Exception { + String key = f.getCanonicalPath(); + if (! ANCHORS.containsKey(key)) { + Set s = new HashSet(); + String c2 = IOUtils.read(f); + Matcher m2 = p2.matcher(c2); + while (m2.find()) { + s.add(m2.group(2)); + } + ANCHORS.put(key, s); + } + return ANCHORS.get(key).contains(anchor); + } + + private static void resolveLinks(File f) throws Exception { + String contents = IOUtils.read(f); + Matcher m = p.matcher(contents); + while (m.find()) { + String link = m.group(2); + String anchor = null; + if (link.startsWith("https://") || link.startsWith("http://") || link.startsWith("mailto:")) + continue; + links++; + if (link.indexOf('?') != -1) + link = link.substring(0, link.indexOf('?')); + + if (link.indexOf('#') != -1) { + anchor = link.substring(link.lastIndexOf('#')+1); + link = link.substring(0, link.lastIndexOf('#')); + File f2 = link.isEmpty() ? f : new File(f.getParentFile().getAbsolutePath() + "/" + link); + if (! f2.exists()) { + error(f, "missingLink=["+link+"]"); + } else if (anchor != null) { + if (f2.isFile()) { + boolean foundAnchor = hasAnchor(f2, anchor); + if (! foundAnchor) + error(f, "missingAnchor=["+link+"#"+anchor+"]"); + } else { + error(f, "invalidAnchor=["+link+"#"+anchor+"]"); + } + } + } + } + } + + private static void error(File f, String msg) { + errors++; + System.out.flush(); + System.err.println("ERROR: " + f.getAbsolutePath() + ", " + msg); + } +} -- To stop receiving notification emails like this one, please contact jamesbognar@apache.org.