mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 02:09:44 +02:00
GP-3430 - Updated the gradle buildHelp task to better handle its inputs up-do-date state
This commit is contained in:
parent
0d71657d05
commit
a7668c7f85
32 changed files with 690 additions and 266 deletions
|
@ -357,17 +357,6 @@ public class GHelpBuilder {
|
|||
errorMessage(buffy.toString());
|
||||
}
|
||||
|
||||
private static void warningMessage(String... message) {
|
||||
StringBuilder buffy = new StringBuilder();
|
||||
buffy.append("\n");
|
||||
buffy.append(" !!!!! WARNING !!!!!\n");
|
||||
for (String string : message) {
|
||||
buffy.append('\t').append('\t').append(string).append('\n');
|
||||
}
|
||||
buffy.append("\n");
|
||||
errorMessage(buffy.toString());
|
||||
}
|
||||
|
||||
private static void printErrorMessage(String message) {
|
||||
// this prevents error messages getting interspersed with output messages
|
||||
flush();
|
||||
|
|
|
@ -68,7 +68,11 @@ public class HelpBuildUtils {
|
|||
return new DirectoryHelpModuleLocation(file);
|
||||
}
|
||||
else if (file.isFile()) {
|
||||
return new JarHelpModuleLocation(file);
|
||||
JarHelpModuleLocation jarLocation = JarHelpModuleLocation.fromFile(file);
|
||||
if (jarLocation == null) {
|
||||
HelpBuildUtils.debug("Jar file does not contain help: " + file);
|
||||
}
|
||||
return jarLocation;
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"Don't know how to create a help module location for file: " + file);
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
*/
|
||||
package help;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
import ghidra.util.exception.AssertException;
|
||||
import help.validator.LinkDatabase;
|
||||
import help.validator.location.HelpModuleCollection;
|
||||
import help.validator.model.AnchorDefinition;
|
||||
import help.validator.model.GhidraTOCFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class:
|
||||
* <ul>
|
||||
|
@ -129,7 +129,8 @@ public class JavaHelpFilesBuilder {
|
|||
PrintWriter out = new LogFileWriter(mapFile);
|
||||
try {
|
||||
out.println("<?xml version='1.0' encoding='ISO-8859-1' ?>");
|
||||
out.println("<!doctype MAP public \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\">");
|
||||
out.println(
|
||||
"<!doctype MAP public \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\">");
|
||||
out.println("<!-- Auto-generated on " + (new Date()).toString() + " : Do Not Edit -->");
|
||||
out.println("<map version=\"1.0\">");
|
||||
|
||||
|
@ -166,8 +167,8 @@ public class JavaHelpFilesBuilder {
|
|||
}
|
||||
|
||||
if (!parent.endsWith("help")) {
|
||||
throw new AssertException("Map file expected in a directory name 'help'. "
|
||||
+ "Update the map file generation code.");
|
||||
throw new AssertException("Map file expected in a directory name 'help'. " +
|
||||
"Update the map file generation code.");
|
||||
}
|
||||
|
||||
if (!anchorTarget.startsWith("help")) {
|
||||
|
|
|
@ -92,8 +92,11 @@ public class UnusedHelpImageFileFinder {
|
|||
}
|
||||
|
||||
SortedSet<Path> set =
|
||||
new TreeSet<>((f1, f2) -> f1.toUri().toString().toLowerCase().compareTo(
|
||||
f2.toUri().toString().toLowerCase()));
|
||||
new TreeSet<>((f1, f2) -> f1.toUri()
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.compareTo(
|
||||
f2.toUri().toString().toLowerCase()));
|
||||
for (Path file : imageFiles) {
|
||||
IMG img = fileToIMGMap.get(file);
|
||||
if (img == null && !isExcludedImageFile(file)) {
|
||||
|
@ -173,7 +176,10 @@ public class UnusedHelpImageFileFinder {
|
|||
}
|
||||
|
||||
// Create the help directory
|
||||
helpCollections.add(HelpBuildUtils.toLocation(helpDirectoryFile));
|
||||
HelpModuleLocation location = HelpBuildUtils.toLocation(helpDirectoryFile);
|
||||
if (location != null) {
|
||||
helpCollections.add(location);
|
||||
}
|
||||
}
|
||||
|
||||
return helpCollections;
|
||||
|
|
|
@ -20,15 +20,16 @@ import java.net.*;
|
|||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.help.HelpSet;
|
||||
import javax.help.Map.ID;
|
||||
import javax.help.TOCView;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
import help.CustomTOCView.CustomTreeItemDecorator;
|
||||
import help.HelpBuildUtils;
|
||||
import help.TOCItemProvider;
|
||||
import help.CustomTOCView.CustomTreeItemDecorator;
|
||||
import help.validator.model.*;
|
||||
|
||||
/**
|
||||
|
@ -98,7 +99,10 @@ public class HelpModuleCollection implements TOCItemProvider {
|
|||
}
|
||||
|
||||
private HelpModuleCollection(Collection<HelpModuleLocation> locations) {
|
||||
helpLocations = new LinkedHashSet<>(locations);
|
||||
|
||||
helpLocations = locations.stream()
|
||||
.filter(l -> l != null)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
|
||||
loadTOCs();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.*;
|
|||
import javax.help.HelpSet;
|
||||
|
||||
import ghidra.util.exception.AssertException;
|
||||
import help.HelpBuildUtils;
|
||||
import help.validator.model.*;
|
||||
|
||||
public abstract class HelpModuleLocation {
|
||||
|
@ -47,13 +48,16 @@ public abstract class HelpModuleLocation {
|
|||
|
||||
public abstract HelpSet loadHelpSet();
|
||||
|
||||
/** Returns true if this help location represents a source of input files to generate help output */
|
||||
/**
|
||||
* Returns true if this help location represents a source of input files to generate help output
|
||||
* @return true if this help location represents a source of input files to generate help output
|
||||
*/
|
||||
public abstract boolean isHelpInputSource();
|
||||
|
||||
protected void loadHelpTopics() {
|
||||
Path helpTopicsDir = helpDir.resolve("topics");
|
||||
if (!Files.exists(helpTopicsDir)) {
|
||||
throw new AssertException("No topics found in help dir: " + helpDir);
|
||||
HelpBuildUtils.debug("No topics found in help dir: " + this);
|
||||
}
|
||||
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(helpTopicsDir);) {
|
||||
|
@ -65,7 +69,7 @@ public abstract class HelpModuleLocation {
|
|||
}
|
||||
catch (IOException e) {
|
||||
// I suppose there aren't any
|
||||
throw new AssertException("No topics found in help dir: " + helpDir);
|
||||
throw new AssertException("No topics found in help dir: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +197,7 @@ public abstract class HelpModuleLocation {
|
|||
}
|
||||
List<AnchorDefinition> list = map.get(name);
|
||||
if (list == null) {
|
||||
list = new ArrayList<AnchorDefinition>();
|
||||
list = new ArrayList<>();
|
||||
map.put(name, list);
|
||||
}
|
||||
list.add(anchorDefinition);
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.net.*;
|
|||
import java.nio.file.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.help.HelpSet;
|
||||
import javax.help.HelpSetException;
|
||||
|
@ -32,17 +31,29 @@ import help.validator.model.GhidraTOCFile;
|
|||
|
||||
public class JarHelpModuleLocation extends HelpModuleLocation {
|
||||
|
||||
/*
|
||||
* format of 'helpDir':
|
||||
* jar:file:///.../ghidra-prep/Ghidra/Features/Base/build/libs/Base.jar!/help
|
||||
*/
|
||||
private static final Pattern JAR_FILENAME_PATTERN = Pattern.compile(".*/(\\w*)\\.jar!/.*");
|
||||
|
||||
private static Map<String, String> env = new HashMap<String, String>();
|
||||
private static Map<String, String> env = new HashMap<>();
|
||||
static {
|
||||
env.put("create", "false");
|
||||
}
|
||||
|
||||
public static JarHelpModuleLocation fromFile(File jar) {
|
||||
FileSystem fs = getOrCreateJarFS(jar);
|
||||
Path helpRootPath = fs.getPath("/help");
|
||||
if (!Files.exists(helpRootPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Path topicsPath = helpRootPath.resolve("topics");
|
||||
|
||||
if (!Files.exists(topicsPath)) {
|
||||
// all help locations must have a topics directory; we can get here if the jar contains
|
||||
// a package with the name 'help'
|
||||
return null;
|
||||
}
|
||||
|
||||
return new JarHelpModuleLocation(jar, helpRootPath);
|
||||
}
|
||||
|
||||
private static FileSystem getOrCreateJarFS(File jar) {
|
||||
URI jarURI;
|
||||
try {
|
||||
|
@ -64,8 +75,8 @@ public class JarHelpModuleLocation extends HelpModuleLocation {
|
|||
}
|
||||
}
|
||||
|
||||
public JarHelpModuleLocation(File file) {
|
||||
super(getOrCreateJarFS(file).getPath("/help"));
|
||||
private JarHelpModuleLocation(File jar, Path path) {
|
||||
super(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,9 +112,11 @@ public class JarHelpModuleLocation extends HelpModuleLocation {
|
|||
}
|
||||
|
||||
private String getModuleName(File jarFile) {
|
||||
|
||||
String name = jarFile.getName();
|
||||
int dotIndex = name.indexOf('.');
|
||||
int dotIndex = name.indexOf("-help.jar"); // dev mode
|
||||
if (dotIndex == -1) {
|
||||
dotIndex = name.indexOf(".jar"); // production mode
|
||||
}
|
||||
return name.substring(0, dotIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ package help.validator.location;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import help.validator.location.HelpModuleLocation;
|
||||
|
||||
public abstract class HelpModuleLocationTestDouble extends HelpModuleLocation {
|
||||
|
||||
// this class exists to open up the package-level constructor
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue