From 7e0a5e90b4c28450a1a65ccf2bda01a5fd0cb282 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 30 May 2019 16:31:10 -0400 Subject: [PATCH] Build: asciidoc link check improvement - find all link errors before failing --- build.gradle | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 365ed88dd0..cfe2cac2b2 100644 --- a/build.gradle +++ b/build.gradle @@ -859,36 +859,41 @@ task checkAsciidocLinks { dependsOn prepareAsciidocBuild inputs.dir("$buildDir/asciidoc") doLast { + def errors = new ArrayList<>(); + errors.add("*** Anchor reference errors found:") inputs.files.filter{ f -> f.path.endsWith('.adoc') }.each { file -> def doc = file.text - Set anchors = new HashSet<>() + def anchors = new HashSet<>() def matcher = (doc =~ /\[\[([^]]+)\]\]/) while (matcher.find()) { anchors.add(matcher.group(1)) } matcher = (doc =~ /<<([^>]+)>>/) while (matcher.find()) { - String anchor = matcher.group(1); + def anchor = matcher.group(1); def hasComma = anchor.contains(",") if (!anchor.startsWith("./")) { if (hasComma) { anchor = anchor.substring(0, anchor.indexOf(",")); } if (!anchors.contains(anchor)) { - throw new InvalidUserDataException("Anchor '" + anchor + errors.add("\nAnchor '" + anchor + "' not found in '" + file.name + "', if in another file, it needs to be qualified with './fileName.adoc#'") } } else { if (!hasComma) { - throw new InvalidUserDataException("External anchor '" + anchor + errors.add("\nExternal anchor '" + anchor + "' in '" + file.name + "' should have a textual description (,...)") } } } } + if (errors.size() > 1) { + throw new InvalidUserDataException(errors.toString()) + } } }