Class DefaultLib

java.lang.Object
net.ssehub.easy.dslCore.DefaultLib

public class DefaultLib extends 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 Details

    • DEFAULT_LIB_FOLDER_NAME

      public static final String DEFAULT_LIB_FOLDER_NAME
      The usual name of the default lib folder.
      See Also:
    • DEFAULT_MAX_NESTING

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

      private static List<URL> urls
  • Constructor Details

    • DefaultLib

      public DefaultLib()
  • Method Details

    • appendURL

      public static void appendURL(URL url) throws 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:
      IOException - in case that resolving the given URL (if not null) fails
    • appendURLQuietly

      public static void appendURLQuietly(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)
    • prependURL

      public static void prependURL(URL url) throws 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:
      IOException - in case that resolving the given URL (if not null) fails
    • prependURLQuietly

      public static void prependURLQuietly(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(URL url) throws IOException
      Removes a given URL.
      Parameters:
      url - the URL to remove (may be null, is ignored then)
      Throws:
      IOException - in case that resolving the given URL (if not null) fails
    • removeURLQuietly

      public static void removeURLQuietly(URL url)
      Removes a given URL. This operation logs occurred exceptions.
      Parameters:
      url - the URL to remove (may be null, is ignored then)
    • urls

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

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

      public static void append(List<URL> target, URL url) throws 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:
      IOException - in case that resolving the given URL (if not null) fails
    • appendQuietly

      public static void appendQuietly(List<URL> target, 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 URL prepare(URL url) throws IOException
      Prepares a given url.
      Parameters:
      url - the URL to be prepared (ignored if null)
      Returns:
      the prepared URL (may be null)
      Throws:
      IOException - in case that resolving the given URL (if not null) fails
    • appendDefaultLibURLQuietly

      public static URL appendDefaultLibURLQuietly(ClassLoader loader, String bundleId, org.osgi.service.component.ComponentContext context, 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, int, 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
    • appendDefaultLibURLQuietly

      public static URL appendDefaultLibURLQuietly(ClassLoader loader, org.osgi.service.component.ComponentContext context, 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...).
      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
    • findDefaultLibURL

      public static URL findDefaultLibURL(ClassLoader loader, org.osgi.service.component.ComponentContext context, String... parentFolderName) throws 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...).
      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:
      IOException - in case of I/O problems or problems constructing the result URL
    • findDefaultLibURL

      public static URL findDefaultLibURL(ClassLoader loader, String bundleId, org.osgi.service.component.ComponentContext context, String... parentFolderName) throws 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:
      IOException - in case of I/O problems or problems constructing the result URL
    • findDefaultLibURL

      public static URL findDefaultLibURL(ClassLoader loader, String... parentFolderName) throws IOException
      Tries to find the default lib URL. The first pass uses the class loader. If this fails, we use findFallbackLibFolder(int, 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:
      IOException - in case of I/O problems or problems constructing the result URL
      See Also:
    • findDefaultLibURL

      public static URL findDefaultLibURL(ClassLoader loader, int maxNesting, String defaultLibFolderName, String... parentFolderName) throws IOException
      Tries to find the default lib URL. The first pass uses the class loader. If this fails, we use findFallbackLibFolder(int, 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:
      IOException - in case of I/O problems or problems constructing the result URL
    • findFallbackLibFolder

      public static File findFallbackLibFolder(int maxNesting, String defaultLibFolderName, 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 File findFallbackLibFolder(File file, int maxNesting, String folderName, boolean prefix, String defaultLibFolderName)
      Finds a fallback in file or its recursive (for Jenkins) parent folders.
      Parameters:
      file - the file/folder to search
      maxNesting - the maximum file path nesting to search for, 0 is none, negative is unlimited
      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 String composePluginPattern(String pluginId)
      Returns a plugin pattern for searching for the default library.
      Parameters:
      pluginId - the plugin id
      Returns:
      the plugin pattern
    • getLogger

      private static net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger getLogger()
      Returns the logger for this class.
      Returns:
      the logger