Skip to content

Ghidra is a software reverse engineering (SRE) framework

fix build error propagation and bundle status concurrent access

Jason P. Leasure93b1d3f697c2
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
index 3a872a4c46..17a4fcd48a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java
@@ -54,6 +54,7 @@ import ghidra.util.task.*;
* </ul>
*/
public class BundleHost {
+ public static final String ACTIVATING_BUNDLE_ERROR_MSG = "activating bundle";
protected static final boolean STDERR_DEBUGGING = false;
private static final String SAVE_STATE_TAG_FILE = "BundleHost_FILE";
private static final String SAVE_STATE_TAG_ENABLE = "BundleHost_ENABLE";
@@ -129,8 +130,8 @@ public class BundleHost {
}
/**
- * If there is currently a bundle managed with file {@code bundleFile},
- * return its {@link GhidraBundle}, otherwise return {@code null}.
+ * Assuming there is currently a bundle managed with file {@code bundleFile},
+ * return its {@link GhidraBundle}, otherwise show an error dialog and return {@code null}.
*
* @param bundleFile the bundleFile of the sought bundle
* @return a {@link GhidraBundle} or {@code null}
@@ -145,6 +146,17 @@ public class BundleHost {
return bundle;
}
+ /**
+ * If there is currently a bundle managed with file {@code bundleFile},
+ * return its {@link GhidraBundle}, otherwise return {@code null}.
+ *
+ * @param bundleFile the bundleFile of the sought bundle
+ * @return a {@link GhidraBundle} or {@code null}
+ */
+ public GhidraBundle getGhidraBundle(ResourceFile bundleFile) {
+ return fileToBundleMap.get(bundleFile);
+ }
+
private static GhidraBundle createGhidraBundle(BundleHost bundleHost, ResourceFile bundleFile,
boolean enabled, boolean systemBundle) {
if (!bundleFile.exists()) {
@@ -546,7 +558,7 @@ public class BundleHost {
}
catch (BundleException e) {
GhidraBundleException bundleException =
- new GhidraBundleException(bundle, "activating bundle", e);
+ new GhidraBundleException(bundle, ACTIVATING_BUNDLE_ERROR_MSG, e);
fireBundleException(bundleException);
throw bundleException;
}
@@ -658,9 +670,15 @@ public class BundleHost {
monitor.setMaximum(bundlesRemaining.size());
while (!bundlesRemaining.isEmpty() && !monitor.isCancelled()) {
- List<GhidraBundle> resolvableBundles = bundlesRemaining.stream()
- .filter(bundle -> canResolveAll(bundle.getAllRequirements()))
- .collect(Collectors.toList());
+ List<GhidraBundle> resolvableBundles = bundlesRemaining.stream().filter(bundle -> {
+ try {
+ return canResolveAll(bundle.getAllRequirements());
+ }
+ catch (GhidraBundleException e) {
+ // failure in last round will set fireBundleException
+ }
+ return false;
+ }).collect(Collectors.toList());
if (resolvableBundles.isEmpty()) {
// final round, try everything we couldn't resolve to generate errors
resolvableBundles = bundlesRemaining;
@@ -678,6 +696,9 @@ public class BundleHost {
bundle.build(console);
activateSynchronously(bundle.getLocationIdentifier());
}
+ catch (GhidraBundleException e) {
+ fireBundleException(e);
+ }
catch (Exception e) {
e.printStackTrace(console);
}
@@ -799,8 +820,8 @@ public class BundleHost {
}
if (isSystem != bundle.isSystemBundle()) {
bundle.systemBundle = isSystem;
- Msg.error(this, String.format("Error, bundle %s went from %system to %system", bundleFile,
- isSystem ? "not " : "", isSystem ? "" : "not "));
+ Msg.error(this, String.format("Error, bundle %s went from %system to %system",
+ bundleFile, isSystem ? "not " : "", isSystem ? "" : "not "));
}
}
else if (isSystem) {
@@ -878,7 +899,8 @@ public class BundleHost {
}
else {
Msg.error(this,
- String.format("Error, bundle event for non-GhidraBundle: %s\n", osgiBundle.getLocation()));
+ String.format("Error, bundle event for non-GhidraBundle: %s\n",
+ osgiBundle.getLocation()));
}
break;
// force "inactive" updates for all other states
@@ -889,7 +911,8 @@ public class BundleHost {
}
else {
Msg.error(this,
- String.format("Error, bundle event for non-GhidraBundle: %s\n", osgiBundle.getLocation()));
+ String.format("Error, bundle event for non-GhidraBundle: %s\n",
+ osgiBundle.getLocation()));
}
break;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHostListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHostListener.java
index 6c07d356bb..d849a2d734 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHostListener.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHostListener.java
@@ -26,7 +26,7 @@ public interface BundleHostListener {
* Invoked when a bundle is built.
*
* @param bundle the bundle
- * @param summary a summary of the build
+ * @param summary a summary of the build, or null if nothing changed (build returned false)
*/
default void bundleBuilt(GhidraBundle bundle, String summary) {
//
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java
index 4003dd93be..9dc775fadd 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java
@@ -413,6 +413,9 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
GhidraBundle bundle = bundleHost.getExistingGhidraBundle(status.getFile());
if (!(bundle instanceof GhidraPlaceholderBundle)) {
status.setBusy(true);
+ if (status.getSummary().startsWith(BundleHost.ACTIVATING_BUNDLE_ERROR_MSG)) {
+ status.setSummary("");
+ }
bundleHost.enable(bundle);
bundles.add(bundle);
}
@@ -488,6 +491,9 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
GhidraBundle bundle = bundleHost.getExistingGhidraBundle(status.getFile());
if (activate) {
bundle.build(console.getStdErr());
+ if (status.getSummary().startsWith(BundleHost.ACTIVATING_BUNDLE_ERROR_MSG)) {
+ status.setSummary("");
+ }
bundleHost.activateSynchronously(bundle.getLocationIdentifier());
}
else { // deactivate
@@ -495,6 +501,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {
}
}
catch (Exception e) {
+ status.setSummary(e.getMessage());
Msg.error(this, "Error during activation/deactivation of bundle", e);
}
finally {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusTableModel.java
index 66ecdf742d..7f6221992c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusTableModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusTableModel.java
@@ -32,8 +32,7 @@ import generic.jar.ResourceFile;
import generic.util.Path;
import ghidra.docking.settings.Settings;
import ghidra.framework.plugintool.ServiceProvider;
-import ghidra.util.Msg;
-import ghidra.util.SystemUtilities;
+import ghidra.util.*;
import ghidra.util.table.column.*;
/**
@@ -60,6 +59,7 @@ public class BundleStatusTableModel
super(provider.getTool());
this.provider = provider;
this.bundleHost = bundleHost;
+
statuses = new ArrayList<>();
for (GhidraBundle bundle : bundleHost.getGhidraBundles()) {
addNewStatus(bundle);
@@ -72,17 +72,12 @@ public class BundleStatusTableModel
setDefaultTableSortState(TableSortState.createDefaultSortState(1, true));
}
- BundleStatus getStatus(GhidraBundle bundle) {
+ private BundleStatus getStatus(GhidraBundle bundle) {
return getStatusFromLoc(bundle.getLocationIdentifier());
}
- BundleStatus getStatusFromLoc(String bundleLoc) {
- BundleStatus status = bundleLocToStatusMap.get(bundleLoc);
- if (status == null) {
- Msg.showError(BundleStatusTableModel.this, provider.getComponent(),
- "bundle status error", "bundle has no status!");
- }
- return status;
+ private BundleStatus getStatusFromLoc(String bundleLoc) {
+ return bundleLocToStatusMap.get(bundleLoc);
}
@Override
@@ -93,14 +88,10 @@ public class BundleStatusTableModel
@Override
public void fireTableChanged(TableModelEvent e) {
- if (SwingUtilities.isEventDispatchThread()) {
- super.fireTableChanged(e);
- return;
- }
- final TableModelEvent e1 = e;
- SwingUtilities.invokeLater(() -> BundleStatusTableModel.super.fireTableChanged(e1));
+ Swing.runIfSwingOrRunLater(() -> BundleStatusTableModel.super.fireTableChanged(e));
}
+ // must be called on the swing thread
private void addNewStatusNoFire(GhidraBundle bundle) {
BundleStatus status = new BundleStatus(bundle.getFile(), bundle.isEnabled(),
bundle.isSystemBundle(), bundle.getLocationIdentifier());
@@ -117,11 +108,14 @@ public class BundleStatusTableModel
* add new status and fire a table update
*/
private void addNewStatus(GhidraBundle bundle) {
- int index = statuses.size();
- addNewStatusNoFire(bundle);
- fireTableRowsInserted(index, index);
+ Swing.runLater(() -> {
+ int index = statuses.size();
+ addNewStatusNoFire(bundle);
+ fireTableRowsInserted(index, index);
+ });
}
+ // must be called from the swing thread
private int removeStatusNoFire(BundleStatus status) {
if (!status.isReadOnly()) {
int statusIndex = statuses.indexOf(status);
@@ -133,24 +127,21 @@ public class BundleStatusTableModel
}
void removeStatus(BundleStatus status) {
- int rowIndex = removeStatusNoFire(status);
- if (rowIndex >= 0) {
- fireTableRowsDeleted(rowIndex, rowIndex);
- }
- }
-
- void remove(int[] modelRows) {
- List<BundleStatus> toRemove = Arrays.stream(modelRows)
- .mapToObj(statuses::get)
- .collect(Collectors.toUnmodifiableList());
- removeStatuses(toRemove);
+ Swing.runLater(() -> {
+ int rowIndex = removeStatusNoFire(status);
+ if (rowIndex >= 0) {
+ fireTableRowsDeleted(rowIndex, rowIndex);
+ }
+ });
}
void removeStatuses(List<BundleStatus> toRemove) {
- for (BundleStatus status : toRemove) {
- removeStatusNoFire(status);
- }
- fireTableDataChanged();
+ Swing.runLater(() -> {
+ for (BundleStatus status : toRemove) {
+ removeStatusNoFire(status);
+ }
+ fireTableDataChanged();
+ });
}
/***************************************************/
@@ -188,6 +179,7 @@ public class BundleStatusTableModel
return statuses;
}
+ // only used in testing
void setModelData(List<BundleStatus> statuses) {
this.statuses = statuses;
computeCache();
@@ -283,6 +275,8 @@ public class BundleStatusTableModel
/**
* (re)compute cached mapping from bundleloc to bundlepath
+ *
+ * <p>only used in testing
*/
private void computeCache() {
bundleLocToStatusMap.clear();
@@ -298,68 +292,88 @@ public class BundleStatusTableModel
protected class MyBundleHostListener implements BundleHostListener {
@Override
public void bundleBuilt(GhidraBundle bundle, String summary) {
- BundleStatus status = getStatus(bundle);
- status.setSummary(summary);
- int rowIndex = getRowIndex(status);
- fireTableRowsUpdated(rowIndex, rowIndex);
+ if (summary != null) {
+ Swing.runLater(() -> {
+ BundleStatus status = getStatus(bundle);
+ status.setSummary(summary);
+ int rowIndex = getRowIndex(status);
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ });
+ }
}
@Override
public void bundleActivationChange(GhidraBundle bundle, boolean newActivation) {
- BundleStatus status = getStatus(bundle);
- int rowIndex = getRowIndex(status);
- status.setBusy(false);
- if (newActivation) {
- status.setActive(true);
- }
- else {
- status.setActive(false);
- }
- fireTableRowsUpdated(rowIndex, rowIndex);
+ Swing.runLater(() -> {
+ BundleStatus status = getStatus(bundle);
+ int rowIndex = getRowIndex(status);
+ status.setBusy(false);
+ if (newActivation) {
+ status.setActive(true);
+ }
+ else {
+ status.setActive(false);
+ }
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ });
}
@Override
public void bundleAdded(GhidraBundle bundle) {
- addNewStatus(bundle);
+ Swing.runLater(() -> {
+ addNewStatus(bundle);
+ });
}
@Override
public void bundlesAdded(Collection<GhidraBundle> bundles) {
- int index = statuses.size();
- for (GhidraBundle bundle : bundles) {
- addNewStatusNoFire(bundle);
- }
- fireTableRowsInserted(index, bundles.size() - 1);
+ Swing.runLater(() -> {
+ int index = statuses.size();
+ for (GhidraBundle bundle : bundles) {
+ addNewStatusNoFire(bundle);
+ }
+ fireTableRowsInserted(index, bundles.size() - 1);
+ });
}
@Override
public void bundleRemoved(GhidraBundle bundle) {
- BundleStatus status = getStatus(bundle);
- removeStatus(status);
+ Swing.runLater(() -> {
+ BundleStatus status = getStatus(bundle);
+ removeStatus(status);
+ });
}
@Override
public void bundlesRemoved(Collection<GhidraBundle> bundles) {
- List<BundleStatus> toRemove = bundles.stream()
- .map(BundleStatusTableModel.this::getStatus)
- .collect(Collectors.toUnmodifiableList());
- removeStatuses(toRemove);
+ Swing.runLater(() -> {
+ List<BundleStatus> toRemove = bundles.stream()
+ .map(BundleStatusTableModel.this::getStatus)
+ .collect(Collectors.toUnmodifiableList());
+ removeStatuses(toRemove);
+ });
}
@Override
public void bundleEnablementChange(GhidraBundle bundle, boolean newEnablement) {
- BundleStatus status = getStatus(bundle);
- status.setEnabled(newEnablement);
- int rowIndex = getRowIndex(status);
- fireTableRowsUpdated(rowIndex, rowIndex);
+ Swing.runLater(() -> {
+ BundleStatus status = getStatus(bundle);
+ status.setEnabled(newEnablement);
+ int rowIndex = getRowIndex(status);
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ });
}
@Override
public void bundleException(GhidraBundleException exception) {
- BundleStatus status = getStatusFromLoc(exception.getBundleLocation());
- status.setSummary(exception.getMessage());
- int rowIndex = getRowIndex(status);
- fireTableRowsUpdated(rowIndex, rowIndex);
+ Swing.runLater(() -> {
+ BundleStatus status = getStatusFromLoc(exception.getBundleLocation());
+ if (status != null) {
+ status.setSummary(exception.getMessage());
+ int rowIndex = getRowIndex(status);
+ fireTableRowsUpdated(rowIndex, rowIndex);
+ }
+ });
}
}
@@ -416,7 +430,7 @@ public class BundleStatusTableModel
if (!status.isEnabled()) {
return "(DISABLED)";
}
- GhidraBundle bundle = bundleHost.getExistingGhidraBundle(status.getFile());
+ GhidraBundle bundle = bundleHost.getGhidraBundle(status.getFile());
if (bundle != null) {
Bundle osgiBundle = bundle.getOSGiBundle();
if (osgiBundle != null) {
@@ -516,9 +530,9 @@ public class BundleStatusTableModel
@Override
public String getValue(BundleStatus status, Settings settings, List<BundleStatus> data,
ServiceProvider serviceProvider0) throws IllegalArgumentException {
- GhidraBundle bundle = bundleHost.getExistingGhidraBundle(status.getFile());
+ GhidraBundle bundle = bundleHost.getGhidraBundle(status.getFile());
if (bundle == null) {
- return "bundle cache error";
+ return "no bundle";
}
else if (bundle instanceof GhidraPlaceholderBundle) {
// placeholders will have a summary assigned on construction
@@ -539,7 +553,7 @@ public class BundleStatusTableModel
JLabel label = (JLabel) super.getTableCellRendererComponent(data);
label.setFont(defaultFont.deriveFont(defaultFont.getStyle() | Font.BOLD));
label.setText(Path.toPathString(file));
- GhidraBundle bundle = bundleHost.getExistingGhidraBundle(file);
+ GhidraBundle bundle = bundleHost.getGhidraBundle(file);
if (bundle == null || bundle instanceof GhidraPlaceholderBundle || !file.exists()) {
label.setForeground(COLOR_BUNDLE_ERROR);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java
index 7cfee06ccd..2473c4cae9 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundle.java
@@ -83,7 +83,7 @@ public abstract class GhidraBundle {
*/
public abstract String getLocationIdentifier();
- abstract List<BundleRequirement> getAllRequirements();
+ abstract List<BundleRequirement> getAllRequirements() throws GhidraBundleException;
/**
* @return the file where this bundle is loaded from
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundleException.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundleException.java
index f36521f83f..41ae84130e 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundleException.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraBundleException.java
@@ -79,7 +79,7 @@ public class GhidraBundleException extends OSGiException {
default:
return "No exception type";
case BundleException.UNSPECIFIED:
- return "UNSPECIFIED";
+ return e.getMessage();
// The operation was unsupported. This type can be used anywhere a BundleException can be thrown.
case BundleException.UNSUPPORTED_OPERATION:
return "UNSUPPORTED_OPERATION";
@@ -99,8 +99,8 @@ public class GhidraBundleException extends OSGiException {
return message;
}
// parse the package constraints from filters in the BundleRequirement string
- String packages =
- OSGiUtils.extractPackageNamesFromFailedResolution(bundleException.getMessage())
+ String packages = OSGiUtils
+ .extractPackageNamesFromFailedResolution(bundleException.getMessage())
.stream()
.distinct()
.collect(Collectors.joining("\n"));
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java
index a1b9be400d..26e782f1ac 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraJarBundle.java
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.List;
import java.util.jar.Manifest;
+import org.osgi.framework.BundleException;
import org.osgi.framework.wiring.BundleRequirement;
import aQute.bnd.osgi.Constants;
@@ -62,15 +63,20 @@ public class GhidraJarBundle extends GhidraBundle {
}
@Override
- public List<BundleRequirement> getAllRequirements() {
+ public List<BundleRequirement> getAllRequirements() throws GhidraBundleException {
try (Jar jar = new Jar(file.getFile(true))) {
Manifest manifest = jar.getManifest();
- String importPackageString = manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
+ String importPackageString =
+ manifest.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
if (importPackageString != null) {
return OSGiUtils.parseImportPackage(importPackageString);
}
return Collections.emptyList();
}
+ catch (BundleException e) {
+ throw new GhidraBundleException(this.getLocationIdentifier(), "error parsing imports",
+ e);
+ }
catch (Exception e) {
throw new RuntimeException(e);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
index 85a58747ac..840561a713 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java
@@ -197,7 +197,7 @@ public class GhidraSourceBundle extends GhidraBundle {
}
/**
- * get any errors associated with building the given source file.
+ * Get any errors associated with building the given source file.
*
* @param sourceFile the source file
* @return a {@link BuildError} object
@@ -206,6 +206,15 @@ public class GhidraSourceBundle extends GhidraBundle {
return buildErrors.get(sourceFile);
}
+ /**
+ * Get the mapping from source file to BuildError.
+ *
+ * @return the error file map
+ */
+ public Map<ResourceFile, BuildError> getAllErrors() {
+ return Collections.unmodifiableMap(buildErrors);
+ }
+
private String getPreviousBuildErrors() {
return buildErrors.values()
.stream()
@@ -240,8 +249,8 @@ public class GhidraSourceBundle extends GhidraBundle {
requirements = OSGiUtils.parseImportPackage(importPackage);
}
catch (BundleException e) {
- throw new GhidraBundleException(getLocationIdentifier(), "parsing metadata",
- e);
+ throw new GhidraBundleException(getLocationIdentifier(),
+ "@importpackage error", e);
}
sourceFileToRequirements.put(rootSourceFile, requirements);
for (BundleRequirement requirement : requirements) {
@@ -265,13 +274,8 @@ public class GhidraSourceBundle extends GhidraBundle {
}
@Override
- public List<BundleRequirement> getAllRequirements() {
- try {
- updateRequirementsFromMetadata();
- }
- catch (GhidraBundleException e) {
- throw new RuntimeException(e);
- }
+ public List<BundleRequirement> getAllRequirements() throws GhidraBundleException {
+ updateRequirementsFromMetadata();
Map<String, BundleRequirement> reqs = getComputedReqs();
// insert requirements from a source manifest
ResourceFile manifestFile = getSourceManifestFile();
@@ -490,6 +494,7 @@ public class GhidraSourceBundle extends GhidraBundle {
getSourceDirectory().toString(), buildErrorsLastTime,
buildErrorsLastTime > 1 ? "s" : "");
writer.printf("%s\n", getPreviousBuildErrors());
+ writer.flush();
}
}
else {
@@ -515,6 +520,7 @@ public class GhidraSourceBundle extends GhidraBundle {
bundleHost.notifyBundleBuilt(this, summary);
return true;
}
+ bundleHost.notifyBundleBuilt(this, null);
return false;
}
@@ -630,7 +636,7 @@ public class GhidraSourceBundle extends GhidraBundle {
* bundle requirements.
*/
private BundleJavaManager createBundleJavaManager(PrintWriter writer, Summary summary,
- List<String> options) throws IOException {
+ List<String> options) throws IOException, GhidraBundleException {
final ResourceFileJavaFileManager resourceFileJavaManager = new ResourceFileJavaFileManager(
Collections.singletonList(getSourceDirectory()), buildErrors.keySet());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java
index bb0136eb73..5f3b76a747 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java
@@ -1168,13 +1168,28 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
@Override
public void bundleBuilt(GhidraBundle bundle, String summary) {
+ // on enable, build can happen before the refresh populates the info manager with
+ // this bundle's scripts, so allow for the possibility and create the info here.
if (bundle instanceof GhidraSourceBundle) {
GhidraSourceBundle sourceBundle = (GhidraSourceBundle) bundle;
- for (ResourceFile sourceFile : sourceBundle.getNewSources()) {
- if (infoManager.containsMetadata(sourceFile)) {
- ScriptInfo scriptInfo = infoManager.getExistingScriptInfo(sourceFile);
- BuildError e = sourceBundle.getErrors(sourceFile);
- scriptInfo.setCompileErrors(e != null);
+ ResourceFile sourceDirectory = sourceBundle.getFile();
+ if (summary == null) {
+ // a null summary means the build didn't change anything,
+ // so use any errors from the last build
+ for (ResourceFile sourceFile : sourceBundle.getAllErrors().keySet()) {
+ if (sourceFile.getParentFile().equals(sourceDirectory)) {
+ ScriptInfo scriptInfo = infoManager.getScriptInfo(sourceFile);
+ scriptInfo.setCompileErrors(true);
+ }
+ }
+ }
+ else {
+ for (ResourceFile sourceFile : sourceBundle.getNewSources()) {
+ if (sourceFile.getParentFile().equals(sourceDirectory)) {
+ ScriptInfo scriptInfo = infoManager.getScriptInfo(sourceFile);
+ BuildError e = sourceBundle.getErrors(sourceFile);
+ scriptInfo.setCompileErrors(e != null);
+ }
}
}
tableModel.fireTableDataChanged();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/BundleHostTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/BundleHostTest.java
index 3c0653150e..c894cfacc6 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/BundleHostTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/BundleHostTest.java
@@ -67,7 +67,9 @@ public class BundleHostTest extends AbstractGhidraHeadlessIntegrationTest {
@Override
public void bundleBuilt(GhidraBundle gbundle, String summary) {
- this.lastBuildSummary = summary;
+ if (summary != null) {
+ this.lastBuildSummary = summary;
+ }
}
}