Package ghidra.util
Class SystemUtilities
java.lang.Object
ghidra.util.SystemUtilities
General purpose class to provide convenience methods for doing "System" type
stuff, e.g., find resources, date/time, etc. All methods in this class are
static.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
System property that signals to override the font settings for Java and Ghidra components.static final String
The system property that can be checked during runtime to determine if we are running with a GUI or headless.static final String
The system property that can be checked during runtime to determine if we are running in single-jar mode.static final String
The system property that can be checked during testing to determine if the system is running in batch, automated test mode.static final String
The system property that can be checked during testing to determine if the system is running in test mode. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Font
Deprecated, for removal: This API element is subject to removal in a future version.Use the theming system for fontsstatic void
assertThisIsTheSwingThread
(String errorMessage) A development/testing time method to make sure the current thread is the swing thread.static void
assertTrue
(boolean booleanValue, String string) static <T extends Comparable<T>>
intcompareTo
(T c1, T c2) static boolean
getBooleanProperty
(String name, boolean defaultValue) Gets the boolean value of the system property by the given name.static String
getCleanUserName
(String name) Clean the specified user name to eliminate any spaces or leading domain name which may be present (e.g., "MyDomain\John Doe" becomes "JohnDoe").static int
Returns the default size (in number of threads) for a CPU processing bound thread pool.static Integer
Returns a non-null value if the system property is set that triggers the font override setting, which makes all Java and Ghidra component fonts the same size.static File
getSourceLocationForClass
(Class<?> classObject) Returns a file that contains the given class.static String
Get the user that is running the application.static boolean
isArrayEqual
(Object[] array1, Object[] array2) static boolean
Returns whether or not the two indicated objects are equal.static boolean
Returns true if this is the event dispatch thread.static boolean
Returns true if we are running in development mode.static boolean
Returns true if the system is running without a GUI.static boolean
Returns true if the application is a release and not in development or testingstatic boolean
Returns true if the system is running during a batch, automated test.static boolean
Returns true if the system is running during a test.static boolean
printString
(String string, PrintStream printStream) A debugging utility that allows you to create a conditional breakpoint in Eclipse that will print items for you while it is performing its tests.static void
static void
Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.static void
Calls the given runnable on the Swing thread.static <T> T
runSwingNow
(Supplier<T> s) Calls the given suppler on the Swing thread, blocking with aSwingUtilities.invokeAndWait(Runnable)
.
-
Field Details
-
FONT_SIZE_OVERRIDE_PROPERTY_NAME
System property that signals to override the font settings for Java and Ghidra components.- See Also:
-
TESTING_PROPERTY
The system property that can be checked during testing to determine if the system is running in test mode.- See Also:
-
TESTING_BATCH_PROPERTY
The system property that can be checked during testing to determine if the system is running in batch, automated test mode.- See Also:
-
HEADLESS_PROPERTY
The system property that can be checked during runtime to determine if we are running with a GUI or headless.- See Also:
-
SINGLE_JAR_MODE_PROPERTY
The system property that can be checked during runtime to determine if we are running in single-jar mode.- See Also:
-
-
Constructor Details
-
SystemUtilities
public SystemUtilities()
-
-
Method Details
-
getCleanUserName
Clean the specified user name to eliminate any spaces or leading domain name which may be present (e.g., "MyDomain\John Doe" becomes "JohnDoe").- Parameters:
name
- user name string to be cleaned-up- Returns:
- the clean user name
-
getUserName
Get the user that is running the application. This name may be modified to eliminate any spaces or leading domain name which may be present in Java'suser.name
system property (seegetCleanUserName(String)
).- Returns:
- the user name
-
getBooleanProperty
Gets the boolean value of the system property by the given name. If the property is not set, the defaultValue is returned. If the value is set, then it will be passed intoBoolean.parseBoolean(String)
.- Parameters:
name
- the property name to checkdefaultValue
- the default value- Returns:
- true if the property is set and has a value of 'true', ignoring case
-
getFontSizeOverrideValue
Returns a non-null value if the system property is set that triggers the font override setting, which makes all Java and Ghidra component fonts the same size.- Returns:
- a non-null value if the system property is set that triggers the font override setting, which makes all Java and Ghidra component fonts the same size.
- See Also:
-
adjustForFontSizeOverride
Deprecated, for removal: This API element is subject to removal in a future version.Use the theming system for fontsNo longer supported. Use the theming system for fonts- Parameters:
font
- the font- Returns:
- the same font passed in
-
isInTestingMode
public static boolean isInTestingMode()Returns true if the system is running during a test.- Returns:
- true if the system is running during a test.
-
isInTestingBatchMode
public static boolean isInTestingBatchMode()Returns true if the system is running during a batch, automated test.- Returns:
- true if the system is running during a batch, automated test.
-
isInHeadlessMode
public static boolean isInHeadlessMode()Returns true if the system is running without a GUI.- Returns:
- true if the system is running without a GUI.
-
runSwingNow
Calls the given suppler on the Swing thread, blocking with aSwingUtilities.invokeAndWait(Runnable)
. Use this method when you need to get a value while being on the Swing thread.String value = runSwingNow(() -> label.getText());
- Parameters:
s
- the supplier that will be called on the Swing thread- Returns:
- the result of the supplier
- See Also:
-
runSwingNow
Calls the given runnable on the Swing thread.- Parameters:
r
- the runnable- See Also:
-
runSwingLater
Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.- Parameters:
r
- the runnable
-
runIfSwingOrPostSwingLater
-
isInDevelopmentMode
public static boolean isInDevelopmentMode()Returns true if we are running in development mode. The assumption is that if this class is in a jar file, then we are in production mode.- Returns:
- true if we are running in development mode
-
isInReleaseMode
public static boolean isInReleaseMode()Returns true if the application is a release and not in development or testing- Returns:
- true if the application is a release and not in development or testing
-
isEqual
Returns whether or not the two indicated objects are equal. It allows either or both of the specified objects to be null.- Parameters:
o1
- the first object or nullo2
- the second object or null- Returns:
- true if the objects are equal.
-
compareTo
-
isArrayEqual
-
assertTrue
-
assertThisIsTheSwingThread
A development/testing time method to make sure the current thread is the swing thread.- Parameters:
errorMessage
- The message to display when the assert fails
-
getSourceLocationForClass
Returns a file that contains the given class. If the class is in a jar file, then the jar file will be returned. If the file is in a .class file, then the directory containing the package root will be returned (i.e. the "bin" directory).- Parameters:
classObject
- the class for which to get the location- Returns:
- the containing location
-
isEventDispatchThread
public static boolean isEventDispatchThread()Returns true if this is the event dispatch thread. Note that this method returns true in headless mode because any thread in headless mode can dispatch its own events. In swing environments, the swing thread is usually used to dispatch events.- Returns:
- true if this is the event dispatch thread -OR- is in headless mode.
-
printString
A debugging utility that allows you to create a conditional breakpoint in Eclipse that will print items for you while it is performing its tests. This method always returns false. This means to use it you will have to OR (||) your conditional breakpoint expressions if you want them to pass. Otherwise, you can make this method be the only breakpoint expression and it will never stop on the breakpoint, but will still print your debug.This method is useful to print values of code that you cannot edit while debugging.
Example, inside of your conditional breakpoint for a method on a Sun Java file you can put something like:
printString("Value of first arg: " + arg0, System.err)
Note: Don't remove this method simply because no code is referencing it, as it is used by conditional breakpoints.
- Parameters:
string
- The string to printprintStream
- The stream to print to (System.our or err)- Returns:
- The string passed in so that you can use this method in an evaluation
-
getDefaultThreadPoolSize
public static int getDefaultThreadPoolSize()Returns the default size (in number of threads) for a CPU processing bound thread pool.- Returns:
- the default pool size.
-