GP-1424 - remove 'refresh' action from data type manager

This commit is contained in:
dragonmacher
2021-10-22 09:11:29 -04:00
parent 7b2d5f8c32
commit 9a9c1fc64a
9 changed files with 45 additions and 195 deletions
@@ -214,7 +214,6 @@ public class DataTypesProvider extends ComponentProviderAdapter {
addLocalAction(new OpenProjectArchiveAction(plugin));
addLocalAction(new CreateArchiveAction(plugin));
addLocalAction(new CreateProjectArchiveAction(plugin));
addLocalAction(new RefreshAction(plugin));
ToggleDockingAction previewAction = getPreviewWindowAction();
addLocalAction(previewAction);
@@ -1,61 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.plugin.core.datamgr.actions;
import docking.ActionContext;
import docking.action.DockingAction;
import docking.action.MenuData;
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
import ghidra.util.classfinder.ClassSearchTask;
import ghidra.util.task.*;
/**
* Class for action to refresh the built-in data types from the class path.
*/
public class RefreshAction extends DockingAction implements TaskListener {
private final DataTypeManagerPlugin plugin;
public RefreshAction(DataTypeManagerPlugin plugin) {
super("Refresh BuiltInTypes", plugin.getName());
this.plugin = plugin;
setMenuBarData(new MenuData(new String[] { "Refresh BuiltInTypes" }, null, "R2"));
setDescription("Searches the class path to refresh the list of Ghidra BuiltIn data types.");
setEnabled(true);
}
@Override
public void actionPerformed(ActionContext context) {
setEnabled(false);
Task task = new ClassSearchTask();
task.addTaskListener(this);
new TaskLauncher(task, plugin.getProvider().getComponent(), 0);
}
@Override
public void taskCompleted(Task task) {
setEnabled(true);
}
@Override
public void taskCancelled(Task task) {
setEnabled(true);
}
}
@@ -39,7 +39,7 @@ public class HeadlessGhidraApplicationConfiguration extends ApplicationConfigura
monitor.setMessage("Performing class searching...");
performClassSearching();
// Locate cacerts if found (must be done before module initialization)
// Locate certs if found (must be done before module initialization)
locateCACertsFile();
monitor.setMessage("Performing module initialization...");
@@ -73,7 +73,7 @@ public class HeadlessGhidraApplicationConfiguration extends ApplicationConfigura
// The class searcher searches the classpath, and Ghidra's classpath should be complete
// for this configuration at this point.
try {
ClassSearcher.search(false, monitor);
ClassSearcher.search(monitor);
}
catch (CancelledException e) {
Msg.debug(this, "Class searching unexpectedly cancelled.");
@@ -81,7 +81,7 @@ public class HeadlessGhidraApplicationConfiguration extends ApplicationConfigura
}
/**
* Locate cacerts file within the Ghidra root directory. If found this will be used
* Locate certs file within the Ghidra root directory. If found this will be used
* for initializing the ApplicationTrustManager used for SSL/PKI.
*/
private void locateCACertsFile() {
@@ -63,8 +63,6 @@ import ghidra.program.database.ProgramDB;
import ghidra.program.database.data.ProgramDataTypeManager;
import ghidra.program.model.data.*;
import ghidra.test.*;
import ghidra.util.classfinder.ClassSearchTask;
import ghidra.util.task.Task;
import ghidra.util.task.TaskMonitor;
import util.CollectionUtils;
import utilities.util.FileUtilities;
@@ -664,38 +662,6 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe
assertFalse(action.isSelected());
}
@Test
public void testRefreshBuiltins() throws Exception {
try {
doTestRefreshBuiltins();
}
finally {
cleanupTestBuiltin();
}
}
private void doTestRefreshBuiltins() throws Exception {
GTreeNode treeRoot = tree.getModelRoot();
GTreeNode builtInNode = treeRoot.getChild("BuiltInTypes");
assertNull("Test setup Error: ghidra.app.test.TestDataType was not removed!",
builtInNode.getChild("TestDataType"));
compileJavaDataType();
DockingActionIf action = getAction(plugin, "Refresh BuiltInTypes");
assertTrue(action.isEnabledForContext(treeContext));
DataTypeTestUtils.performAction(action, tree, false);
waitForTasks();
waitForProgram();
waitForActionToBeEnabled(action);
builtInNode = treeRoot.getChild("BuiltInTypes");
assertNotNull(builtInNode.getChild("TestDataType"));
}
@Test
public void testDataTypePreviewCopyHtmlText() throws Exception {
@@ -1207,7 +1173,7 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe
}
/**
* This directory is bin in eclipse; it will be a resources directory in the classpath when run
* This directory is bin in eclipse; it will be a resources directory in the classpath when run
* in batch mode. The directory is one specifically created by and for this test.
* @return class output directory
* @throws FileNotFoundException Could not find class output directory
@@ -1265,31 +1231,6 @@ public class DataTypeManagerPluginTest extends AbstractGhidraHeadedIntegrationTe
}
}
private void cleanupTestBuiltin() throws Exception {
File binDir = getClassesDirectory();
File javaFile = new File(binDir, "TestDataType.java");
File classFile = new File(binDir, "TestDataType.class");
javaFile.delete();
classFile.delete();
// force built-ins to get restored
Task task = new ClassSearchTask();
task.run(TaskMonitor.DUMMY);
DockingActionIf action = getAction(plugin, "Refresh BuiltInTypes");
assertTrue(action.isEnabledForContext(treeContext));
DataTypeTestUtils.performAction(action, tree, false);
waitForTasks();
waitForProgram();
waitForActionToBeEnabled(action);
GTreeNode treeRoot = tree.getModelRoot();
GTreeNode builtInNode = treeRoot.getChild("BuiltInTypes");
assertNull("Test setup Error: ghidra.app.test.TestDataType was not removed!",
builtInNode.getChild("TestDataType"));
}
private File getTestDataTypeFile() {
URL url = getClass().getResource("TestDataType.txt");
try {
@@ -1,41 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.util.classfinder;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.Task;
import ghidra.util.task.TaskMonitor;
/**
* Task for searching for classes. This allows for a runtime refresh of scanned classes.
*/
public class ClassSearchTask extends Task {
public ClassSearchTask() {
super("Refreshing List of Ghidra Class Files", true, false, true);
}
@Override
public void run(final TaskMonitor monitor) {
try {
ClassSearcher.search(true, monitor);
}
catch (CancelledException e) {
// user cancelled
}
}
}
@@ -82,7 +82,7 @@ public class ClassSearcher {
}
/**
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes that implement or
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes that implement or
* derive from the given class
*
* @param c the filter class
@@ -93,14 +93,14 @@ public class ClassSearcher {
}
/**
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes that
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes that
* implement or derive from the given class
*
* @param c the filter class
* @param classFilter A Predicate that tests class objects (that are already of type T)
* for further filtering, <code>null</code> is equivalent to "return true"
* @return {@link ExtensionPointProperties#priority() priority-sorted} list of
* classes that implement or extend T and pass the filtering test performed by the
* @return {@link ExtensionPointProperties#priority() priority-sorted} list of
* classes that implement or extend T and pass the filtering test performed by the
* predicate
*/
@SuppressWarnings("unchecked") // we checked the type of each use so we know the casts are safe
@@ -130,14 +130,14 @@ public class ClassSearcher {
}
/**
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes
* Get {@link ExtensionPointProperties#priority() priority-sorted} classes
* instances that implement or derive from the given class
*
* @param c the filter class
* @param filter A Predicate that tests class objects (that are already of type T)
* for further filtering, <code>null</code> is equivalent to "return true"
* @return {@link ExtensionPointProperties#priority() priority-sorted} list of
* classes instances that implement or extend T and pass the filtering test performed by
* @return {@link ExtensionPointProperties#priority() priority-sorted} list of
* classes instances that implement or extend T and pass the filtering test performed by
* the predicate
*/
public static <T> List<T> getInstances(Class<T> c, ClassFilter filter) {
@@ -210,20 +210,32 @@ public class ClassSearcher {
listenerList.remove(l);
}
/**
* This deprecated method is now simply a pass-through for {@link #search(TaskMonitor)}.
*
* @param forceRefresh ignored
* @param monitor the task monitor
* @throws CancelledException if cancelled
* @deprecated use {@link #search(TaskMonitor)} instead
*/
@Deprecated(forRemoval = true, since = "10.1") // remove 2 releases after 10.1
public static void search(boolean forceRefresh, TaskMonitor monitor)
throws CancelledException {
search(monitor);
}
/**
* Searches the classpath and updates the list of available classes which
* satisfy the class filter. Classes which
* data types, and language providers. When the search completes and was
* not cancelled, the change listeners are notified.
*
* @param forceRefresh if true the class cache is ignored and the search is performed
* from scratch.
* @param monitor the progress monitor for the search.
* @throws CancelledException if the operation is cancelled
*/
public static void search(boolean forceRefresh, TaskMonitor monitor) throws CancelledException {
public static void search(TaskMonitor monitor) throws CancelledException {
if (hasSearched && !forceRefresh) {
if (hasSearched) {
log.trace("Already searched for classes: using cached results");
return;
}
@@ -65,7 +65,7 @@ public abstract class StandAloneApplication implements GenericStandAloneApplicat
}
/**
* Creates a new application using the specified application name
* Creates a new application using the specified application name
* and version.
* @param name application name
* @param version application version
@@ -146,7 +146,7 @@ public abstract class StandAloneApplication implements GenericStandAloneApplicat
Application.initializeApplication(layout, configuration);
try {
ClassSearcher.search(false, configuration.getTaskMonitor());
ClassSearcher.search(configuration.getTaskMonitor());
}
catch (CancelledException e) {
Msg.debug(this, "Class searching unexpectedly cancelled.");
@@ -41,11 +41,11 @@ import ghidra.util.exception.*;
import ghidra.util.task.*;
/**
* DataTypeArchiveTransformer changes (transforms) a new archive file so that it appears to be
* DataTypeArchiveTransformer changes (transforms) a new archive file so that it appears to be
* an updated copy of a previously existing data type archive. This allows us to parse a new
* version of each standard GDT file we supply. This class changes the IDs on the data types
* so they will match the previous version's IDs. This allows the new data type archive and
* its data types to become the associated data types where the previous version data types
* so they will match the previous version's IDs. This allows the new data type archive and
* its data types to become the associated data types where the previous version data types
* were applied.
*/
public class DataTypeArchiveTransformer implements GhidraLaunchable {
@@ -158,7 +158,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
monitor.checkCanceled();
DataType newDataType = allDataTypes.next();
if (isAnonymousType(newDataType)) {
// Skip anonymous types, they are matched as components of composites or
// Skip anonymous types, they are matched as components of composites or
// later unmatched enums are matched in categories.
continue;
}
@@ -169,7 +169,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
DataType oldDataType =
transformDataType(newDataType, oldFileArchive, newFileArchive);
// Now process children anonymous data types for composites.
// Now process children anonymous data types for composites.
processAnonymous(oldDataType, newDataType, oldFileArchive, newFileArchive);
// monitor.incrementProgress(1);
@@ -202,8 +202,8 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
private static void processUnmatchedEnums(FileDataTypeManager oldFileArchive,
FileDataTypeManager newFileArchive, TaskMonitor monitor) throws CancelledException {
// Find all anonymous enums and if not already matched to a data type in the old
// archive, then try to match with an anonymous enum in the same category of the
// Find all anonymous enums and if not already matched to a data type in the old
// archive, then try to match with an anonymous enum in the same category of the
// old archive.
Iterator<DataType> allDataTypes = newFileArchive.getAllDataTypes();
while (allDataTypes.hasNext()) {
@@ -287,9 +287,9 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
private static void processAnonymous(DataType oldDataType, DataType newDataType,
FileDataTypeManager oldFileArchive, FileDataTypeManager newFileArchive) {
// If we have composites, then get any component with an anonymous data type in the
// newDataType, and look for it by matching field name in the old composite.
// If the composites are anonymous then look for matching components by ordinal
// If we have composites, then get any component with an anonymous data type in the
// newDataType, and look for it by matching field name in the old composite.
// If the composites are anonymous then look for matching components by ordinal
// if the number of components matches.
if (newDataType instanceof Composite && oldDataType instanceof Composite) {
Composite newComposite = (Composite) newDataType;
@@ -346,7 +346,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
if (isAnonymousType(newCompDt) || anonymousPointerDepth > 0 ||
anonymousArrayNumElements > 0 || anonymousTypeDefDepth > 0) {
// Found an anonymous type, anonymous pointer, or anonymous array,
// Found an anonymous type, anonymous pointer, or anonymous array,
// so get the matching component by field name or ordinal.
DataTypeComponent matchingComponent =
getAnonymousMatch(oldComposite, newComposite, newComponent);
@@ -388,7 +388,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
// Got a match so set the ID.
transformDataType(newCompDt, newFileArchive, oldCompDt);
// Now process children anonymous data types for anonymous composites.
// Now process children anonymous data types for anonymous composites.
processAnonymous(oldCompDt, newCompDt, oldFileArchive, newFileArchive);
}
}
@@ -405,7 +405,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
transformDataType(newDataType, newFileArchive, oldDataType);
}
// Now process children anonymous data types for anonymous composites.
// Now process children anonymous data types for anonymous composites.
processAnonymous(oldDataType, newDataType, oldFileArchive, newFileArchive);
}
@@ -753,7 +753,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
public void launch(GhidraApplicationLayout layout, String[] args) {
ApplicationConfiguration appConfig = new DockingApplicationConfiguration();
Application.initializeApplication(layout, appConfig);
// Perform Class searching so we load data type classes that may have moved or
// Perform Class searching so we load data type classes that may have moved or
// changed name. This is needed to map a data type's old path name to the new one.
performClassSearching(appConfig.getTaskMonitor());
@@ -874,7 +874,7 @@ public class DataTypeArchiveTransformer implements GhidraLaunchable {
// The class searcher searches the classpath, and Ghidra's classpath should be complete
// for this configuration at this point.
try {
ClassSearcher.search(false, monitor);
ClassSearcher.search(monitor);
}
catch (CancelledException e) {
Msg.debug(this, "Class searching unexpectedly cancelled.");
@@ -29,7 +29,7 @@ public class GhidraScriptUtilTest extends AbstractGenericTest {
@Before
public void setup() throws CancelledException {
ClassSearcher.search(false, new ConsoleTaskMonitor());
ClassSearcher.search(new ConsoleTaskMonitor());
}
@Test