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

This commit is contained in:
Chris Hostetter 2017-10-26 10:37:29 -07:00
parent 706f039fb2
commit 3be50df7b6
1 changed files with 36 additions and 6 deletions

View File

@ -67,9 +67,21 @@ public class BuildNavAndPDFBody {
if (null == mainPage) { if (null == mainPage) {
throw new RuntimeException("no main-page found with shortname: " + mainPageShortname); 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, // Build up the PDF file,
@ -213,7 +225,14 @@ public class BuildNavAndPDFBody {
public final String permalink; public final String permalink;
public final List<String> kidShortnames; public final List<String> kidShortnames;
/** NOTE: not populated on construction /** 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; public final List<Page> kids;
private final List<Page> mutableKids; private final List<Page> mutableKids;
@ -258,15 +277,26 @@ public class BuildNavAndPDFBody {
this.kids = Collections.<Page>unmodifiableList(mutableKids); 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) { for (String kidShortname : kidShortnames) {
Page kid = allPages.get(kidShortname); Page kid = allPages.get(kidShortname);
if (null == kid) { if (null == kid) {
throw new RuntimeException("Unable to locate " + kidShortname + "; child of " + shortname + "("+file.toString()); throw new RuntimeException("Unable to locate " + kidShortname + "; child of " + shortname + "("+file.toString());
} }
mutableKids.add(kid); mutableKids.add(kid);
kid.buildKidsRecursive(allPages); kid.buildPageTreeRecursive(this, allPages);
} }
} }