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>.nameis the label of the propertyproperty.<key>.descriptionis the optional description of the propertyproperty.category.<category>is the category labelproperty.category.<category>.descriptionis the category descriptionproperty.category.<category>.<subcategory>is the sub-category labelproperty.category.<category>.<subcategory>.descriptionis the sub-category description
- Since:
- 3.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPropertyDefinition.Builderstatic classPropertyDefinition.Result
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static PropertyDefinition.Builderbuilder(java.lang.String key)java.lang.Stringcategory()Category where the property appears in settings pages.java.lang.StringdefaultValue()java.lang.StringdeprecatedKey()java.lang.Stringdescription()java.util.List<PropertyFieldDefinition>fields()booleanglobal()Is the property displayed in global settings page ?intindex()Order to display properties in Sonar UI.java.lang.Stringkey()Unique key within all plugins.booleanmultiValues()java.lang.Stringname()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.StringpropertySetKey()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.StringsubCategory()Sub-category where property appears in settings pages.java.lang.StringtoString()PropertyTypetype()PropertyDefinition.Resultvalidate(java.lang.String value)static PropertyDefinition.Resultvalidate(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:REGEXPandtype:comma_separated__list_of_types. For examplekey:new_.*will match any metric which key starts bynew_. For exampletype:INT,FLOATwill match any metric of typeINTorFLOAT. For exampletype:NUMERICwill 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:
toStringin classjava.lang.Object
-
-