aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-06 14:24:23 +0200
committerDavid Gageot <david@gageot.net>2012-07-06 14:51:51 +0200
commit794e495aaa2cb8c848a3fd0cb48c502abdb72963 (patch)
tree2029d15cbe4c8a0c440a146300ce7c8e7c824e06 /sonar-server
parentb7fb648be56f846c25b70716f713805a9adb4653 (diff)
downloadsonarqube-794e495aaa2cb8c848a3fd0cb48c502abdb72963.tar.gz
sonarqube-794e495aaa2cb8c848a3fd0cb48c502abdb72963.zip
SONAR-3432 Support Regular expressions
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/properties_helper.rb25
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb35
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/property_type.rb22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_REGULAR_EXPRESSION.html.erb2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/changeParentProfile.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/initialData.xml2
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/ruleReverted.xml4
10 files changed, 53 insertions, 45 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
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml
index f34a0b494fd..cc9d1869478 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren-result.xml
@@ -3,7 +3,7 @@
<rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="r"/>
+ <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
<rules_profiles id="1" version="2" used_profile="false" provided="false" name="parent" default_profile="0" language="java" parent_name="[null]" enabled="true"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml
index 62081abc403..75c3d712a0f 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldActivateInChildren.xml
@@ -3,7 +3,7 @@
<rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="r"/>
+ <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
<rules_profiles id="1" version="1" used_profile="true" provided="false" name="parent" default_profile="0" language="java" parent_name="[null]" enabled="true"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/changeParentProfile.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/changeParentProfile.xml
index 7c4d381feea..b5d2d18e454 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/changeParentProfile.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/changeParentProfile.xml
@@ -5,7 +5,7 @@
<rules id="2" name="bar" description="test2" plugin_config_key="checker/bar"
plugin_rule_key="checkstyle.rule2" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="r"/>
+ <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
<rules_profiles id="1" version="1" used_profile="true" provided="false" name="parent" default_profile="0" language="java" parent_name="[null]" enabled="true"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/initialData.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/initialData.xml
index aa0cb98276e..7aeb11f9b99 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/initialData.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/initialData.xml
@@ -5,7 +5,7 @@
<rules id="2" name="bar" description="test2" plugin_config_key="checker/bar"
plugin_rule_key="checkstyle.rule2" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="r"/>
+ <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
<rules_profiles id="1" version="1" used_profile="true" provided="false" name="parent" default_profile="0" language="java" parent_name="[null]" enabled="true"/>
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/ruleReverted.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/ruleReverted.xml
index 2ec87b2cd7b..e682eb176a8 100644
--- a/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/ruleReverted.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/configuration/RuleChangeTest/ruleReverted.xml
@@ -2,8 +2,8 @@
<rules id="2" name="bar" description="test2" plugin_config_key="checker/bar"
plugin_rule_key="checkstyle.rule2" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
- <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="r"/>
- <rules_parameters id="14" rule_id="2" name="param2" description="[null]" param_type="r"/>
+ <rules_parameters id="13" rule_id="2" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
+ <rules_parameters id="14" rule_id="2" name="param2" description="[null]" param_type="REGULAR_EXPRESSION"/>
<rules_profiles id="1" version="1" used_profile="true" provided="false" name="parent" default_profile="0" language="java" parent_name="[null]" enabled="true"/>