Class InstalledDependenciesSetup


  • public class InstalledDependenciesSetup
    extends de.iip_ecosphere.platform.support.iip_aas.config.AbstractSetup
    Provides access to installed dependencies on the actual resource, e.g., the location of a specific Java version or of Python. The instantiation process shall provide a YamlFile called installedDependencies.yml linking symbolic program/dependency names to installation folders where the respective binary can be found. The information shall be taken from service dependencies in the configuration model. Java versions shall be mapped to keys like "JAVAx" where x represents the Java major version, older just without the leading "1.", newer as the major version, see getJavaKey() for the actual version.
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_FNAME
      Name of the default configuration file with extension (no path).
      static java.lang.String DEFAULT_NAME
      Just the name of the default configuration file, no extension, no path.
      private static InstalledDependenciesSetup instance  
      static java.lang.String KEY_JAVA_11  
      static java.lang.String KEY_JAVA_8  
      static java.lang.String KEY_PREFIX_JAVA
      The prefix for Java program/dependency keys.
      private java.util.Map<java.lang.String,​java.io.File> locations  
      static java.lang.String PROPERTY_PATH  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addDefaultEntry​(java.lang.String key, java.io.File value)
      Adds a default location entry.
      static InstalledDependenciesSetup getInstance()
      Returns a singleton instance via readFromYaml().
      static java.lang.String getJavaKey()
      Returns the program/dependency key for the actual Java version.
      java.io.File getLocation​(java.lang.String key)
      Returns the location for a given program/dependency key.
      java.util.Map<java.lang.String,​java.io.File> getLocations()
      Returns the locations.
      static java.io.File location​(java.lang.String key)
      Returns a location from getInstance() via getLocation(String), throws an exception if no such location is present.
      static InstalledDependenciesSetup readFromYaml()
      Reads the default yaml file, taking into account the system property PROPERTY_PATH, the current directory as additional resource folder and the file system root.
      static InstalledDependenciesSetup readFromYaml​(java.lang.String fileName)
      Reads the given yaml file via the ResourceLoader, taking into account the system property PROPERTY_PATH, the current directory as additional resource folder and the file system root.
      void setLocation​(java.lang.String key, java.io.File location)
      Sets a single location, but ensures the default values.
      void setLocations​(java.util.Map<java.lang.String,​java.io.File> locations)
      Changes the locations.
      private void setupDefaults()
      Sets up the default values.
      • Methods inherited from class de.iip_ecosphere.platform.support.setup.AbstractSetup

        createYaml, isNotEmpty, readFromYaml, readFromYaml, readFromYaml
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_NAME

        public static final java.lang.String DEFAULT_NAME
        Just the name of the default configuration file, no extension, no path.
        See Also:
        Constant Field Values
      • DEFAULT_FNAME

        public static final java.lang.String DEFAULT_FNAME
        Name of the default configuration file with extension (no path).
        See Also:
        Constant Field Values
      • KEY_PREFIX_JAVA

        public static final java.lang.String KEY_PREFIX_JAVA
        The prefix for Java program/dependency keys.
        See Also:
        Constant Field Values
      • locations

        private java.util.Map<java.lang.String,​java.io.File> locations
    • Constructor Detail

      • InstalledDependenciesSetup

        public InstalledDependenciesSetup()
        Sets up default values before overriding.
    • Method Detail

      • setupDefaults

        private void setupDefaults()
        Sets up the default values.
      • addDefaultEntry

        private void addDefaultEntry​(java.lang.String key,
                                     java.io.File value)
        Adds a default location entry. Does not override existing values.
        Parameters:
        key - the key
        value - the value
      • getJavaKey

        public static java.lang.String getJavaKey()
        Returns the program/dependency key for the actual Java version.
        Returns:
        the key
      • getLocations

        public java.util.Map<java.lang.String,​java.io.File> getLocations()
        Returns the locations.
        Returns:
        the locations
      • getLocation

        public java.io.File getLocation​(java.lang.String key)
        Returns the location for a given program/dependency key.
        Parameters:
        key - the key
        Returns:
        the location, may be null for none
      • setLocations

        public void setLocations​(java.util.Map<java.lang.String,​java.io.File> locations)
        Changes the locations. [required by SnakeYaml]
        Parameters:
        locations - the locations
      • setLocation

        public void setLocation​(java.lang.String key,
                                java.io.File location)
        Sets a single location, but ensures the default values.
        Parameters:
        key - the key to set
        location - the new location
      • readFromYaml

        public static InstalledDependenciesSetup readFromYaml​(java.lang.String fileName)
        Reads the given yaml file via the ResourceLoader, taking into account the system property PROPERTY_PATH, the current directory as additional resource folder and the file system root.
        Parameters:
        fileName - the file to read
        Returns:
        the setup instance, if not found the default instance
      • readFromYaml

        public static InstalledDependenciesSetup readFromYaml()
        Reads the default yaml file, taking into account the system property PROPERTY_PATH, the current directory as additional resource folder and the file system root.
        Returns:
        the setup instance, if not found the default instance
      • location

        public static java.io.File location​(java.lang.String key)
                                     throws java.util.concurrent.ExecutionException
        Returns a location from getInstance() via getLocation(String), throws an exception if no such location is present.
        Parameters:
        key - the key to look for
        Returns:
        the location
        Throws:
        java.util.concurrent.ExecutionException - if the key cannot be found