Class 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 component Configuration.
    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:
    • property.<key>.name is the label of the property
    • property.<key>.description is the optional description of the property
    • property.category.<category> is the category label
    • property.category.<category>.description is the category description
    • property.category.<category>.<subcategory> is the sub-category label
    • property.category.<category>.<subcategory>.description is the sub-category description
    Since:
    3.6
    • 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.
      • 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()
      • options

        public java.util.List<java.lang.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 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.
      • 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 class java.lang.Object