Merge remote-tracking branch 'origin/GP-1-dragonmacher-help-validation-tweak'

This commit is contained in:
Ryan Kurtz
2021-10-25 13:32:48 -04:00
2 changed files with 50 additions and 39 deletions
@@ -32,11 +32,11 @@ import javax.swing.UIManager;
import docking.ComponentProvider;
import docking.action.DockingActionIf;
import generic.concurrent.GThreadPool;
import generic.util.WindowUtilities;
import ghidra.util.*;
import ghidra.util.exception.AssertException;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskLauncher;
import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
import utilities.util.reflection.ReflectionUtilities;
@@ -188,6 +188,7 @@ public class HelpManager implements HelpService {
/**
* Returns the master help set (the one into which all other help sets are merged).
* @return the help set
*/
public GHelpSet getMasterHelpSet() {
return mainHS;
@@ -443,21 +444,20 @@ public class HelpManager implements HelpService {
return;
}
TaskLauncher.launchNonModal("Validating Help", monitor -> {
try {
printBadHelp(monitor);
}
catch (CancelledException e) {
// user cancelled; just exit
}
});
GThreadPool.runAsync(Swing.GSWING_THREAD_POOL_NAME, this::doPrintBadHelp);
}
private void printBadHelp(TaskMonitor monitor) throws CancelledException {
private void doPrintBadHelp() {
Map<Object, HelpLocation> badHelp = getInvalidHelpLocations(monitor);
if (badHelp.isEmpty()) {
return;
Map<Object, HelpLocation> badHelp;
try {
badHelp = getInvalidHelpLocations(TaskMonitor.DUMMY);
if (badHelp.isEmpty()) {
return;
}
}
catch (CancelledException e) {
return; // user cancelled
}
StringBuilder buffy = new StringBuilder();
@@ -474,7 +474,6 @@ public class HelpManager implements HelpService {
throws CancelledException {
Map<Object, HelpLocation> map = new WeakHashMap<>();
Map<Object, HelpLocation> helpLocationsCopy = copyHelpLocations();
monitor.initialize(helpLocationsCopy.size());
Set<Entry<Object, HelpLocation>> entries = helpLocationsCopy.entrySet();
@@ -657,7 +656,7 @@ public class HelpManager implements HelpService {
/**
* Create a new help set for the given url, if one does
* not already exist.
* @param classLoader
* @param classLoader the class loader
*/
private HelpSet createHelpSet(URL url, GHelpClassLoader classLoader) throws HelpSetException {
if (!urlToHelpSets.containsKey(url)) {
@@ -76,6 +76,18 @@ public class GThreadPool {
return threadPool;
}
/**
* Runs the given runnable in a background thread using a shared thread pool of the given name.
* @param poolName the thread pool name
* @param r the runnable
* @return the future
*/
public static CompletableFuture<Void> runAsync(String poolName, Runnable r) {
GThreadPool pool = getSharedThreadPool(poolName);
Executor ex = pool.getExecutor();
return CompletableFuture.runAsync(r, ex);
}
private GThreadPool(String name) {
this.name = name;
executor = new GThreadPoolExecutor();