Package net.ssehub.easy.dslCore
Class DefaultLib
- java.lang.Object
-
- net.ssehub.easy.dslCore.DefaultLib
-
public class DefaultLib extends java.lang.ObjectCollects 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 usingIResourceInitializer.resolve(URL).- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_LIB_FOLDER_NAMEThe usual name of the default lib folder.static intDEFAULT_MAX_NESTINGMaximum 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 voidappend(java.util.List<java.net.URL> target, java.net.URL url)Addsurltotarget.static voidappendAll(java.util.List<java.net.URL> target)Appends all registered URLs.static java.net.URLappendDefaultLibURLQuietly(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 componentcontext.static java.net.URLappendDefaultLibURLQuietly(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 componentcontext.static voidappendQuietly(java.util.List<java.net.URL> target, java.net.URL url)Addsurltotarget.static voidappendURL(java.net.URL url)Appends a given URL to the list of default library URLs.static voidappendURLQuietly(java.net.URL url)Appends a given URL to the list of default library URLs.static java.lang.StringcomposePluginPattern(java.lang.String pluginId)Returns a plugin pattern for searching for the default library.static java.net.URLfindDefaultLibURL(java.lang.ClassLoader loader, int maxNesting, java.lang.String defaultLibFolderName, java.lang.String... parentFolderName)Tries to find the default lib URL.static java.net.URLfindDefaultLibURL(java.lang.ClassLoader loader, java.lang.String... parentFolderName)Tries to find the default lib URL.static java.net.URLfindDefaultLibURL(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 componentcontext(with precedence using the actual installation location of the bundle), but explicit fallback bundle id to be used withcomposePluginPattern(String).static java.net.URLfindDefaultLibURL(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 componentcontext.static java.io.FilefindFallbackLibFolder(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.FilefindFallbackLibFolder(java.io.File file, int maxNesting, java.lang.String folderName, boolean prefix, java.lang.String defaultLibFolderName)Finds a fallback infileor its recursive (for Jenkins) parent folders.private static EASyLoggerFactory.EASyLoggergetLogger()Returns the logger for this class.private static java.net.URLprepare(java.net.URL url)Prepares a givenurl.static voidprependURL(java.net.URL url)Prepends a given URL to the list of default library URLs.static voidprependURLQuietly(java.net.URL url)Appends a given URL to the list of default library URLs.static voidremoveURL(java.net.URL url)Removes a given URL.static voidremoveURLQuietly(java.net.URL url)Removes a given URL.static java.lang.Iterable<java.net.URL>urls()Returns an iterable to all registered URLs.
-
-
-
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
-
-
Method Detail
-
appendURL
public static void appendURL(java.net.URL url) throws java.io.IOExceptionAppends 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.IOExceptionPrepends 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.IOExceptionRemoves 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.IOExceptionAddsurltotarget. [helper]- Parameters:
target- the target collection to be modified as a side effecturl- 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)Addsurltotarget. This operation logs occurred exceptions. [helper]- Parameters:
target- the target collection to be modified as a side effecturl- the URL to remove (may be null, is ignored then)
-
prepare
private static java.net.URL prepare(java.net.URL url) throws java.io.IOExceptionPrepares a givenurl.- 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 componentcontext. This includes the symbolic bundle name (as pattern viacomposePluginPattern(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 libbundleId- the explicit bundle id to search for if we cannot identify the installation location fromcontext(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 componentcontext. This includes the symbolic bundle name (as pattern viacomposePluginPattern(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 libcontext- 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.IOExceptionTries to find the default lib URL based on information provided by the componentcontext. This includes the symbolic bundle name (as pattern viacomposePluginPattern(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 libcontext- 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.IOExceptionTries to find the default lib URL based on information provided by the componentcontext(with precedence using the actual installation location of the bundle), but explicit fallback bundle id to be used withcomposePluginPattern(String). UsesfindDefaultLibURL(ClassLoader, String...).- Parameters:
loader- the class loader for holding the default libbundleId- the explicit bundle id to search for if we cannot identify the installation location fromcontext(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.IOExceptionTries to find the default lib URL. The first pass uses the class loader. If this fails, we use#findFallbackLibFolder(String, String), which searches forparentFoldercontainingDEFAULT_LIB_FOLDER_NAMEstarting 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 libparentFolderName- 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.IOExceptionTries to find the default lib URL. The first pass uses the class loader. If this fails, we use#findFallbackLibFolder(String, String), which searches forparentFoldercontainingdefaultLibFolderNamestarting 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 libmaxNesting- the maximum file path nesting to search for,0is none, negative is unlimiteddefaultLibFolderName- name of the contained default lib folderparentFolderName- 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,0is none, negative is unlimiteddefaultLibFolderName- name of the contained default lib folderparentFolderName- 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 infileor its recursive (for Jenkins) parent folders.- Parameters:
maxNesting- the maximum file path nesting to search for,0is none, negative is unlimitedfile- the file/folder to searchfolderName- the folder name to search for, null to search fordefaultLibFolderName(second pass)prefix- whetherfolderNameshall be considered as a file name prefix or a full file namedefaultLibFolderName- 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
-
getLogger
private static EASyLoggerFactory.EASyLogger getLogger()
Returns the logger for this class.- Returns:
- the logger
-
-