Package org.sonar.api.config
Class PropertyDefinition
- java.lang.Object
-
- org.sonar.api.config.PropertyDefinition
-
@ScannerSide @ServerSide @ComputeEngineSide @SonarLintSide @ExtensionPoint public final class PropertyDefinition extends java.lang.Object
Declare a plugin property. Values are available at runtime through the componentConfiguration
.
It's the programmatic alternative to the annotationProperty
. It is more testable and adds new features like sub-categories and ordering.
Example:public class MyPlugin extends SonarPlugin { public List getExtensions() { return Arrays.asList( PropertyDefinition.builder("sonar.foo").name("Foo").build(), PropertyDefinition.builder("sonar.bar").name("Bar").defaultValue("123").type(PropertyType.INTEGER).build() ); } }
Keys in localization bundles are:property.<key>.name
is the label of the propertyproperty.<key>.description
is the optional description of the propertyproperty.category.<category>
is the category labelproperty.category.<category>.description
is the category descriptionproperty.category.<category>.<subcategory>
is the sub-category labelproperty.category.<category>.<subcategory>.description
is the sub-category description
- Since:
- 3.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PropertyDefinition.Builder
static class
PropertyDefinition.Result
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static PropertyDefinition.Builder
builder(java.lang.String key)
java.lang.String
category()
Category where the property appears in settings pages.java.lang.String
defaultValue()
java.lang.String
deprecatedKey()
java.lang.String
description()
java.util.List<PropertyFieldDefinition>
fields()
boolean
global()
Is the property displayed in global settings page ?int
index()
Order to display properties in Sonar UI.java.lang.String
key()
Unique key within all plugins.boolean
multiValues()
java.lang.String
name()
java.util.List<java.lang.String>
options()
Options for *_LIST types
Options for property of typePropertyType.SINGLE_SELECT_LIST
.
For example {"property_1", "property_3", "property_3"}).java.lang.String
propertySetKey()
Deprecated.since 6.1, as it was not used and too complex to maintain.java.util.List<java.lang.String>
qualifiers()
Qualifiers that can display this propertyjava.lang.String
subCategory()
Sub-category where property appears in settings pages.java.lang.String
toString()
PropertyType
type()
PropertyDefinition.Result
validate(java.lang.String value)
static PropertyDefinition.Result
validate(PropertyType type, java.lang.String value, java.util.List<java.lang.String> options)
-
-
-
Method Detail
-
builder
public static PropertyDefinition.Builder builder(java.lang.String key)
- Parameters:
key
- the unique property key. If it ends with ".secured" then users need the administration permission to access the value.
-
validate
public static PropertyDefinition.Result validate(PropertyType type, @Nullable java.lang.String value, java.util.List<java.lang.String> options)
-
validate
public PropertyDefinition.Result validate(@Nullable java.lang.String value)
-
key
public java.lang.String key()
Unique key within all plugins. It's recommended to prefix the key by 'sonar.' and the plugin name. Examples : 'sonar.cobertura.reportPath' and 'sonar.cpd.minimumTokens'.
-
defaultValue
public java.lang.String defaultValue()
-
name
public java.lang.String name()
-
type
public PropertyType type()
-
options
public java.util.List<java.lang.String> options()
Options for *_LIST types
Options for property of typePropertyType.SINGLE_SELECT_LIST
.
For example {"property_1", "property_3", "property_3"}).
Options for property of typePropertyType.METRIC
.
If no option is specified, any metric will match. If options are specified, all must match for the metric to be displayed. Three types of filter are supportedkey:REGEXP
,domain:REGEXP
andtype:comma_separated__list_of_types
. For examplekey:new_.*
will match any metric which key starts bynew_
. For exampletype:INT,FLOAT
will match any metric of typeINT
orFLOAT
. For exampletype:NUMERIC
will match any metric of numerictype.
-
description
public java.lang.String description()
-
category
public java.lang.String category()
Category where the property appears in settings pages. By default equal to plugin name.
-
subCategory
public java.lang.String subCategory()
Sub-category where property appears in settings pages. By default sub-category is the category.
-
qualifiers
public java.util.List<java.lang.String> qualifiers()
Qualifiers that can display this property
-
global
public boolean global()
Is the property displayed in global settings page ?
-
multiValues
public boolean multiValues()
-
propertySetKey
@Deprecated public java.lang.String propertySetKey()
Deprecated.since 6.1, as it was not used and too complex to maintain.
-
fields
public java.util.List<PropertyFieldDefinition> fields()
-
deprecatedKey
public java.lang.String deprecatedKey()
-
index
public int index()
Order to display properties in Sonar UI. When two properties have the same index then it is sorted by lexicographic order of property name.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-