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 doOnGetProperties(String key)
           
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()
           
 Double getDouble(String key)
           
 Encryption getEncryption()
           
 Float getFloat(String key)
           
 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, Float value)
           
 Settings setProperty(String key, Integer value)
           
 Settings setProperty(String key, Long value)
           
 Settings setProperty(String key, String value)
           
 Settings setProperty(String key, String[] values)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected Map<String,String> properties

definitions

protected 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 Encryption getEncryption()

getDefaultValue

public String getDefaultValue(String key)

hasKey

public boolean hasKey(String key)

hasDefaultValue

public boolean hasDefaultValue(String key)

getString

public String getString(String key)

getClearString

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


getBoolean

public boolean getBoolean(String key)

getInt

public 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 long getLong(String key)

getDate

public Date getDate(String key)

getDateTime

public Date getDateTime(String key)

getFloat

public Float getFloat(String key)

getDouble

public Double getDouble(String key)

getStringArray

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

Examples :


getStringLines

public 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 String[] getStringArrayBySeparator(String key,
                                          String separator)
Value is splitted and trimmed.


getKeysStartingWith

public List<String> getKeysStartingWith(String prefix)

appendProperty

public Settings appendProperty(String key,
                               String value)

setProperty

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

setProperty

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

setProperty

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

setProperty

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

setProperty

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

setProperty

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

setProperty

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

setProperty

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

addProperties

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

addProperties

public Settings addProperties(Properties props)

addSystemProperties

public Settings addSystemProperties()

addEnvironmentVariables

public Settings addEnvironmentVariables()

setProperties

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

setProperty

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

removeProperty

public Settings removeProperty(String key)

clear

public Settings clear()

getProperties

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

getDefinitions

public 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()

doOnGetProperties

protected void doOnGetProperties(String key)


Copyright © 2009-2013 SonarSource. All Rights Reserved.