Class Settings

java.lang.Object
org.sonar.api.config.Settings
org.sonar.api.config.internal.Settings
Direct Known Subclasses:
MapSettings

public abstract class Settings extends org.sonar.api.config.Settings
Implementation of the deprecated Settings interface
  • Constructor Details

    • Settings

      protected Settings(org.sonar.api.config.PropertyDefinitions definitions, Encryption encryption)
  • Method Details

    • get

      protected abstract Optional<String> get(String key)
    • set

      protected abstract void set(String key, String value)
      Add the settings with the specified key and value, both are trimmed and neither can be null.
      Throws:
      NullPointerException - if key and/or value is null.
    • remove

      protected abstract void remove(String key)
    • getProperties

      public abstract Map<String,String> getProperties()
      Immutable map of the properties that have non-default values. The default values defined by PropertyDefinitions are ignored, so the returned values are not the effective values. Basically only the non-empty results of getRawString(String) are returned.

      Values are not decrypted if they are encrypted with a secret key.

    • getEncryption

      public Encryption getEncryption()
    • getRawString

      public Optional<String> getRawString(String key)
      The value that overrides the default value. It may be encrypted with a secret key. Use getString(String) to get the effective and decrypted value.
      Since:
      6.1
    • getDefinitions

      public org.sonar.api.config.PropertyDefinitions getDefinitions()
      All the property definitions declared by core and plugins.
    • getDefinition

      public Optional<org.sonar.api.config.PropertyDefinition> getDefinition(String key)
      The definition related to the specified property. It may be empty.
      Since:
      6.1
    • hasKey

      public boolean hasKey(String key)
      Specified by:
      hasKey in class org.sonar.api.config.Settings
      Returns:
      true if the property has a non-default value, else false.
    • getDefaultValue

      @CheckForNull public String getDefaultValue(String key)
    • hasDefaultValue

      public boolean hasDefaultValue(String key)
    • getString

      @CheckForNull public String getString(String key)
      The effective value of the specified property. Can return null if the property is not set and has no defined default value.

      If the property is encrypted with a secret key, then the returned value is decrypted.

      Specified by:
      getString in class org.sonar.api.config.Settings
      Throws:
      IllegalStateException - if value is encrypted but fails to be decrypted.
    • getBoolean

      public boolean getBoolean(String key)
      Effective value as boolean. It is false if getString(String) does not return "true", even if it's not a boolean representation.
      Specified by:
      getBoolean in class org.sonar.api.config.Settings
      Returns:
      true if the effective value is "true", else false.
    • getInt

      public int getInt(String key)
      Effective value as int.
      Specified by:
      getInt in class org.sonar.api.config.Settings
      Returns:
      the value as int. If the property does not have value nor default value, then 0 is returned.
      Throws:
      NumberFormatException - if value is not empty and is not a parsable integer
    • getLong

      public long getLong(String key)
      Effective value as long.
      Specified by:
      getLong in class org.sonar.api.config.Settings
      Returns:
      the value as long. If the property does not have value nor default value, then 0L is returned.
      Throws:
      NumberFormatException - if value is not empty and is not a parsable long
    • getDate

      @CheckForNull public Date getDate(String key)
      Effective value as Date, without time fields. Format is DateUtils.DATE_FORMAT.
      Specified by:
      getDate in class org.sonar.api.config.Settings
      Returns:
      the value as a Date. If the property does not have value nor default value, then null is returned.
      Throws:
      RuntimeException - if value is not empty and is not in accordance with DateUtils.DATE_FORMAT.
    • getDateTime

      @CheckForNull public Date getDateTime(String key)
      Effective value as Date, with time fields. Format is DateUtils.DATETIME_FORMAT.
      Specified by:
      getDateTime in class org.sonar.api.config.Settings
      Returns:
      the value as a Date. If the property does not have value nor default value, then null is returned.
      Throws:
      RuntimeException - if value is not empty and is not in accordance with DateUtils.DATETIME_FORMAT.
    • getFloat

      @CheckForNull public Float getFloat(String key)
      Effective value as Float.
      Specified by:
      getFloat in class org.sonar.api.config.Settings
      Returns:
      the value as Float. If the property does not have value nor default value, then null is returned.
      Throws:
      NumberFormatException - if value is not empty and is not a parsable number
    • getDouble

      @CheckForNull public Double getDouble(String key)
      Effective value as Double.
      Specified by:
      getDouble in class org.sonar.api.config.Settings
      Returns:
      the value as Double. If the property does not have value nor default value, then null is returned.
      Throws:
      NumberFormatException - if value is not empty and is not a parsable number
    • getStringArray

      public String[] getStringArray(String key)
      Value is split by comma and trimmed. Never returns null.
      Examples :
      • "one,two,three " -> ["one", "two", "three"]
      • " one, two, three " -> ["one", "two", "three"]
      • "one, , three" -> ["one", "", "three"]
      Specified by:
      getStringArray in class org.sonar.api.config.Settings
    • getStringLines

      public String[] getStringLines(String key)
      Value is split by carriage returns.
      Specified by:
      getStringLines in class org.sonar.api.config.Settings
      Returns:
      non-null array of lines. The line termination characters are excluded.
      Since:
      3.2
    • getStringArrayBySeparator

      public String[] getStringArrayBySeparator(String key, String separator)
      Value is split and trimmed.
      Specified by:
      getStringArrayBySeparator in class org.sonar.api.config.Settings
    • appendProperty

      public Settings appendProperty(String key, @Nullable String value)
    • setProperty

      public Settings setProperty(String key, @Nullable String[] values)
    • setProperty

      public Settings setProperty(String key, @Nullable String value)
      Change a property value in a restricted scope only, depending on execution context. New value is never persisted. New value is ephemeral and kept in memory only:
      • during current analysis in the case of scanner stack
      • during processing of current HTTP request in the case of web server stack
      • during execution of current task in the case of Compute Engine stack
      Property is temporarily removed if the parameter value is null
    • setProperty

      public Settings setProperty(String key, @Nullable Boolean value)
      See Also:
    • setProperty

      public Settings setProperty(String key, @Nullable Integer value)
      See Also:
    • setProperty

      public Settings setProperty(String key, @Nullable Long value)
      See Also:
    • setProperty

      public Settings setProperty(String key, @Nullable Double value)
      See Also:
    • setProperty

      public Settings setProperty(String key, @Nullable Float value)
      See Also:
    • setProperty

      public Settings setProperty(String key, @Nullable Date date)
      See Also:
    • addProperties

      public Settings addProperties(Map<String,String> props)
    • addProperties

      public Settings addProperties(Properties props)
    • setProperty

      public Settings setProperty(String key, @Nullable Date date, boolean includeTime)
      See Also:
    • removeProperty

      public Settings removeProperty(String key)
    • getKeysStartingWith

      public List<String> getKeysStartingWith(String prefix)
      Specified by:
      getKeysStartingWith in class org.sonar.api.config.Settings