diff options
author | David Gageot <david@gageot.net> | 2012-07-06 14:24:23 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-06 14:51:51 +0200 |
commit | 794e495aaa2cb8c848a3fd0cb48c502abdb72963 (patch) | |
tree | 2029d15cbe4c8a0c440a146300ce7c8e7c824e06 /sonar-server/src/main | |
parent | b7fb648be56f846c25b70716f713805a9adb4653 (diff) | |
download | sonarqube-794e495aaa2cb8c848a3fd0cb48c502abdb72963.tar.gz sonarqube-794e495aaa2cb8c848a3fd0cb48c502abdb72963.zip |
SONAR-3432 Support Regular expressions
Diffstat (limited to 'sonar-server/src/main')
5 files changed, 47 insertions, 39 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb index 999d06c0f7a..f9f215479c0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb @@ -20,21 +20,30 @@ module PropertiesHelper def property_value(key, type, value, options = {}) - if type==PropertyType::TYPE_INTEGER - text_field_tag key, value, {:size => 10}.update(options) + if type==PropertyType::TYPE_STRING + text_field_tag key, value, {:size => 25}.update(options) + + elsif type==PropertyType::TYPE_TEXT + text_area_tag key, value, {:size => '40x6'}.update(options) + + elsif type==PropertyType::TYPE_PASSWORD + password_field_tag key, value, {:size => 25}.update(options) elsif type==PropertyType::TYPE_BOOLEAN check_box_tag key, "true", value=='true', options - elsif type==PropertyType::TYPE_FLOAT + elsif type==PropertyType::TYPE_INTEGER text_field_tag key, value, {:size => 10}.update(options) - elsif type==PropertyType::TYPE_STRING - text_field_tag key, value, {:size => 25}.update(options) + elsif type==PropertyType::TYPE_FLOAT + text_field_tag key, value, {:size => 10}.update(options) elsif type==PropertyType::TYPE_METRIC select_tag key, options_grouped_by_domain(Metric.all.select{|m| m.display?}.sort_by(&:short_name), value, :include_empty => true), options + elsif type==PropertyType::TYPE_REGULAR_EXPRESSION + text_field_tag key, value, {:size => 25}.update(options) + elsif type==PropertyType::TYPE_FILTER user_filters = options_key(value, ::Filter.find(:all, :conditions => ['user_id=?', current_user.id]).sort_by(&:id)) shared_filters = options_key(value, ::Filter.find(:all, :conditions => ['(user_id<>? or user_id is null) and shared=?', current_user.id, true]).sort_by(&:id)) @@ -44,12 +53,6 @@ module PropertiesHelper "#{filters_combo} #{filter_link}" - elsif type==PropertyType::TYPE_TEXT - text_area_tag key, value, {:size => '40x6'}.update(options) - - elsif type==PropertyType::TYPE_PASSWORD - password_field_tag key, value, {:size => 25}.update(options) - else hidden_field_tag key, options end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb index 1a8fb4051d3..aa4beee3dbf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb @@ -22,7 +22,6 @@ module RulesConfigurationHelper PARAM_TYPE_STRING_LIST = "s{}" PARAM_TYPE_INTEGER_LIST = "i{}" - PARAM_TYPE_REGEXP = "r" # Kept for compatibility with old rule param type def type_with_compatibility(type) @@ -31,23 +30,27 @@ module RulesConfigurationHelper return PropertyType::TYPE_INTEGER if type == 'i' return PropertyType::TYPE_INTEGER if type == PARAM_TYPE_INTEGER_LIST return PropertyType::TYPE_BOOLEAN if type == 'b' - return PropertyType::TYPE_STRING if type == PARAM_TYPE_REGEXP + return PropertyType::TYPE_REGULAR_EXPRESSION if type == 'r' return PropertyType::TYPE_STRING if is_set(type) type end - def readable_type(type) - return "Set of comma delimited strings" if type == PARAM_TYPE_STRING_LIST - return "Number" if type_with_compatibility(type) == PropertyType::TYPE_INTEGER - return "Set of comma delimited numbers" if type == PARAM_TYPE_INTEGER_LIST - return "Regular expression" if type == PARAM_TYPE_REGEXP - return "Set of comma delimited values" if is_set(type) + def readable_type(param_type) + type=type_with_compatibility(param_type) + + return "Set of comma delimited strings" if param_type == PARAM_TYPE_STRING_LIST + return "Number" if type == PropertyType::TYPE_INTEGER + return "Set of comma delimited numbers" if param_type == PARAM_TYPE_INTEGER_LIST + return "Regular expression" if type == PropertyType::TYPE_REGULAR_EXPRESSION + return "Set of comma delimited values" if is_set(param_type) "" end def param_value_input(parameter, value, options = {}) - property_value 'value', type_with_compatibility(parameter.param_type), value, {:id => parameter.id}.update(options) + type=type_with_compatibility(parameter.param_type) + + property_value 'value', type, value, {:id => parameter.id}.update(options) end def is_set(type) @@ -71,18 +74,12 @@ module RulesConfigurationHelper errors.add("#{value}", "'#{n}' must be an integer.") end end - elsif param_type == RulesConfigurationHelper::PARAM_TYPE_REGEXP - if !Api::Utils.is_regexp?(attribute) - errors.add("#{value}", "'#{attribute}' must be a regular expression") - end + elsif type == PropertyType::TYPE_REGULAR_EXPRESSION + errors.add("#{value}", "'#{attribute}' must be a regular expression") unless Api::Utils.is_regexp?(attribute) elsif type == PropertyType::TYPE_INTEGER - if !Api::Utils.is_integer?(attribute) - errors.add("#{value}", "'#{attribute}' must be an integer.") - end + errors.add("#{value}", "'#{attribute}' must be an integer.") unless Api::Utils.is_integer?(attribute) elsif type == PropertyType::TYPE_BOOLEAN - if !Api::Utils.is_boolean?(attribute) - errors.add("#{value}", "'#{attribute}' must be one of : true,false") - end + errors.add("#{value}", "'#{attribute}' must be one of : true,false") unless Api::Utils.is_boolean?(attribute) end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb index dc6764f7850..1fe7ec88aa4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -47,7 +47,7 @@ class Api::Utils def self.is_regexp?(s) begin - Regexp.new(S) + Regexp.new(s) true rescue false diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property_type.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property_type.rb index 9a9cd071e8c..8fcb9f06da3 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property_type.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/property_type.rb @@ -18,14 +18,18 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class PropertyType - TYPE_INTEGER = 'INTEGER' + TYPE_STRING = 'STRING' + TYPE_TEXT = 'TEXT' + TYPE_PASSWORD = 'PASSWORD' TYPE_BOOLEAN = 'BOOLEAN' + TYPE_INTEGER = 'INTEGER' TYPE_FLOAT = 'FLOAT' - TYPE_STRING = 'STRING' + #TYPE_SINGLE_SELECT_LIST = 'SINGLE_SELECT_LIST' TYPE_METRIC = 'METRIC' + TYPE_LICENSE = 'LICENSE' + TYPE_REGULAR_EXPRESSION = 'REGULAR_EXPRESSION' + TYPE_FILTER = 'FILTER' - TYPE_TEXT = 'TEXT' - TYPE_PASSWORD = 'PASSWORD' def self.text_to_value(text, type) case type @@ -46,10 +50,12 @@ class PropertyType errors.add_to_base("Unknown type for property #{key}") unless type if text_value.empty? errors.add_to_base("#{key} is empty") unless optional - else - errors.add_to_base("#{key} is not an integer") if type==PropertyType::TYPE_INTEGER && !Api::Utils.is_integer?(text_value) - errors.add_to_base("#{key} is not a decimal number") if type==PropertyType::TYPE_FLOAT && !Api::Utils.is_number?(text_value) - errors.add_to_base("#{key} is not a boolean") if type==PropertyType::TYPE_BOOLEAN && !(text_value=="true" || text_value=="false") + return end + + errors.add_to_base("#{key} is not an integer") if type==TYPE_INTEGER && !Api::Utils.is_integer?(text_value) + errors.add_to_base("#{key} is not a decimal number") if type==TYPE_FLOAT && !Api::Utils.is_number?(text_value) + errors.add_to_base("#{key} is not a boolean") if type==TYPE_BOOLEAN && !Api::Utils.is_boolean?(text_value) + errors.add_to_base("#{key} is not a regular expression") if type==TYPE_REGULAR_EXPRESSION && !Api::Utils.is_regexp?(text_value) end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb new file mode 100644 index 00000000000..b4c3b451f4d --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb @@ -0,0 +1,2 @@ +<input type="text" name="<%= h property.getKey() -%>" 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 |