GP-4294 - Fixed exception looking for extensions when running headlessly in fat jar mode

This commit is contained in:
dragonmacher 2024-02-06 17:01:02 -05:00
parent dffb5fd859
commit 359faba77a
3 changed files with 49 additions and 35 deletions

View file

@ -23,11 +23,11 @@ import java.util.*;
import generic.jar.ResourceFile;
import ghidra.framework.ApplicationProperties;
import ghidra.framework.GModule;
import utility.application.ApplicationLayout;
import ghidra.util.Msg;
import utility.module.ModuleUtilities;
/**
* The Ghidra jar application layout defines the customizable elements of the Ghidra application's
* The Ghidra jar application layout defines the customizable elements of the Ghidra application's
* directory structure when running in "single jar mode."
*/
public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
@ -51,7 +51,11 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
protected Collection<ResourceFile> findGhidraApplicationRootDirs() {
List<ResourceFile> dirs = new ArrayList<>();
String appPropPath = "/_Root/Ghidra/" + ApplicationProperties.PROPERTY_FILE;
URL appPropUrl = ApplicationLayout.class.getResource(appPropPath);
URL appPropUrl = getClass().getResource(appPropPath);
if (appPropUrl == null) {
throw new IllegalStateException(
"The Ghidra Jar must have an application.properties file at " + appPropPath);
}
ResourceFile rootDir = fromUrl(appPropUrl).getParentFile();
dirs.add(rootDir);
return dirs;
@ -79,7 +83,12 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
@Override
protected List<ResourceFile> findExtensionInstallationDirectories() {
URL extensionInstallUrl = ApplicationLayout.class.getResource("/_Root/Ghidra/Extensions");
String path = "/_Root/Ghidra/Extensions";
URL extensionInstallUrl = getClass().getResource(path);
if (extensionInstallUrl == null) {
Msg.debug(this, "No Extensions dir found at " + path);
return List.of();
}
ResourceFile extensionInstallDir = fromUrl(extensionInstallUrl);
return Collections.singletonList(extensionInstallDir);
}
@ -94,7 +103,7 @@ public class GhidraJarApplicationLayout extends GhidraApplicationLayout {
String urlString = url.toExternalForm();
try {
// Decode the URL to replace things like %20 with real spaces.
// Note: can't use URLDecoder.decode(String, Charset) because Utility must be
// Note: can't use URLDecoder.decode(String, Charset) because Utility must be
// Java 1.8 compatible.
urlString = URLDecoder.decode(urlString, "UTF-8");
}