This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ef68ba  Bring back the in-house xref-checker to reduce the build time 
by 20s
5ef68ba is described below

commit 5ef68ba5e1014612ae5c424e6a5e841a523e5f19
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Apr 1 11:17:45 2020 +0200

    Bring back the in-house xref-checker to reduce the build time by 20s
---
 docs/components/antora.yml                         |  1 -
 docs/pom.xml                                       | 14 +++---
 .../camel/maven/packaging/XRefCheckMojo.java       | 53 +++++++++++++++++-----
 3 files changed, 49 insertions(+), 19 deletions(-)

diff --git a/docs/components/antora.yml b/docs/components/antora.yml
index 2477222..98806e4 100644
--- a/docs/components/antora.yml
+++ b/docs/components/antora.yml
@@ -22,4 +22,3 @@ nav:
   - modules/ROOT/nav.adoc
   - modules/dataformats/nav.adoc
   - modules/languages/nav.adoc
-  - modules/eips/nav.adoc
\ No newline at end of file
diff --git a/docs/pom.xml b/docs/pom.xml
index bf94ca1..df85925 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -89,16 +89,18 @@
                             
<commandlineArgs>${project.basedir}/node/yarn/dist/bin/yarn.js 
--non-interactive gulp</commandlineArgs>
                         </configuration>
                     </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.camel</groupId>
+                <artifactId>camel-package-maven-plugin</artifactId>
+                <executions>
                     <execution>
-                        <id>antora-check-xref</id>
+                        <id>xref-check</id>
                         <goals>
-                            <goal>exec</goal>
+                            <goal>xref-check</goal>
                         </goals>
                         <phase>generate-resources</phase>
-                        <configuration>
-                            
<executable>${project.basedir}/node/node</executable>
-                            
<commandlineArgs>${project.basedir}/node_modules/@antora/cli/bin/antora 
--generator @antora/xref-validator 
antora-playbook-local-xref-check.yml</commandlineArgs>
-                        </configuration>
                     </execution>
                 </executions>
             </plugin>
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/XRefCheckMojo.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/XRefCheckMojo.java
index 26a582f..ab8d237 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/XRefCheckMojo.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/XRefCheckMojo.java
@@ -21,10 +21,7 @@ import java.io.IOException;
 import java.io.Reader;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -73,7 +70,12 @@ public class XRefCheckMojo extends AbstractMojo {
         try (Reader r = Files.newBufferedReader(path.resolve(PLAYBOOK))) {
             site = (Map) yaml.loadFromReader(r);
         }
-        Map<String, Path> pages = new HashMap<>();
+        Map<String, String> attributes = (Map) ((Map) 
site.get("asciidoc")).get("attributes");
+        if (attributes != null) {
+            attributes = attributes.entrySet().stream()
+                    .collect(Collectors.toMap(e -> "{" + e.getKey() + "}", e 
-> e.getValue()));
+        }
+        Map<String, Path> pages = new TreeMap<>();
         for (Map component : (List<Map>) ((Map) 
site.get("content")).get("sources")) {
             String url = (String) component.get("url");
             String startPath = (String) component.get("start_path");
@@ -83,39 +85,66 @@ public class XRefCheckMojo extends AbstractMojo {
                 antora = (Map) yaml.loadFromReader(r);
             }
             String name = (String) antora.get("name");
-            List<Path> navs = ((List<String>) antora.get("nav")).stream()
+            List<Path> navs = Optional.ofNullable((List<String>) 
antora.get("nav"))
+                    .map(List::stream)
+                    .orElse(Stream.empty())
                     .map(root::resolve)
                     .collect(Collectors.toList());
             for (Path nav : navs) {
-                pages.put(name + "::" + nav.getFileName().toString(), nav);
+                pages.put(name + ":ROOT:" + nav.getFileName().toString(), nav);
             }
             Files.list(root.resolve("modules"))
                     .filter(Files::isDirectory)
                     .filter(p -> Files.isDirectory(p.resolve("pages")))
                     .forEach(module -> {
+                        String m = module.getFileName().toString();
                         Path pagesDir = module.resolve("pages");
                         walk(pagesDir)
                                 .filter(Files::isRegularFile)
                                 .forEach(page -> {
                                     Path rel = pagesDir.relativize(page);
-                                    pages.put(name + "::" + rel.toString(), 
page);
+                                    pages.put(name + ":" + m + ":" + 
rel.toString(), page);
                                 });
                     });
         }
 
-        Pattern xref = 
Pattern.compile("\\b(?<all>xref:(?<link>[^\\[]+.adoc)\\[[^\\]]*\\])");
+        Pattern xref = 
Pattern.compile("\\b(?<all>xref:(?<link>[^\\[]+.adoc)[^\\]]*\\])");
         for (Map.Entry<String, Path> page : pages.entrySet()) {
+            int firstDot = page.getKey().indexOf(":");
+            int secondDot = firstDot >= 0 ? page.getKey().indexOf(":", 
firstDot + 1) : -1;
+            String component = secondDot >= 0 ? page.getKey().substring(0, 
firstDot) : "";
+            String module = secondDot >= 0 ? page.getKey().substring(firstDot 
+ 1, secondDot) : "";
             String str = PackageHelper.loadText(page.getValue());
+            for (Map.Entry<String, String> repl : attributes.entrySet()) {
+                str = str.replace(repl.getKey(), repl.getValue());
+            }
             Matcher m = xref.matcher(str);
             while (m.find()) {
                 String link = m.group("link");
                 String all = m.group("all");
-                if (!link.contains("::")) {
-                    link = page.getKey().substring(0, 
page.getKey().indexOf("::")) + "::" + link;
+                String[] groups = link.split(":");
+                String cl, ml, rem;
+                if (groups.length == 3) {
+                    cl = groups[0];
+                    ml = groups[1].isEmpty() ? "ROOT" : groups[1];
+                    rem = groups[2];
+                } else if (groups.length == 2) {
+                    cl = component;
+                    ml = groups[0];
+                    rem = groups[1];
+                } else {
+                    cl = component;
+                    ml = module;
+                    rem = groups[0];
+                }
+                if (cl.startsWith("latest@")) {
+                    cl = cl.substring("latest@".length());
                 }
+                link = cl + ":" + ml + ":" + rem;
                 if (!pages.containsKey(link)) {
                     long line = str.chars().limit(m.start()).filter(c -> c == 
'\n').count() + 1;
-                    unresolved.add(page.getKey() + " (" + page.getValue() + ") 
at line " + line + ": " + all);
+                    String prnt = 
Stream.of(all.split("\n")).map(String::trim).collect(Collectors.joining(" "));
+                    unresolved.add(page.getKey() + " (" + page.getValue() + ") 
at line " + line + ": " + prnt);
                 }
             }
         }

Reply via email to