Class Application


  • public class Application
    extends java.lang.Object
    The Application class provides a variety of static convenience methods for accessing Application elements that can be used once the initializeApplication(utility.application.ApplicationLayout, ghidra.framework.ApplicationConfiguration) call has been made.

    In order to initialize an application, an ApplicationLayout and an ApplicationConfiguration must be provided. The layout and configuration come in a variety of flavors, and are what makes the Application class usable across a range of tools.

    Example use case:

       ApplicationLayout layout = new GhidraApplicationLayout();
       ApplicationConfiguration configuration = new GhidraApplicationConfiguration();
       Application.initalizeApplication(layout, configuration);
     
    • Method Detail

      • initializeApplication

        public static void initializeApplication​(ApplicationLayout layout,
                                                 ApplicationConfiguration configuration)
        Initializes the application. The static methods of this class cannot be used until the application is initialized.
        Parameters:
        layout - The application layout to be used by the application.
        configuration - The application configuration to be used by the application.
      • isInitialized

        public static boolean isInitialized()
        Checks to see if the application has been initialized.
        Returns:
        true if the application has been initialized; otherwise, false.
      • initializeLogging

        public static void initializeLogging​(java.io.File logFile,
                                             java.io.File scriptLogFile)
        If the Application was previously initialized with logging disabled, this method may be used to perform delayed logging initialization.
        Parameters:
        logFile - application log file, if null the default application.log will be stored within the user's application settings directory
        scriptLogFile - scripting log file, if null the default script.log will be stored within the user's application settings directory
        Throws:
        AssertException - if Application has not yet been initialized, or logging was previously configured for the application.
      • getModuleContainingClass

        public static ResourceFile getModuleContainingClass​(java.lang.String className)
      • getMyModuleRootDirectory

        public static ResourceFile getMyModuleRootDirectory()
        Returns the module root directory that contains the class that called this method.
        Returns:
        the module root directory that contains the class that called this method.
      • getName

        public static java.lang.String getName()
        Returns the name of the application.
        Returns:
        the name of the application.
      • getApplicationProperty

        public static java.lang.String getApplicationProperty​(java.lang.String propertyName)
        Returns the value of the give application property name.
        Parameters:
        propertyName - the name of the application property to retrieve.
        Returns:
        the value of the give application property name.
      • getApplicationRootDirectories

        public static java.util.Collection<ResourceFile> getApplicationRootDirectories()
        Returns a list of the application root directories. An application root directory is a directory containing one or more modules. Applications support multiple application root directories so that it can contain modules that don't have a common file system root. This is useful if the application contains modules from more than one source code repository. Application roots are returned in the order they appear in the classpath.
        Returns:
        a list of root directories containing modules for this application.
      • getApplicationRootDirectory

        public static ResourceFile getApplicationRootDirectory()
        Returns the application root directory. An application root directory is a directory containing one or more modules. In development mode there may be multiple application root directories, which can be retrieved via getApplicationRootDirectories().

        In an installation of the application, there will only be one application root directory.

        Note: Be sure you understand that there may be multiple application root directories in development mode. In general you should not be using this method for searching for files yourself, but instead using the various find* methods of this class.

        Returns:
        Returns the application root directory.
        See Also:
        getApplicationRootDirectories()
      • getUserSettingsDirectory

        public static java.io.File getUserSettingsDirectory()
        Returns the File containing the user configuration settings for this application.
        Returns:
        the File containing the user configuration settings for this application.
      • getUserTempDirectory

        public static java.io.File getUserTempDirectory()
        Returns the temporary directory specific to the user and the application. Directory has name of <username>-<appname> This directory may be removed at system reboot or during periodic system cleanup of unused temp files. This directory is specific to the application name but not the version. Resources stored within this directory should utilize some form of access locking or unique naming. Transient resources should be deleted when no longer in use.
        Returns:
        temp directory
      • getUserCacheDirectory

        public static java.io.File getUserCacheDirectory()
        Returns the cache directory specific to the user and the application. The intention is for directory contents to be preserved, however the specific location is platform specific and contents may be removed when not in use and may in fact be the same directory the user temp directory. This directory is specific to the application name but not the version. Resources stored within this directory should utilize some form of access locking and/or unique naming.
        Returns:
        cache directory
      • getModuleRootDirectories

        public static java.util.Collection<ResourceFile> getModuleRootDirectories()
        Returns a collection of all the module root directories. A module root directory is the top-level directory of a module.
        Returns:
        a collection of all the module root directories.
      • getInstallationDirectory

        public static ResourceFile getInstallationDirectory()
        Returns the installation directory. In an installation, there is only one application root and its parent is the installation directory. If not an installation, then this call doesn't really make sense, but it will return the parent of the first installation root.
        Returns:
      • getModuleRootDir

        public static ResourceFile getModuleRootDir​(java.lang.String moduleName)
        Return the module root directory for the module with the given name.
        Parameters:
        moduleName - the name of the module.
        Returns:
        the module root directory for the module with the given name or null if not found.
      • isTestBuild

        public static boolean isTestBuild()
        Returns true if this build was not built through the official build process, but instead was created using the "buildLocal" call.
        Returns:
        true if this build was not built using the official build process.
      • inSingleJarMode

        public static boolean inSingleJarMode()
        Checks whether or not the application is in "single jar" mode.
        Returns:
        true if the application is in "single jar" mode; otherwise, false.
      • getApplicationVersion

        public static java.lang.String getApplicationVersion()
        Returns the version of this build.
        Returns:
        the version of this build.
      • getBuildDate

        public static java.lang.String getBuildDate()
        Returns the date this build was created.
        Returns:
        the date this build was created.
      • getApplicationReleaseName

        public static java.lang.String getApplicationReleaseName()
        Returns the release name for this build.
        Returns:
        the application release name.
      • getApplicationSourceRevisions

        public static java.util.Map<java.lang.String,​java.lang.String> getApplicationSourceRevisions()
        Return the source repository revisions used in the build process or null if not applicable.
        Returns:
        source revision map or null if not applicable
      • getLibraryDirectories

        public static java.util.Collection<ResourceFile> getLibraryDirectories()
        Returns a collection of module library directories. Library directories are optional for a module.
        Returns:
        a collection of module library directories.
      • findFilesByExtensionInApplication

        public static java.util.List<ResourceFile> findFilesByExtensionInApplication​(java.lang.String extension)
        Returns all files within any module's data directory that end with the given extension.
        Parameters:
        extension - the extension of files to be found.
        Returns:
        all files within any module's data directory that end with the given extension.
      • findDataFileInAnyModule

        public static ResourceFile findDataFileInAnyModule​(java.lang.String relativePath)
        Finds the first file that exists with the relative path in any module.
        Parameters:
        relativePath - the path from the module root
        Returns:
        the first file that exists with the relative path in any module.
      • findFilesByExtensionInMyModule

        public static java.util.List<ResourceFile> findFilesByExtensionInMyModule​(java.lang.String extension)
        Returns a list of all files with the given extension that are located in the module of the calling class.
        Parameters:
        extension - the filename extension for which to find file.s
        Returns:
        a list of all files with the given extension that are located in the module of the calling class.
      • findFilesByExtension

        public static java.util.List<ResourceFile> findFilesByExtension​(java.lang.String moduleName,
                                                                        java.lang.String extension)
                                                                 throws java.lang.IllegalArgumentException
        Returns a list of all files with the given extension that are located in the named module.
        Parameters:
        moduleName - the name of the module for which to look for files with the given extension.
        extension - the filename extension for which to find file.s
        Returns:
        a list of all files with the given extension that are located in the named module.
        Throws:
        java.lang.IllegalArgumentException
      • findModuleSubDirectories

        public static java.util.List<ResourceFile> findModuleSubDirectories​(java.lang.String relativePath)
        Returns a list of all directories in any module that have the given module relative path. For example, a relative path of "foo/bar" will return all directories that are of the form /data/foo/bar
        Parameters:
        relativePath - the module relative path to search for.
        Returns:
        a list of all directories in any module that have the given module relative path.
      • getModuleDataSubDirectory

        public static ResourceFile getModuleDataSubDirectory​(java.lang.String relativePath)
                                                      throws java.io.FileNotFoundException,
                                                             java.io.IOException
        Returns the directory relative to the calling class's module's data directory.
        Parameters:
        relativePath - the path relative the module's data directory
        Throws:
        java.io.FileNotFoundException - if the directory does not exist.
        java.io.IOException - if an error occurred trying to access the directory.
      • getModuleDataSubDirectory

        public static ResourceFile getModuleDataSubDirectory​(java.lang.String moduleName,
                                                             java.lang.String relativePath)
                                                      throws java.io.FileNotFoundException,
                                                             java.io.IOException
        Return the directory relative the the name module's data directory. (i.e. "/data" will be prepended to the given path)
        Parameters:
        moduleName - the name of the module.
        relativePath - the path relative to the module's data directory.
        Throws:
        java.io.FileNotFoundException - if the directory does not exist
        java.io.IOException - if an error occurred trying to access the directory.
      • getModuleSubDirectory

        public static ResourceFile getModuleSubDirectory​(java.lang.String moduleName,
                                                         java.lang.String relativePath)
                                                  throws java.io.FileNotFoundException,
                                                         java.io.IOException
        Return the directory relative the the name module's directory.
        Parameters:
        moduleName - the name of the module.
        relativePath - the path relative to the module's root directory.
        Throws:
        java.io.FileNotFoundException - if the directory does not exist
        java.io.IOException - if an error occurred trying to access the directory.
      • getModuleDataFile

        public static ResourceFile getModuleDataFile​(java.lang.String relativeDataPath)
                                              throws java.io.FileNotFoundException
        Returns the file relative to the calling class's module's data directory
        Parameters:
        relativeDataPath - the path relative the to module's data directory
        Throws:
        java.io.FileNotFoundException - if the file or module does not exist.
      • getModuleDataFile

        public static ResourceFile getModuleDataFile​(java.lang.String moduleName,
                                                     java.lang.String relativeDataPath)
                                              throws java.io.FileNotFoundException
        Returns the file relative to the named module's data directory. (i.e. "data/" will be prepended to the give path)
        Parameters:
        moduleName - the name of the module.
        relativeDataPath - the path relative to the module's data directory.
        Throws:
        java.io.FileNotFoundException - if the file does not exist.
      • getModuleFile

        public static ResourceFile getModuleFile​(java.lang.String moduleName,
                                                 java.lang.String relativePath)
                                          throws java.io.FileNotFoundException
        Returns the file relative to the named module's directory.
        Parameters:
        moduleName - the name of the module.
        relativeDataPath - the path relative to the module's data directory.
        Throws:
        java.io.FileNotFoundException - if the file does not exist.
      • getOSFile

        public static java.io.File getOSFile​(java.lang.String moduleName,
                                             java.lang.String exactFilename)
                                      throws java.io.FileNotFoundException
        Returns the OS specific file within the given module with the given name.
        Parameters:
        moduleName - the name of the module
        exactFilename - the name of the OS file within the module.
        Throws:
        java.io.FileNotFoundException - if the file does not exist.
      • getOSFile

        public static java.io.File getOSFile​(java.lang.String exactFilename)
                                      throws java.io.FileNotFoundException
        Returns the OS specific file in the calling class's module.
        Parameters:
        exactFilename - the name of the OS specific file.
        Throws:
        java.io.FileNotFoundException - if the file does not exist.