org.sonar.api.config
Class Settings

java.lang.Object
  extended by org.sonar.api.config.Settings
All Implemented Interfaces:
BatchComponent, ServerComponent

public class Settings
extends Object
implements BatchComponent, ServerComponent

Project Settings on batch side, Global Settings on server side. This component does not access to database, so property changed via setter methods are not persisted.

This component replaces the deprecated org.apache.commons.configuration.Configuration

Since:
2.12

Field Summary
protected  PropertyDefinitions definitions
           
protected  Map<String,String> properties
           
 
Constructor Summary
Settings()
           
Settings(PropertyDefinitions definitions)
           
Settings(Settings other)
          Clone settings.
 
Method Summary
 Settings addEnvironmentVariables()
           
 Settings addProperties(Map<String,String> props)
           
 Settings addProperties(Properties props)
           
 Settings addSystemProperties()
           
 Settings appendProperty(String key, String value)
           
 Settings clear()
           
static Settings createForComponent(Object component)
          Create empty settings.
protected  void doOnClearProperties()
           
protected  void doOnRemoveProperty(String key)
           
protected  void doOnSetProperty(String key, String value)
           
 boolean getBoolean(String key)
           
protected  String getClearString(String key)
          Does not decrypt value.
 Date getDate(String key)
           
 Date getDateTime(String key)
           
 String getDefaultValue(String key)
           
 PropertyDefinitions getDefinitions()
           
 Encryption getEncryption()
           
 int getInt(String key)
           
 List<String> getKeysStartingWith(String prefix)
           
 long getLong(String key)
           
 Map<String,String> getProperties()
           
 String getString(String key)
           
 String[] getStringArray(String key)
          Value is split by comma and trimmed.
 String[] getStringArrayBySeparator(String key, String separator)
          Value is splitted and trimmed.
 String[] getStringLines(String key)
          Value is split by carriage returns.
 boolean hasDefaultValue(String key)
           
 boolean hasKey(String key)
           
 Settings removeProperty(String key)
           
 Settings setProperties(Map<String,String> props)
           
 Settings setProperty(String key, Boolean value)
           
 Settings setProperty(String key, Date date)
           
 Settings setProperty(String key, Date date, boolean includeTime)
           
 Settings setProperty(String key, Double value)
           
 Settings setProperty(String key, Integer value)
           
 Settings setProperty(String key, Long value)
           
 Settings setProperty(String key, String value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected final Map<String,String> properties

definitions

protected final PropertyDefinitions definitions
Constructor Detail

Settings

public Settings()

Settings

public Settings(PropertyDefinitions definitions)

Settings

public Settings(Settings other)
Clone settings. Actions are not propagated to cloned settings.

Since:
3.1
Method Detail

getEncryption

public final Encryption getEncryption()

getDefaultValue

public final String getDefaultValue(String key)

hasKey

public final boolean hasKey(String key)

hasDefaultValue

public final boolean hasDefaultValue(String key)

getString

public final String getString(String key)

getClearString

protected String getClearString(String key)
Does not decrypt value.


getBoolean

public final boolean getBoolean(String key)

getInt

public final int getInt(String key)
Returns:
the value as int. If the property does not exist and has no default value, then 0 is returned.

getLong

public final long getLong(String key)

getDate

public final Date getDate(String key)

getDateTime

public final Date getDateTime(String key)

getStringArray

public final String[] getStringArray(String key)
Value is split by comma and trimmed.

Examples :


getStringLines

public final String[] getStringLines(String key)
Value is split by carriage returns.

Returns:
non-null array of lines. The line termination characters are excluded.
Since:
3.2

getStringArrayBySeparator

public final String[] getStringArrayBySeparator(String key,
                                                String separator)
Value is splitted and trimmed.


getKeysStartingWith

public final List<String> getKeysStartingWith(String prefix)

appendProperty

public final Settings appendProperty(String key,
                                     String value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  String value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Boolean value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Integer value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Long value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Double value)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Date date)

addProperties

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

addProperties

public final Settings addProperties(Properties props)

addSystemProperties

public final Settings addSystemProperties()

addEnvironmentVariables

public final Settings addEnvironmentVariables()

setProperties

public final Settings setProperties(Map<String,String> props)

setProperty

public final Settings setProperty(String key,
                                  @Nullable
                                  Date date,
                                  boolean includeTime)

removeProperty

public final Settings removeProperty(String key)

clear

public final Settings clear()

getProperties

public final Map<String,String> getProperties()
Returns:
unmodifiable properties

getDefinitions

public final PropertyDefinitions getDefinitions()

createForComponent

public static Settings createForComponent(Object component)
Create empty settings. Definition of available properties is loaded from the given annotated class. This method is usually used by unit tests.


doOnSetProperty

protected void doOnSetProperty(String key,
                               @Nullable
                               String value)

doOnRemoveProperty

protected void doOnRemoveProperty(String key)

doOnClearProperties

protected void doOnClearProperties()


Copyright © 2009-2012 SonarSource. All Rights Reserved.