org.sonar.api.config
Class PropertyDefinition

java.lang.Object
  extended by org.sonar.api.config.PropertyDefinition
All Implemented Interfaces:
BatchComponent, BatchExtension, Extension, ServerComponent, ServerExtension

public final class PropertyDefinition
extends Object
implements BatchExtension, ServerExtension

Declare a plugin property. Values are available at runtime through the component Settings.

It's the programmatic alternative to the annotation Property. 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:

Since:
3.6

Nested Class Summary
static class PropertyDefinition.Builder
           
static class PropertyDefinition.Result
           
 
Method Summary
static PropertyDefinition.Builder builder(String key)
           
 String category()
          Category where the property appears in settings pages.
 String defaultValue()
           
 String deprecatedKey()
           
 String description()
           
 List<PropertyFieldDefinition> fields()
           
 boolean global()
          Is the property displayed in global settings page ?
 int index()
          Order to display properties in Sonar UI.
 String key()
          Unique key within all plugins.
 boolean multiValues()
           
 String name()
           
 List<String> options()
          Options for *_LIST types

Options for property of type PropertyType.SINGLE_SELECT_LIST For example {"property_1", "property_3", "property_3"}).

 String propertySetKey()
           
 List<String> qualifiers()
          Qualifiers that can display this property
 String subCategory()
          Sub-category where property appears in settings pages.
 String toString()
           
 PropertyType type()
           
static PropertyDefinition.Result validate(PropertyType type, String value, List<String> options)
           
 PropertyDefinition.Result validate(String value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

builder

public static PropertyDefinition.Builder builder(String key)

validate

public static PropertyDefinition.Result validate(PropertyType type,
                                                 @Nullable
                                                 String value,
                                                 List<String> options)

validate

public PropertyDefinition.Result validate(@Nullable
                                          String value)

key

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

name

public String name()

type

public PropertyType type()

options

public List<String> options()
Options for *_LIST types

Options for property of type PropertyType.SINGLE_SELECT_LIST For example {"property_1", "property_3", "property_3"}).

Options for property of type PropertyType.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 supported key:REGEXP, domain:REGEXP and type:comma_separated__list_of_types. For example key:new_.* will match any metric which key starts by new_. For example type:INT,FLOAT will match any metric of type INT or FLOAT. For example type:NUMERIC will match any metric of numerictype.


description

public String description()

category

public String category()
Category where the property appears in settings pages. By default equal to plugin name.


subCategory

public String subCategory()
Sub-category where property appears in settings pages. By default sub-category is the category.


qualifiers

public List<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

public String propertySetKey()

fields

public List<PropertyFieldDefinition> fields()

deprecatedKey

public 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 String toString()
Overrides:
toString in class Object


Copyright © 2009-2013 SonarSource. All Rights Reserved.