Skip to content

Commit 11aee1a

Browse files
Promote hidden to a first-class flag on PropertyDefinition
Persist `hidden` as an instance field on PropertyDefinition with a public `hidden()` getter, so consumers can filter UI listings on it. Drop the build-time mutex that forbade combining `.hidden()` with `.onConfigScopes(...)` / `.onlyOnConfigScopes(...)`, and drop the `if (hidden) global = false` coercion. `hidden` is now orthogonal to `global` and `configScopes`, enabling per-project-settable properties that are not exposed in the Settings UI.
1 parent 98b2cff commit 11aee1a

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private String getKey() {
136136
private final String category;
137137
private final List<ConfigScope> configScopes;
138138
private final boolean global;
139+
private final boolean hidden;
139140
private final boolean multiValues;
140141
private final String deprecatedKey;
141142
private final List<PropertyFieldDefinition> fields;
@@ -153,6 +154,7 @@ private PropertyDefinition(Builder builder) {
153154
this.category = builder.category;
154155
this.subCategory = builder.subCategory;
155156
this.global = builder.global;
157+
this.hidden = builder.hidden;
156158
this.type = builder.type;
157159
this.options = builder.options;
158160
this.multiValues = builder.multiValues;
@@ -344,6 +346,14 @@ public boolean global() {
344346
return global;
345347
}
346348

349+
/**
350+
* Hidden properties are not discoverable, and typically don't appear in the UI.
351+
* They can only be configured via the API.
352+
*/
353+
public boolean hidden() {
354+
return hidden;
355+
}
356+
347357
public boolean multiValues() {
348358
return multiValues;
349359
}
@@ -667,11 +677,7 @@ public PropertyDefinition build() {
667677
checkArgument(!isEmpty(key), "Key must be set");
668678
fixType(key, type);
669679
checkArgument(onConfigScopes.isEmpty() || onlyOnConfigScopes.isEmpty(), "Cannot use both forQualifiers and onlyForQualifiers");
670-
checkArgument(!hidden || (onConfigScopes.isEmpty() && onlyOnConfigScopes.isEmpty()), "Cannot be hidden and defining qualifiers on which to display");
671680
checkArgument(!JSON.equals(type) || !multiValues, "Multivalues are not allowed to be defined for JSON-type property.");
672-
if (hidden) {
673-
global = false;
674-
}
675681
if (!fields.isEmpty()) {
676682
type = PROPERTY_SET;
677683
}

plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,34 @@ public void should_create_hidden_property() {
108108
assertThat(def.key()).isEqualTo("hello");
109109
assertThat(def.qualifiers()).isEmpty();
110110
assertThat(def.configScopes()).isEmpty();
111+
assertThat(def.global()).isTrue();
112+
assertThat(def.hidden()).isTrue();
113+
}
114+
115+
@Test
116+
public void should_create_hidden_property_with_on_config_scopes() {
117+
PropertyDefinition def = PropertyDefinition.builder("hello")
118+
.name("Hello")
119+
.hidden()
120+
.onConfigScopes(ConfigScope.PROJECT)
121+
.build();
122+
123+
assertThat(def.hidden()).isTrue();
124+
assertThat(def.global()).isTrue();
125+
assertThat(def.configScopes()).containsExactly(ConfigScope.PROJECT);
126+
}
127+
128+
@Test
129+
public void should_create_hidden_property_with_only_on_config_scopes() {
130+
PropertyDefinition def = PropertyDefinition.builder("hello")
131+
.name("Hello")
132+
.hidden()
133+
.onlyOnConfigScopes(ConfigScope.PROJECT)
134+
.build();
135+
136+
assertThat(def.hidden()).isTrue();
111137
assertThat(def.global()).isFalse();
138+
assertThat(def.configScopes()).containsExactly(ConfigScope.PROJECT);
112139
}
113140

114141
@Test
@@ -125,6 +152,7 @@ public void should_create_property_with_default_values() {
125152
assertThat(def.description()).isEmpty();
126153
assertThat(def.type()).isEqualTo(PropertyType.STRING);
127154
assertThat(def.global()).isTrue();
155+
assertThat(def.hidden()).isFalse();
128156
assertThat(def.qualifiers()).isEmpty();
129157
assertThat(def.configScopes()).isEmpty();
130158
assertThat(def.multiValues()).isFalse();
@@ -320,22 +348,6 @@ public void should_not_create_json_multivalue() {
320348
.hasMessage("Multivalues are not allowed to be defined for JSON-type property.");
321349
}
322350

323-
@Test
324-
public void should_not_authorize_defining_on_qualifiers_and_hidden() {
325-
Builder builder = PropertyDefinition.builder("foo").name("foo").onQualifiers(org.sonar.api.resources.Qualifiers.PROJECT).hidden();
326-
assertThatThrownBy(builder::build)
327-
.isInstanceOf(IllegalArgumentException.class)
328-
.hasMessage("Cannot be hidden and defining qualifiers on which to display");
329-
}
330-
331-
@Test
332-
public void should_not_authorize_defining_ony_on_qualifiers_and_hidden() {
333-
Builder builder = PropertyDefinition.builder("foo").name("foo").onlyOnQualifiers(org.sonar.api.resources.Qualifiers.PROJECT).hidden();
334-
assertThatThrownBy(builder::build)
335-
.isInstanceOf(IllegalArgumentException.class)
336-
.hasMessage("Cannot be hidden and defining qualifiers on which to display");
337-
}
338-
339351
@Test
340352
public void should_not_authorize_defining_on_qualifiers_and_only_on_qualifiers() {
341353
Builder builder = PropertyDefinition.builder("foo").name("foo").onQualifiers(org.sonar.api.resources.Qualifiers.MODULE)

0 commit comments

Comments
 (0)