You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 09:59:49 UTC

[lucene] 36/50: SOLR-11552: ref-guide tools should fail build if any page exists with #parents != 1

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

dweiss pushed a commit to branch branch_7_1
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit b40675bb36bbe4fe8d8134eab177ff46c9d51e80
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Thu Oct 26 10:37:29 2017 -0700

    SOLR-11552: ref-guide tools should fail build if any page exists with #parents != 1
    
    (cherry picked from commit 3be50df7b6212e48f13a132d8abcd14a8dbd3255)
---
 solr/solr-ref-guide/tools/BuildNavAndPDFBody.java | 42 +++++++++++++++++++----
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/solr/solr-ref-guide/tools/BuildNavAndPDFBody.java b/solr/solr-ref-guide/tools/BuildNavAndPDFBody.java
index b1f0cf3..3188ab6 100644
--- a/solr/solr-ref-guide/tools/BuildNavAndPDFBody.java
+++ b/solr/solr-ref-guide/tools/BuildNavAndPDFBody.java
@@ -67,9 +67,21 @@ public class BuildNavAndPDFBody {
     if (null == mainPage) {
       throw new RuntimeException("no main-page found with shortname: " + mainPageShortname);
     }
-    mainPage.buildKidsRecursive(allPages);
+    // NOTE: mainPage claims to be it's own parent to prevent anyone decendent from introducing a loop
+    mainPage.buildPageTreeRecursive(mainPage, allPages);
 
-    // TODO: use depthFirstWalk to prune allPages to validate that we don't have any loops or orphan pages
+    { // validate that there are no orphan pages
+      int orphans = 0;
+      for (Page p : allPages.values()) {
+        if (null == p.getParent()) {
+          orphans++;
+          System.err.println("ERROR: Orphan page: " + p.file);
+        }
+      }
+      if (0 != orphans) {
+        throw new RuntimeException("Found " + orphans + " orphan pages (which are not in the 'page-children' attribute of any other pages)");
+      }
+    }
 
 
     // Build up the PDF file,
@@ -213,7 +225,14 @@ public class BuildNavAndPDFBody {
     public final String permalink;
     public final List<String> kidShortnames;
     /** NOTE: not populated on construction
-     * @see #buildKidsRecursive
+     * @see #buildPageTreeRecursive
+     */
+    private Page parent;
+    public Page getParent() {
+      return parent;
+    }
+    /** NOTE: not populated on construction
+     * @see #buildPageTreeRecursive
      */
     public final List<Page> kids;
     private final List<Page> mutableKids;
@@ -248,15 +267,26 @@ public class BuildNavAndPDFBody {
       this.kids = Collections.<Page>unmodifiableList(mutableKids);
     }
 
-    /** Recursively populates {@link #kids} from {@link #kidShortnames} via the <code>allPages</code> Map */
-    public void buildKidsRecursive(Map<String,Page> allPages) {
+    /** 
+     * Recursively sets {@link #getParent} and populates {@link #kids} from {@link #kidShortnames} 
+     * via the <code>allPages</code> Map 
+     */
+    public void buildPageTreeRecursive(Page parent, Map<String,Page> allPages) {
+      if (null != parent) {
+        if (null != this.parent) {
+          // as long as we also check (later) that every page has a parent, this check (prior to recusion)
+          // also ensures we never have any loops
+          throw new RuntimeException(file.getName() + " is listed as the child of (at least) 2 pages: '" + parent.shortname + "' and '" + this.parent.shortname + "'");
+        }
+        this.parent = parent;
+      }
       for (String kidShortname : kidShortnames) {
         Page kid = allPages.get(kidShortname);
         if (null == kid) {
           throw new RuntimeException("Unable to locate " + kidShortname + "; child of " + shortname + "("+file.toString());
         }
         mutableKids.add(kid);
-        kid.buildKidsRecursive(allPages);
+        kid.buildPageTreeRecursive(this, allPages);
       }
     }