diff --git a/Ghidra/Features/Base/build.gradle b/Ghidra/Features/Base/build.gradle
index 3361951924..eb9a2c3486 100644
--- a/Ghidra/Features/Base/build.gradle
+++ b/Ghidra/Features/Base/build.gradle
@@ -123,7 +123,7 @@ task buildJavacc {
description = " Compiles the JavaCC files\n"
}
-// Note: this must happen before the standard buildHelp for Base
+// Note: this must happen before the standard buildModuleHelp for Base
tasks.register('generateExtraHelpFiles') {
group = 'private'
@@ -193,7 +193,7 @@ def createTipsHelpFile(input, output) {
compileJava.dependsOn buildJavacc
rootProject.prepDev.dependsOn buildJavacc
-// 'indexHelp' is defined in the buildHelp.gradle 'script plugin'
+// 'indexHelp' is defined in the helpProject.gradle 'script plugin'
indexHelp.dependsOn generateExtraHelpFiles
zipSourceSubproject.dependsOn buildCPPParser
diff --git a/Ghidra/Features/Jython/src/main/help/help/TOC_Source.xml b/Ghidra/Features/Jython/src/main/help/help/TOC_Source.xml
index cf46dcb1b7..d161e9b355 100644
--- a/Ghidra/Features/Jython/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/Jython/src/main/help/help/TOC_Source.xml
@@ -3,7 +3,10 @@
-
+
+
+
diff --git a/Ghidra/Features/PDB/src/main/help/help/TOC_Source.xml b/Ghidra/Features/PDB/src/main/help/help/TOC_Source.xml
index cd29ebf273..7167596387 100644
--- a/Ghidra/Features/PDB/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/PDB/src/main/help/help/TOC_Source.xml
@@ -50,7 +50,10 @@
-
+
+
+
diff --git a/Ghidra/Features/PyGhidra/src/main/help/help/TOC_Source.xml b/Ghidra/Features/PyGhidra/src/main/help/help/TOC_Source.xml
index 28de8c3882..27be9a551a 100644
--- a/Ghidra/Features/PyGhidra/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/PyGhidra/src/main/help/help/TOC_Source.xml
@@ -3,7 +3,10 @@
-
+
+
+
diff --git a/Ghidra/Features/Sarif/src/main/help/help/TOC_Source.xml b/Ghidra/Features/Sarif/src/main/help/help/TOC_Source.xml
index d88893ccd2..ae1ea05db5 100644
--- a/Ghidra/Features/Sarif/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/Sarif/src/main/help/help/TOC_Source.xml
@@ -50,7 +50,10 @@
-
+
+
+
diff --git a/Ghidra/Framework/Help/build.gradle b/Ghidra/Framework/Help/build.gradle
index ba6960c375..de3410c49c 100644
--- a/Ghidra/Framework/Help/build.gradle
+++ b/Ghidra/Framework/Help/build.gradle
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,3 +31,85 @@ dependencies {
//api name:'jh2.with.debug'
api 'javax.help:javahelp:2.0.05'
}
+
+/*
+ * Get all help tasks from all projects
+ */
+def getAllHelpTasks() {
+
+ List list = new ArrayList()
+ rootProject.allprojects {
+ tasks.each {
+ if (it.name == 'buildModuleHelp') {
+ list.add(it)
+ }
+ }
+ }
+ return list
+}
+
+/*
+ * A task at the Ghidra tool top-level build that will trigger all 'buildModuleHelp' tasks to run,
+ * this building help. Additionally, this task will perform any needed validation after all help
+ * modules are built.
+ */
+tasks.register('buildHelp') {
+
+ description 'Build all Ghidra help'
+
+ dependsOn { getAllHelpTasks() } // all 'buildHelpModule' tasks
+ dependsOn 'validateHelpTocFiles' // the validate TOC task to run after all help is built
+}
+
+
+
+/*
+ * Gathers all generated help TOC files and validates them.
+ */
+tasks.register('validateHelpTocFiles', JavaExec) {
+
+ group = "private"
+
+ dependsOn { getAllHelpTasks() } // all 'buildHelpModule' tasks to provide TOC inputs
+
+ // we need our Help java files compiled
+ dependsOn jar
+
+ mainClass = 'help.GHelpTocValidator'
+
+ // to allow remote debugging of the help build jvm
+ // jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=13001'
+
+ // print debug info
+ // args '-debug'
+
+ doFirst {
+
+ // get the Help module jar file, since it has classes we use
+ classpath += jar.outputs.files
+
+ // get the classpath items used by the Help module, since we use those classes
+ classpath += configurations.runtimeClasspath
+
+ // add each Module-help.jar file created by 'buildModuleHelp' to the application inputs
+ rootProject.allprojects.forEach {
+
+ // /build/libs/Module-help.jar
+ def helpLibDir = it.file('build/libs')
+ if (helpLibDir.isDirectory()) {
+
+ helpLibDir.listFiles().each {
+ String name = it.getName()
+ if (name.endsWith('-help.jar')) {
+ args "${it.absolutePath}"
+ }
+ }
+ }
+
+ }
+
+ // Sigal that any System.out messages from this Java process should be logged at INFO level.
+ // To see this output, run gradle with the '-i' option to show INFO messages.
+ logging.captureStandardOutput LogLevel.INFO
+ }
+}
diff --git a/Ghidra/Framework/Help/src/main/java/help/GHelpBuilder.java b/Ghidra/Framework/Help/src/main/java/help/GHelpBuilder.java
index b15242ba77..521460283f 100644
--- a/Ghidra/Framework/Help/src/main/java/help/GHelpBuilder.java
+++ b/Ghidra/Framework/Help/src/main/java/help/GHelpBuilder.java
@@ -15,6 +15,8 @@
*/
package help;
+import static help.GHelpMsg.*;
+
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
@@ -96,7 +98,7 @@ public class GHelpBuilder {
if (results.failed()) {
String message = "Found invalid help:\n" + results.getMessage();
if (ignoreInvalid) {
- printErrorMessage(message);
+ error(message);
}
else {
exitWithError(message, null);
@@ -267,15 +269,6 @@ public class GHelpBuilder {
}
}
- private static void flush() {
- System.out.flush();
- System.out.println();
- System.out.flush();
- System.err.flush();
- System.err.println();
- System.err.flush();
- }
-
private static void debug(String string) {
if (debugEnabled) {
flush();
@@ -290,7 +283,7 @@ public class GHelpBuilder {
if (opt.equals(OUTPUT_DIRECTORY_OPTION)) {
i++;
if (i >= args.length) {
- errorMessage(OUTPUT_DIRECTORY_OPTION + " requires an argument");
+ error(OUTPUT_DIRECTORY_OPTION + " requires an argument");
printUsage();
System.exit(1);
}
@@ -299,7 +292,7 @@ public class GHelpBuilder {
else if (opt.equals(MODULE_NAME_OPTION)) {
i++;
if (i >= args.length) {
- errorMessage(MODULE_NAME_OPTION + " requires an argument");
+ error(MODULE_NAME_OPTION + " requires an argument");
printUsage();
System.exit(1);
}
@@ -308,7 +301,7 @@ public class GHelpBuilder {
else if (opt.equals(HELP_PATHS_OPTION)) {
i++;
if (i >= args.length) {
- errorMessage(HELP_PATHS_OPTION + " requires an argument");
+ error(HELP_PATHS_OPTION + " requires an argument");
printUsage();
System.exit(1);
}
@@ -322,7 +315,7 @@ public class GHelpBuilder {
else if (opt.equals(HELP_PATHS_GENERATED_OPTION)) {
i++;
if (i >= args.length) {
- errorMessage(HELP_PATHS_GENERATED_OPTION + " requires an argument");
+ error(HELP_PATHS_GENERATED_OPTION + " requires an argument");
printUsage();
System.exit(1);
}
@@ -340,7 +333,7 @@ public class GHelpBuilder {
ignoreInvalid = true;
}
else if (opt.startsWith("-")) {
- errorMessage("Unknown option " + opt);
+ error("Unknown option " + opt);
printUsage();
System.exit(1);
}
@@ -353,17 +346,17 @@ public class GHelpBuilder {
HelpBuildUtils.debug = debugEnabled;
if (helpInputDirectories.size() == 0) {
- errorMessage("Must specify at least one input directory");
+ error("Must specify at least one input directory");
printUsage();
System.exit(1);
}
if (outputDirectoryName == null) {
- errorMessage("Missing output directory: " + OUTPUT_DIRECTORY_OPTION + " [output]");
+ error("Missing output directory: " + OUTPUT_DIRECTORY_OPTION + " [output]");
printUsage();
System.exit(1);
}
if (moduleName == null) {
- errorMessage("Missing module name: " + MODULE_NAME_OPTION + " [name]");
+ error("Missing module name: " + MODULE_NAME_OPTION + " [name]");
printUsage();
System.exit(1);
}
@@ -385,35 +378,7 @@ public class GHelpBuilder {
buffy.append(" ").append(IGNORE_INVALID_SWITCH).append("\n");
buffy.append(" to continue despite broken links and anchors\n");
- errorMessage(buffy.toString());
- }
-
- private static void printErrorMessage(String message) {
- // this prevents error messages getting interspersed with output messages
- flush();
- errorMessage(message);
- }
-
- private static void errorMessage(String message) {
- errorMessage(message, null);
- }
-
- private static void errorMessage(String message, Throwable t) {
- try {
- // give the output thread a chance to finish it's output (this is a workaround for
- // the Eclipse editor, and its use of two threads in its console).
- Thread.sleep(250);
- }
- catch (InterruptedException e) {
- // don't care; we tried
- }
-
- System.err.println("[" + GHelpBuilder.class.getSimpleName() + "] " + message);
- if (t != null) {
- t.printStackTrace();
- }
-
- flush();
+ error(buffy.toString());
}
//==================================================================================================
diff --git a/Ghidra/Framework/Help/src/main/java/help/GHelpMsg.java b/Ghidra/Framework/Help/src/main/java/help/GHelpMsg.java
new file mode 100644
index 0000000000..f254488e60
--- /dev/null
+++ b/Ghidra/Framework/Help/src/main/java/help/GHelpMsg.java
@@ -0,0 +1,62 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package help;
+
+import utilities.util.reflection.ReflectionUtilities;
+
+/**
+ * Contains helpful methods for emitting messages to the console.
+ */
+public class GHelpMsg {
+
+ public static void error(String message) {
+ error(message, null);
+ }
+
+ public static void error(String message, Throwable t) {
+
+ flush();
+
+ try {
+ // give the output thread a chance to finish it's output (this is a workaround for
+ // the Eclipse editor, and its use of two threads in its console).
+ Thread.sleep(250);
+ }
+ catch (InterruptedException e) {
+ // don't care; we tried
+ }
+
+ String caller = ReflectionUtilities.getClassNameOlderThan(GHelpMsg.class);
+ int index = caller.lastIndexOf('.');
+ caller = caller.substring(index + 1);
+
+ System.err.println("[" + caller + "] " + message);
+ if (t != null) {
+ t.printStackTrace();
+ }
+
+ flush();
+ }
+
+ public static void flush() {
+ System.out.flush();
+ System.out.println();
+ System.out.flush();
+ System.err.flush();
+ System.err.println();
+ System.err.flush();
+ }
+}
diff --git a/Ghidra/Framework/Help/src/main/java/help/GHelpTocValidator.java b/Ghidra/Framework/Help/src/main/java/help/GHelpTocValidator.java
new file mode 100644
index 0000000000..d9877d359c
--- /dev/null
+++ b/Ghidra/Framework/Help/src/main/java/help/GHelpTocValidator.java
@@ -0,0 +1,85 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package help;
+
+import static help.GHelpMsg.*;
+
+import java.io.File;
+import java.util.*;
+
+import generic.application.GenericApplicationLayout;
+import ghidra.framework.Application;
+import ghidra.framework.ApplicationConfiguration;
+import help.validator.LinkDatabase;
+import help.validator.location.HelpModuleCollection;
+
+/**
+ * Checks for errors in source TOC files, such as conflicting sort groups. This validator is meant
+ * to be used when all system TOC files have been built. Individual module TOC files are validated
+ * for correctness with their dependencies when they are built. This class is needed to validate
+ * all TOC files, including for leaf modules that don't have each other as dependencies.
+ */
+public class GHelpTocValidator {
+
+ private static final String DEBUG_SWITCH = "-debug";
+
+ private Collection helpInputDirectories = new LinkedHashSet<>();
+
+ public static void main(String[] args) throws Exception {
+ GHelpTocValidator validator = new GHelpTocValidator();
+
+ ApplicationConfiguration config = new ApplicationConfiguration();
+ Application.initializeApplication(new GenericApplicationLayout("Help TOC Validator", "0.1"),
+ config);
+
+ validator.validate(args);
+ }
+
+ private void validate(String[] args) {
+
+ parseArguments(args);
+
+ List allHelp = new ArrayList<>(helpInputDirectories);
+ HelpModuleCollection help = HelpModuleCollection.fromFiles(allHelp);
+ LinkDatabase linkDatabase = new LinkDatabase(help);
+ linkDatabase.validateAllTOCs();
+ }
+
+ private void parseArguments(String[] args) {
+
+ boolean debugEnabled = false;
+ for (String opt : args) {
+ if (opt.equals(DEBUG_SWITCH)) {
+ debugEnabled = true;
+ }
+ else if (opt.startsWith("-")) {
+ error("Unknown option " + opt);
+ System.exit(1);
+ }
+ else {
+ // It must just be an input
+ helpInputDirectories.add(new File(opt));
+ }
+ }
+
+ HelpBuildUtils.debug = debugEnabled;
+
+ if (helpInputDirectories.size() == 0) {
+ error("Must specify at least one help jar file");
+ System.exit(1);
+ }
+ }
+}
diff --git a/Ghidra/Framework/Help/src/main/java/help/HelpBuildUtils.java b/Ghidra/Framework/Help/src/main/java/help/HelpBuildUtils.java
index b58b1f29f3..51792843b1 100644
--- a/Ghidra/Framework/Help/src/main/java/help/HelpBuildUtils.java
+++ b/Ghidra/Framework/Help/src/main/java/help/HelpBuildUtils.java
@@ -428,10 +428,10 @@ public class HelpBuildUtils {
return false;
}
- private static final Path DEFAULT_FS_ROOT;
+ private static final Path DEFAULT_ROOT_DIR;
static {
try {
- DEFAULT_FS_ROOT = Paths.get(".").toRealPath().getRoot();
+ DEFAULT_ROOT_DIR = Paths.get(".").toRealPath().getRoot();
}
catch (IOException e) {
throw new RuntimeException(
@@ -439,7 +439,7 @@ public class HelpBuildUtils {
}
}
- private static Path toFSGivenRoot(Path root, Path path) {
+ private static Path relativeToRoot(Path root, Path path) {
if (path.getNameCount() == 0) {
if (path.isAbsolute()) {
return root;
@@ -459,12 +459,12 @@ public class HelpBuildUtils {
return temp;
}
- public static Path toDefaultFS(Path path) {
- return toFSGivenRoot(DEFAULT_FS_ROOT, path);
+ public static Path relativeToWorkingDir(Path path) {
+ return relativeToRoot(DEFAULT_ROOT_DIR, path);
}
- public static Path toFS(Path targetFS, Path path) {
- return toFSGivenRoot(targetFS.toAbsolutePath().getRoot(), path);
+ public static Path relativeTo(Path targetFS, Path path) {
+ return relativeToRoot(targetFS.toAbsolutePath().getRoot(), path);
}
public static Path createReferencePath(URI fileURI) {
diff --git a/Ghidra/Framework/Help/src/main/java/help/JavaHelpFilesBuilder.java b/Ghidra/Framework/Help/src/main/java/help/JavaHelpFilesBuilder.java
index 425f1115cf..89ebcf0b77 100644
--- a/Ghidra/Framework/Help/src/main/java/help/JavaHelpFilesBuilder.java
+++ b/Ghidra/Framework/Help/src/main/java/help/JavaHelpFilesBuilder.java
@@ -17,7 +17,8 @@ package help;
import java.io.*;
import java.nio.file.*;
-import java.util.*;
+import java.util.Collection;
+import java.util.Date;
import ghidra.util.exception.AssertException;
import help.validator.LinkDatabase;
@@ -135,9 +136,7 @@ public class JavaHelpFilesBuilder {
out.println("