Package alpine

Class Config

java.lang.Object
alpine.Config

public class Config extends Object
The Config class is responsible for reading the application.properties file.
Since:
1.0.0
Author:
Steve Springett
  • Constructor Details

    • Config

      public Config()
  • Method Details

    • getInstance

      public static Config getInstance()
      Returns an instance of the Config object.
      Returns:
      a Config object
      Since:
      1.0.0
    • getSystemUuid

      public String getSystemUuid()
      Returns the UUID unique to a system deployment.
      Returns:
      the UUID unique to a deployed system
      Since:
      1.8.0
    • getFrameworkName

      public String getFrameworkName()
      Returns the Alpine component name.
      Returns:
      the Alpine name
      Since:
      1.0.0
    • getFrameworkVersion

      public String getFrameworkVersion()
      Returns the Alpine version.
      Returns:
      the Alpine version
      Since:
      1.0.0
    • getFrameworkBuildTimestamp

      public String getFrameworkBuildTimestamp()
      Returns the Alpine built timestamp.
      Returns:
      the timestamp in which this version of Alpine was built
      Since:
      1.0.0
    • getFrameworkBuildUuid

      public String getFrameworkBuildUuid()
      Returns the Alpine UUID.
      Returns:
      the UUID unique to this build of Alpine
      Since:
      1.3.0
    • getApplicationName

      public String getApplicationName()
      Returns the Application component name.
      Returns:
      the Application name
      Since:
      1.0.0
    • getApplicationVersion

      public String getApplicationVersion()
      Returns the Application version.
      Returns:
      the Application version
      Since:
      1.0.0
    • getApplicationBuildTimestamp

      public String getApplicationBuildTimestamp()
      Returns the Application built timestamp.
      Returns:
      the timestamp in which this version of the Application was built
      Since:
      1.0.0
    • getApplicationBuildUuid

      public String getApplicationBuildUuid()
      Returns the Application UUID.
      Returns:
      the UUID unique to this build of the application
      Since:
      1.3.0
    • getDataDirectorty

      public File getDataDirectorty()
      Returns the fully qualified path to the configured data directory. Expects a fully qualified path or a path starting with ~/ Defaults to ~/.alpine if data directory is not specified.
      Returns:
      a File object of the data directory
      Since:
      1.0.0
    • getProperty

      public String getProperty(Config.Key key)
      Return the configured value for the specified Key. As of v1.4.3, this method will first check if the key has been specified as an environment variable. If it has, the method will return the value. If it hasn't been specified in the environment, it will retrieve the value (and optional default value) from the properties configuration. This method is Docker-friendly in that configuration can be specified via environment variables which is a common method of configuration when configuration files are not easily accessible.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a String of the value of the configuration
      Since:
      1.0.0
    • getPropertyOrFile

      public String getPropertyOrFile(Config.AlpineKey key)
      Check if key with _FILE postfix appended is a defined property name, either in the environment or in the properties configuration. If yes, the named file is read and its content will be the key's value. This method is defined so that passwords can be read from docker secret.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a String of the value of the configuration
      Since:
      1.7.0
    • getPropertyAsInt

      public int getPropertyAsInt(Config.Key key)
      Return the configured value for the specified Key.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a int of the value of the configuration
      Since:
      1.0.0
    • getPropertyAsLong

      public long getPropertyAsLong(Config.Key key)
      Return the configured value for the specified Key.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a long of the value of the configuration
      Since:
      1.0.0
    • getPropertyAsBoolean

      public boolean getPropertyAsBoolean(Config.Key key)
      Return the configured value for the specified Key.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a boolean of the value of the configuration
      Since:
      1.0.0
    • getPropertyAsList

      public List<String> getPropertyAsList(Config.Key key)
      Return the configured value for the specified Key.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a list of the comma-separated values of the configuration, or an empty list otherwise
      Since:
      2.2.5
    • getPassThroughProperties

      public Map<String,String> getPassThroughProperties(String prefix)
      Get "pass-through" properties with a given prefix.

      Pass-through properties do not have corresponding Config.Keys. Their main use-case is to allow users to configure certain aspects of libraries and frameworks used by Alpine, without Alpine having to introduce Config.AlpineKeys for every single option.

      Properties are read from both environment variables, and PROP_FILE. When a property is defined in both environment and application.properties, environment takes precedence.

      Properties must be prefixed with ALPINE_ (for environment variables) or alpine. (for application.properties) respectively. The Alpine prefix will be removed in keys of the returned Map, but the given prefix will be retained.

      Parameters:
      prefix - Prefix of the properties to fetch
      Returns:
      A Map containing the matched properties
      Since:
      2.3.0
    • getProperty

      @Deprecated public String getProperty(String key)
      Deprecated.
      Return the configured value for the specified Key.
      Parameters:
      key - The Key to return the configuration for
      Returns:
      a String of the value of the configuration
      Since:
      1.0.0
    • getProperty

      @Deprecated public String getProperty(String key, String defaultValue)
      Deprecated.
      Return the configured value for the specified Key.
      Parameters:
      key - The String of the key to return the configuration for
      defaultValue - The default value if the key cannot be found
      Returns:
      a String of the value of the configuration
      Since:
      1.0.0
    • isUnitTestsEnabled

      public static boolean isUnitTestsEnabled()
      Determins is unit tests are enabled by checking if the 'alpine.unittests.enabled' system property is set to true or false.
      Returns:
      true if unit tests are enabled, false if not
      Since:
      1.0.0
    • enableUnitTests

      public static void enableUnitTests()
      Enables unit tests by setting 'alpine.unittests.enabled' system property to true.
      Since:
      1.0.0