You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2017/10/26 17:38:39 UTC

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

SOLR-11552: ref-guide tools should fail build if any page exists with #parents != 1

(cherry picked from commit 3be50df7b6212e48f13a132d8abcd14a8dbd3255)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b40675bb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b40675bb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b40675bb

Branch: refs/heads/branch_7_1
Commit: b40675bb36bbe4fe8d8134eab177ff46c9d51e80
Parents: 2ece0e4
Author: Chris Hostetter <ho...@apache.org>
Authored: Thu Oct 26 10:37:29 2017 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Thu Oct 26 10:38:11 2017 -0700

----------------------------------------------------------------------
 .../tools/BuildNavAndPDFBody.java               | 42 +++++++++++++++++---
 1 file changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b40675bb/solr/solr-ref-guide/tools/BuildNavAndPDFBody.java
----------------------------------------------------------------------
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);
       }
     }