Finding external modules from the classpath instead of the

eclipse.project.dir property.
This commit is contained in:
Ryan Kurtz 2019-08-09 13:49:53 -04:00
parent 351cf56e6e
commit 3a12b5bbe2
2 changed files with 28 additions and 28 deletions

View file

@ -933,18 +933,6 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E
ResourceFile myModuleRootDirectory = ResourceFile myModuleRootDirectory =
Application.getModuleContainingClass(getClass().getName()); Application.getModuleContainingClass(getClass().getName());
if (myModuleRootDirectory == null) {
if (!SystemUtilities.isInDevelopmentMode()) {
Msg.warn(this, "Unable to identify pcodetest module directory!\n" +
"Project must contain Module.manifest file, and if developing module using Eclipse\n" +
"w/ GhidraDev the VM argument -Declipse.project.dir=<project-path> must be specified.");
}
else {
Msg.warn(this,
"Unable to identify pcodetest module directory! Project must contain Module.manifest file");
}
}
if (myModuleRootDirectory != null) { if (myModuleRootDirectory != null) {
File myModuleRoot = myModuleRootDirectory.getFile(false); File myModuleRoot = myModuleRootDirectory.getFile(false);
if (myModuleRoot != null) { if (myModuleRoot != null) {
@ -954,6 +942,10 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E
} }
} }
} }
else {
Msg.warn(this,
"Unable to identify pcodetest module directory! Project must contain Module.manifest file");
}
if (resourcesTestDataDir == null || !resourcesTestDataDir.isDirectory()) { if (resourcesTestDataDir == null || !resourcesTestDataDir.isDirectory()) {
findTestResourceDirectory(DEFAULT_PROCESSOR_TEST_MODULE); findTestResourceDirectory(DEFAULT_PROCESSOR_TEST_MODULE);

View file

@ -22,6 +22,7 @@ import generic.jar.ResourceFile;
import ghidra.framework.ApplicationProperties; import ghidra.framework.ApplicationProperties;
import ghidra.framework.GModule; import ghidra.framework.GModule;
import ghidra.util.SystemUtilities; import ghidra.util.SystemUtilities;
import utilities.util.FileUtilities;
import utility.application.ApplicationLayout; import utility.application.ApplicationLayout;
import utility.application.ApplicationUtilities; import utility.application.ApplicationUtilities;
import utility.module.ModuleUtilities; import utility.module.ModuleUtilities;
@ -142,23 +143,30 @@ public class GhidraApplicationLayout extends ApplicationLayout {
Collection<ResourceFile> moduleRootDirectories = Collection<ResourceFile> moduleRootDirectories =
ModuleUtilities.findModuleRootDirectories(applicationRootDirs, new ArrayList<>()); ModuleUtilities.findModuleRootDirectories(applicationRootDirs, new ArrayList<>());
// If Ghidra was launched from our Eclipse GhidraDev plugin, we want to add the // Examine the classpath to look for modules outside of the application root directories.
// Eclipse module project (and it's dependent projects) to the list of module root // These might exist if Ghidra was launched from an Eclipse project that resides
// directories so Ghidra can discover them. // external to the Ghidra installation.
String eclipseProjectDirProperty = System.getProperty("eclipse.project.dir"); for (String entry : System.getProperty("java.class.path", "").split(File.pathSeparator)) {
if (eclipseProjectDirProperty != null && !eclipseProjectDirProperty.isEmpty()) { final ResourceFile classpathEntry = new ResourceFile(entry);
ResourceFile eclipseProjectDir = new ResourceFile(eclipseProjectDirProperty);
if (ModuleUtilities.isModuleDirectory(eclipseProjectDir)) { // We only care about directories (skip jars)
moduleRootDirectories.add(eclipseProjectDir); if (!classpathEntry.isDirectory()) {
continue;
} }
}
String eclipseProjectDependencies = System.getProperty("eclipse.project.dependencies"); // Skip classpath entries that live in an application root directory...we've already
if (eclipseProjectDependencies != null && !eclipseProjectDependencies.isEmpty()) { // found those.
for (String path : eclipseProjectDependencies.split(File.pathSeparator)) { if (applicationRootDirs.stream().anyMatch(dir -> FileUtilities.isPathContainedWithin(
ResourceFile eclipseProjectDir = new ResourceFile(path); dir.getFile(false), classpathEntry.getFile(false)))) {
if (ModuleUtilities.isModuleDirectory(eclipseProjectDir)) { continue;
moduleRootDirectories.add(eclipseProjectDir); }
}
// We are going to assume that the classpath entry is in a subdirectory of the module
// directory (i.e., bin/), so only check parent directory for the module.
ResourceFile classpathEntryParent = classpathEntry.getParentFile();
if (classpathEntryParent != null &&
ModuleUtilities.isModuleDirectory(classpathEntryParent)) {
moduleRootDirectories.add(classpathEntryParent);
} }
} }