@BatchSide @ServerSide @ComputeEngineSide public class Settings extends Object
For testing, you can create a new empty Settings
component using Settings()
and then
populate it using all variant of setProperty
.
If you want to test with default values of your properties taken into account there are two ways dependening on how you declare your properties.
@Properties({
@Property(
key = "sonar.myProp",
defaultValue = "A default value",
name = "My property"),
})
public class MyPlugin extends SonarPlugin {
then you can use:
new Settings(new PropertyDefinitions(MyPlugin.class))
PropertyDefinition.builder(String)
way like:
public class MyPlugin extends SonarPlugin {
public List getExtensions() {
return Arrays.asList(
PropertyDefinition.builder("sonar.myProp").name("My property").defaultValue("A default value").build()
);
}
}
then you can use:
new Settings(new PropertyDefinitions(new MyPlugin().getExtensions()))
Modifier and Type | Field and Description |
---|---|
protected PropertyDefinitions |
definitions |
protected Map<String,String> |
properties |
Constructor and Description |
---|
Settings() |
Settings(PropertyDefinitions definitions) |
Settings(Settings other)
Clone settings.
|
protected Map<String,String> properties
protected PropertyDefinitions definitions
public Settings()
public Settings(PropertyDefinitions definitions)
public Encryption getEncryption()
@CheckForNull public String getDefaultValue(String key)
public boolean hasDefaultValue(String key)
@CheckForNull public String getString(String key)
@CheckForNull protected String getClearString(String key)
public boolean getBoolean(String key)
public int getInt(String key)
@CheckForNull public Date getDate(String key)
@CheckForNull public Date getDateTime(String key)
@CheckForNull public Float getFloat(String key)
@CheckForNull public Double getDouble(String key)
public String[] getStringArray(String key)
public String[] getStringLines(String key)
public String[] getStringArrayBySeparator(String key, String separator)
public List<String> getKeysStartingWith(String prefix)
public Settings appendProperty(String key, String value)
public Settings setProperty(String key, @Nullable String[] values)
public Settings setProperty(String key, @Nullable String value)
public Settings setProperty(String key, @Nullable Boolean value)
public Settings setProperty(String key, @Nullable Integer value)
public Settings setProperty(String key, @Nullable Long value)
public Settings setProperty(String key, @Nullable Double value)
public Settings setProperty(String key, @Nullable Float value)
public Settings setProperty(String key, @Nullable Date date)
public Settings addProperties(Map<String,String> props)
public Settings addProperties(Properties props)
@Deprecated public Settings addSystemProperties()
@Deprecated public Settings addEnvironmentVariables()
public Settings setProperties(Map<String,String> props)
public Settings setProperty(String key, @Nullable Date date, boolean includeTime)
public Settings removeProperty(String key)
public Map<String,String> getProperties()
public PropertyDefinitions getDefinitions()
public static Settings createForComponent(Object component)
protected void doOnSetProperty(String key, @Nullable String value)
protected void doOnRemoveProperty(String key)
protected void doOnClearProperties()
protected void doOnGetProperties(String key)
Copyright © 2009–2017 SonarSource. All rights reserved.