]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3529 API: ability to define property sets.
authorDavid Gageot <david@gageot.net>
Mon, 24 Sep 2012 17:14:20 +0000 (19:14 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 24 Sep 2012 17:24:13 +0000 (19:24 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java
sonar-server/src/main/webapp/WEB-INF/app/models/property_set.rb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb

diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java
new file mode 100644 (file)
index 0000000..aadfa06
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Sonar, open source software quality management 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.api.config;
+
+/**
+ * @since 3.3
+ */
+public class PropertySetValue {
+}
index 3ec41a5cf6e79594bb8f44c867db3635778902fc..d9b55af11099fc61a8e43f1e3cbc9be4fe6d3613 100644 (file)
@@ -27,16 +27,12 @@ import com.google.common.collect.Maps;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.BatchComponent;
+import org.sonar.api.PropertyType;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.utils.DateUtils;
 
 import javax.annotation.Nullable;
-
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 /**
  * Project Settings on batch side, Global Settings on server side. This component does not access to database, so
@@ -184,6 +180,20 @@ public class Settings implements BatchComponent, ServerComponent {
     return getStringArrayBySeparator(key, ",");
   }
 
+  public final PropertySetValue getPropertySetValue(String key) {
+    PropertyDefinition property = getDefinitions().get(key);
+    if ((null == property) || (property.getType() != PropertyType.PROPERTY_SET)) {
+      throw new IllegalArgumentException("Property " + key + " is not of type PROPERTY_SET");
+    }
+
+    String propertySetValueName = getString(key);
+
+    // read json for given key
+    // search value for given propertySetValueName
+
+    return null;
+  }
+
   /**
    * Value is split by carriage returns.
    *
index 610072104708639eecd577f8b301459294cdc4e8..b7e20fe1a1e5d3796551998181137e8f259cb0ac 100644 (file)
 # 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']
+class PropertySet < ActiveRecord::Base
+  attr_accessor :name
+
+  def self.columns
+    @columns ||= [];
+  end
+
+  def self.column(name, sql_type = nil, default = nil, null = true)
+    columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
+  end
+
+  def self.findAll(set_name)
+    ActiveSupport::JSON.decode(values_as_json(set_name)).map { |set| PropertySet.new(set) }
+  end
+
+  def save(validate = true)
+    validate ? valid? : true
+  end
+
+  private
+
+  def self.values_as_json(set_name)
+    json = Property.value('sonar.property_set.' + set_name)
+
+    #json || '[]'
+    json || '[{"name":"set1"},{"name":"set2"}]'
   end
 end
index ad61e35f16b51a85bfd2693349eb7d0390e66af5..613c806d5815be80b9db329ca5db5d42951200d3 100644 (file)
@@ -1,6 +1,6 @@
 <select name="<%= input_name(property) -%>" id="input_<%= h property.key -%>">
   <option value=""><%= message('default') -%></option>
-  <% property_set_values(property).each do |option| %>
+  <% property_set_values(property).map(&:name).each do |option| %>
     <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
   <% end %>
   <option value="">New value...</option>