Class BootstrapResourceUtils

java.lang.Object
org.lsst.ccs.bootstrap.BootstrapResourceUtils

public abstract class BootstrapResourceUtils extends Object
Utility methods for loading Bootstrap Resources.

The utility methods provided in this class are meant to be used throughout the CCS environment to load resources in the Bootstrap environment.

For a description on how to control the Bootstrap environment please refer to the following manual.

Author:
The LSST CCS Team
  • Constructor Details

    • BootstrapResourceUtils

      public BootstrapResourceUtils()
  • Method Details

    • separateArgumentsForOptions

      public static List<String>[] separateArgumentsForOptions(String[] args, Options options)
    • getBootstrapSystemProperties

      public static Properties getBootstrapSystemProperties()
      Return the Bootstrap System Properties object.

      This function builds a Properties object by searching and chaining properties according to the following search criteria

      • System Properties: System Properties are the first Properties to be added to the merge chain.
      • Bootstrap Resources search : The Bootstrap Resources directories (defined by the environment variable CCS_RESOURCE_PATH) are searched in the reversed order. In each directory properties are merged by searching for application and global properties files (these files are loaded from the file system).
      • Command line : Properties specified from the command line with the -D option are added to the top of the Properties chain.
      Returns:
      The merged Properties object.
    • getPathOfPropertiesFileInUserResourceDirectories

      public static String getPathOfPropertiesFileInUserResourceDirectories(String propertyFileName)
      Utility function to find the top most property file in the user provided resource directories (as specified in the CCS_RESOURCE_PATH environment variable). If the CCS_RESOURCE_PATH environment variable is not specified null will be returned. If specified the first property file will be returned scanning the resource directories in CCS_RESOURCE_PATH left to right.
      Parameters:
      propertyFileName - The name of the property file to get
      Returns:
      The full path of the property file.
    • getPathOfResourceInUserResourceDirectories

      public static String getPathOfResourceInUserResourceDirectories(String fullFileName)
    • getResourceURI

      public static URI getResourceURI(String resourceName) throws MalformedURLException
      Utility function to find the URL of a resource by name. The first instance of this resource will be loaded scanning all the CCS resource paths from the top most to the lower one (the actual resource directory in the distribution).
      Parameters:
      resourceName - The name of the resource get
      Returns:
      The full path of the resource.
      Throws:
      MalformedURLException
    • getResourceURL

      public static URL getResourceURL(String resourceName) throws MalformedURLException
      Throws:
      MalformedURLException
    • getTopUserResourceDirectory

      public static String getTopUserResourceDirectory()
      Utility function to get the top User defined Resource Directory. This is the left-most directory defined in environment variable CCS_RESOURCE_PATH. If not defined, null is returned.
      Returns:
      the top user defined Resource directory. Null if not defined.
    • getBootstrapProperties

      public static Properties getBootstrapProperties(String fileName, Class clazz)
      Utility function to fetch Properties in the Bootstrap environment.

      This function builds a Properties object by searching and chaining properties according to the following search criteria

      • Classpath search: getResourceAsStream is invoked on the provided class. The method is first invoked for fileName. If not input stream is found it is then invoked for "/"+fileName
      • System Properties: if the parameter includeSystem is set to true, System Properties are added to the chain
      • Bootstrap Resources search: The Bootstrap Resources directories (defined by the environment variable CCS_RESOURCE_PATH) are searched in the reversed order. In each directory properties are merged by searching for application, global and topic (defined by fileName) properties files (these files are loaded from the file system). If fileName is a path to a properties file, two searches are performed for each resource directory: the first one is for the fully qualified path; if this yields no result, the properties file is then searched at the root of each resource directory.
      • Command line: Properties specified from the command line with the -D option are added to the top of the Properties chain.
      Parameters:
      fileName - The name of the properties file to load. This can be a path.
      clazz - The class on which getResourceAsStream is invoked for the classpath search. If null BootstrapResourceUtils.class is used.
      Returns:
      The merged Properties object.
    • getBootstrapProperties

      public static Properties getBootstrapProperties(String fileName)
      Utility function to fetch Properties in the Bootstrap environment.

      This function is similar to #getBootstrapProperties(java.lang.String, boolean, java.lang.Class). In this case the Class object is set to null and it defaults to BootstrapResourceUtils.class.

      Parameters:
      fileName - The name of the properties file to load. This can be a path.
      Returns:
      The merged Properties object.
      See Also:
      • #getBootstrapProperties(java.lang.String, boolean, java.lang.Class)
    • getBootstrapPropertiesInputStream

      public static InputStream getBootstrapPropertiesInputStream(String fileName, Class clazz)
      Get an InputStream corresponding to the Bootstrap Properties object.

      This function is similar to #getBootstrapProperties(java.lang.String, boolean, java.lang.Class). Rather than a Properties object it returns the InputStream corresponsing to that Properties object. This is done by invoking on a ByteArrayOutputStream and then returning an ByteArrayInputStream.

      Parameters:
      fileName - The name of the properties file to load. This can be a path.
      clazz - The class on which getResourceAsStream is invoked for the classpath search. If null BootstrapResourceUtils.class is used.
      Returns:
      The input stream for the specified properties file. Null if the properties file does not exist.
      See Also:
      • BootstrapResourceUtils#getBootstrapProperties(java.lang.String, boolean, java.lang.Class)
    • getBootstrapResource

      public static InputStream getBootstrapResource(String resourceName, Class clazz)
      Utility functions to look for resources (excluding Properties) in the Bootstrap environment.

      This function will search for the desired resource following the search criteria described below. It will return an InputStream for the first resource found.

      Search Criteria:

      • Bootstrap Resources search: The Bootstrap Resources directories (defined by the environment variable CCS_RESOURCE_PATH) are searched in the defined order. If fileName is a path to a resource, two searches are performed for each resource directory: the first one is for the fully qualified path; if this yields no result, the resource file is then searched at the root of each resource directory.
      • Classpath search: getResourceAsStrean is invoked on the provided clazz. The method is first invoked for fileName. If not input stream is found it is then invoked for "/"+fileName

      For Properties refer to {@link #getBootstrapProperties(java.lang.String, boolean,java.lang.Class).

      Parameters:
      resourceName - The name of the resource. This can be a path.
      clazz - The class on which getResourceAsStream is invoked for the classpath search. If null BootstrapResourceUtils.class is used.
      Returns:
      The InputStream of the first found resource. It will return null if the resource is not found.
    • getBootstrapResource

      public static InputStream getBootstrapResource(String resourceName)
      Utility functions to look for resources (excluding Properties) in the Bootstrap environment.

      Internally it invokes getBootstrapResource(java.lang.String,java.lang.Class) with Class set to BootstrapResourceUtils.class.

      Parameters:
      resourceName - The name of the resource. This can be a path.
      Returns:
      The InputStream of the first found resource.
      See Also:
    • getAllKeysInProperties

      public static Set<Object> getAllKeysInProperties(Properties props)
      Utility method to fetch all the keys in a properties file, including its parent, to loop over them.

      This method keeps into account if a Properties object has a parent and goes down the parent chain to fetch all the keys.

      Parameters:
      props - The Properties object
      Returns:
      The Set of all the keys in the Properties object.
    • getOrderedListOfResourceDirectories

      public static List<String> getOrderedListOfResourceDirectories()
      Get the ordered list of resource directories. The built in default is: - Distribution resources directory: distribution/etc/ - System resources directory: /etc/ccs/ - User resources directory: ~/.ccs/etc/ By setting the environment variable CCS_RESOURCE_PATH, the developer can change which resource directories are searched and in which order. When the CCS_RESOURCE_PATH environment variable is set, the distribution resource directory will be still searched first, before any of the directories provided by the user. This list is built once and its result is cached.
      Returns:
      The list of ordered directories used to search for resources.
    • findMatchingResources

      public static Set<String> findMatchingResources(String pattern)
      Find all resources that match the provided regular expression pattern. All resource directories will be searched.
      Parameters:
      pattern - The regular expression pattern to be used in the search.
      Returns:
      The Set of the resource file names matching the provided pattern.
    • getManifestVersionsForClass

      public static Properties getManifestVersionsForClass(Class clazz)
      Get the version information written in the jar file manifest for a given Class.
      Parameters:
      clazz - The class for which the versions are to be fetched.
      Returns:
      The properties containing the version information. An empty properties object if the jar file cannot be found.
    • getManifestVersionsForDistribution

      public static Properties getManifestVersionsForDistribution()
      Get the version information written in the jar file manifest for the given distribution.
      Returns:
      The properties containing the version information.
    • scanManifestForVersions

      protected static Properties scanManifestForVersions(File f)