Class ModuleUtilities

java.lang.Object
utility.module.ModuleUtilities

public class ModuleUtilities extends Object
Utility methods for module related things.
  • Field Details

  • Constructor Details

    • ModuleUtilities

      public ModuleUtilities()
  • Method Details

    • isModuleDirectory

      public static boolean isModuleDirectory(ResourceFile dir)
      Checks if the given directory is a module.
      Parameters:
      dir - the directory to check.
      Returns:
      true if the given directory is a module
    • isModuleDirectory

      public static boolean isModuleDirectory(Path path)
      Returns true if the given path is a module root directory.
      Parameters:
      path - the path to check
      Returns:
      true if the given path is a module root directory.
    • findModuleRootDirectories

      public static Collection<ResourceFile> findModuleRootDirectories(ResourceFile rootDir, Collection<ResourceFile> moduleRootDirs)
      Searches the given root directory for module root directories. Adds any discovered module root directories to the given collection.
      Parameters:
      rootDir - The directory to start looking for module root directories in.
      moduleRootDirs - A collection to add discovered module root directories to.
      Returns:
      The given collection with any discovered modules added.
    • findModuleRootDirectories

      public static Collection<ResourceFile> findModuleRootDirectories(Collection<ResourceFile> rootDirs)
      Searches the given root directories for module root directories. Adds any discovered module root directories to the returned collection.

      Note: if you need to control the type of collection used to store the module roots, then call findModuleRootDirectories(Collection, Collection).

      Parameters:
      rootDirs - The directories to look for module root directories in.
      Returns:
      a new collection with any discovered modules added.
    • findModuleRootDirectories

      public static Collection<ResourceFile> findModuleRootDirectories(Collection<ResourceFile> rootDirs, Collection<ResourceFile> moduleRootDirs)
      Searches the given root directories for module root directories. Adds any discovered module root directories to the given collection.
      Parameters:
      rootDirs - The directories to look for module root directories in.
      moduleRootDirs - A collection to add discovered module root directories to.
      Returns:
      The given collection with any discovered modules added.
    • findJarModuleRootDirectories

      public static Collection<ResourceFile> findJarModuleRootDirectories(ResourceFile rootDir, Collection<ResourceFile> moduleRootDirs) throws IOException
      Searches the given jar root directory for module root directories. Uses a "module list" file to locate the module root directories. Adds any discovered module root directories to the given collection.
      Parameters:
      rootDir - The jar directory to start looking for module root directories in.
      moduleRootDirs - A collection to add discovered module root directories to.
      Returns:
      The given collection with any discovered modules added.
      Throws:
      IOException - if there was a problem reading the module list file.
    • findModules

      public static Map<String,GModule> findModules(Collection<ResourceFile> appRootDirs, Collection<ResourceFile> moduleRootDirs)
      Searches for modules in a given collection of module root directories.
      Parameters:
      appRootDirs - The collection of application root directories associated with the the given list of module root directories.
      moduleRootDirs - A collection of module root directories to search for modules in.
      Returns:
      The discovered modules as a map (mapping module name to module for convenience).
    • findModules

      public static Map<String,GModule> findModules(Collection<ResourceFile> appRootDirs, Collection<ResourceFile> moduleRootDirs, Predicate<GModule> moduleFilter)
      Searches for modules in a given collection of module root directories.
      Parameters:
      appRootDirs - The collection of application root directories associated with the the given list of module root directories.
      moduleRootDirs - A collection of module root directories to search for modules in.
      moduleFilter - a predicate used to filter modules; a given module will not be included when the predicate returns false.
      Returns:
      The discovered modules as a map (mapping module name to module for convenience).
    • getModuleLibDirectories

      public static Collection<ResourceFile> getModuleLibDirectories(Collection<GModule> modules)
      Gets the library directories from the given modules.

      In release mode, we expect these directories to be in each module's lib subdirectory.

      If not in release mode (i.e., development mode, testing mode, etc), we expect these directories to be in each module's build/libs subdirectory.

      NOTE: If Eclipse is being used this method may still return jars built by Gradle. It is up to the caller of this method to determine if they should be used instead of the classes compiled by Eclipse.

      Parameters:
      modules - The modules to get the library directories of.
      Returns:
      A collection of library directories from the given modules.
    • getModuleBinDirectories

      public static Collection<ResourceFile> getModuleBinDirectories(Collection<GModule> modules)
      Gets the directory locations of the .class files and resources from the given modules.
      Parameters:
      modules - The modules to get the compiled .class and resources directories of.
      Returns:
      A collection of directories containing classes and resources from the given modules.
    • isInModule

      public static boolean isInModule(String pathName)
      Returns true if the given path is parented by a module root directory.

      For example, given a module path of /some/dir/features/cool_module/, then this method will return true for these paths:

      /some/dir/features/cool_module
      /some/dir/features/cool_module/some/child/dir

      and false for these paths:

      /some/random/path
      /some/dir/features/

      Parameters:
      pathName - the path name to check
      Returns:
      true if the given path is parented by a module root directory.
      See Also:
    • getModule

      public static Path getModule(String pathName)
      Returns the path of the module containing the given path string, if it is parented by a module root directory.

      For example, given a module path of /some/dir/features/cool_module/, then this method will return that module path, given these paths:

      /some/dir/features/cool_module
      /some/dir/features/cool_module/some/child/dir

      and null for these paths:

      /some/random/path
      /some/dir/features/

      Parameters:
      pathName - the path name to check
      Returns:
      the module root directory; null if the path is not in a module
      See Also:
    • findRepoRoot

      public static File findRepoRoot(File f)
      Returns a file that is the root folder of the repository containing the given file. 'Root' here means a folder that contains a repository folder. As an example, given a repo structure of:

      /userdir/repoRoot/repoDir/.git

      then this method, given will produce the following results (input -> output):

      /userdir/repoRoot/repoDir/.git -> /userdir/repoRoot
      /userdir/repoRoot/repoDir -> /userdir/repoRoot
      /userdir/repoRoot -> /userdir/repoRoot

      Parameters:
      f - the child file of the desired repo
      Returns:
      a file that is the root folder of the repository containing the given file; null if the given file is not under a repo directory or itself a repo root
    • findRepo

      public static File findRepo(File f)
      Returns a file that is the repository folder containing the given file. As an example, given a repo structure of:

      /userdir/repoRoot/repoDir/.git

      then this method, given will produce the following results (input -> output):

      /userdir/repoRoot/repoDir/.git -> /userdir/repoRoot/repoDir
      /userdir/repoRoot/repoDir -> /userdir/repoRoot/repoDir

      Parameters:
      f - the child file of the desired repo
      Returns:
      a file that is the repo folder of the repository containing the given file; null if the given file is not under a repo directory
    • isExternalModule

      public static boolean isExternalModule(GModule module, ApplicationLayout layout)
      Checks to see if the given module is external to the Ghidra installation directory
      Parameters:
      module - the module to check
      layout - Ghidra's layout
      Returns:
      true if the given module is external to the Ghidra installation directory
    • isUninstalled

      public static boolean isUninstalled(String path)
      Returns true if the given module has been uninstalled.
      Parameters:
      path - the module path to check
      Returns:
      true if uninstalled
    • isUninstalled

      public static boolean isUninstalled(File dir)
      Returns true if the given module has been uninstalled.
      Parameters:
      dir - the module dir to check
      Returns:
      true if uninstalled
    • isUninstalled

      public static boolean isUninstalled(ResourceFile dir)
      Returns true if the given module has been uninstalled.
      Parameters:
      dir - the module dir to check
      Returns:
      true if uninstalled