]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3529 API: ability to define property sets.
authorDavid Gageot <david@gageot.net>
Mon, 24 Sep 2012 16:45:21 +0000 (18:45 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 24 Sep 2012 16:46:23 +0000 (18:46 +0200)
18 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
sonar-plugin-api/src/main/java/org/sonar/api/Property.java
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_BOOLEAN.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_FLOAT.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_INTEGER.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_LICENSE.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_METRIC.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PASSWORD.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_SINGLE_SELECT_LIST.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_STRING.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_TEXT.html.erb

index 710fdd66929b1f713e5650cc03e07117c22842df..f5338025e33b4f46f219cf1c349158bd8599e37e 100644 (file)
@@ -63,6 +63,7 @@ import java.util.List;
     name = "Toto",
     global = true,
     type = PropertyType.PROPERTY_SET,
+    property_set_name = "myset",
     category = CoreProperties.CATEGORY_GENERAL),
   @Property(
     key = CoreProperties.PROJECT_LANGUAGE_PROPERTY,
index d76dc019a8829ba2fc7ff205fe201f37228dcf44..64037142ac218512a8127d8ca5714449eacc1cce 100644 (file)
@@ -98,4 +98,11 @@ public @interface Property {
    * @since 3.3
    */
   boolean multiValues() default false;
+
+  /**
+   * Name of the property set. Used only when type = <code>PropertyType.PROPERTY_SET</code>.
+   *
+   * @since 3.3
+   */
+  String property_set_name() default "";
 }
index 69a8f16c87991559eccf966d810adc6b2b103fae..5464b2f3cdd4a98a99f1b78397c226d295e7e6a7 100644 (file)
@@ -67,6 +67,7 @@ public final class PropertyDefinition {
   private boolean onModule = false;
   private boolean isGlobal = true;
   private boolean multiValues;
+  private String property_set_name;
 
   private PropertyDefinition(Property annotation) {
     this.key = annotation.key();
@@ -80,6 +81,7 @@ public final class PropertyDefinition {
     this.type = fixType(annotation.key(), annotation.type());
     this.options = annotation.options();
     this.multiValues = annotation.multiValues();
+    this.property_set_name = annotation.property_set_name();
   }
 
   private static PropertyType fixType(String key, PropertyType type) {
@@ -180,4 +182,11 @@ public final class PropertyDefinition {
   public boolean isMultiValues() {
     return multiValues;
   }
+
+  /**
+   * @since 3.3
+   */
+  public String getProperty_set_name() {
+    return property_set_name;
+  }
 }
index d65d3af3c861a065bd11d8af1aecc1d4da69f6eb..061bb99a575b36c84d7dc0aef9e9712fe1676901 100644 (file)
@@ -47,6 +47,7 @@ public class PropertyDefinitionTest {
     assertThat(def.isOnProject()).isTrue();
     assertThat(def.isOnModule()).isTrue();
     assertThat(def.isMultiValues()).isTrue();
+    assertThat(def.getProperty_set_name()).isEmpty();
   }
 
   @Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
@@ -74,6 +75,21 @@ public class PropertyDefinitionTest {
     assertThat(def.isMultiValues()).isFalse();
   }
 
+  @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, property_set_name = "set1"))
+  static class WithPropertySet {
+  }
+
+  @Test
+  public void should_support_property_sets() {
+    Properties props = AnnotationUtils.getAnnotation(WithPropertySet.class, Properties.class);
+    Property prop = props.value()[0];
+
+    PropertyDefinition def = PropertyDefinition.create(prop);
+
+    assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET);
+    assertThat(def.getProperty_set_name()).isEqualTo("set1");
+  }
+
   @Properties(@Property(key = "hello", name = "Hello"))
   static class DefaultValues {
   }
@@ -131,7 +147,7 @@ public class PropertyDefinitionTest {
 
   @Test
   public void validate_single_select_list() {
-    PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[] {"de", "en"});
+    PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[]{"de", "en"});
 
     assertThat(def.validate(null).isValid()).isTrue();
     assertThat(def.validate("").isValid()).isTrue();
index fe7ab2ea4eee3d4bf3fdbd65ed06b4874bbf3c6e..d64fd1d3744cca7a6edaf1db2bc3a60f525136d3 100644 (file)
@@ -53,4 +53,12 @@ module SettingsHelper
   def by_name(categories)
     categories.sort_by { |category| category_name(category) }
   end
+
+  def input_name(property)
+    h(property.key) + (property.multi_values ? '[]' : '')
+  end
+
+  def property_set_values(property)
+    PropertySet.findAll(property.property_set_name);
+  end
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb
new file mode 100644 (file)
index 0000000..6100721
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with {library}; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+class PropertySet
+  def self.findAll(property_set_name)
+    [property_set_name + '1', property_set_name + '2']
+  end
+end
index cb3ee1a3b318c744f409a1d2e8f63961b792cf83..ed62ce8d565cfd142e1c7d9ee01236968901def8 100644 (file)
             <% value = property_value(property) -%>
             <% if property.multi_values -%>
               <% value.each do |sub_value| -%>
-                <%= render "settings/multi_value", :property => property, :value => sub_value -%>
+                <%= render "settings/multi_value", :property => property, :value => sub_value, :multi => true -%>
               <% end -%>
               <div class="template" style="display:none;">
-                <%= render "settings/multi_value", :property => property, :value => nil -%>
+                <%= render "settings/multi_value", :property => property, :value => nil, :multi => true -%>
               </div>
               <button class="add_value"><%= message('settings.add') -%></button>
               <br/>
             <% else -%>
-              <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%>
+              <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value, :multi => false -%>
             <% end -%>
 
             <% p = @updated_properties[property.key] if @updated_properties -%>
index 9271bbd0c929bffa2d8bc45c472d5787f8afeff2..b1643852f5c85fe85660e825d590e1d124d19123 100644 (file)
@@ -1,4 +1,4 @@
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>">
   <option value="" <%= 'selected' if value.blank? -%>><%= message('default') -%></option>
   <option value="true" <%= 'selected' if value=='true' -%>><%= message('true') -%></option>
   <option value="false" <%= 'selected' if value=='false' -%>><%= message('false') -%></option>
index 163677b4478533997318faa0015ba736695a5ced..9694f05758ecafb47785ceffab7a4003f1dadd84 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
index 5603dfe4a750a4c4fe06f24269a003145eb49b0b..767aa39ad63fb5c56491b53a2fc1f76eb5829fb4 100644 (file)
@@ -1 +1 @@
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey()-%>"/>
\ No newline at end of file
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey()-%>"/>
\ No newline at end of file
index 69996fa44191309661d2ded486e9732e57aa6439..566f2c37959dc0d1fce5311b36b9659cd9af4c79 100644 (file)
@@ -6,7 +6,7 @@
      date = license.getExpirationDateAsString()
 %>
   <div class="width100">
-    <textarea rows="6" name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>" style="float: left;width: 390px"><%= h value -%></textarea>
+    <textarea rows="6" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>" style="float: left;width: 390px"><%= h value -%></textarea>
 
     <div style="margin-left: 400px">
       <table>
index 45ed790ecf6be7f20d7dfd2ca0e991bf7a83cbb0..ac5d599482cac9218c5fdd3d7b30778756f853cc 100644 (file)
@@ -1,4 +1,4 @@
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>">
   <option value=""><%= message('default') -%></option>
   <%
    metrics_per_domain={}
index e8b70971e02e3012f10b872d4998b50ebaac66c1..5b3a604ca8d4bf43a0935aba2ff94b16b89f487c 100644 (file)
@@ -1 +1 @@
-<input type="password" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
+<input type="password" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
\ No newline at end of file
index a27d0b0dc2cf56d4da21e0d4057896d9680d5bf3..ad61e35f16b51a85bfd2693349eb7d0390e66af5 100644 (file)
@@ -1 +1,7 @@
-NOT IMPLEMENTED YET
\ No newline at end of file
+<select name="<%= input_name(property) -%>" id="input_<%= h property.key -%>">
+  <option value=""><%= message('default') -%></option>
+  <% property_set_values(property).each do |option| %>
+    <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
+  <% end %>
+  <option value="">New value...</option>
+</select>
index b4c3b451f4d84f638cbc12374b107a43ecd3fdc9..b5e2126fc196be364398fa27adb0a05a9c582dbd 100644 (file)
@@ -1,2 +1,2 @@
-<input type="text" name="<%= h property.getKey() -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= h property.getKey() -%>"/>
 <%= link_to_function(image_tag('zoom.png'), "enlargeTextInput('#{property.getKey()}')", :class => 'nolink') -%>
\ No newline at end of file
index ac0e0d3d86792508ce68d0db33c3c9407e6ce916..1e6839f1524992987741fe2c4dfb5e7138871124 100644 (file)
@@ -1,4 +1,4 @@
-<select name="<%= h property.getKey() -%>" id="input_<%= h property.key-%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.key-%>">
   <option value=""><%= message('default') -%></option>
   <% property.options.each do |option| %>
     <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
index 07d91a2313e095c76121114606955325cda97251..ee1ec69bd150616106d3624f9144db31afe9dbc1 100644 (file)
@@ -1,4 +1,4 @@
-<input type="text" name="<%= h property.key -%>[]" value="<%= h value if value -%>" size="50" id="input_<%= property.key.parameterize -%>"/>
+<input type="text" name="<%= input_name(property) -%>" value="<%= h value if value -%>" size="50" id="input_<%= property.key.parameterize -%>"/>
 <% unless property.multi_values -%>
   <%= link_to_function(image_tag('zoom.png'), "enlargeTextInput('input_#{property.key.parameterize}')", :class => 'nolink') -%>
 <% end -%>
index dfefb03af9f633769a9a92630589278b5d6da476..ce59e4a8a07873ca9a193a260d61b3d6b7172be2 100644 (file)
@@ -1 +1 @@
-<textarea rows="5" cols="80" class="width100" name="<%= h property.getKey() -%>" id="input_<%= h property.getKey() -%>"><%= h value if value -%></textarea>
\ No newline at end of file
+<textarea rows="5" cols="80" class="width100" name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>"><%= h value if value -%></textarea>
\ No newline at end of file