diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java index b6876c9834..3b3100c4a5 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/TestEnv.java @@ -35,6 +35,7 @@ import ghidra.app.events.OpenProgramPluginEvent; import ghidra.app.plugin.core.analysis.AutoAnalysisManager; import ghidra.app.plugin.core.progmgr.ProgramManagerPlugin; import ghidra.app.plugin.core.script.GhidraScriptMgrPlugin; +import ghidra.app.script.GhidraScript; import ghidra.app.script.JavaScriptProvider; import ghidra.app.services.ProgramManager; import ghidra.base.project.GhidraProject; @@ -550,15 +551,18 @@ public class TestEnv { } public ScriptTaskListener runScript(File script) throws PluginException { - JavaScriptProvider scriptProvider = new JavaScriptProvider(); PrintWriter writer = new PrintWriter(System.out); ResourceFile resourceFile = new ResourceFile(script); - Boolean result = (Boolean) AbstractGenericTest.invokeInstanceMethod("compile", - scriptProvider, new Class[] { ResourceFile.class, PrintWriter.class }, - new Object[] { resourceFile, writer }); - - if (!result) { + GhidraScript scr=null; + try { + scr=scriptProvider.getScriptInstance(resourceFile, writer); + } + catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + + } + if (scr==null) { writer.flush(); throw new RuntimeException("Failed to compile script " + script.getAbsolutePath()); } @@ -881,7 +885,7 @@ public class TestEnv { Project project = frontEndToolInstance.getProject(); ToolServices toolServices = project.getToolServices(); - PluginTool newTool = (PluginTool) toolServices.launchTool(toolName, null); + PluginTool newTool = toolServices.launchTool(toolName, null); if (newTool == null) { // couldn't find the tool in the workspace...check the test area newTool = launchDefaultToolByName(toolName); diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java index 73b1918169..a1d6ed0feb 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java @@ -21,6 +21,7 @@ import java.awt.Window; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -38,15 +39,15 @@ import org.junit.*; import docking.ActionContext; import docking.action.DockingActionIf; import docking.widgets.OptionDialog; +import docking.widgets.bundlemanager.BundlePath; +import docking.widgets.bundlemanager.BundlePathManager; import docking.widgets.filter.FilterTextField; -import docking.widgets.pathmanager.PathManager; import docking.widgets.table.GDynamicColumnTableModel; import docking.widgets.table.RowObjectTableModel; import docking.widgets.tree.GTree; import docking.widgets.tree.GTreeNode; import generic.jar.ResourceFile; import generic.test.TestUtils; -import generic.util.Path; import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin; import ghidra.app.plugin.core.console.ConsoleComponentProvider; import ghidra.app.script.*; @@ -65,7 +66,6 @@ import ghidra.util.table.GhidraTable; import ghidra.util.table.GhidraTableFilterPanel; import ghidra.util.task.*; import util.CollectionUtils; -import utilities.util.FileUtilities; public abstract class AbstractGhidraScriptMgrPluginTest extends AbstractGhidraHeadedIntegrationTest { @@ -125,7 +125,7 @@ public abstract class AbstractGhidraScriptMgrPluginTest assertNotNull(scriptTable); // this clears out the static map that accumulates values between tests - GhidraScriptUtil.clean(); + GhidraScriptUtil.clearMetadata(); runSwing(() -> provider.refresh()); cleanupOldTestFiles(); @@ -171,13 +171,19 @@ public abstract class AbstractGhidraScriptMgrPluginTest env.dispose(); } + static protected void wipe(Path path) throws IOException { + if (Files.exists(path)) { + for (Path p : (Iterable) Files.walk(path).sorted( + Comparator.reverseOrder())::iterator) { + Files.deleteIfExists(p); + } + } + } + protected void wipeUserScripts() throws IOException { - java.nio.file.Path userScriptDir = - java.nio.file.Paths.get(GhidraScriptUtil.USER_SCRIPTS_DIR); - Iterator it = Files.list(userScriptDir).iterator(); - while (it.hasNext()) { - Files.walk(it.next()).sorted(Comparator.reverseOrder()).map( - java.nio.file.Path::toFile).forEach(File::delete); + Path userScriptDir = java.nio.file.Paths.get(GhidraScriptUtil.USER_SCRIPTS_DIR); + for (Path p : (Iterable) Files.list(userScriptDir)::iterator) { + wipe(p); } } @@ -220,13 +226,13 @@ public abstract class AbstractGhidraScriptMgrPluginTest } protected void assertScriptManagerKnowsAbout(ResourceFile script) { - assertTrue(GhidraScriptUtil.contains(script)); + assertTrue(GhidraScriptUtil.containsMetadata(script)); assertNull(provider.getActionManager().get(script)); } protected void assertScriptManagerForgotAbout(ResourceFile script) { - assertFalse(GhidraScriptUtil.contains(script)); + assertFalse(GhidraScriptUtil.containsMetadata(script)); assertNull(provider.getActionManager().get(script)); assertNull(provider.getEditorMap().get(script)); } @@ -965,25 +971,17 @@ public abstract class AbstractGhidraScriptMgrPluginTest } - protected void addScriptPath(final File file) { - final PathManager pathManager = (PathManager) getInstanceField("pathManager", provider); - runSwing(() -> pathManager.addPath(new ResourceFile(file), true)); - } - - protected void cleanupOldTestFiles() { - // remove the 'bin' directory so that any scripts we use will be recompiled - List dirs = GhidraScriptUtil.getScriptBinDirectories(); - for (ResourceFile file : dirs) { - FileUtilities.deleteDir(file.getFile(false)); - file.mkdir();// recreate the file or the compiler will complain - } + protected void cleanupOldTestFiles() throws IOException { + // remove the compiled bundles directory so that any scripts we use will be recompiled + wipe(GhidraScriptUtil.getCompiledBundlesDir()); String myTestName = super.testName.getMethodName(); // destroy any NewScriptxxx files...and Temp ones too - PathManager pathManager = (PathManager) TestUtils.getInstanceField("pathManager", provider); - List paths = pathManager.getPaths(); - for (Path path : paths) { + BundlePathManager pathManager = + (BundlePathManager) TestUtils.getInstanceField("bundlePathManager", provider); + List paths = pathManager.getPaths(); + for (BundlePath path : paths) { File file = path.getPath().getFile(false); File[] listFiles = file.listFiles(); if (listFiles == null) { @@ -1034,7 +1032,7 @@ public abstract class AbstractGhidraScriptMgrPluginTest waitForSwing(); int waitCount = 0; - while (!flag.ended && waitCount < 201) { + while (!flag.ended && waitCount < 301) { try { Thread.sleep(DEFAULT_WAIT_DELAY); } diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java index 891a840485..94d2184ee7 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java @@ -150,9 +150,12 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes // remove all class files from the user script bin dir File userScriptsBinDir = SourceBundleInfo.getBindirFromScriptFile(new ResourceFile(newScriptFile)).toFile(); - File[] userScriptBinDirFiles = userScriptsBinDir.listFiles(classFileFilter); - for (File file : userScriptBinDirFiles) { - file.delete(); + File[] userScriptBinDirFiles; + if (userScriptsBinDir.exists()) { + userScriptBinDirFiles = userScriptsBinDir.listFiles(classFileFilter); + for (File file : userScriptBinDirFiles) { + file.delete(); + } } userScriptBinDirFiles = userScriptsDir.listFiles(classFileFilter); isEmpty = userScriptBinDirFiles == null || userScriptBinDirFiles.length == 0; @@ -213,7 +216,7 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes FileUtilities.deleteDir(tempScriptDir); tempScriptDir.mkdir(); - addScriptPath(tempScriptDir); + provider.enableScriptDirectory(new ResourceFile(tempScriptDir)); // create a script file in that directory String rawScriptName = testName.getMethodName(); diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java index 87465b1d7e..5b12ed22e6 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java @@ -29,11 +29,11 @@ import org.junit.Test; import docking.KeyEntryTextField; import docking.action.DockingActionIf; +import docking.widgets.bundlemanager.BundlePath; +import docking.widgets.bundlemanager.BundlePathManager; import docking.widgets.filter.FilterTextField; import docking.widgets.list.ListPanel; -import docking.widgets.pathmanager.PathManager; import generic.jar.ResourceFile; -import generic.util.Path; import ghidra.app.script.GhidraScriptUtil; import ghidra.app.script.JavaScriptProvider; import ghidra.util.StringUtilities; @@ -284,15 +284,15 @@ public class GhidraScriptMgrPlugin3Test extends AbstractGhidraScriptMgrPluginTes performAction(pathAction, false); waitForSwing(); - PickPathsDialog pathsDialog = waitForDialogComponent(PickPathsDialog.class); + BundlePathSelectionDialog pathsDialog = waitForDialogComponent(BundlePathSelectionDialog.class); final File dir = new File(getTestDirectoryPath() + "/test_scripts"); dir.mkdirs(); - final PathManager pathManager = pathsDialog.getPathManager(); + final BundlePathManager pathManager = pathsDialog.getBundleManager(); SwingUtilities.invokeLater(() -> { - List paths = pathManager.getPaths(); - paths.add(0, new Path(dir)); + List paths = pathManager.getPaths(); + paths.add(0, new BundlePath(dir)); pathManager.setPaths(paths); }); waitForSwing(); diff --git a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/GhidraScriptMgrPluginScreenShots.java b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/GhidraScriptMgrPluginScreenShots.java index dec2596397..558404d21e 100644 --- a/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/GhidraScriptMgrPluginScreenShots.java +++ b/Ghidra/Test/IntegrationTest/src/screen/java/help/screenshot/GhidraScriptMgrPluginScreenShots.java @@ -24,11 +24,11 @@ import org.junit.Test; import docking.ComponentProvider; import docking.DockingWindowManager; -import docking.widgets.pathmanager.PathManager; +import docking.widgets.bundlemanager.BundlePath; +import docking.widgets.bundlemanager.BundlePathManager; import docking.widgets.tree.GTree; import docking.widgets.tree.GTreeNode; import generic.jar.ResourceFile; -import generic.util.Path; import ghidra.app.plugin.core.console.ConsoleComponentProvider; import ghidra.app.plugin.core.script.*; import ghidra.app.script.GhidraScriptUtil; @@ -112,18 +112,18 @@ public class GhidraScriptMgrPluginScreenShots extends GhidraScreenShotGenerator @Test public void testScript_Dirs() throws Exception { - List paths = new ArrayList<>(); - paths.add(new Path("$USER_HOME/ghidra_scripts")); - paths.add(new Path("$GHIDRA_HOME/Features/Base/ghidra_scripts")); - paths.add(new Path("/User/defined/invalid/directory")); + List paths = new ArrayList<>(); + paths.add(new BundlePath("$USER_HOME/ghidra_scripts")); + paths.add(new BundlePath("$GHIDRA_HOME/Features/Base/ghidra_scripts")); + paths.add(new BundlePath("/User/defined/invalid/directory")); ComponentProvider provider = showProvider(GhidraScriptComponentProvider.class); - PathManager pathManager = (PathManager) getInstanceField("pathManager", provider); - pathManager.setPaths(paths); - final PickPathsDialog pathsDialog = new PickPathsDialog(null, pathManager); + BundlePathManager bundleManager = (BundlePathManager) getInstanceField("bundlePathManager", provider); + bundleManager.setPaths(paths); + final BundlePathSelectionDialog pathsDialog = new BundlePathSelectionDialog(null, bundleManager); runSwing(() -> DockingWindowManager.showDialog(null, pathsDialog), false); - PickPathsDialog dialog = waitForDialogComponent(PickPathsDialog.class); + BundlePathSelectionDialog dialog = waitForDialogComponent(BundlePathSelectionDialog.class); captureDialog(dialog); }