mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-24 13:11:47 +00:00
Help - fixed intermittent bug in help build system related to the Dummy
help set
This commit is contained in:
parent
00a5a4dc01
commit
c7afc468c5
@ -16,8 +16,7 @@
|
||||
package help.validator.location;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.help.HelpSet;
|
||||
|
||||
@ -43,21 +42,13 @@ public class DirectoryHelpModuleLocation extends HelpModuleLocation {
|
||||
|
||||
@Override
|
||||
public GhidraTOCFile loadSourceTOCFile() {
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(helpDir, "TOC_Source*.xml")) {
|
||||
for (Path file : ds) {
|
||||
Path sourceTocPath = helpDir.resolve("TOC_Source.xml");
|
||||
try {
|
||||
return GhidraTOCFile.createGhidraTOCFile(file);
|
||||
return GhidraTOCFile.createGhidraTOCFile(sourceTocPath);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AssertException("Unexpected error loading source TOC file!: " + file,
|
||||
throw new AssertException("Unexpected error loading source TOC file!: " + sourceTocPath,
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new AssertException("Error reading help path: " + helpDir);
|
||||
}
|
||||
|
||||
throw new AssertException("Help module has no TOC_Source.xml file: " + helpDir);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ package help.validator.location;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
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,6 +32,12 @@ 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>();
|
||||
static {
|
||||
env.put("create", "false");
|
||||
@ -69,19 +75,51 @@ public class JarHelpModuleLocation extends HelpModuleLocation {
|
||||
|
||||
@Override
|
||||
public HelpSet loadHelpSet() {
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(helpDir, "*_HelpSet.hs");) {
|
||||
for (Path path : ds) {
|
||||
return new GHelpSet(null, path.toUri().toURL());
|
||||
|
||||
// Our convention is to name the help set after the module
|
||||
File jarFile = getJarFile();
|
||||
String moduleName = getModuleName(jarFile);
|
||||
Path hsPath = helpDir.resolve(moduleName + "_HelpSet.hs");
|
||||
try {
|
||||
return new GHelpSet(null, hsPath.toUri().toURL());
|
||||
}
|
||||
catch (MalformedURLException | HelpSetException e) {
|
||||
throw new AssertException(
|
||||
"Pre-built help jar file is missing it's help set: " + helpDir, e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new AssertException("No _HelpSet.hs file found for help directory: " + helpDir);
|
||||
}
|
||||
catch (HelpSetException e) {
|
||||
throw new AssertException("Error loading help set for " + helpDir);
|
||||
}
|
||||
|
||||
throw new AssertException("Pre-built help jar file is missing it's help set: " + helpDir);
|
||||
private File getJarFile() {
|
||||
|
||||
// format: jar:file:///.../Ghidra/Features/<module>/build/libs/<module>.jar!/help
|
||||
String uriString = helpDir.toUri().toString();
|
||||
int start = uriString.indexOf("file:/");
|
||||
String chopped = uriString.substring(start);
|
||||
int end = chopped.indexOf("!");
|
||||
chopped = chopped.substring(0, end);
|
||||
return new File(chopped);
|
||||
}
|
||||
|
||||
private String getModuleName(File jarFile) {
|
||||
|
||||
String name = jarFile.getName();
|
||||
int dotIndex = name.indexOf('.');
|
||||
return name.substring(0, dotIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getHelpModuleLocation() {
|
||||
// start format: jar:file:///.../Ghidra/Features/Base/build/libs/Base.jar!/help
|
||||
|
||||
// format: file:///.../Ghidra/Features/<module>/build/libs/<module>.jar
|
||||
File jarFile = getJarFile();
|
||||
String moduleName = getModuleName(jarFile);
|
||||
String fullPath = jarFile.getPath();
|
||||
int moduleNameStart = fullPath.indexOf(moduleName);
|
||||
int end = moduleNameStart + moduleName.length();
|
||||
String moduleString = fullPath.substring(0, end);
|
||||
Path modulePath = Paths.get(moduleString);
|
||||
return modulePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user