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, 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).
    • getModuleLibDirectories

      public static Collection<ResourceFile> getModuleLibDirectories(Map<String,GModule> modules)
      Gets the "lib" directories from the given modules.
      Parameters:
      modules - The modules to get the lib directories of.
      Returns:
      A collection of lib directories from the given modules.
    • getModuleBinDirectories

      public static Collection<ResourceFile> getModuleBinDirectories(Map<String,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