Class DefaultLib


  • public class DefaultLib
    extends java.lang.Object
    Collects URLs representing the IVML/VIL/VTL default library. Sequence of registered URLs is relevant as loading happens along that sequence. Files of default library must be exported by the containing bundle and shall be registered by the respective bundle. Given URLs are resolved and prepared using IResourceInitializer.resolve(URL).
    Author:
    Holger Eichelberger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_LIB_FOLDER_NAME
      The usual name of the default lib folder.
      static int DEFAULT_MAX_NESTING
      Maximum nesting to search for fallback locations.
      private static java.util.List<java.net.URL> urls  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultLib()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void append​(java.util.List<java.net.URL> target, java.net.URL url)
      Adds url to target.
      static void appendAll​(java.util.List<java.net.URL> target)
      Appends all registered URLs.
      static java.net.URL appendDefaultLibURLQuietly​(java.lang.ClassLoader loader, java.lang.String bundleId, org.osgi.service.component.ComponentContext context, java.lang.String... parentFolderName)
      Tries to find the default lib URL based on information provided by the component context.
      static java.net.URL appendDefaultLibURLQuietly​(java.lang.ClassLoader loader, org.osgi.service.component.ComponentContext context, java.lang.String... parentFolderName)
      Tries to find the default lib URL based on information provided by the component context.
      static void appendQuietly​(java.util.List<java.net.URL> target, java.net.URL url)
      Adds url to target.
      static void appendURL​(java.net.URL url)
      Appends a given URL to the list of default library URLs.
      static void appendURLQuietly​(java.net.URL url)
      Appends a given URL to the list of default library URLs.
      static java.lang.String composePluginPattern​(java.lang.String pluginId)
      Returns a plugin pattern for searching for the default library.
      static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader, int maxNesting, java.lang.String defaultLibFolderName, java.lang.String... parentFolderName)
      Tries to find the default lib URL.
      static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader, java.lang.String... parentFolderName)
      Tries to find the default lib URL.
      static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader, java.lang.String bundleId, org.osgi.service.component.ComponentContext context, java.lang.String... parentFolderName)
      Tries to find the default lib URL based on information provided by the component context (with precedence using the actual installation location of the bundle), but explicit fallback bundle id to be used with composePluginPattern(String).
      static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader, org.osgi.service.component.ComponentContext context, java.lang.String... parentFolderName)
      Tries to find the default lib URL based on information provided by the component context.
      static java.io.File findFallbackLibFolder​(int maxNesting, java.lang.String defaultLibFolderName, java.lang.String... parentFolderName)
      Tries to Find a fallback in the actual folder or its recursive (for Jenkins) parent folders.
      private static java.io.File findFallbackLibFolder​(java.io.File file, int maxNesting, java.lang.String folderName, boolean prefix, java.lang.String defaultLibFolderName)
      Finds a fallback in file or its recursive (for Jenkins) parent folders.
      private static EASyLoggerFactory.EASyLogger getLogger()
      Returns the logger for this class.
      private static java.net.URL prepare​(java.net.URL url)
      Prepares a given url.
      static void prependURL​(java.net.URL url)
      Prepends a given URL to the list of default library URLs.
      static void prependURLQuietly​(java.net.URL url)
      Appends a given URL to the list of default library URLs.
      static void removeURL​(java.net.URL url)
      Removes a given URL.
      static void removeURLQuietly​(java.net.URL url)
      Removes a given URL.
      static java.lang.Iterable<java.net.URL> urls()
      Returns an iterable to all registered URLs.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_LIB_FOLDER_NAME

        public static final java.lang.String DEFAULT_LIB_FOLDER_NAME
        The usual name of the default lib folder.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_NESTING

        public static final int DEFAULT_MAX_NESTING
        Maximum nesting to search for fallback locations.
        See Also:
        Constant Field Values
      • urls

        private static java.util.List<java.net.URL> urls
    • Constructor Detail

      • DefaultLib

        public DefaultLib()
    • Method Detail

      • appendURL

        public static void appendURL​(java.net.URL url)
                              throws java.io.IOException
        Appends a given URL to the list of default library URLs.
        Parameters:
        url - the URL to append (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • appendURLQuietly

        public static void appendURLQuietly​(java.net.URL url)
        Appends a given URL to the list of default library URLs. This operation logs occurred exceptions.
        Parameters:
        url - the URL to append (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • prependURL

        public static void prependURL​(java.net.URL url)
                               throws java.io.IOException
        Prepends a given URL to the list of default library URLs.
        Parameters:
        url - the URL to prepend (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • prependURLQuietly

        public static void prependURLQuietly​(java.net.URL url)
        Appends a given URL to the list of default library URLs. This operation logs occurred exceptions.
        Parameters:
        url - the URL to append (may be null, is ignored then)
      • removeURL

        public static void removeURL​(java.net.URL url)
                              throws java.io.IOException
        Removes a given URL.
        Parameters:
        url - the URL to remove (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • removeURLQuietly

        public static void removeURLQuietly​(java.net.URL url)
        Removes a given URL. This operation logs occurred exceptions.
        Parameters:
        url - the URL to remove (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • urls

        public static java.lang.Iterable<java.net.URL> urls()
        Returns an iterable to all registered URLs.
        Returns:
        the iterable
      • appendAll

        public static void appendAll​(java.util.List<java.net.URL> target)
        Appends all registered URLs.
        Parameters:
        target - the target collection to be modified as a side effect
      • append

        public static void append​(java.util.List<java.net.URL> target,
                                  java.net.URL url)
                           throws java.io.IOException
        Adds url to target. [helper]
        Parameters:
        target - the target collection to be modified as a side effect
        url - the URL to remove (may be null, is ignored then)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • appendQuietly

        public static void appendQuietly​(java.util.List<java.net.URL> target,
                                         java.net.URL url)
        Adds url to target. This operation logs occurred exceptions. [helper]
        Parameters:
        target - the target collection to be modified as a side effect
        url - the URL to remove (may be null, is ignored then)
      • prepare

        private static java.net.URL prepare​(java.net.URL url)
                                     throws java.io.IOException
        Prepares a given url.
        Parameters:
        url - the URL to be prepared (ignored if null)
        Returns:
        the prepared URL (may be null)
        Throws:
        java.io.IOException - in case that resolving the given URL (if not null) fails
      • appendDefaultLibURLQuietly

        public static java.net.URL appendDefaultLibURLQuietly​(java.lang.ClassLoader loader,
                                                              java.lang.String bundleId,
                                                              org.osgi.service.component.ComponentContext context,
                                                              java.lang.String... parentFolderName)
        Tries to find the default lib URL based on information provided by the component context. This includes the symbolic bundle name (as pattern via composePluginPattern(String) or, with precedence, the actual installation location of the bundle. Uses #findDefaultLibURL(ClassLoader, ComponentContext, String, String...).
        Parameters:
        loader - the class loader for holding the default lib
        bundleId - the explicit bundle id to search for if we cannot identify the installation location from context (may be null for none)
        context - the component context (may be null for none)
        parentFolderName - name(s) of the parent folder, may be a simple folder name, a folder name with path prefix using / or a prefix name ending with * (path possible)
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
      • appendDefaultLibURLQuietly

        public static java.net.URL appendDefaultLibURLQuietly​(java.lang.ClassLoader loader,
                                                              org.osgi.service.component.ComponentContext context,
                                                              java.lang.String... parentFolderName)
        Tries to find the default lib URL based on information provided by the component context. This includes the symbolic bundle name (as pattern via composePluginPattern(String) or, with precedence, the actual installation location of the bundle. Uses #findDefaultLibURL(ClassLoader, ComponentContext, String, String...).
        Parameters:
        loader - the class loader for holding the default lib
        context - the component context (may be null for none)
        parentFolderName - name(s) of the parent folder, may be a simple folder name, a folder name with path prefix using / or a prefix name ending with * (path possible)
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
      • findDefaultLibURL

        public static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader,
                                                     org.osgi.service.component.ComponentContext context,
                                                     java.lang.String... parentFolderName)
                                              throws java.io.IOException
        Tries to find the default lib URL based on information provided by the component context. This includes the symbolic bundle name (as pattern via composePluginPattern(String) or, with precedence, the actual installation location of the bundle. Uses #findDefaultLibURL(ClassLoader, ComponentContext, String, String...).
        Parameters:
        loader - the class loader for holding the default lib
        context - the component context (may be null for none)
        parentFolderName - name(s) of the parent folder, may be a simple folder name, a folder name with path prefix using / or a prefix name ending with * (path possible)
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
      • findDefaultLibURL

        public static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader,
                                                     java.lang.String bundleId,
                                                     org.osgi.service.component.ComponentContext context,
                                                     java.lang.String... parentFolderName)
                                              throws java.io.IOException
        Tries to find the default lib URL based on information provided by the component context (with precedence using the actual installation location of the bundle), but explicit fallback bundle id to be used with composePluginPattern(String). Uses findDefaultLibURL(ClassLoader, String...).
        Parameters:
        loader - the class loader for holding the default lib
        bundleId - the explicit bundle id to search for if we cannot identify the installation location from context (may be null for none)
        context - the component context (may be null for none)
        parentFolderName - name(s) of the parent folder, may be a simple folder name, a folder name with path prefix using / or a prefix name ending with * (path possible)
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
      • findDefaultLibURL

        public static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader,
                                                     java.lang.String... parentFolderName)
                                              throws java.io.IOException
        Tries to find the default lib URL. The first pass uses the class loader. If this fails, we use #findFallbackLibFolder(String, String), which searches for parentFolder containing DEFAULT_LIB_FOLDER_NAME starting at the current folder walking up to the root folder. This method limits the path to a nesting level of 3. This complicated approach may be needed in standalone/CI testing.
        Parameters:
        loader - the class loader for holding the default lib
        parentFolderName - name(s) of the parent folder, may be a simple folder name, a folder name with path prefix using / or a prefix name ending with * (path possible)
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
        See Also:
        #findDefaultLibURL(ClassLoader, String, String)
      • findDefaultLibURL

        public static java.net.URL findDefaultLibURL​(java.lang.ClassLoader loader,
                                                     int maxNesting,
                                                     java.lang.String defaultLibFolderName,
                                                     java.lang.String... parentFolderName)
                                              throws java.io.IOException
        Tries to find the default lib URL. The first pass uses the class loader. If this fails, we use #findFallbackLibFolder(String, String), which searches for parentFolder containing defaultLibFolderName starting at the current folder walking up to the root folder. This complicated approach may be needed in standalon/CI testing.
        Parameters:
        loader - the class loader for holding the default lib
        maxNesting - the maximum file path nesting to search for, 0 is none, negative is unlimited
        defaultLibFolderName - name of the contained default lib folder
        parentFolderName - name(s) of the parent folder(s), may be full names, paths or prefix search patterns (ending with a star), see e.g., composePluginPattern(String).
        Returns:
        the default lib URL or null
        Throws:
        java.io.IOException - in case of I/O problems or problems constructing the result URL
      • findFallbackLibFolder

        public static java.io.File findFallbackLibFolder​(int maxNesting,
                                                         java.lang.String defaultLibFolderName,
                                                         java.lang.String... parentFolderName)
        Tries to Find a fallback in the actual folder or its recursive (for Jenkins) parent folders.
        Parameters:
        maxNesting - the maximum file path nesting to search for, 0 is none, negative is unlimited
        defaultLibFolderName - name of the contained default lib folder
        parentFolderName - name(s) of the parent folder(s), may be full names, paths or prefix search patterns (ending with a star), see e.g., composePluginPattern(String).
        Returns:
        the fallback folder or null if there is none
      • findFallbackLibFolder

        private static java.io.File findFallbackLibFolder​(java.io.File file,
                                                          int maxNesting,
                                                          java.lang.String folderName,
                                                          boolean prefix,
                                                          java.lang.String defaultLibFolderName)
        Finds a fallback in file or its recursive (for Jenkins) parent folders.
        Parameters:
        maxNesting - the maximum file path nesting to search for, 0 is none, negative is unlimited
        file - the file/folder to search
        folderName - the folder name to search for, null to search for defaultLibFolderName (second pass)
        prefix - whether folderName shall be considered as a file name prefix or a full file name
        defaultLibFolderName - the default lib folder name
        Returns:
        the fallback folder or null if the is none
      • composePluginPattern

        public static java.lang.String composePluginPattern​(java.lang.String pluginId)
        Returns a plugin pattern for searching for the default library.
        Parameters:
        pluginId - the plugin id
        Returns:
        the plugin pattern