Merge remote-tracking branch 'origin/GP-0-dragonmacher-screenshot-fix-1-24-25'

This commit is contained in:
Ryan Kurtz
2025-01-24 17:45:42 -05:00
4 changed files with 21 additions and 20 deletions
@@ -4,9 +4,9 @@
* 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.
@@ -21,7 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import docking.test.AbstractDockingTest;
import ghidra.GhidraTestApplicationLayout;
@@ -93,7 +93,7 @@ public abstract class AbstractGhidraHeadlessIntegrationTest extends AbstractDock
System.setProperty(GhidraScriptConstants.USER_SCRIPTS_DIR_PROPERTY, getTestDirectoryPath());
}
@BeforeClass
@AfterClass
public static void cleanDbTestDir() {
// keep files around in batch mode to allow tests to run faster; assume batch mode performs
// its own cleanup; only run once per class to allow subsequent tests to be faster
@@ -87,6 +87,8 @@ import resources.ResourceManager;
public abstract class AbstractScreenShotGenerator extends AbstractGhidraHeadedIntegrationTest {
private static final String SCREENSHOT_USER_NAME = "User-1";
static {
System.setProperty("user.name", "User-1");
}
@@ -122,6 +124,13 @@ public abstract class AbstractScreenShotGenerator extends AbstractGhidraHeadedIn
@Before
public void setUp() throws Exception {
// sanity check to ensure out user name override above is still working
String path = getTestDirectoryPath();
assertTrue("Seeing this failure means that some call has initialized the temporary test " +
"directory before out static call to change user.name above",
path.contains(SCREENSHOT_USER_NAME));
env = newTestEnv();
prepareTool();
@@ -72,7 +72,8 @@ public abstract class AbstractGTest {
// 10x longer than normal
// private static final int PRIVATE_MAX_WAIT_TIMEOUT = DEFAULT_WAIT_TIMEOUT * 10;
private static String testDirectoryPath = createTestDirectoryPath();
// let this get created lazily so that subclasses can change system state first
private static String testDirectoryPath; // = createTestDirectoryPath();
@Rule
public TestName testName = new TestName();
@@ -95,14 +96,11 @@ public abstract class AbstractGTest {
public TestRule ignoreUnfinishedRule = new IgnoreUnfinishedRule();
/**
* Get the directory path within which all temporary test data files should be created.
*
* @return test directory path ending with a File.separator character
* Get the directory path within which all temporary test data files should be created. This
* method will only initialize the test directory path one time.
*/
private static String createTestDirectoryPath() {
private static void initializeTestDirectoryPath() {
if (testDirectoryPath == null) {
//
// Build unique test data directory. Note that we can't make any calls which
// depend upon Application initialization, so we have to create directories using
@@ -123,8 +121,6 @@ public abstract class AbstractGTest {
}
System.out.println("Created test directory: " + testDir);
}
return testDirectoryPath;
}
private static String buildBatchDirectoryPath() {
@@ -150,6 +146,7 @@ public abstract class AbstractGTest {
}
public static String getTestDirectoryPath() {
initializeTestDirectoryPath();
return testDirectoryPath;
}
@@ -4,9 +4,9 @@
* 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.
@@ -21,7 +21,6 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import ghidra.util.Msg;
import ghidra.util.SystemUtilities;
import ghidra.util.exception.AssertException;
import utilities.util.FileUtilities;
@@ -107,10 +106,6 @@ public class TestApplicationUtils {
}
// Assumption - in an installation the current user dir is /.../<Ghidra Install Dir>/Ghidra
String currentDir = System.getProperty("user.dir");
Msg.debug(null, "user.dir: " + currentDir);
// Assume that core library files are bundled in a jar file. Find the installation
// directory by using the distributed jar file.
File jarFile = SystemUtilities.getSourceLocationForClass(SystemUtilities.class);