Interface SystemWrapper


public interface SystemWrapper
This wrapper aims to allow to load additional and custom system properties without passing them explicitly and directly to the JVM. Usually in Silverpeas, these custom system properties define the context of its execution.

By default it wraps the System class; hence its name. The way those custom system properties are loaded is at the discretion of the implementor. In opposite to the System class in which all the methods are static, this class allowed to be instantiated so that different context can be prepared for the tests without implying necessarily the System class.

Author:
Yohann Chastagnier
Implementation Requirements:
The SystemWrapper implementation is loaded from the the Java SPI (Java Service Provider Interface) and its instance is kept in memory for further retrieval.
Implementation Note:
Whatever the number of available implementations of this interface, only the first found one is used. Nevertheless, by using the @Priority annotation, the implementation to use can be explicitly indicated.
  • Method Details

    • getInstance

      static SystemWrapper getInstance()
      Gets the wrapped single System instance of the SystemWrapper. If the implementation isn't yet loaded, then it is loaded and instantiated once time.
      Returns:
      the instance of the System Wrapper.
      Implementation Note:
      The implementation is loaded and instantiated by Java SPI at first call. The single instance is then kept in memory so that it is returned at each next call.
    • getenv

      default String getenv(String name)
      Gets the value of a environment variable.
      Parameters:
      name - the name of the variable.
      Returns:
      the value of the requested environment variable.
    • getenv

      default Map<String,String> getenv()
      Gets all the environment variables.
      Returns:
      the map of environment variables.
    • getProperties

      default Properties getProperties()
      Gets the system properties.
      Returns:
      the system properties.
      See Also:
    • setProperties

      default void setProperties(Properties props)
      Sets the specified properties in the system properties. Opposite to the method System.setProperties(Properties) that replace the system properties with the specified ones, this method adds the specified ones among the existing system properties.
      Parameters:
      props - the system properties to add.
      See Also:
    • setProperty

      default String setProperty(String key, String value)
      Sets a new system property. If the property isn't valued, id est has a null or an empty value, then it is not set. Only non-null and not empty property can be set.
      Parameters:
      key - the key of the property.
      value - a non-null and non-empty value of the property.
      Returns:
      the previous value of the system property, or null if it did not have one or if the property to set isn't valid.
      See Also:
    • getProperty

      default String getProperty(String key)
      Gets a system property.
      Parameters:
      key - the key of the system property.
      Returns:
      the string value of the system property, or null if there is no property with that key.
    • getProperty

      default String getProperty(String key, String def)
      Gets a system property.
      Parameters:
      key - the key of the system property.
      def - the default value if there is no property value with the key.
      Returns:
      the string value of the system property, or the default value if there is no property with that key.