Class ASClassLoaderUtil


  • public class ASClassLoaderUtil
    extends Object
    Utils to get information about classes or libraries to load. This class does not actually load the classes itself.
    • Field Detail

      • deplLogger

        public static final Logger deplLogger
    • Constructor Detail

      • ASClassLoaderUtil

        public ASClassLoaderUtil()
    • Method Detail

      • getModuleClassPath

        public static String getModuleClassPath​(org.glassfish.hk2.api.ServiceLocator habitat,
                                                String moduleId,
                                                String deploymentLibs)
        Gets the classpath associated with a module, suffixing libraries defined [if any] for the application
        Parameters:
        habitat - the habitat the application resides in.
        moduleId - Module id of the module
        deploymentLibs - libraries option passed through deployment
        Returns:
        A File.pathSeparator separated list of classpaths for the passed in module, including the module specified "libraries" defined for the module.
      • getModuleClassPath

        public static String getModuleClassPath​(org.glassfish.hk2.api.ServiceLocator habitat,
                                                DeploymentContext context)
        Parameters:
        habitat -
        context -
        Returns:
      • getLibrariesAsURLs

        public static URL[] getLibrariesAsURLs​(Set<String> librariesStr,
                                               ServerEnvironment env)
        converts libraries specified via EXTENSION_LIST entry in MANIFEST.MF of all of the libraries of the deployed archive to The libraries are made available to the application in the order specified.
        Parameters:
        librariesStr - is a comma-separated list of library JAR files
        env - the server environment
        Returns:
        array of URL
      • getDeployParamLibrariesAsURLs

        public static URL[] getDeployParamLibrariesAsURLs​(String librariesStr,
                                                          ServerEnvironment env)
        converts libraries specified via the --libraries deployment option to URL[]. The library JAR files are specified by either relative or absolute paths. The relative path is relative to instance-root/lib/applibs. The libraries are made available to the application in the order specified.
        Parameters:
        librariesStr - is a comma-separated list of library JAR files
        env - the server environment
        Returns:
        array of URL
      • getURLs

        public static URL[] getURLs​(File[] dirs,
                                    File[] jarDirs,
                                    boolean ignoreZip)
                             throws IOException
        Returns an array of urls that contains ..
            i.   all the valid directories from the given directory (dirs) array
            ii.  all jar files from the given directory (jarDirs) array
            iii. all zip files from the given directory (jarDirs) array if
                 not ignoring zip file (ignoreZip is false).
         
        Parameters:
        dirs - array of directory path names
        jarDirs - array of path name to directories that contains JAR & ZIP files.
        ignoreZip - whether to ignore zip files
        Returns:
        an array of urls that contains all the valid dirs, *.jar & *.zip
        Throws:
        IOException - if an i/o error while constructing the urls
      • getURLsAsList

        public static List<URL> getURLsAsList​(File[] dirs,
                                              File[] jarDirs,
                                              boolean ignoreZip)
                                       throws IOException
        Returns a list of urls that contains ..
            i.   all the valid directories from the given directory (dirs) array
            ii.  all jar files from the given directory (jarDirs) array
            iii. all zip files from the given directory (jarDirs) array if
                 not ignoring zip file (ignoreZip is false).
         
        Parameters:
        dirs - array of directory path names
        jarDirs - array of path name to directories that contains JAR & ZIP files.
        ignoreZip - whether to ignore zip files
        Returns:
        an array of urls that contains all the valid dirs, *.jar & *.zip
        Throws:
        IOException - if an i/o error while constructing the urls
      • convertURLListToArray

        public static URL[] convertURLListToArray​(List<URL> list)
        Converts a list of a URLs to an array
        Parameters:
        list -
        Returns:
        an empty array if list is null
      • getURLsFromClasspath

        public static List<URL> getURLsFromClasspath​(String classpath,
                                                     String delimiter,
                                                     String rootPath)
        get URL list from classpath
        Parameters:
        classpath - classpath string containing the classpaths
        delimiter - delimiter to separate the classpath components in the classpath string
        rootPath - root path of the classpath if the paths are relative
        Returns:
        urlList URL list from the given classpath
      • getManifest

        public static Manifest getManifest​(String rootPath)
        Returns the manifest file for the given root path. Example: |--repository/ | |--applications/ | |--converter/ | |--ejb-jar-ic_jar/ <---- rootPath | |--META-INF/ | |--MANIFEST.MF
        Parameters:
        rootPath - absolute path to the module
        Returns:
        the manifest file for the given module
      • getManifestClassPathAsURLs

        public static List<URL> getManifestClassPathAsURLs​(Manifest manifest,
                                                           String rootPath)
        Returns the class path (if any) from the given manifest file as an URL list.
        Parameters:
        manifest - manifest file of an archive
        rootPath - root path to the module
        Returns:
        a list of URLs an empty list if given manifest is null
      • getAppLibDirLibraries

        public static URL[] getAppLibDirLibraries​(File appRoot,
                                                  String appLibDir,
                                                  String compatibilityProp)
                                           throws IOException
        add all the libraries packaged in the application library directory
        Parameters:
        appRoot - the application root
        appLibDir - the Application library directory
        compatibilityProp - the version of the release that we need to maintain backward compatibility
        Returns:
        an array of URLs
        Throws:
        IOException
      • getAppLibDirLibrariesAsList

        public static List<URL> getAppLibDirLibrariesAsList​(File appRoot,
                                                            String appLibDir,
                                                            String compatibilityProp)
                                                     throws IOException
        Gets a list of all the libraries packaged in the application library directory
        Parameters:
        appRoot - the application root
        appLibDir - the Application library directory
        compatibilityProp - if this is "v2" then Glassfish v2 library locations will also be added
        Returns:
        a List of the URLs
        Throws:
        IOException
      • getLibDirectoryJarURIs

        public static List<URI> getLibDirectoryJarURIs​(File moduleLibDirectory)
                                                throws Exception
        Returns all jar files if the directory
        Parameters:
        moduleLibDirectory - the directory to search
        Returns:
        a list of URIs
        Throws:
        Exception