Class ModuleUtilities


  • public class ModuleUtilities
    extends java.lang.Object
    Utility methods for module related things.
    • Constructor Summary

      Constructors 
      Constructor Description
      ModuleUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Collection<ResourceFile> findJarModuleRootDirectories​(ResourceFile rootDir, java.util.Collection<ResourceFile> moduleRootDirs)
      Searches the given jar root directory for module root directories.
      static java.util.Collection<ResourceFile> findModuleRootDirectories​(ResourceFile rootDir, java.util.Collection<ResourceFile> moduleRootDirs)
      Searches the given root directory for module root directories.
      static java.util.Collection<ResourceFile> findModuleRootDirectories​(java.util.Collection<ResourceFile> rootDirs, java.util.Collection<ResourceFile> moduleRootDirs)
      Searches the given root directories for module root directories.
      static java.util.Map<java.lang.String,​GModule> findModules​(java.util.Collection<ResourceFile> appRootDirs, java.util.Collection<ResourceFile> moduleRootDirs)
      Searches for modules in a given collection of module root directories.
      static java.io.File findRepo​(java.io.File f)
      Returns a file that is the repository folder containing the given file.
      static java.io.File findRepoRoot​(java.io.File f)
      Returns a file that is the root folder of the repository containing the given file.
      static java.nio.file.Path getModule​(java.lang.String pathName)
      Returns the path of the module containing the given path string, if it is parented by a module root directory.
      static java.util.Collection<ResourceFile> getModuleBinDirectories​(java.util.Map<java.lang.String,​GModule> modules)
      Gets the directory locations of the .class files and resources from the given modules.
      static java.util.Collection<ResourceFile> getModuleLibDirectories​(java.util.Map<java.lang.String,​GModule> modules)
      Gets the "lib" directories from the given modules.
      static boolean isInModule​(java.lang.String pathName)
      Returns true if the given path is parented by a module root directory.
      static boolean isModuleDirectory​(ResourceFile dir)
      Checks if the given directory is a module.
      static boolean isModuleDirectory​(java.nio.file.Path path)
      Returns true if the given path is a module root directory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MANIFEST_FILE_NAME

        public static final java.lang.String MANIFEST_FILE_NAME
        See Also:
        Constant Field Values
      • MANIFEST_FILE_NAME_UNINSTALLED

        public static final java.lang.String MANIFEST_FILE_NAME_UNINSTALLED
        See Also:
        Constant Field Values
    • Constructor Detail

      • ModuleUtilities

        public ModuleUtilities()
    • Method Detail

      • 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​(java.nio.file.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 java.util.Collection<ResourceFile> findModuleRootDirectories​(ResourceFile rootDir,
                                                                                   java.util.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 java.util.Collection<ResourceFile> findModuleRootDirectories​(java.util.Collection<ResourceFile> rootDirs,
                                                                                   java.util.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 java.util.Collection<ResourceFile> findJarModuleRootDirectories​(ResourceFile rootDir,
                                                                                      java.util.Collection<ResourceFile> moduleRootDirs)
                                                                               throws java.io.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:
        java.io.IOException - if there was a problem reading the module list file.
      • findModules

        public static java.util.Map<java.lang.String,​GModule> findModules​(java.util.Collection<ResourceFile> appRootDirs,
                                                                                java.util.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 java.util.Collection<ResourceFile> getModuleLibDirectories​(java.util.Map<java.lang.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 java.util.Collection<ResourceFile> getModuleBinDirectories​(java.util.Map<java.lang.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​(java.lang.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:
        isModuleDirectory(Path)
      • getModule

        public static java.nio.file.Path getModule​(java.lang.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:
        isModuleDirectory(Path)
      • findRepoRoot

        public static java.io.File findRepoRoot​(java.io.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 java.io.File findRepo​(java.io.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