diff options
author | David Gageot <david@gageot.net> | 2012-09-24 19:14:20 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-09-24 19:24:13 +0200 |
commit | 082a1b5cf450f5f0837d0d51efe3a4f90c24181b (patch) | |
tree | 6040617bb6152d5b339922e26444ba21cd1796ab | |
parent | dffab878ddf772d36f56b94ee1a739bc3fc1a984 (diff) | |
download | sonarqube-082a1b5cf450f5f0837d0d51efe3a4f90c24181b.tar.gz sonarqube-082a1b5cf450f5f0837d0d51efe3a4f90c24181b.zip |
SONAR-3529 API: ability to define property sets.
4 files changed, 69 insertions, 10 deletions
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 index 00000000000..aadfa06a969 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertySetValue.java @@ -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 { +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java index 3ec41a5cf6e..d9b55af1109 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Settings.java @@ -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. * 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 index 61007210470..b7e20fe1a1e 100644 --- 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 @@ -17,8 +17,31 @@ # 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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb index ad61e35f16b..613c806d581 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb @@ -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> |