public List getExtensions() {
return ImmutableList.of(
- PropertyDefinition.build(CoreProperties.CPD_CROSS_RPOJECT)
+ PropertyDefinition.builder(CoreProperties.CPD_CROSS_RPOJECT)
.defaultValue(CoreProperties.CPD_CROSS_RPOJECT_DEFAULT_VALUE + "")
.name("Cross project duplication detection")
.description("SonarQube supports the detection of cross project duplications. Activating this property will slightly increase each Sonar analysis time.")
- .qualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
- .global(true)
+ .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.category(CoreProperties.CATEGORY_DUPLICATIONS)
.type(PropertyType.BOOLEAN)
.build(),
- PropertyDefinition.build(CoreProperties.CPD_SKIP_PROPERTY)
+ PropertyDefinition.builder(CoreProperties.CPD_SKIP_PROPERTY)
.defaultValue("false")
.name("Skip")
.description("Disable detection of duplications")
- .global(false)
+ .hidden()
.category(CoreProperties.CATEGORY_DUPLICATIONS)
.type(PropertyType.BOOLEAN)
.build(),
- PropertyDefinition.build(CoreProperties.CPD_EXCLUSIONS)
+ PropertyDefinition.builder(CoreProperties.CPD_EXCLUSIONS)
.defaultValue("")
.name("Duplication exclusions")
.description("Patterns used to exclude some source files from the duplication detection mechanism. " +
"See the \"Exclusions\" category to know how to use wildcards to specify this property.")
- .qualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
- .global(true)
+ .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.category(CoreProperties.CATEGORY_DUPLICATIONS)
.multiValues(true)
.build(),
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.sonar.api.BatchExtension;
import javax.annotation.Nullable;
+import java.util.Arrays;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
/**
* @since 3.6
*/
- public static Builder build(String key) {
+ public static Builder builder(String key) {
return new Builder(key);
}
* @since 3.6
*/
static PropertyDefinition create(Property annotation) {
+ Builder builder = PropertyDefinition.builder(annotation.key())
+ .name(annotation.name())
+ .defaultValue(annotation.defaultValue())
+ .description(annotation.description())
+ .category(annotation.category())
+ .type(annotation.type())
+ .options(Arrays.asList(annotation.options()))
+ .multiValues(annotation.multiValues())
+ .propertySetKey(annotation.propertySetKey())
+ .fields(PropertyFieldDefinition.create(annotation.fields()))
+ .deprecatedKey(annotation.deprecatedKey())
+ .index(annotation.index());
List<String> qualifiers = newArrayList();
if (annotation.project()) {
qualifiers.add(Qualifiers.PROJECT);
if (annotation.module()) {
qualifiers.add(Qualifiers.MODULE);
}
- return PropertyDefinition.build(annotation.key())
- .name(annotation.name())
- .defaultValue(annotation.defaultValue())
- .description(annotation.description())
- .global(annotation.global())
- .qualifiers(qualifiers)
- .category(annotation.category())
- .type(annotation.type())
- .options(annotation.options())
- .multiValues(annotation.multiValues())
- .propertySetKey(annotation.propertySetKey())
- .fields(PropertyFieldDefinition.create(annotation.fields()))
- .deprecatedKey(annotation.deprecatedKey())
- .index(annotation.index())
- .build();
+ if (annotation.global()) {
+ builder.onQualifiers(qualifiers);
+ } else {
+ builder.onlyOnQualifiers(qualifiers);
+ }
+ return builder.build();
}
public static Result validate(PropertyType type, @Nullable String value, List<String> options) {
private String propertySetKey;
private List<PropertyFieldDefinition> fields;
private String deprecatedKey;
+ private boolean hidden;
private int index;
private Builder(String key) {
this.qualifiers = newArrayList();
this.options = newArrayList();
this.fields = newArrayList();
+ this.hidden = false;
this.index = 999;
}
return this;
}
- public Builder qualifiers(String... qualifiers) {
- this.qualifiers.addAll(newArrayList(qualifiers));
+ public Builder onQualifiers(String first, String... rest) {
+ this.qualifiers = Lists.asList(first, rest);
+ this.global = true;
+ return this;
+ }
+
+ public Builder onQualifiers(List<String> qualifiers) {
+ this.qualifiers = ImmutableList.copyOf(qualifiers);
+ this.global = true;
return this;
}
- public Builder qualifiers(List<String> qualifiers) {
- this.qualifiers.addAll(qualifiers);
+ public Builder onlyOnQualifiers(String first, String... rest) {
+ this.qualifiers = Lists.asList(first, rest);
+ this.global = false;
return this;
}
- public Builder global(boolean global) {
- this.global = global;
+ public Builder onlyOnQualifiers(List<String> qualifiers) {
+ this.qualifiers = ImmutableList.copyOf(qualifiers);
+ this.global = false;
return this;
}
return this;
}
- public Builder options(String... options) {
- this.options.addAll(ImmutableList.copyOf(options));
+ public Builder options(String first, String... rest) {
+ this.options.addAll(Lists.asList(first, rest));
return this;
}
return this;
}
- public Builder fields(PropertyFieldDefinition... fields) {
- this.fields.addAll(ImmutableList.copyOf(fields));
+ public Builder fields(PropertyFieldDefinition first, PropertyFieldDefinition... rest) {
+ this.fields.addAll(Lists.asList(first, rest));
return this;
}
return this;
}
+ public Builder hidden() {
+ this.hidden = true;
+ return this;
+ }
+
public Builder index(int index) {
this.index = index;
return this;
public PropertyDefinition build() {
Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Key must be set");
fixType(key, type);
+ Preconditions.checkArgument(!hidden || qualifiers.isEmpty(), "Cannot be hidden and defining qualifiers on which to display");
+ if (hidden) {
+ global = false;
+ }
return new PropertyDefinition(this);
}
@Test
public void should_create_property() {
- PropertyDefinition def = PropertyDefinition.build("hello")
+ PropertyDefinition def = PropertyDefinition.builder("hello")
.name("Hello")
.defaultValue("world")
.category("categ")
.options("de", "en")
.description("desc")
.type(PropertyType.FLOAT)
- .global(false)
- .qualifiers(Qualifiers.FILE, Qualifiers.CLASS)
+ .onlyOnQualifiers(Qualifiers.FILE, Qualifiers.CLASS)
.multiValues(true)
.propertySetKey("set")
.build();
assertThat(def.fields()).isEmpty();
}
+ @Test
+ public void should_create_hidden_property() {
+ PropertyDefinition def = PropertyDefinition.builder("hello")
+ .name("Hello")
+ .hidden()
+ .build();
+
+ assertThat(def.key()).isEqualTo("hello");
+ assertThat(def.qualifiers()).isEmpty();
+ assertThat(def.global()).isFalse();
+ }
+
@Test
public void should_create_property_with_default_values() {
- PropertyDefinition def = PropertyDefinition.build("hello")
+ PropertyDefinition def = PropertyDefinition.builder("hello")
.name("Hello")
.build();
@Test
public void should_support_property_sets() {
- PropertyDefinition def = PropertyDefinition.build("hello")
+ PropertyDefinition def = PropertyDefinition.builder("hello")
.name("Hello")
.fields(
PropertyFieldDefinition.build("first").name("First").description("Description").options("A", "B").build(),
@Test
public void should_validate_string() {
- PropertyDefinition def = PropertyDefinition.build("foo").name("foo").type(PropertyType.STRING).build();
+ PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.STRING).build();
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
@Test
public void should_validate_boolean() {
- PropertyDefinition def = PropertyDefinition.build("foo").name("foo").type(PropertyType.BOOLEAN).build();
+ PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.BOOLEAN).build();
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
@Test
public void should_validate_integer() {
- PropertyDefinition def = PropertyDefinition.build("foo").name("foo").type(PropertyType.INTEGER).build();
+ PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.INTEGER).build();
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
@Test
public void should_validate_float() {
- PropertyDefinition def = PropertyDefinition.build("foo").name("foo").type(PropertyType.FLOAT).build();
+ PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.FLOAT).build();
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
@Test
public void should_validate_single_select_list() {
- PropertyDefinition def = PropertyDefinition.build("foo").name("foo").type(PropertyType.SINGLE_SELECT_LIST).options("de", "en").build();
+ PropertyDefinition def = PropertyDefinition.builder("foo").name("foo").type(PropertyType.SINGLE_SELECT_LIST).options("de", "en").build();
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();
@Test
public void should_auto_detect_password_type() {
- PropertyDefinition def = PropertyDefinition.build("scm.password.secured").name("SCM password").build();
+ PropertyDefinition def = PropertyDefinition.builder("scm.password.secured").name("SCM password").build();
assertThat(def.key()).isEqualTo("scm.password.secured");
assertThat(def.type()).isEqualTo(PropertyType.PASSWORD);
@Test
public void should_auto_detect_license_type() {
- PropertyDefinition def = PropertyDefinition.build("views.license.secured").name("Views license").build();
+ PropertyDefinition def = PropertyDefinition.builder("views.license.secured").name("Views license").build();
assertThat(def.key()).isEqualTo("views.license.secured");
assertThat(def.type()).isEqualTo(PropertyType.LICENSE);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void should_not_define_qualifier_and_hidden() {
+ PropertyDefinition.builder("foo").name("foo").onQualifiers(Qualifiers.FILE).hidden().build();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void should_not_authorise_empty_key() {
+ PropertyDefinition.builder(null).build();
+ }
+
@Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true, propertySetKey = "set"))
static class Init {
@Test
public void should_inspect_plugin_objects() {
PropertyDefinitions def = new PropertyDefinitions(
- PropertyDefinition.build("foo").name("Foo").build(),
- PropertyDefinition.build("one").name("One").build(),
- PropertyDefinition.build("two").name("Two").defaultValue("2").build()
+ PropertyDefinition.builder("foo").name("Foo").build(),
+ PropertyDefinition.builder("one").name("One").build(),
+ PropertyDefinition.builder("two").name("Two").defaultValue("2").build()
);
assertProperties(def);
@Test
public void test_categories() {
PropertyDefinitions def = new PropertyDefinitions(
- PropertyDefinition.build("inCateg").name("In Categ").category("categ").build(),
- PropertyDefinition.build("noCateg").name("No categ").build()
+ PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(),
+ PropertyDefinition.builder("noCateg").name("No categ").build()
);
assertThat(def.getCategory("inCateg")).isEqualTo("categ");
@Test
public void test_default_category() {
PropertyDefinitions def = new PropertyDefinitions();
- def.addComponent(PropertyDefinition.build("inCateg").name("In Categ").category("categ").build(), "default");
- def.addComponent(PropertyDefinition.build("noCateg").name("No categ").build(), "default");
+ def.addComponent(PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(), "default");
+ def.addComponent(PropertyDefinition.builder("noCateg").name("No categ").build(), "default");
assertThat(def.getCategory("inCateg")).isEqualTo("categ");
assertThat(def.getCategory("noCateg")).isEqualTo("default");
@Test
public void should_group_by_category() {
PropertyDefinitions def = new PropertyDefinitions(
- PropertyDefinition.build("global1").name("Global1").category("catGlobal1").global(true).build(),
- PropertyDefinition.build("global2").name("Global2").category("catGlobal1").global(true).build(),
- PropertyDefinition.build("global3").name("Global3").category("catGlobal2").global(true).build(),
- PropertyDefinition.build("project").name("Project").category("catProject").global(false).qualifiers(Qualifiers.PROJECT).build(),
- PropertyDefinition.build("module").name("Module").category("catModule").global(false).qualifiers(Qualifiers.MODULE).build(),
- PropertyDefinition.build("view").name("View").category("catView").global(false).qualifiers(Qualifiers.VIEW).build()
+ PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(),
+ PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(),
+ PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(),
+ PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(),
+ PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(),
+ PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build()
);
assertThat(def.getPropertiesByCategory(null).keySet()).containsOnly("catGlobal1", "catGlobal2");
@Test
public void should_group_by_subcategory() {
PropertyDefinitions def = new PropertyDefinitions(
- PropertyDefinition.build("global1").name("Global1").category("catGlobal1").subcategory("sub1").global(true).build(),
- PropertyDefinition.build("global2").name("Global2").category("catGlobal1").subcategory("sub2").global(true).build(),
- PropertyDefinition.build("global3").name("Global3").category("catGlobal1").global(true).build(),
- PropertyDefinition.build("global4").name("Global4").category("catGlobal2").global(true).build()
+ PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subcategory("sub1").build(),
+ PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subcategory("sub2").build(),
+ PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(),
+ PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build()
);
assertThat(def.getPropertiesByCategory(null).get("catGlobal1").keySet()).containsOnly("default", "sub1", "sub2");