summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-15 19:04:35 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-01-15 19:04:35 +0100
commiteee67d858e54897e03090ab87839eec39b8e2454 (patch)
tree2f1a97ebbb065cc5527c7998362cb0e5d87fca4a /sonar-server
parent196238b73cd4723b0a44f9bd437460a91234e693 (diff)
downloadsonarqube-eee67d858e54897e03090ab87839eec39b8e2454.tar.gz
sonarqube-eee67d858e54897e03090ab87839eec39b8e2454.zip
SONAR-4923 Switch "Coding Rules reloaded" with "Coding Rules" (and previous "Coding Rules" become "Old Coding Rules")
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java2
-rw-r--r--sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java39
-rw-r--r--sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java39
-rw-r--r--sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb372
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb446
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb384
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb (renamed from sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb)8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/helpers/rules_configuration_helper.rb11
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb48
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb)36
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb)89
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb)22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb51
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb)26
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb)22
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb (renamed from sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb)20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb36
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb87
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb43
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb26
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb20
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb20
-rw-r--r--sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java48
-rw-r--r--sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java48
-rw-r--r--sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java7
28 files changed, 1084 insertions, 897 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 7c01ff6da0c..97e0e29544c 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -362,6 +362,8 @@ public final class Platform {
servicesContainer.addSingleton(IntegerTypeValidation.class);
servicesContainer.addSingleton(FloatTypeValidation.class);
servicesContainer.addSingleton(BooleanTypeValidation.class);
+ servicesContainer.addSingleton(TextTypeValidation.class);
+ servicesContainer.addSingleton(StringTypeValidation.class);
servicesContainer.addSingleton(StringListTypeValidation.class);
ServerExtensionInstaller extensionRegistrar = servicesContainer.getComponentByType(ServerExtensionInstaller.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java b/sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java
new file mode 100644
index 00000000000..ac33ffd7ac8
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/util/StringTypeValidation.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.sonar.api.PropertyType;
+
+import java.util.List;
+
+public class StringTypeValidation implements TypeValidation {
+
+ @Override
+ public String key() {
+ return PropertyType.STRING.name();
+ }
+
+ @Override
+ public void validate(String value, List<String> options) {
+ // Nothing to do
+ }
+
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java b/sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java
new file mode 100644
index 00000000000..c4e9df5778f
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/util/TextTypeValidation.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.sonar.api.PropertyType;
+
+import java.util.List;
+
+public class TextTypeValidation implements TypeValidation {
+
+ @Override
+ public String key() {
+ return PropertyType.TEXT.name();
+ }
+
+ @Override
+ public void validate(String value, List<String> options) {
+ // Nothing to do
+ }
+
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java b/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java
index 5c28b425714..e3b9e84b080 100644
--- a/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java
+++ b/sonar-server/src/main/java/org/sonar/server/util/TypeValidations.java
@@ -23,6 +23,7 @@ package org.sonar.server.util;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.sonar.api.ServerComponent;
+import org.sonar.server.exceptions.BadRequestException;
import java.util.List;
@@ -40,11 +41,15 @@ public class TypeValidations implements ServerComponent {
}
private TypeValidation findByKey(final String key) {
- return Iterables.find(typeValidationList, new Predicate<TypeValidation>() {
+ TypeValidation typeValidation = Iterables.find(typeValidationList, new Predicate<TypeValidation>() {
@Override
public boolean apply(TypeValidation input) {
return input.key().equals(key);
}
- });
+ }, null);
+ if (typeValidation == null) {
+ throw new BadRequestException(String.format("Type '%s' is not valid.", key));
+ }
+ return typeValidation;
}
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb
deleted file mode 100644
index 13a808a4abb..00000000000
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/new_rules_configuration_controller.rb
+++ /dev/null
@@ -1,372 +0,0 @@
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2013 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube 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.
-#
-# SonarQube 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 this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-require 'cgi'
-require 'java'
-
-class NewRulesConfigurationController < ApplicationController
-
- SECTION=Navigation::SECTION_QUALITY_PROFILES
-
- STATUS_ACTIVE = "ACTIVE"
- STATUS_INACTIVE = "INACTIVE"
-
- ANY_SELECTION = []
- RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
-
- def index
- require_parameters :id
-
- call_backend do
- @profile = Internal.quality_profiles.profile(params[:id].to_i)
- @parent_profile = Internal.quality_profiles.parent(@profile) if @profile.parent()
-
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
- {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}}
-
- init_params
- @criteria_params = criteria_params
- stop_watch = Internal.profiling.start("rules", "BASIC")
-
- @pagination = Api::Pagination.new(params)
- paging = Java::OrgSonarServerQualityprofile::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
-
- criteria = init_criteria
- query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
- if @activation==STATUS_ACTIVE
- result = Internal.quality_profiles.searchProfileRules(query, paging)
- else
- result = Internal.quality_profiles.searchInactiveProfileRules(query, paging)
- end
-
- @pagination.count = result.paging.total
- unless @searchtext.blank?
- if @activation==STATUS_ACTIVE
- @hidden_inactives = Internal.quality_profiles.countProfileRules(query)
- else
- @hidden_actives = Internal.quality_profiles.countInactiveProfileRules(query)
- end
- end
- stop_watch.stop("found #{@pagination.count} rules with criteria #{criteria.to_json}, displaying #{@pagination.per_page} items")
-
- @current_rules = result.rules
-
- @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }
- @select_priority = ANY_SELECTION + RULE_PRIORITIES
- @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
- @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
- [message('rules_configuration.overrides'), 'OVERRIDES']]
- @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
- [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
- [message('rules.status.ready'), Rule::STATUS_READY]]
- @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
- end
- end
-
-
- #
- #
- # POST /rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
- #
- #
- def revert_rule
- verify_post_request
- require_parameters :id, :active_rule_id
-
- active_rule_id = params[:active_rule_id].to_i
- call_backend do
- Internal.quality_profiles.revertActiveRule(active_rule_id)
- end
-
- redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id].to_i, :commit => nil})
- end
-
-
- #
- #
- # POST /rules_configuration/activate_rule?id=<profile id>&rule_id=<rule id>&level=<priority>
- #
- # If the parameter "level" is blank or null, then the rule is removed from the profile.
- #
- #
- def activate_rule
- verify_post_request
- require_parameters :id, :rule_id
-
- rule = nil
- profile_id = params[:id].to_i
- rule_id = params[:rule_id].to_i
- call_backend do
- severity = params[:level]
- if severity.blank?
- # deactivate the rule
- Internal.quality_profiles.deactivateRule(profile_id, rule_id)
- rule = Internal.quality_profiles.findByRule(rule_id)
- else
- # activate the rule
- Internal.quality_profiles.activateRule(profile_id, rule_id, severity)
- rule = Internal.quality_profiles.findByProfileAndRule(profile_id, rule_id)
- end
- end
-
- profile = Internal.quality_profiles.profile(profile_id)
- parent_profile = Internal.quality_profiles.parent(profile)
-
- render :update do |page|
- page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile})
- page.assign('localModifications', true)
- end
- end
-
-
- #
- #
- # GET /rules_configuration/new/<profile id>?rule_id=<rule id>
- #
- #
- def new
- # form to duplicate a rule
- require_parameters :id, :rule_id
- @profile = Internal.quality_profiles.profile(params[:id].to_i)
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
- {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}}
-
- @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
- end
-
- #
- #
- # POST /rules_configuration/create/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
- #
- #
- def create
- verify_post_request
- require_parameters :id, :rule_id
-
- profile_id = params[:id].to_i
- rule_id = params[:rule_id].to_i
- new_rule = nil
- call_backend do
- new_rule = Internal.quality_profiles.createRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
- end
-
- if new_rule
- redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{new_rule.name()}\"", :rule_activation => 'INACTIVE', "plugins[]" => new_rule.repositoryKey()
- else
- redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
- end
- end
-
-
- # deprecated since 2.3
- def export
- redirect_to request.query_parameters.merge({:controller => 'profiles', :action => 'export'})
- end
-
- #
- #
- # GET /rules_configuration/new/<profile id>?rule_id=<rule id>
- #
- #
- def edit
- # form to edit a rule
- require_parameters :id, :rule_id
-
- call_backend do
- @profile = Internal.quality_profiles.profile(params[:id].to_i)
- @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
- if @rule.ruleId().nil?
- redirect_to :action => 'index', :id => params[:id]
- else
- @parent_rule = Internal.quality_profiles.rule(@rule.ruleId())
- @active_rules = Internal.quality_profiles.countActiveRules(@rule)
- end
- end
- end
-
- #
- #
- # POST /rules_configuration/update/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
- #
- #
- def update
- verify_post_request
- require_parameters :id, :rule_id
-
- profile_id = params[:id].to_i
- rule_id = params[:rule_id].to_i
- rule = nil
- call_backend do
- rule = Internal.quality_profiles.updateRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
- end
-
- if rule
- redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{rule.name()}\"", :rule_activation => '', "plugins[]" => rule.repositoryKey()
- else
- redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
- end
- end
-
-
- #
- #
- # POST /rules_configuration/delete/<profile id>?rule_id=<rule id>
- #
- #
- def delete
- verify_post_request
- require_parameters :id, :rule_id
-
- call_backend do
- Internal.quality_profiles.deleteRule(params[:rule_id].to_i)
- flash[:notice]=message('rules_configuration.rule_deleted')
- end
- redirect_to :action => 'index', :id => params[:id]
- end
-
- #
- #
- # POST /rules_configuration/bulk_edit?id=<profile id>&&bulk_action=<action>
- #
- # Values of the parameter 'bulk_action' :
- # - 'activate' : activate all the selected rules with their default priority
- # - 'deactivate' : deactivate all the selected rules
- #
- #
- def bulk_edit
- verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters :id, :bulk_action
-
- stop_watch = Internal.profiling.start("rules", "BASIC")
- @profile = Internal.quality_profiles.profile(params[:id].to_i)
- init_params
- criteria = init_criteria
- query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
- activation = params[:rule_activation] || STATUS_ACTIVE
- case params[:bulk_action]
- when 'activate'
- count = Internal.quality_profiles.bulkActivateRule(query)
- stop_watch.stop("Activate #{count} rules with criteria #{criteria.to_json}")
-
- flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
- activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
-
- when 'deactivate'
- count = Internal.quality_profiles.bulkDeactivateRule(query)
- stop_watch.stop("Deactivate #{count} rules with criteria #{criteria.to_json}")
-
- flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
- activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
- end
-
- url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :id => @profile.id, :rule_activation => activation})
- redirect_to url_parameters
- end
-
-
- def update_param
- verify_post_request
-
- access_denied unless has_role?(:profileadmin)
- require_parameters :param_id, :active_rule_id, :profile_id
-
- rule = nil
- profile_id = params[:profile_id].to_i
- active_rule_id = params[:active_rule_id].to_i
- call_backend do
- Internal.quality_profiles.updateActiveRuleParam(active_rule_id, params[:param_id], params[:value])
- rule = Internal.quality_profiles.findByActiveRuleId(active_rule_id)
- end
-
- profile = Internal.quality_profiles.profile(profile_id)
- parent_profile = Internal.quality_profiles.parent(profile)
- render :partial => 'rule', :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile}
- end
-
-
- def update_rule_note
- verify_post_request
- require_parameters :rule_id, :active_rule_id
-
- rule = nil
- call_backend do
- rule = Internal.quality_profiles.updateRuleNote(params[:active_rule_id].to_i, params[:rule_id].to_i, params[:text])
- end
- render :partial => 'rule_note', :locals => {:rule => rule}
- end
-
-
- def update_active_rule_note
- verify_post_request
- require_parameters :active_rule_id, :note
-
- rule = nil
- call_backend do
- rule = Internal.quality_profiles.updateActiveRuleNote(params[:active_rule_id].to_i, params[:note])
- end
- render :partial => 'active_rule_note', :locals => {:rule => rule}
- end
-
-
- def delete_active_rule_note
- verify_post_request
- require_parameters :active_rule_id
-
- rule = nil
- call_backend do
- rule = Internal.quality_profiles.deleteActiveRuleNote(params[:active_rule_id].to_i)
- end
- render :partial => 'active_rule_note', :locals => {:rule => rule}
- end
-
-
- private
-
- def init_params
- @id = params[:id]
- @priorities = filter_any(params[:priorities]) || ['']
- @repositories = filter_any(params[:repositories]) || ['']
- @activation = params[:rule_activation] || STATUS_ACTIVE
- @inheritance = params[:inheritance] || 'any'
- @status = params[:status]
- @sort_by = !params[:sort_by].blank? ? params[:sort_by] : Rule::SORT_BY_RULE_NAME
- @searchtext = params[:searchtext]
- end
-
- def filter_any(array)
- if array && array.size>1 && array.include?('')
- array=[''] #keep only 'any'
- end
- array
- end
-
- def init_criteria()
- {"profileId" => @profile.id.to_i, "activation" => @activation, "severities" => @priorities, "inheritance" => @inheritance, "statuses" => @status,
- "repositoryKeys" => @repositories, "nameOrKey" => @searchtext, "include_parameters_and_notes" => true, "language" => @profile.language, "sort_by" => @sort_by}
- end
-
- def criteria_params
- new_params = params.clone
- new_params.delete('controller')
- new_params.delete('action')
- new_params
- end
-
-end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb
new file mode 100644
index 00000000000..ee3faeba0aa
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/old_rules_configuration_controller.rb
@@ -0,0 +1,446 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+require 'cgi'
+
+class OldRulesConfigurationController < ApplicationController
+
+ SECTION=Navigation::SECTION_QUALITY_PROFILES
+
+ STATUS_ACTIVE = "ACTIVE"
+ STATUS_INACTIVE = "INACTIVE"
+
+ ANY_SELECTION = []
+ RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
+
+ def index
+ require_parameters :id
+
+ @profile = Profile.find(params[:id])
+ add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+ {:name => @profile.name, :url => {:controller => 'old_rules_configuration', :action => 'index', :id => @profile.id}}
+
+ init_params()
+
+ @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
+ @select_priority = ANY_SELECTION + RULE_PRIORITIES
+ @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
+ @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
+ [message('rules_configuration.overrides'), 'OVERRIDES']]
+ @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
+ [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
+ [message('rules.status.ready'), Rule::STATUS_READY]]
+ @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
+
+ begin
+ stop_watch = Internal.profiling.start("rules", "BASIC")
+
+ criteria = {
+ :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status,
+ :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by}
+ @rules = Rule.search(java_facade, criteria)
+
+ unless @searchtext.blank?
+ if @activation==STATUS_ACTIVE
+ @hidden_inactives = Rule.search(java_facade, {
+ :profile => @profile, :activation => STATUS_INACTIVE, :priorities => @priorities, :status => @status,
+ :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+
+ elsif @activation==STATUS_INACTIVE
+ @hidden_actives = Rule.search(java_facade, {
+ :profile => @profile, :activation => STATUS_ACTIVE, :priorities => @priorities, :status => @status,
+ :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+ end
+ end
+
+ stop_watch.stop("found #{@rules.size} rules with criteria #{criteria.to_json}")
+ rescue
+ @rules = []
+ end
+ @pagination = Api::Pagination.new(params)
+ @pagination.count = @rules.size
+ @current_rules = @rules[@pagination.offset, @pagination.limit]
+ end
+
+
+ #
+ #
+ # POST /old_rules_configuration/revert_rule?id=<profile id>&active_rule_id=<active rule id>
+ #
+ #
+ def revert_rule
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :active_rule_id
+ id = params[:id].to_i
+ rule_id = params[:active_rule_id].to_i
+ java_facade.revertRule(id, rule_id, current_user.name)
+ redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id], :commit => nil})
+ end
+
+
+ #
+ #
+ # POST /old_rules_configuration/activate_rule?id=<profile id>&rule_id=<rule id>&level=<priority>
+ #
+ # If the parameter "level" is blank or null, then the rule is removed from the profile.
+ #
+ #
+ def activate_rule
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ profile = Profile.find(params[:id].to_i)
+ if profile
+ rule=Rule.first(:conditions => ["id = ? and status <> ?", params[:rule_id].to_i, Rule::STATUS_REMOVED])
+ priority=params[:level]
+
+ active_rule=profile.active_by_rule_id(rule.id)
+ if priority.blank?
+ # deactivate the rule
+ if active_rule
+ java_facade.ruleDeactivated(profile.id, active_rule.id, current_user.name)
+ active_rule.destroy
+ active_rule=nil
+ end
+ else
+ # activate the rule
+ activated = false
+ if active_rule.nil?
+ active_rule = ActiveRule.new(:profile_id => profile.id, :rule => rule)
+ rule.parameters.select { |p| p.default_value.present? }.each do |p|
+ active_rule.active_rule_parameters.build(:rules_parameter => p, :value => p.default_value, :rules_parameter_key => p.name)
+ end
+ activated = true
+ end
+ old_severity = active_rule.failure_level
+ active_rule.failure_level=Sonar::RulePriority.id(priority)
+ active_rule.save!
+ if activated
+ java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
+ else
+ java_facade.ruleSeverityChanged(profile.id, active_rule.id, old_severity, active_rule.failure_level, current_user.name)
+ end
+ end
+ if active_rule
+ active_rule.reload
+ end
+
+ render :update do |page|
+ page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:profile => profile, :rule => rule, :active_rule => active_rule})
+ page.assign('localModifications', true)
+ end
+ end
+ end
+
+
+ #
+ #
+ # GET /old_rules_configuration/new/<profile id>?rule_id=<rule id>
+ #
+ #
+ def new
+ # form to duplicate a rule
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ @profile = Profile.find(params[:id].to_i)
+ add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
+
+ @rule = Rule.find(params[:rule_id])
+ end
+
+ #
+ #
+ # POST /old_rules_configuration/create/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
+ #
+ #
+ def create
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ profile = Profile.find(params[:id].to_i)
+ template=Rule.find(params[:rule_id])
+ # TODO Call Internal.rule.create(...) ?
+ rule=Rule.create(params[:rule].merge(
+ {
+ :priority => Sonar::RulePriority.id(params[:rule][:priority]),
+ :parent_id => template.id,
+ :plugin_name => template.plugin_name,
+ :cardinality => 'SINGLE',
+ :plugin_rule_key => "#{template.plugin_rule_key}_#{Time.now.to_i}",
+ :plugin_config_key => template.plugin_config_key,
+ :status => Rule::STATUS_READY,
+ :language => profile.language
+ }
+ ))
+
+ template.parameters.each do |template_parameter|
+ rule.rules_parameters.build(:name => template_parameter.name, :param_type => template_parameter.param_type, :description => template_parameter.description,
+ :default_value => params[:rule_param][template_parameter.name])
+ end
+
+ if rule.save
+ Internal.rules.saveOrUpdate(rule.id)
+ redirect_to :action => 'index', :id => profile.id, :searchtext => "\"#{rule.name}\"", :rule_activation => 'INACTIVE', "plugins[]" => rule.plugin_name
+
+ else
+ flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
+ redirect_to :action => 'new', :id => profile.id, :rule_id => params[:rule_id]
+ end
+ end
+
+
+ # deprecated since 2.3
+ def export
+ redirect_to request.query_parameters.merge({:controller => 'profiles', :action => 'export'})
+ end
+
+ #
+ #
+ # GET /old_rules_configuration/new/<profile id>?rule_id=<rule id>
+ #
+ #
+ def edit
+ # form to edit a rule
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ @profile = Profile.find(params[:id])
+ @rule = Rule.find(params[:rule_id])
+ if !@rule.editable?
+ redirect_to :action => 'index', :id => params[:id]
+ end
+ end
+
+ #
+ #
+ # POST /old_rules_configuration/update/<profile id>?rule_id=<rule id>&rule[name]=<new name>&...
+ #
+ #
+ def update
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ rule=Rule.find(params[:rule_id])
+ if rule.editable?
+ rule.name=params[:rule][:name]
+ rule.description=params[:rule][:description]
+ rule.priority=Sonar::RulePriority.id(params[:rule][:priority])
+ rule.parameters.each do |parameter|
+ parameter.default_value=params[:rule_param][parameter.name]
+ parameter.save
+ end
+ if rule.save
+ Internal.rules.saveOrUpdate(rule.id)
+ redirect_to :action => 'index', :id => params[:id], :searchtext => "\"#{rule.name}\"", :rule_activation => '', "plugins[]" => rule.plugin_name
+ else
+ flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
+ redirect_to :action => 'new', :id => params[:id], :rule_id => params[:rule_id]
+ end
+ else
+ flash[:error]='Unknown rule'
+ redirect_to :action => 'index', :id => params[:id]
+ end
+ end
+
+
+ #
+ #
+ # POST /old_rules_configuration/delete/<profile id>?rule_id=<rule id>
+ #
+ #
+ def delete
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :rule_id
+ rule=Rule.find(params[:rule_id])
+ if rule.editable?
+ rule.status=Rule::STATUS_REMOVED
+ rule.save
+ Internal.rules.saveOrUpdate(rule.id)
+
+ # it's mandatory to execute 'destroy_all' but not 'delete_all' because active_rule_parameters must
+ # also be destroyed in cascade.
+ ActiveRule.destroy_all("rule_id=#{rule.id}")
+ flash[:notice]=message('rules_configuration.rule_deleted')
+ else
+ flash[:error]=message('rules_configuration.unknown_rule')
+ end
+ redirect_to :action => 'index', :id => params[:id]
+ end
+
+ #
+ #
+ # POST /old_rules_configuration/bulk_edit?id=<profile id>&bulk_rule_ids=<list of rule ids>&bulk_action=<action>
+ #
+ # Values of the parameter 'bulk_action' :
+ # - 'activate' : activate all the selected rules with their default priority
+ # - 'deactivate' : deactivate all the selected rules
+ #
+ #
+ def bulk_edit
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :id, :bulk_rule_ids, :bulk_action
+ profile = Profile.find(params[:id].to_i)
+ rule_ids = params[:bulk_rule_ids].split(',').map { |id| id.to_i }
+ activation=params[:rule_activation] || STATUS_ACTIVE
+
+ case params[:bulk_action]
+ when 'activate'
+ count=activate_rules(profile, rule_ids)
+ flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
+ activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
+
+ when 'deactivate'
+ count=deactivate_rules(profile, rule_ids)
+ flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
+ activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
+ end
+
+ url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :bulk_rule_ids => nil, :id => profile.id, :rule_activation => activation})
+ redirect_to url_parameters
+ end
+
+
+ def update_param
+ verify_post_request
+ #access_denied unless has_role?(:profileadmin)
+ require_parameters :profile_id, :param_id, :active_rule_id
+
+ profile = Profile.find(params[:profile_id].to_i)
+ rule_param = RulesParameter.find(params[:param_id].to_i)
+ active_rule = ActiveRule.find(params[:active_rule_id].to_i)
+ # As the active param can be null, we should not raise a RecordNotFound exception when it's not found (as it would be done when using find(:id) function)
+ active_param = ActiveRuleParameter.find_by_id(params[:id].to_i) if params[:id].to_i > 0
+
+ value = params[:value]
+ if value != ""
+ active_param = ActiveRuleParameter.new(:rules_parameter => rule_param, :active_rule => active_rule, :rules_parameter_key => rule_param.name) if active_param.nil?
+ old_value = active_param.value
+ active_param.value = value
+ if active_param.save! && active_param.valid?
+ active_param.reload
+ java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, value, current_user.name)
+ end
+ elsif !active_param.nil?
+ old_value = active_param.value
+ active_param.destroy
+ java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, nil, current_user.name)
+ end
+ # let's reload the active rule
+ active_rule = ActiveRule.find(params[:active_rule_id].to_i)
+ render :partial => 'rule', :locals => {:profile => profile, :rule => active_rule.rule, :active_rule => active_rule}
+ end
+
+
+ def update_rule_note
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :rule_id
+ rule = Rule.find(params[:rule_id])
+ note = rule.note
+ unless note
+ note = RuleNote.new({:rule => rule})
+ # set the note on the rule to avoid reloading the rule
+ rule.note = note
+ end
+ note.text = params[:text]
+ note.user_login = current_user.login
+ note.save!
+ render :partial => 'rule_note', :locals => {:rule => rule}
+ end
+
+
+ def update_active_rule_note
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :active_rule_id, :note
+ active_rule = ActiveRule.find(params[:active_rule_id])
+ note = active_rule.note
+ unless note
+ note = ActiveRuleNote.new({:active_rule => active_rule})
+ # set the note on the rule to avoid reloading the rule
+ active_rule.note = note
+ end
+ note.text = params[:note]
+ note.user_login = current_user.login
+ note.save!
+ render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+ end
+
+
+ def delete_active_rule_note
+ verify_post_request
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :active_rule_id
+ active_rule = ActiveRule.find(params[:active_rule_id])
+ active_rule.note.destroy if active_rule.note
+ active_rule.note = nil
+ render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+ end
+
+
+ private
+
+ # return the number of newly activated rules
+ def activate_rules(profile, rule_ids)
+ count=0
+ rule_ids_to_activate=(rule_ids - profile.active_rules.map { |ar| ar.rule_id })
+ unless rule_ids_to_activate.empty?
+ rules_to_activate=Rule.all(:conditions => ["status <> ? AND id IN (?)", Rule::STATUS_REMOVED, rule_ids_to_activate])
+ count = rules_to_activate.size
+ rules_to_activate.each do |rule|
+ active_rule = profile.active_rules.create(:rule => rule, :failure_level => rule.priority)
+ java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
+ end
+ end
+ count
+ end
+
+ def deactivate_rules(profile, rule_ids)
+ count=0
+ profile.active_rules.each do |ar|
+ if rule_ids.include?(ar.rule_id) && !ar.inheritance.present?
+ java_facade.ruleDeactivated(profile.id, ar.id, current_user.name)
+ ar.destroy
+ count+=1
+ end
+ end
+ count
+ end
+
+ def init_params
+ @id = params[:id]
+ @priorities = filter_any(params[:priorities]) || ['']
+ @repositories = filter_any(params[:repositories]) || ['']
+ @activation = params[:rule_activation] || STATUS_ACTIVE
+ @inheritance = params[:inheritance] || 'any'
+ @status = params[:status]
+ @sort_by = !params[:sort_by].blank? ? params[:sort_by] : Rule::SORT_BY_RULE_NAME
+ @searchtext = params[:searchtext]
+ end
+
+ def filter_any(array)
+ if array && array.size>1 && array.include?('')
+ array=[''] #keep only 'any'
+ end
+ array
+ end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
index 5c5a24dcdf3..74ab0442349 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
@@ -18,6 +18,7 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
require 'cgi'
+require 'java'
class RulesConfigurationController < ApplicationController
@@ -32,50 +33,50 @@ class RulesConfigurationController < ApplicationController
def index
require_parameters :id
- @profile = Profile.find(params[:id])
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
- {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
-
- init_params()
+ call_backend do
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ @parent_profile = Internal.quality_profiles.parent(@profile) if @profile.parent()
- @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
- @select_priority = ANY_SELECTION + RULE_PRIORITIES
- @select_activation = [[message('any'), 'any'], [message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
- @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
- [message('rules_configuration.overrides'), 'OVERRIDES']]
- @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
- [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
- [message('rules.status.ready'), Rule::STATUS_READY]]
- @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
+ add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+ {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
- begin
+ init_params
+ @criteria_params = criteria_params
stop_watch = Internal.profiling.start("rules", "BASIC")
- criteria = {
- :profile => @profile, :activation => @activation, :priorities => @priorities, :inheritance => @inheritance, :status => @status,
- :repositories => @repositories, :searchtext => @searchtext, :include_parameters_and_notes => true, :language => @profile.language, :sort_by => @sort_by}
- @rules = Rule.search(java_facade, criteria)
+ @pagination = Api::Pagination.new(params)
+ paging = Java::OrgSonarServerQualityprofile::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
+ criteria = init_criteria
+ query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
+ if @activation==STATUS_ACTIVE
+ result = Internal.quality_profiles.searchProfileRules(query, paging)
+ else
+ result = Internal.quality_profiles.searchInactiveProfileRules(query, paging)
+ end
+
+ @pagination.count = result.paging.total
unless @searchtext.blank?
- if @activation==STATUS_ACTIVE
- @hidden_inactives = Rule.search(java_facade, {
- :profile => @profile, :activation => STATUS_INACTIVE, :priorities => @priorities, :status => @status,
- :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
-
- elsif @activation==STATUS_INACTIVE
- @hidden_actives = Rule.search(java_facade, {
- :profile => @profile, :activation => STATUS_ACTIVE, :priorities => @priorities, :status => @status,
- :repositories => @repositories, :language => @profile.language, :searchtext => @searchtext, :include_parameters_and_notes => false}).size
+ if @activation == STATUS_ACTIVE
+ @hidden_inactives = Internal.quality_profiles.countInactiveProfileRules(query)
+ else
+ @hidden_actives = Internal.quality_profiles.countProfileRules(query)
end
end
-
- stop_watch.stop("found #{@rules.size} rules with criteria #{criteria.to_json}")
- rescue
- @rules = []
+ stop_watch.stop("found #{@pagination.count} rules with criteria #{criteria.to_json}, displaying #{@pagination.per_page} items")
+
+ @current_rules = result.rules
+
+ @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
+ @select_priority = ANY_SELECTION + RULE_PRIORITIES
+ @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
+ @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
+ [message('rules_configuration.overrides'), 'OVERRIDES']]
+ @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
+ [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
+ [message('rules.status.ready'), Rule::STATUS_READY]]
+ @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
end
- @pagination = Api::Pagination.new(params)
- @pagination.count = @rules.size
- @current_rules = @rules[@pagination.offset, @pagination.limit]
end
@@ -86,12 +87,14 @@ class RulesConfigurationController < ApplicationController
#
def revert_rule
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :active_rule_id
- id = params[:id].to_i
- rule_id = params[:active_rule_id].to_i
- java_facade.revertRule(id, rule_id, current_user.name)
- redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id], :commit => nil})
+
+ active_rule_id = params[:active_rule_id].to_i
+ call_backend do
+ Internal.quality_profiles.revertActiveRule(active_rule_id)
+ end
+
+ redirect_to request.query_parameters.merge({:action => 'index', :id => params[:id].to_i, :commit => nil})
end
@@ -104,48 +107,30 @@ class RulesConfigurationController < ApplicationController
#
def activate_rule
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- profile = Profile.find(params[:id].to_i)
- if profile
- rule=Rule.first(:conditions => ["id = ? and status <> ?", params[:rule_id].to_i, Rule::STATUS_REMOVED])
- priority=params[:level]
- active_rule=profile.active_by_rule_id(rule.id)
- if priority.blank?
+ rule = nil
+ profile_id = params[:id].to_i
+ rule_id = params[:rule_id].to_i
+ call_backend do
+ severity = params[:level]
+ if severity.blank?
# deactivate the rule
- if active_rule
- java_facade.ruleDeactivated(profile.id, active_rule.id, current_user.name)
- active_rule.destroy
- active_rule=nil
- end
+ Internal.quality_profiles.deactivateRule(profile_id, rule_id)
+ rule = Internal.quality_profiles.findByRule(rule_id)
else
# activate the rule
- activated = false
- if active_rule.nil?
- active_rule = ActiveRule.new(:profile_id => profile.id, :rule => rule)
- rule.parameters.select { |p| p.default_value.present? }.each do |p|
- active_rule.active_rule_parameters.build(:rules_parameter => p, :value => p.default_value, :rules_parameter_key => p.name)
- end
- activated = true
- end
- old_severity = active_rule.failure_level
- active_rule.failure_level=Sonar::RulePriority.id(priority)
- active_rule.save!
- if activated
- java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
- else
- java_facade.ruleSeverityChanged(profile.id, active_rule.id, old_severity, active_rule.failure_level, current_user.name)
- end
- end
- if active_rule
- active_rule.reload
+ Internal.quality_profiles.activateRule(profile_id, rule_id, severity)
+ rule = Internal.quality_profiles.findByProfileAndRule(profile_id, rule_id)
end
+ end
- render :update do |page|
- page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:profile => profile, :rule => rule, :active_rule => active_rule})
- page.assign('localModifications', true)
- end
+ profile = Internal.quality_profiles.profile(profile_id)
+ parent_profile = Internal.quality_profiles.parent(profile)
+
+ render :update do |page|
+ page.replace_html("rule_#{rule.id}", :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile})
+ page.assign('localModifications', true)
end
end
@@ -157,12 +142,12 @@ class RulesConfigurationController < ApplicationController
#
def new
# form to duplicate a rule
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- @profile = Profile.find(params[:id].to_i)
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+ {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
- @rule = Rule.find(params[:rule_id])
+ @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
end
#
@@ -172,36 +157,19 @@ class RulesConfigurationController < ApplicationController
#
def create
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- profile = Profile.find(params[:id].to_i)
- template=Rule.find(params[:rule_id])
- # TODO Call Internal.rule.create(...) ?
- rule=Rule.create(params[:rule].merge(
- {
- :priority => Sonar::RulePriority.id(params[:rule][:priority]),
- :parent_id => template.id,
- :plugin_name => template.plugin_name,
- :cardinality => 'SINGLE',
- :plugin_rule_key => "#{template.plugin_rule_key}_#{Time.now.to_i}",
- :plugin_config_key => template.plugin_config_key,
- :status => Rule::STATUS_READY,
- :language => profile.language
- }
- ))
-
- template.parameters.each do |template_parameter|
- rule.rules_parameters.build(:name => template_parameter.name, :param_type => template_parameter.param_type, :description => template_parameter.description,
- :default_value => params[:rule_param][template_parameter.name])
- end
- if rule.save
- Internal.rules.saveOrUpdate(rule.id)
- redirect_to :action => 'index', :id => profile.id, :searchtext => "\"#{rule.name}\"", :rule_activation => 'INACTIVE', "plugins[]" => rule.plugin_name
+ profile_id = params[:id].to_i
+ rule_id = params[:rule_id].to_i
+ new_rule = nil
+ call_backend do
+ new_rule = Internal.quality_profiles.createRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
+ end
+ if new_rule
+ redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{new_rule.name()}\"", :rule_activation => 'INACTIVE', "plugins[]" => new_rule.repositoryKey()
else
- flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
- redirect_to :action => 'new', :id => profile.id, :rule_id => params[:rule_id]
+ redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
end
end
@@ -218,12 +186,17 @@ class RulesConfigurationController < ApplicationController
#
def edit
# form to edit a rule
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- @profile = Profile.find(params[:id])
- @rule = Rule.find(params[:rule_id])
- if !@rule.editable?
- redirect_to :action => 'index', :id => params[:id]
+
+ call_backend do
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
+ if @rule.ruleId().nil?
+ redirect_to :action => 'index', :id => params[:id]
+ else
+ @parent_rule = Internal.quality_profiles.rule(@rule.ruleId())
+ @active_rules = Internal.quality_profiles.countActiveRules(@rule)
+ end
end
end
@@ -234,27 +207,19 @@ class RulesConfigurationController < ApplicationController
#
def update
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- rule=Rule.find(params[:rule_id])
- if rule.editable?
- rule.name=params[:rule][:name]
- rule.description=params[:rule][:description]
- rule.priority=Sonar::RulePriority.id(params[:rule][:priority])
- rule.parameters.each do |parameter|
- parameter.default_value=params[:rule_param][parameter.name]
- parameter.save
- end
- if rule.save
- Internal.rules.saveOrUpdate(rule.id)
- redirect_to :action => 'index', :id => params[:id], :searchtext => "\"#{rule.name}\"", :rule_activation => '', "plugins[]" => rule.plugin_name
- else
- flash[:error]=message('rules_configuration.rule_not_valid_message_x', :params => rule.errors.full_messages.join('<br/>'))
- redirect_to :action => 'new', :id => params[:id], :rule_id => params[:rule_id]
- end
+
+ profile_id = params[:id].to_i
+ rule_id = params[:rule_id].to_i
+ rule = nil
+ call_backend do
+ rule = Internal.quality_profiles.updateRule(rule_id, params[:rule][:name], params[:rule][:priority], params[:rule][:description], params[:rule_param])
+ end
+
+ if rule
+ redirect_to :action => 'index', :id => profile_id, :searchtext => "\"#{rule.name()}\"", :rule_activation => '', "plugins[]" => rule.repositoryKey()
else
- flash[:error]='Unknown rule'
- redirect_to :action => 'index', :id => params[:id]
+ redirect_to :action => 'new', :id => profile_id, :rule_id => rule_id
end
end
@@ -266,27 +231,18 @@ class RulesConfigurationController < ApplicationController
#
def delete
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- rule=Rule.find(params[:rule_id])
- if rule.editable?
- rule.status=Rule::STATUS_REMOVED
- rule.save
- Internal.rules.saveOrUpdate(rule.id)
-
- # it's mandatory to execute 'destroy_all' but not 'delete_all' because active_rule_parameters must
- # also be destroyed in cascade.
- ActiveRule.destroy_all("rule_id=#{rule.id}")
+
+ call_backend do
+ Internal.quality_profiles.deleteRule(params[:rule_id].to_i)
flash[:notice]=message('rules_configuration.rule_deleted')
- else
- flash[:error]=message('rules_configuration.unknown_rule')
end
redirect_to :action => 'index', :id => params[:id]
end
#
#
- # POST /rules_configuration/bulk_edit?id=<profile id>&bulk_rule_ids=<list of rule ids>&bulk_action=<action>
+ # POST /rules_configuration/bulk_edit?id=<profile id>&&bulk_action=<action>
#
# Values of the parameter 'bulk_action' :
# - 'activate' : activate all the selected rules with their default priority
@@ -296,134 +252,92 @@ class RulesConfigurationController < ApplicationController
def bulk_edit
verify_post_request
access_denied unless has_role?(:profileadmin)
- require_parameters :id, :bulk_rule_ids, :bulk_action
- profile = Profile.find(params[:id].to_i)
- rule_ids = params[:bulk_rule_ids].split(',').map { |id| id.to_i }
- activation=params[:rule_activation] || STATUS_ACTIVE
-
+ require_parameters :id, :bulk_action
+
+ stop_watch = Internal.profiling.start("rules", "BASIC")
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ init_params
+ criteria = init_criteria
+ query = Java::OrgSonarServerRule::ProfileRuleQuery::parse(criteria.to_java)
+ activation = params[:rule_activation] || STATUS_ACTIVE
case params[:bulk_action]
when 'activate'
- count=activate_rules(profile, rule_ids)
+ count = Internal.quality_profiles.bulkActivateRule(query)
+ stop_watch.stop("Activate #{count} rules with criteria #{criteria.to_json}")
+
flash[:notice]=message('rules_configuration.x_rules_have_been_activated', :params => count)
activation=STATUS_ACTIVE if activation==STATUS_INACTIVE
when 'deactivate'
- count=deactivate_rules(profile, rule_ids)
+ count = Internal.quality_profiles.bulkDeactivateRule(query)
+ stop_watch.stop("Deactivate #{count} rules with criteria #{criteria.to_json}")
+
flash[:notice]=message('rules_configuration.x_rules_have_been_deactivated', :params => count)
activation=STATUS_INACTIVE if activation==STATUS_ACTIVE
end
- url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :bulk_rule_ids => nil, :id => profile.id, :rule_activation => activation})
+ url_parameters=request.query_parameters.merge({:action => 'index', :bulk_action => nil, :id => @profile.id, :rule_activation => activation})
redirect_to url_parameters
end
def update_param
verify_post_request
- #access_denied unless has_role?(:profileadmin)
- require_parameters :profile_id, :param_id, :active_rule_id
-
- profile = Profile.find(params[:profile_id].to_i)
- rule_param = RulesParameter.find(params[:param_id].to_i)
- active_rule = ActiveRule.find(params[:active_rule_id].to_i)
- # As the active param can be null, we should not raise a RecordNotFound exception when it's not found (as it would be done when using find(:id) function)
- active_param = ActiveRuleParameter.find_by_id(params[:id].to_i) if params[:id].to_i > 0
-
- value = params[:value]
- if value != ""
- active_param = ActiveRuleParameter.new(:rules_parameter => rule_param, :active_rule => active_rule, :rules_parameter_key => rule_param.name) if active_param.nil?
- old_value = active_param.value
- active_param.value = value
- if active_param.save! && active_param.valid?
- active_param.reload
- java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, value, current_user.name)
- end
- elsif !active_param.nil?
- old_value = active_param.value
- active_param.destroy
- java_facade.ruleParamChanged(profile.id, active_rule.id, rule_param.name, old_value, nil, current_user.name)
+
+ access_denied unless has_role?(:profileadmin)
+ require_parameters :param_id, :active_rule_id, :profile_id
+
+ rule = nil
+ profile_id = params[:profile_id].to_i
+ active_rule_id = params[:active_rule_id].to_i
+ call_backend do
+ Internal.quality_profiles.updateActiveRuleParam(active_rule_id, params[:param_id], params[:value])
+ rule = Internal.quality_profiles.findByActiveRuleId(active_rule_id)
end
- # let's reload the active rule
- active_rule = ActiveRule.find(params[:active_rule_id].to_i)
- render :partial => 'rule', :locals => {:profile => profile, :rule => active_rule.rule, :active_rule => active_rule}
+
+ profile = Internal.quality_profiles.profile(profile_id)
+ parent_profile = Internal.quality_profiles.parent(profile)
+ render :partial => 'rule', :locals => {:rule => rule, :profile => profile, :parent_profile => parent_profile}
end
def update_rule_note
verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters :rule_id
- rule = Rule.find(params[:rule_id])
- note = rule.note
- unless note
- note = RuleNote.new({:rule => rule})
- # set the note on the rule to avoid reloading the rule
- rule.note = note
+ require_parameters :rule_id, :active_rule_id
+
+ rule = nil
+ call_backend do
+ rule = Internal.quality_profiles.updateRuleNote(params[:active_rule_id].to_i, params[:rule_id].to_i, params[:text])
end
- note.text = params[:text]
- note.user_login = current_user.login
- note.save!
render :partial => 'rule_note', :locals => {:rule => rule}
end
def update_active_rule_note
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :active_rule_id, :note
- active_rule = ActiveRule.find(params[:active_rule_id])
- note = active_rule.note
- unless note
- note = ActiveRuleNote.new({:active_rule => active_rule})
- # set the note on the rule to avoid reloading the rule
- active_rule.note = note
+
+ rule = nil
+ call_backend do
+ rule = Internal.quality_profiles.updateActiveRuleNote(params[:active_rule_id].to_i, params[:note])
end
- note.text = params[:note]
- note.user_login = current_user.login
- note.save!
- render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
+ render :partial => 'active_rule_note', :locals => {:rule => rule}
end
def delete_active_rule_note
verify_post_request
- access_denied unless has_role?(:profileadmin)
require_parameters :active_rule_id
- active_rule = ActiveRule.find(params[:active_rule_id])
- active_rule.note.destroy if active_rule.note
- active_rule.note = nil
- render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => active_rule.rules_profile}
- end
-
- private
-
- # return the number of newly activated rules
- def activate_rules(profile, rule_ids)
- count=0
- rule_ids_to_activate=(rule_ids - profile.active_rules.map { |ar| ar.rule_id })
- unless rule_ids_to_activate.empty?
- rules_to_activate=Rule.all(:conditions => ["status <> ? AND id IN (?)", Rule::STATUS_REMOVED, rule_ids_to_activate])
- count = rules_to_activate.size
- rules_to_activate.each do |rule|
- active_rule = profile.active_rules.create(:rule => rule, :failure_level => rule.priority)
- java_facade.ruleActivated(profile.id, active_rule.id, current_user.name)
- end
+ rule = nil
+ call_backend do
+ rule = Internal.quality_profiles.deleteActiveRuleNote(params[:active_rule_id].to_i)
end
- count
+ render :partial => 'active_rule_note', :locals => {:rule => rule}
end
- def deactivate_rules(profile, rule_ids)
- count=0
- profile.active_rules.each do |ar|
- if rule_ids.include?(ar.rule_id) && !ar.inheritance.present?
- java_facade.ruleDeactivated(profile.id, ar.id, current_user.name)
- ar.destroy
- count+=1
- end
- end
- count
- end
+
+ private
def init_params
@id = params[:id]
@@ -443,4 +357,16 @@ class RulesConfigurationController < ApplicationController
array
end
+ def init_criteria()
+ {"profileId" => @profile.id.to_i, "activation" => @activation, "severities" => @priorities, "inheritance" => @inheritance, "statuses" => @status,
+ "repositoryKeys" => @repositories, "nameOrKey" => @searchtext, "include_parameters_and_notes" => true, "language" => @profile.language, "sort_by" => @sort_by}
+ end
+
+ def criteria_params
+ new_params = params.clone
+ new_params.delete('controller')
+ new_params.delete('action')
+ new_params
+ end
+
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb
index 448c873bf49..e66d9fe0d4d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/new_rules_configuration_helper.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/old_rules_configuration_helper.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-module NewRulesConfigurationHelper
+module OldRulesConfigurationHelper
include PropertiesHelper
PARAM_TYPE_STRING_LIST = "s{}"
@@ -47,10 +47,10 @@ module NewRulesConfigurationHelper
""
end
- def param_value_input(rule, parameter, value, options = {})
- type = type_with_compatibility(parameter.type().to_s)
+ def param_value_input(parameter, value, options = {})
+ type=type_with_compatibility(parameter.param_type)
name = options[:name] || 'value'
- property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id().to_s}#{parameter.key().to_s}", :size => options[:size] }.update(options)
+ property_input_field name, type, value, 'WIDGET', {:id => parameter.id, :size => options[:size] }.update(options)
end
def is_set(type)
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 f93ce912fc1..2a1c0dd9301 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
@@ -47,10 +47,10 @@ module RulesConfigurationHelper
""
end
- def param_value_input(parameter, value, options = {})
- type=type_with_compatibility(parameter.param_type)
+ def param_value_input(rule, parameter, value, options = {})
+ type = type_with_compatibility(parameter.type().to_s)
name = options[:name] || 'value'
- property_input_field name, type, value, 'WIDGET', {:id => parameter.id, :size => options[:size] }.update(options)
+ property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id().to_s}#{parameter.key().to_s}", :size => options[:size] }.update(options)
end
def is_set(type)
@@ -82,5 +82,10 @@ module RulesConfigurationHelper
errors.add("#{value}", "'#{attribute}' must be one of : true,false") unless Api::Utils.is_boolean?(attribute)
end
end
+
+ def rule_key(qProfileRule)
+ "#{qProfileRule.repositoryKey().to_s}:#{qProfileRule.key().to_s}"
+ end
+
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb
deleted file mode 100644
index 064c2220d9b..00000000000
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_param.html.erb
+++ /dev/null
@@ -1,48 +0,0 @@
-<% # locals = rule, profile, parameter, parent_active_rule
- param_id = "#{rule.id}#{parameter.key}"
- # Display default value only for inactive rules
- param_value = parameter.default_value if !rule.activeRuleId
- param_value = parameter.value if !param_value
- active_rule_id = rule.activeRuleId
- read_only = rule.activeRuleId.nil? || !profiles_administrator?
-%>
-
-<td class="form-key-cell"><%= parameter.key -%></td>
-
-<td class="form-val-cell">
- <form onsubmit="$j.ajax({ url: '<%= ApplicationController.root_context -%>/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>',
- type:'post',beforeSend: function(request){$j('#param_loading_<%=param_id-%>').show();$j('#error_<%=param_id-%>').hide();},
- data: $j(this).serialize(),
- success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
- complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=param_id-%>').hide();},
- error: function(request){$j('#error_<%=param_id-%>').text(request.responseText);$j('#error_<%=param_id-%>').show();}
- }); return false;"
- name="form-<%=u parameter.key-%>" method="post"
- action="<%= ApplicationController.root_context -%>/new_rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>">
-
- <div id="error_<%= param_id -%>" class="error" style="display: none"></div>
-
- <span id="text_<%= param_id -%>"><%= param_value_input(rule, parameter, param_value, :disabled => read_only) -%></span>
-
- <% unless read_only %>
- <%= submit_tag(message('update_verb'), :id => 'submit_' + param_id.to_s) %>
- <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= param_id -%>" class="rule-param-loading">
- <% end %>
-
- <% if !rule.nil? && rule.overrides? && parent_active_rule
- ancestor_param = parent_active_rule.params.to_a.find {|param| param.key() == parameter.key}
- ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
- %>
- <% if ancestor_value != param_value %>
- <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
- <span class="form-val-note" style="font-weight: bold; vertical-align: middle;">
- <%= message('rules_configuration.original_value') -%>
- : <%= ancestor_value.blank? ? '(' + message('rules_configuration.parent_parameter.empty') + ')' : ancestor_value -%>
- </span>
- <% end %>
- <% end %>
-
- <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.type) + ')') if !readable_type(parameter.type).empty? -%></div>
-
- </form>
-</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb
index a053e5a0523..2928711646c 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_active_rule_note.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_active_rule_note.html.erb
@@ -1,19 +1,19 @@
-<% #locals = rule, profile
- note = rule.activeRuleNote
- active_note_detail_div_id = "and_" + rule.activeRuleId.to_s
- add_active_note_button_id = "aanb_" + rule.activeRuleId.to_s
- edit_active_note_link_id = "eanl_" + rule.activeRuleId.to_s
- delete_active_note_link_id = "danl_" + rule.activeRuleId.to_s
- active_note_form_div_id = "anf_" + rule.activeRuleId.to_s
- active_note_textarea_id = "ant_" + rule.activeRuleId.to_s
- submit_active_note_update_button_id = "sanub_" + rule.activeRuleId.to_s
+<% #locals = active_rule, profile
+ note = active_rule.note
+ active_note_detail_div_id = "and_" + active_rule.id.to_s
+ add_active_note_button_id = "aanb_" + active_rule.id.to_s
+ edit_active_note_link_id = "eanl_" + active_rule.id.to_s
+ delete_active_note_link_id = "danl_" + active_rule.id.to_s
+ active_note_form_div_id = "anf_" + active_rule.id.to_s
+ active_note_textarea_id = "ant_" + active_rule.id.to_s
+ submit_active_note_update_button_id = "sanub_" + active_rule.id.to_s
%>
<div id="<%= active_note_detail_div_id -%>">
- <% if !note.nil? %>
+ <% if note %>
<blockquote class="spacer-bottom">
<cite>
- <b><%= User.find_active_by_login(note.userLogin).name -%></b> (<%= distance_of_time_in_words_to_now(Time.at(note.updatedAt.time/1000)) -%>)&nbsp;
+ <b><%= note.user.name -%></b> (<%= distance_of_time_in_words_to_now(note.updated_at) -%>)&nbsp;
<% if profiles_administrator? %>
| &nbsp;
<a href="#" id="<%= edit_active_note_link_id -%>" class="link-action"
@@ -22,14 +22,14 @@
<a class="link-action"
onclick="if(confirm('<%= escape_javascript(message('rules_configuration.confirm_delete_note')) -%>')){
$j.ajax({
- url: '<%=ApplicationController.root_context-%>/new_rules_configuration/delete_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
+ url: '<%=ApplicationController.root_context-%>/old_rules_configuration/delete_active_rule_note?active_rule_id=<%=active_rule.id-%>',
type: 'post',
- success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
+ success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
});};return false;"
href="#!"><%=message('delete')-%></a>
<% end %>
</cite>
- <p><%= note.data -%></p>
+ <p><%= note.html_text -%></p>
</blockquote>
<% elsif profiles_administrator? %>
<a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
@@ -39,20 +39,20 @@
<% if profiles_administrator? %>
<form onsubmit="$j.ajax({
- url:'<%= ApplicationController.root_context -%>/new_rules_configuration/update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
+ url:'<%= ApplicationController.root_context -%>/old_rules_configuration/update_active_rule_note?active_rule_id=<%=active_rule.id-%>',
data: $j(this).serialize(),
type:'post',
- success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
+ success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
});
return false;"
method="post"
- action="<%= ApplicationController.root_context -%>/new_rules_configuration//update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>">
+ action="<%= ApplicationController.root_context -%>/old_rules_configuration//update_active_rule_note?active_rule_id=<%=active_rule.id-%>">
<table id="<%= active_note_form_div_id -%>" style="display: none" class="admin table width100">
<tbody>
<tr>
<td class="width100" colspan="2">
<textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
- onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.data) unless note.nil? -%></textarea>
+ onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.plain_text) if note -%></textarea>
</td>
</tr>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb
index b6525281c89..a04a2e467bb 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule.html.erb
@@ -1,37 +1,37 @@
-<% #locals = rule, profile, parent_profile -%>
-
-<td nowrap valign="top" class="left" x="<%= rule.severity -%>" width="1%">
+<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
<form id="levels_<%= rule.id -%>" action="" class="rule-levels-form">
<% enable_modification = profiles_administrator?
select_box_id = "levels_select_#{rule.id}"
check_box_id = "levels_check_#{rule.id}"
- activate_rule = "$j.ajax({url:'#{ApplicationController.root_context}/new_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type: 'POST',
+ activate_rule = "$j.ajax({url:'#{ApplicationController.root_context}/old_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type: 'POST',
beforeSend: function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
data: 'level='+ get_level_for_rule($j('#levels_select_#{rule.id} :selected'),$j('#levels_check_#{rule.id}'))});"
changel_level = "if($j('#levels_check_#{rule.id}').prop('checked'))
- {$j.ajax({url:'#{ApplicationController.root_context}/new_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type:'POST',
+ {$j.ajax({url:'#{ApplicationController.root_context}/old_rules_configuration/activate_rule/#{profile.id}?rule_id=#{rule.id}',type:'POST',
beforeSend:function(request){$j('#levels_#{rule.id}').replaceWith('<img src=\"#{ApplicationController.root_context}/images/loading.gif\"/>');},
data:'level='+$j('#levels_select_#{rule.id} :selected').val()})}"
%>
- <%= check_box_tag(check_box_id, 'yes', !rule.activeRuleId.nil?, :onclick => activate_rule, :disabled => !enable_modification || rule.inherited? || rule.overrides?) %>
- <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, rule.severity),
- {:onchange => changel_level, :disabled => (!(enable_modification))}) %>
+ <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overrides?))) %>
+ <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
+ {:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
- <% if rule.inherited? %>
- <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
- <% elsif rule.overrides? %>
- <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
+ <% if active_rule %>
+ <% if active_rule.inherited? %>
+ <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
+ <% elsif active_rule.overrides? %>
+ <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
+ <% end %>
<% end %>
</form>
</td>
<td class="left" colspan="2">
- <% unless rule.status != "READY" %>
+ <% unless rule.ready? %>
<div class="rule-status">
- <% if rule.status == "BETA" %>
+ <% if rule.beta? %>
<span><%= message('rules.status.beta') %></span>
- <% elsif rule.status == "DEPRECATED" %>
+ <% elsif rule.deprecated? %>
<span><%= message('rules.status.deprecated') %></span>
<% end %>
</div>
@@ -50,36 +50,40 @@
</div>
<%
- parent_active_rule = Internal.quality_profiles.parentProfileRule(rule) if (rule.inherited? || rule.overrides?)
- if parent_active_rule || !rule.params.empty?
+ ancestor_profile = profile.parent
+ ancestor_active_rule = ancestor_profile.active_by_rule_id(rule.id) if ancestor_profile && active_rule && (active_rule.inherited? || active_rule.overrides?)
+ if ancestor_active_rule || !rule.parameters.empty?
%>
<table width="100%" class="table spacer-bottom bordered background-gray">
<%
- if parent_active_rule
- parent_active_rule_link = link_to parent_profile.name, :controller => 'rules_configuration', :action => 'index',
- :id => parent_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
+ if ancestor_active_rule
+ ancestor_active_rule_link = link_to ancestor_profile.name, :controller => 'rules_configuration', :action => 'index',
+ :id => ancestor_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
%>
<tr>
<td colspan="2">
- <%= message(rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
- :params => parent_active_rule_link) -%>
- <% if parent_active_rule.severity != rule.severity %>
+ <%= message(active_rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
+ :params => ancestor_active_rule_link) -%>
+ <% if ancestor_active_rule.priority != active_rule.priority %>
<img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
<span class="form-val-note" style="font-weight: bold"> <%= message('rules_configuration.original_severity') -%>
- : <%= parent_active_rule.severity -%></span>
+ : <%= ancestor_active_rule.priority_text -%></span>
<% end %>
- <% if profiles_administrator? && rule.overrides? %>
- <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => rule.activeRuleId} -%>" method="post" style="display: inline">
+ <% if profiles_administrator? && active_rule.overrides? %>
+ <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id} -%>" method="post" style="display: inline">
<input type="submit" value="<%= message('rules_configuration.revert_to_parent_definition') -%>">
</form>
<% end %>
</td>
</tr>
<% end %>
- <% rule.params.each do |parameter| %>
- <tr id="param_<%= parameter.key -%>">
+ <% rule.parameters.sort.each do |parameter|
+ active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
+ %>
+ <tr id="param_<%= parameter.id -%>">
<%= render :partial => 'rule_param', :object => nil,
- :locals => {:parameter => parameter, :profile => profile, :rule => rule, :parent_active_rule => parent_active_rule} %>
+ :locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :rule => rule,
+ :active_rule => active_rule, :ancestor_active_rule => ancestor_active_rule} %>
</tr>
<%
end
@@ -87,9 +91,11 @@
</table>
<% end %>
- <div id="active_rule_note_<%= rule.activeRuleId -%>">
- <%= render :partial => 'active_rule_note', :locals => {:rule => rule} %>
- </div>
+ <% if active_rule %>
+ <div id="active_rule_note_<%= active_rule.id -%>">
+ <%= render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => profile} %>
+ </div>
+ <% end %>
<% if profiles_administrator? %>
<% if rule.template? %>
@@ -101,23 +107,14 @@
<% end %>
<div class="note">
- <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repositoryKey %></span>
+ <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repository_key %></span>
&nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
- <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.key %></span>
- <% unless rule.systemTags.isEmpty && rule.adminTags.isEmpty %>
- &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
- <% rule.systemTags.each do |tag| %>
- <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #efe;padding: 1px 2px"><%= tag -%></span>
- <% end %>
- <% rule.adminTags.each do |tag| %>
- <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #eef;padding: 1px 2px"><%= tag -%></span>
- <% end %>
- <% end %>
+ <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.plugin_rule_key %></span>
&nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
- <% if rule.status == "REMOVED" %>
- <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.updatedAt)) %></span>
+ <% if rule.removed? %>
+ <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(rule.updated_at) %></span>
<% else %>
- <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.createdAt)) %></span>
+ <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(rule.created_at) %></span>
<% end %>
</div>
</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb
index ee8392dd7a2..f9f88e91b9b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/_rule_note.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_note.html.erb
@@ -1,5 +1,5 @@
<% #locals = rule
- note = rule.ruleNote
+ note = rule.note
note_detail_div_id = "nd_" + rule.id.to_s
note_extend_link_id = "nel_" + rule.id.to_s
note_form_div_id = "nf_" + rule.id.to_s
@@ -9,17 +9,15 @@
<div id="<%= note_detail_div_id -%>">
<div class="marginbottom10">
- <% unless rule.description.nil? %>
- <% if rule.description.strip.start_with?('<p>') %>
- <%= Internal.text.interpretMacros(rule.description) %>
- <% else %>
- <p><%= Internal.text.interpretMacros(rule.description) %></p>
- <% end %>
+ <% if rule.description.strip.start_with?('<p>') %>
+ <%= Internal.text.interpretMacros(rule.description) %>
+ <% else %>
+ <p><%= Internal.text.interpretMacros(rule.description) %></p>
<% end %>
</div>
- <% unless rule.ruleNote.nil? %>
- <p><%= rule.ruleNote.data -%></p>
+ <% if note && !note.text.strip.blank? %>
+ <p><%= note.html_text -%></p>
<% end %>
<% if profiles_administrator? %>
@@ -34,13 +32,13 @@
<div id="<%= note_form_div_id -%>" style="display: none" class="admin">
<form onsubmit="$j.ajax({
- url:'<%=ApplicationController.root_context-%>/new_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>&active_rule_id=<%=rule.activeRuleId-%>',
+ url:'<%=ApplicationController.root_context-%>/old_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>',
success:function(response){;$j('#rule_note_<%=rule.id-%>').html(response);},
data: $j(this).serialize(),
type:'post'});
return false;"
method="post"
- action="<%=ApplicationController.root_context-%>/new_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>">
+ action="<%=ApplicationController.root_context-%>/old_rules_configuration/update_rule_note?rule_id=<%=rule.id-%>">
<table class="width100 table">
<tbody>
<tr>
@@ -48,7 +46,7 @@
</tr>
<tr>
<td class="width100" colspan="2">
- <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.data) if note -%></textarea>
+ <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.plain_text) if note -%></textarea>
</td>
</tr>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb
new file mode 100644
index 00000000000..6c510293b5b
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/_rule_param.html.erb
@@ -0,0 +1,51 @@
+<%
+ # Display default value only for inactive rules
+ param_value = parameter.default_value if !active_rule
+ param_value = active_parameter.value if !param_value && active_parameter
+ active_param_id = active_parameter.id if active_parameter
+ active_rule_id = active_rule.id if active_rule
+ read_only = !active_rule || !profiles_administrator?
+%>
+
+<td class="form-key-cell"><%= parameter.name -%></td>
+
+<td class="form-val-cell">
+ <form onsubmit="$j.ajax({ url: '<%= ApplicationController.root_context -%>/old_rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>',
+ type:'post',beforeSend: function(request){$j('#param_loading_<%=parameter.id-%>').show();$j('#error_<%=parameter.id-%>').hide();},
+ data: $j(this).serialize(),
+ success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
+ complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=parameter.id-%>').hide();},
+ error: function(request){$j('#error_<%=parameter.id-%>').text(request.responseText);$j('#error_<%=parameter.id-%>').show();}
+ }); return false;"
+ name="form-<%=u parameter.name-%>" method="post"
+ action="<%= ApplicationController.root_context -%>/old_rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>">
+
+ <div id="error_<%= parameter.id -%>" class="error" style="display: none"></div>
+
+ <span id="text_<%= parameter.id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>
+
+ <% unless read_only %>
+ <%= submit_tag(message('update_verb'), :id => 'submit_' + parameter.id.to_s) %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= parameter.id -%>" class="rule-param-loading">
+ <% if active_parameter and active_parameter.errors.size>0 %>
+ <span class="error"><%= active_parameter.errors.on 'value' %></span>
+ <% end %>
+ <% end %>
+
+ <% if active_rule && active_rule.overrides? && ancestor_active_rule
+ ancestor_param = ancestor_active_rule.active_param_by_param_id(parameter.id)
+ ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
+ %>
+ <% if ancestor_value != param_value %>
+ <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
+ <span class="form-val-note" style="font-weight: bold; vertical-align: middle;">
+ <%= message('rules_configuration.original_value') -%>
+ : <%= ancestor_value.blank? ? '(' + message('rules_configuration.parent_parameter.empty') + ')' : ancestor_value -%>
+ </span>
+ <% end %>
+ <% end %>
+
+ <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%></div>
+
+ </form>
+</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb
index 5e980933a47..fba58000636 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/edit.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/edit.html.erb
@@ -1,13 +1,13 @@
-<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language() -%> / <%= h @profile.name() %></h1>
+<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %></h1>
<%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'Edit rule'} %>
<div class="tabs-panel marginbottom10 background-gray">
-<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id(), :rule_id => @rule.id() -%>" style="display: none"></form>
+<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id, :rule_id => @rule.id -%>" style="display: none"></form>
<script>
function deleteRule() {
- var count = <%= @active_rules -%>;
+ var count = <%= ActiveRule.count(:conditions => {:rule_id => @rule.id}) -%>;
var message = 'Are you sure?';
if (count>0) {
message += ' This rule is activated in ' + count + ' profiles.';
@@ -18,34 +18,34 @@
return false;
}
</script>
-<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id(), :rule_id => @rule.id() -%>">
+<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id, :rule_id => @rule.id -%>">
<table width="100%" class="spaced">
<tr>
<td width="1%" nowrap><%= message('template') -%>:</td>
<td class="sep"> </td>
- <td><%= h @parent_rule.name() -%></td>
+ <td><%= h @rule.parent.name -%></td>
</tr>
<tr>
<td width="1%" nowrap><%= message('name') -%>:</td>
<td class="sep"> </td>
- <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name() -%>" /></td>
+ <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name -%>" /></td>
</tr>
<tr>
<td width="1%" nowrap><%= message('default_severity') -%>:</td>
<td class="sep"> </td>
<td>
<select name="rule[priority]">
- <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.severity())) %>
+ <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.priority)) %>
</select>
</td>
</tr>
- <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
+ <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
<tr>
- <td width="1%" nowrap><%= parameter.key() %>:</td>
+ <td width="1%" nowrap><%= parameter.name %>:</td>
<td class="sep"> </td>
<td>
- <%= param_value_input(@rule, parameter, "#{h parameter.defaultValue()}", {:name => "rule_param[#{h parameter.key() }]", :size => '80x10'}) -%>
- <span class="small"><%= h parameter.description() %></span>
+ <%= param_value_input(parameter, "#{h parameter.default_value}", {:name => "rule_param[#{h parameter.name }]", :size => '80x10'}) -%>
+ <span class="small"><%= h parameter.description %></span>
</td>
</tr>
<% end %>
@@ -53,7 +53,7 @@
<td width="1%" nowrap style="vertical-align: top">Description:</td>
<td class="sep"> </td>
<td valign="top">
- <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description() -%></textarea>
+ <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description -%></textarea>
<span class="small"><%= message('rules_configuration.html_allowed') -%></span>
</td>
</tr>
@@ -61,7 +61,7 @@
<td colspan="3">
<input type="submit" value="<%= message('update_verb') -%>" />
<input type="submit" value="<%= message('delete') -%>" onclick="return deleteRule()" class="red-button" />
- <a href="<%= url_for :action => 'index', :id => @profile.id() -%>"><%= message('cancel') -%></a>
+ <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
</td>
</tr>
</table>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb
index b2c5dbd400a..e25c9911a3d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/index.html.erb
@@ -34,7 +34,7 @@
$j("#rules-search-form").submit();
}
</script>
-<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Coding rules reloaded'} %>
+<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Old Coding rules'} %>
<% enable_modification = profiles_administrator? %>
<div class="tabs-panel marginbottom10 background-gray">
@@ -77,7 +77,7 @@
:placeholder => message('any')
}, {:id => 'search_status', :multiple => true} -%>
</div>
- <% if @profile.isInherited() %>
+ <% if @profile.inherited? %>
<div class="rule-search top">
<span class="note"><%= message('inheritance') -%></span><br/>
<%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
@@ -94,27 +94,28 @@
<% end %>
</div>
<div class="line-block marginbottom10">
- <% if enable_modification && @current_rules.size>0 %>
- <ul style="float: right" class="horizontal">
+ <% if enable_modification && @rules.size>0 %>
+ <ul style="float: right" class="horizontal">
<li class="marginleft10">
<div class="bulk-edit"><%= message('bulk_change') -%>:
- <form action="<%= ApplicationController.root_context -%>/new_rules_configuration/bulk_edit?<%= @criteria_params.to_query -%>" method="POST" id="bulk-form"
+ <form action="<%= ApplicationController.root_context -%>/old_rules_configuration/bulk_edit" method="POST" id="bulk-form"
style="display: inline; vertical-align: middle; padding-right:5px">
<input type="hidden" name="id" value="<%= @profile.id -%>"/>
+ <input type="hidden" name="bulk_rule_ids" value="<%= @rules.map{|r| r.id}.join(',') -%>"/>
<%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
:width => '110px'
}, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
</form>
</div>
</li>
- </ul>
- <% end %>
+ </ul>
+ <% end %>
<h2>
<% if @hidden_actives && @hidden_actives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'ACTIVE'}) -%>"
+ <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
<% if @hidden_inactives && @hidden_inactives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'INACTIVE'}) -%>"
+ <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
</h2>
</div>
@@ -143,9 +144,10 @@
<% end %>
<%
@current_rules.each do |rule|
+ active_rule = @profile.active_by_rule_id(rule.id)
%>
<tr id="rule_<%= rule.id -%>">
- <%= render :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => @profile, :parent_profile => @parent_profile} %>
+ <%= render :partial => 'rule', :object => rule, :locals => {:profile => @profile, :rule => rule, :active_rule => active_rule} %>
</tr>
<% end %>
</tbody>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb
index 46945e3e364..c767c2059fd 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/new_rules_configuration/new.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/old_rules_configuration/new.html.erb
@@ -24,17 +24,15 @@
</select>
</td>
</tr>
- <% if @rule.params && @rule.params.to_a.size > 0 %>
- <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
- <tr>
- <td width="1%" nowrap><%= parameter.key() %>:</td>
- <td class="sep"> </td>
- <td>
- <%= param_value_input(@rule, parameter, "", {:name => "rule_param[#{h parameter.key()}]", :size => '80x10'}) -%>
- <span class="small"><%= h parameter.description() %></span>
- </td>
- </tr>
- <% end %>
+ <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
+ <tr>
+ <td width="1%" nowrap><%= parameter.name %>:</td>
+ <td class="sep"> </td>
+ <td>
+ <%= param_value_input(parameter, "", {:name => "rule_param[#{h parameter.name}]", :size => '80x10'}) -%>
+ <span class="small"><%= h parameter.description %></span>
+ </td>
+ </tr>
<% end %>
<tr>
<td width="1%" nowrap style="vertical-align: top"><%= message('description') -%>:</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb
index 4fc5f49a68f..bf2244fe91b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/_tabs.html.erb
@@ -22,7 +22,7 @@
<a href="<%= url_for :controller => 'profiles', :action => 'changelog', :id => @profile.id -%>" <%= "class='selected'" if selected_tab=='changelog' -%> id="tab-changelog"><%= message('changelog') -%></a>
</li>
<li>
- <a href="<%= url_for :controller => 'new_rules_configuration', :action => 'index', :id => @profile.id %>" <%= "class='selected'" if selected_tab=='Coding rules reloaded' -%> id="tab-rules"><%= message('Coding rules reloaded') -%></a>
+ <a href="<%= url_for :controller => 'old_rules_configuration', :action => 'index', :id => @profile.id %>" <%= "class='selected'" if selected_tab=='Old Coding rules' -%> id="tab-rules"><%= 'Old Coding rules' -%></a>
</li>
<% if new_tab %>
<li>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb
index 246be175dfb..23b66caa197 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_active_rule_note.html.erb
@@ -1,19 +1,19 @@
-<% #locals = active_rule, profile
- note = active_rule.note
- active_note_detail_div_id = "and_" + active_rule.id.to_s
- add_active_note_button_id = "aanb_" + active_rule.id.to_s
- edit_active_note_link_id = "eanl_" + active_rule.id.to_s
- delete_active_note_link_id = "danl_" + active_rule.id.to_s
- active_note_form_div_id = "anf_" + active_rule.id.to_s
- active_note_textarea_id = "ant_" + active_rule.id.to_s
- submit_active_note_update_button_id = "sanub_" + active_rule.id.to_s
+<% #locals = rule, profile
+ note = rule.activeRuleNote
+ active_note_detail_div_id = "and_" + rule.activeRuleId.to_s
+ add_active_note_button_id = "aanb_" + rule.activeRuleId.to_s
+ edit_active_note_link_id = "eanl_" + rule.activeRuleId.to_s
+ delete_active_note_link_id = "danl_" + rule.activeRuleId.to_s
+ active_note_form_div_id = "anf_" + rule.activeRuleId.to_s
+ active_note_textarea_id = "ant_" + rule.activeRuleId.to_s
+ submit_active_note_update_button_id = "sanub_" + rule.activeRuleId.to_s
%>
<div id="<%= active_note_detail_div_id -%>">
- <% if note %>
+ <% if !note.nil? %>
<blockquote class="spacer-bottom">
<cite>
- <b><%= note.user.name -%></b> (<%= distance_of_time_in_words_to_now(note.updated_at) -%>)&nbsp;
+ <b><%= User.find_active_by_login(note.userLogin).name -%></b> (<%= distance_of_time_in_words_to_now(Time.at(note.updatedAt.time/1000)) -%>)&nbsp;
<% if profiles_administrator? %>
| &nbsp;
<a href="#" id="<%= edit_active_note_link_id -%>" class="link-action"
@@ -22,14 +22,14 @@
<a class="link-action"
onclick="if(confirm('<%= escape_javascript(message('rules_configuration.confirm_delete_note')) -%>')){
$j.ajax({
- url: '<%=ApplicationController.root_context-%>/rules_configuration/delete_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+ url: '<%=ApplicationController.root_context-%>/rules_configuration/delete_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
type: 'post',
- success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+ success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
});};return false;"
href="#!"><%=message('delete')-%></a>
<% end %>
</cite>
- <p><%= note.html_text -%></p>
+ <p><%= note.data -%></p>
</blockquote>
<% elsif profiles_administrator? %>
<a href="#" onclick="$j('#<%= active_note_form_div_id -%>').show();$j('#<%= active_note_detail_div_id -%>').hide();$j('#<%= active_note_textarea_id -%>').focus(); return false;"
@@ -39,20 +39,20 @@
<% if profiles_administrator? %>
<form onsubmit="$j.ajax({
- url:'<%= ApplicationController.root_context -%>/rules_configuration/update_active_rule_note?active_rule_id=<%=active_rule.id-%>',
+ url:'<%= ApplicationController.root_context -%>/rules_configuration/update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>',
data: $j(this).serialize(),
type:'post',
- success:function(response){$j('#active_rule_note_<%= active_rule.id -%>').html(response);}
+ success:function(response){$j('#active_rule_note_<%= rule.activeRuleId -%>').html(response);}
});
return false;"
method="post"
- action="<%= ApplicationController.root_context -%>/rules_configuration//update_active_rule_note?active_rule_id=<%=active_rule.id-%>">
+ action="<%= ApplicationController.root_context -%>/rules_configuration//update_active_rule_note?active_rule_id=<%=rule.activeRuleId-%>">
<table id="<%= active_note_form_div_id -%>" style="display: none" class="admin table width100">
<tbody>
<tr>
<td class="width100" colspan="2">
<textarea name="note" id="<%= active_note_textarea_id -%>" rows="10" style="width:100%"
- onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.plain_text) if note -%></textarea>
+ onkeyup="if (this.value=='') $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', true); else $j('#<%= submit_active_note_update_button_id -%>').prop('disabled', false);"><%= h(note.data) unless note.nil? -%></textarea>
</td>
</tr>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
index 7f005ead014..6927d455ecc 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule.html.erb
@@ -1,4 +1,6 @@
-<td nowrap valign="top" class="left" x="<%= active_rule.failure_level if active_rule -%>" width="1%">
+<% #locals = rule, profile, parent_profile -%>
+
+<td nowrap valign="top" class="left" x="<%= rule.severity -%>" width="1%">
<form id="levels_<%= rule.id -%>" action="" class="rule-levels-form">
<% enable_modification = profiles_administrator?
select_box_id = "levels_select_#{rule.id}"
@@ -12,26 +14,24 @@
data:'level='+$j('#levels_select_#{rule.id} :selected').val()})}"
%>
- <%= check_box_tag(check_box_id, 'yes', (!active_rule.nil?), :onclick => activate_rule, :disabled => !enable_modification || (active_rule && (active_rule.inherited? || active_rule.overrides?))) %>
- <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, (active_rule.nil? ? rule.priority_text : active_rule.priority_text)),
- {:onchange => changel_level, :disabled => (!(enable_modification) || active_rule.nil?)}) %>
+ <%= check_box_tag(check_box_id, 'yes', !rule.activeRuleId.nil?, :onclick => activate_rule, :disabled => !enable_modification || rule.inherited? || rule.overrides?) %>
+ <%= select_tag(select_box_id, options_for_select(RulesConfigurationController::RULE_PRIORITIES, rule.severity),
+ {:onchange => changel_level, :disabled => (!(enable_modification))}) %>
- <% if active_rule %>
- <% if active_rule.inherited? %>
- <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
- <% elsif active_rule.overrides? %>
- <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
- <% end %>
+ <% if rule.inherited? %>
+ <img src="<%= ApplicationController.root_context -%>/images/inherited.png" alt="Inherited from parent" title="<%= message('rules_configuration.inherited_from_parent') -%>"/>
+ <% elsif rule.overrides? %>
+ <img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>"/>
<% end %>
</form>
</td>
<td class="left" colspan="2">
- <% unless rule.ready? %>
+ <% unless rule.status == "READY" %>
<div class="rule-status">
- <% if rule.beta? %>
+ <% if rule.status == "BETA" %>
<span><%= message('rules.status.beta') %></span>
- <% elsif rule.deprecated? %>
+ <% elsif rule.status == "DEPRECATED" %>
<span><%= message('rules.status.deprecated') %></span>
<% end %>
</div>
@@ -50,40 +50,36 @@
</div>
<%
- ancestor_profile = profile.parent
- ancestor_active_rule = ancestor_profile.active_by_rule_id(rule.id) if ancestor_profile && active_rule && (active_rule.inherited? || active_rule.overrides?)
- if ancestor_active_rule || !rule.parameters.empty?
+ parent_active_rule = Internal.quality_profiles.parentProfileRule(rule) if (rule.inherited? || rule.overrides?)
+ if parent_active_rule || !rule.params.empty?
%>
<table width="100%" class="table spacer-bottom bordered background-gray">
<%
- if ancestor_active_rule
- ancestor_active_rule_link = link_to ancestor_profile.name, :controller => 'rules_configuration', :action => 'index',
- :id => ancestor_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
+ if parent_active_rule
+ parent_active_rule_link = link_to parent_profile.name, :controller => 'rules_configuration', :action => 'index',
+ :id => parent_profile.id, :rule_id => rule.id, :anchor => 'rule' + rule.id.to_s
%>
<tr>
<td colspan="2">
- <%= message(active_rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
- :params => ancestor_active_rule_link) -%>
- <% if ancestor_active_rule.priority != active_rule.priority %>
+ <%= message(rule.inherited? ? 'rules_configuration.rule_inherited_from_profile_x' : 'rules_configuration.rule_overriding_from_profile_x',
+ :params => parent_active_rule_link) -%>
+ <% if parent_active_rule.severity != rule.severity %>
<img src="<%= ApplicationController.root_context -%>/images/overrides.png" alt="Overrides parent definition" title="<%= message('rules_configuration.overrides_parent_definition') -%>" style="vertical-align: middle"/>
<span class="form-val-note" style="font-weight: bold"> <%= message('rules_configuration.original_severity') -%>
- : <%= ancestor_active_rule.priority_text -%></span>
+ : <%= parent_active_rule.severity -%></span>
<% end %>
- <% if profiles_administrator? && active_rule.overrides? %>
- <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => active_rule.id} -%>" method="post" style="display: inline">
+ <% if profiles_administrator? && rule.overrides? %>
+ <form action="<%= url_for :overwrite_params => {:action => 'revert_rule', :id => profile.id, :active_rule_id => rule.activeRuleId} -%>" method="post" style="display: inline">
<input type="submit" value="<%= message('rules_configuration.revert_to_parent_definition') -%>">
</form>
<% end %>
</td>
</tr>
<% end %>
- <% rule.parameters.sort.each do |parameter|
- active_parameter = active_rule.active_param_by_param_id(parameter.id) if active_rule
- %>
- <tr id="param_<%= parameter.id -%>">
+ <% rule.params.each do |parameter| %>
+ <tr id="param_<%= parameter.key -%>">
<%= render :partial => 'rule_param', :object => nil,
- :locals => {:parameter => parameter, :active_parameter => active_parameter, :profile => profile, :rule => rule,
- :active_rule => active_rule, :ancestor_active_rule => ancestor_active_rule} %>
+ :locals => {:parameter => parameter, :profile => profile, :rule => rule, :parent_active_rule => parent_active_rule} %>
</tr>
<%
end
@@ -91,15 +87,13 @@
</table>
<% end %>
- <% if active_rule %>
- <div id="active_rule_note_<%= active_rule.id -%>">
- <%= render :partial => 'active_rule_note', :locals => {:active_rule => active_rule, :profile => profile} %>
- </div>
- <% end %>
+ <div id="active_rule_note_<%= rule.activeRuleId -%>">
+ <%= render :partial => 'active_rule_note', :locals => {:rule => rule} %>
+ </div>
<% if profiles_administrator? %>
<% if rule.template? %>
- <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule.key}", :class => 'link-action spacer-right' %>
+ <%= link_to message('rules_configuration.copy_rule'), {:action => 'new', :id => profile.id, :rule_id => rule.id}, :id => "copy-#{u rule_key(rule)}", :class => 'link-action spacer-right' %>
<% end %>
<% if rule.editable? %>
<%= link_to message('rules_configuration.edit_rule'), {:action => 'edit', :id => profile.id, :rule_id => rule.id}, :class => 'link-action spacer-right' %>
@@ -107,14 +101,23 @@
<% end %>
<div class="note">
- <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repository_key %></span>
+ <span id="rule_repository_<%= rule.id -%>"><%= message('rules_configuration.repository') %>: <%= rule.repositoryKey %></span>
&nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
- <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.plugin_rule_key %></span>
+ <span id="rule_key_<%= rule.id -%>"><%= message('key') %>: <%= rule.key %></span>
+ <% unless rule.systemTags.isEmpty && rule.adminTags.isEmpty %>
+ &nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
+ <% rule.systemTags.each do |tag| %>
+ <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #efe;padding: 1px 2px"><%= tag -%></span>
+ <% end %>
+ <% rule.adminTags.each do |tag| %>
+ <span id="rule_tag_<%= rule.id -%>_<%= tag -%>" style="background-color: #eef;padding: 1px 2px"><%= tag -%></span>
+ <% end %>
+ <% end %>
&nbsp;<%= image_tag 'sep12.png' -%>&nbsp;
- <% if rule.removed? %>
- <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(rule.updated_at) %></span>
+ <% if rule.status == "REMOVED" %>
+ <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.removed_since') %>: <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.updatedAt)) %></span>
<% else %>
- <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(rule.created_at) %></span>
+ <span id="rule_available_since_<%= rule.id -%>"><%= message('rules_configuration.available_since') %> <%= human_short_date(Api::Utils.java_to_ruby_datetime(rule.createdAt)) %></span>
<% end %>
</div>
</div>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
index 2bf357b1f24..966c94d1c6a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_note.html.erb
@@ -1,5 +1,5 @@
<% #locals = rule
- note = rule.note
+ note = rule.ruleNote
note_detail_div_id = "nd_" + rule.id.to_s
note_extend_link_id = "nel_" + rule.id.to_s
note_form_div_id = "nf_" + rule.id.to_s
@@ -9,15 +9,17 @@
<div id="<%= note_detail_div_id -%>">
<div class="marginbottom10">
- <% if rule.description.strip.start_with?('<p>') %>
- <%= Internal.text.interpretMacros(rule.description) %>
- <% else %>
- <p><%= Internal.text.interpretMacros(rule.description) %></p>
+ <% unless rule.description.nil? %>
+ <% if rule.description.strip.start_with?('<p>') %>
+ <%= Internal.text.interpretMacros(rule.description) %>
+ <% else %>
+ <p><%= Internal.text.interpretMacros(rule.description) %></p>
+ <% end %>
<% end %>
</div>
- <% if note && !note.text.strip.blank? %>
- <p><%= note.html_text -%></p>
+ <% unless rule.ruleNote.nil? %>
+ <p><%= rule.ruleNote.data -%></p>
<% end %>
<% if profiles_administrator? %>
@@ -32,7 +34,7 @@
<div id="<%= note_form_div_id -%>" style="display: none" class="admin">
<form onsubmit="$j.ajax({
- url:'<%=ApplicationController.root_context-%>/rules_configuration/update_rule_note?rule_id=<%=rule.id-%>',
+ url:'<%=ApplicationController.root_context-%>/rules_configuration/update_rule_note?rule_id=<%=rule.id-%>&active_rule_id=<%=rule.activeRuleId-%>',
success:function(response){;$j('#rule_note_<%=rule.id-%>').html(response);},
data: $j(this).serialize(),
type:'post'});
@@ -46,7 +48,7 @@
</tr>
<tr>
<td class="width100" colspan="2">
- <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.plain_text) if note -%></textarea>
+ <textarea name="text" id="<%= note_textarea_id -%>" rows="10" style="width:100%"><%= h(note.data) if note -%></textarea>
</td>
</tr>
<tr>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
index bd034cc8a24..7235ac2d3c9 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/_rule_param.html.erb
@@ -1,39 +1,36 @@
-<%
+<% # locals = rule, profile, parameter, parent_active_rule
+ param_id = "#{rule.id}#{parameter.key}"
# Display default value only for inactive rules
- param_value = parameter.default_value if !active_rule
- param_value = active_parameter.value if !param_value && active_parameter
- active_param_id = active_parameter.id if active_parameter
- active_rule_id = active_rule.id if active_rule
- read_only = !active_rule || !profiles_administrator?
+ param_value = parameter.default_value if !rule.activeRuleId
+ param_value = parameter.value if !param_value
+ active_rule_id = rule.activeRuleId
+ read_only = rule.activeRuleId.nil? || !profiles_administrator?
%>
-<td class="form-key-cell"><%= parameter.name -%></td>
+<td class="form-key-cell"><%= parameter.key -%></td>
<td class="form-val-cell">
- <form onsubmit="$j.ajax({ url: '<%= ApplicationController.root_context -%>/rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>',
- type:'post',beforeSend: function(request){$j('#param_loading_<%=parameter.id-%>').show();$j('#error_<%=parameter.id-%>').hide();},
+ <form onsubmit="$j.ajax({ url: '<%= ApplicationController.root_context -%>/rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>',
+ type:'post',beforeSend: function(request){$j('#param_loading_<%=param_id-%>').show();$j('#error_<%=param_id-%>').hide();},
data: $j(this).serialize(),
success: function(response){$j('#rule_<%=rule.id-%>').html(response);},
- complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=parameter.id-%>').hide();},
- error: function(request){$j('#error_<%=parameter.id-%>').text(request.responseText);$j('#error_<%=parameter.id-%>').show();}
+ complete: function(request){$j('#desc_<%=rule.id-%>').show();$j('#param_loading_<%=param_id-%>').hide();},
+ error: function(request){$j('#error_<%=param_id-%>').text(request.responseText);$j('#error_<%=param_id-%>').show();}
}); return false;"
- name="form-<%=u parameter.name-%>" method="post"
- action="<%= ApplicationController.root_context -%>/rules_configuration/update_param/<%=active_param_id-%>?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.id-%>&profile_id=<%=profile.id-%>">
+ name="form-<%=u parameter.key-%>" method="post"
+ action="<%= ApplicationController.root_context -%>/rules_configuration/update_param/?active_rule_id=<%=active_rule_id-%>&param_id=<%=parameter.key-%>&profile_id=<%=profile.id-%>">
- <div id="error_<%= parameter.id -%>" class="error" style="display: none"></div>
+ <div id="error_<%= param_id -%>" class="error" style="display: none"></div>
- <span id="text_<%= parameter.id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>
+ <span id="text_<%= param_id -%>"><%= param_value_input(rule, parameter, param_value, :disabled => read_only) -%></span>
<% unless read_only %>
- <%= submit_tag(message('update_verb'), :id => 'submit_' + parameter.id.to_s) %>
- <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= parameter.id -%>" class="rule-param-loading">
- <% if active_parameter and active_parameter.errors.size>0 %>
- <span class="error"><%= active_parameter.errors.on 'value' %></span>
- <% end %>
+ <%= submit_tag(message('update_verb'), :id => 'submit_' + param_id.to_s) %>
+ <img src="<%= ApplicationController.root_context -%>/images/loading.gif" style="display:none;" id="param_loading_<%= param_id -%>" class="rule-param-loading">
<% end %>
- <% if active_rule && active_rule.overrides? && ancestor_active_rule
- ancestor_param = ancestor_active_rule.active_param_by_param_id(parameter.id)
+ <% if !rule.nil? && rule.overrides? && parent_active_rule
+ ancestor_param = parent_active_rule.params.to_a.find {|param| param.key() == parameter.key}
ancestor_value = ancestor_param && ancestor_param.value ? ancestor_param.value : ''
%>
<% if ancestor_value != param_value %>
@@ -45,7 +42,7 @@
<% end %>
<% end %>
- <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.param_type) + ')') if !readable_type(parameter.param_type).empty? -%></div>
+ <div class="form-val-note"><%= h(parameter.description || "") -%> <%= ('(' + readable_type(parameter.type) + ')') if !readable_type(parameter.type).empty? -%></div>
</form>
</td>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb
index fba58000636..5e980933a47 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/edit.html.erb
@@ -1,13 +1,13 @@
-<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %></h1>
+<h1 class="marginbottom10"><%= link_to message('quality_profiles.quality_profiles'), :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language() -%> / <%= h @profile.name() %></h1>
<%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'Edit rule'} %>
<div class="tabs-panel marginbottom10 background-gray">
-<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id, :rule_id => @rule.id -%>" style="display: none"></form>
+<form method="POST" id="delete-form" action="<%= url_for :action => 'delete', :id => @profile.id(), :rule_id => @rule.id() -%>" style="display: none"></form>
<script>
function deleteRule() {
- var count = <%= ActiveRule.count(:conditions => {:rule_id => @rule.id}) -%>;
+ var count = <%= @active_rules -%>;
var message = 'Are you sure?';
if (count>0) {
message += ' This rule is activated in ' + count + ' profiles.';
@@ -18,34 +18,34 @@
return false;
}
</script>
-<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id, :rule_id => @rule.id -%>">
+<form method="POST" action="<%= url_for :action => 'update', :id => @profile.id(), :rule_id => @rule.id() -%>">
<table width="100%" class="spaced">
<tr>
<td width="1%" nowrap><%= message('template') -%>:</td>
<td class="sep"> </td>
- <td><%= h @rule.parent.name -%></td>
+ <td><%= h @parent_rule.name() -%></td>
</tr>
<tr>
<td width="1%" nowrap><%= message('name') -%>:</td>
<td class="sep"> </td>
- <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name -%>" /></td>
+ <td><input type="text" name="rule[name]" size="80" value="<%= h @rule.name() -%>" /></td>
</tr>
<tr>
<td width="1%" nowrap><%= message('default_severity') -%>:</td>
<td class="sep"> </td>
<td>
<select name="rule[priority]">
- <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.priority)) %>
+ <%= options_for_select(Sonar::RulePriority.as_options, Sonar::RulePriority.to_s(@rule.severity())) %>
</select>
</td>
</tr>
- <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
+ <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
<tr>
- <td width="1%" nowrap><%= parameter.name %>:</td>
+ <td width="1%" nowrap><%= parameter.key() %>:</td>
<td class="sep"> </td>
<td>
- <%= param_value_input(parameter, "#{h parameter.default_value}", {:name => "rule_param[#{h parameter.name }]", :size => '80x10'}) -%>
- <span class="small"><%= h parameter.description %></span>
+ <%= param_value_input(@rule, parameter, "#{h parameter.defaultValue()}", {:name => "rule_param[#{h parameter.key() }]", :size => '80x10'}) -%>
+ <span class="small"><%= h parameter.description() %></span>
</td>
</tr>
<% end %>
@@ -53,7 +53,7 @@
<td width="1%" nowrap style="vertical-align: top">Description:</td>
<td class="sep"> </td>
<td valign="top">
- <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description -%></textarea>
+ <textarea name="rule[description]" cols="80" rows="10" style="vertical-align: baseline"><%= @rule.description() -%></textarea>
<span class="small"><%= message('rules_configuration.html_allowed') -%></span>
</td>
</tr>
@@ -61,7 +61,7 @@
<td colspan="3">
<input type="submit" value="<%= message('update_verb') -%>" />
<input type="submit" value="<%= message('delete') -%>" onclick="return deleteRule()" class="red-button" />
- <a href="<%= url_for :action => 'index', :id => @profile.id -%>"><%= message('cancel') -%></a>
+ <a href="<%= url_for :action => 'index', :id => @profile.id() -%>"><%= message('cancel') -%></a>
</td>
</tr>
</table>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
index 99095ef180a..2488e4f9f90 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/index.html.erb
@@ -77,7 +77,7 @@
:placeholder => message('any')
}, {:id => 'search_status', :multiple => true} -%>
</div>
- <% if @profile.inherited? %>
+ <% if @profile.isInherited() %>
<div class="rule-search top">
<span class="note"><%= message('inheritance') -%></span><br/>
<%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
@@ -94,28 +94,27 @@
<% end %>
</div>
<div class="line-block marginbottom10">
- <% if enable_modification && @rules.size>0 %>
- <ul style="float: right" class="horizontal">
+ <% if enable_modification && @current_rules.size>0 %>
+ <ul style="float: right" class="horizontal">
<li class="marginleft10">
<div class="bulk-edit"><%= message('bulk_change') -%>:
- <form action="<%= ApplicationController.root_context -%>/rules_configuration/bulk_edit" method="POST" id="bulk-form"
+ <form action="<%= ApplicationController.root_context -%>/rules_configuration/bulk_edit?<%= @criteria_params.to_query -%>" method="POST" id="bulk-form"
style="display: inline; vertical-align: middle; padding-right:5px">
<input type="hidden" name="id" value="<%= @profile.id -%>"/>
- <input type="hidden" name="bulk_rule_ids" value="<%= @rules.map{|r| r.id}.join(',') -%>"/>
<%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
:width => '110px'
}, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
</form>
</div>
</li>
- </ul>
- <% end %>
+ </ul>
+ <% end %>
<h2>
<% if @hidden_actives && @hidden_actives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+ <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'ACTIVE'}) -%>"
id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
<% if @hidden_inactives && @hidden_inactives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => ''}) -%>"
+ <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'INACTIVE'}) -%>"
id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
</h2>
</div>
@@ -144,10 +143,9 @@
<% end %>
<%
@current_rules.each do |rule|
- active_rule = @profile.active_by_rule_id(rule.id)
%>
<tr id="rule_<%= rule.id -%>">
- <%= render :partial => 'rule', :object => rule, :locals => {:profile => @profile, :rule => rule, :active_rule => active_rule} %>
+ <%= render :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => @profile, :parent_profile => @parent_profile} %>
</tr>
<% end %>
</tbody>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb
index c767c2059fd..46945e3e364 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb
@@ -24,15 +24,17 @@
</select>
</td>
</tr>
- <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
- <tr>
- <td width="1%" nowrap><%= parameter.name %>:</td>
- <td class="sep"> </td>
- <td>
- <%= param_value_input(parameter, "", {:name => "rule_param[#{h parameter.name}]", :size => '80x10'}) -%>
- <span class="small"><%= h parameter.description %></span>
- </td>
- </tr>
+ <% if @rule.params && @rule.params.to_a.size > 0 %>
+ <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
+ <tr>
+ <td width="1%" nowrap><%= parameter.key() %>:</td>
+ <td class="sep"> </td>
+ <td>
+ <%= param_value_input(@rule, parameter, "", {:name => "rule_param[#{h parameter.key()}]", :size => '80x10'}) -%>
+ <span class="small"><%= h parameter.description() %></span>
+ </td>
+ </tr>
+ <% end %>
<% end %>
<tr>
<td width="1%" nowrap style="vertical-align: top"><%= message('description') -%>:</td>
diff --git a/sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java b/sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java
new file mode 100644
index 00000000000..3b905c5580b
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/util/StringTypeValidationTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class StringTypeValidationTest {
+
+ StringTypeValidation validation;
+
+ @Before
+ public void setUp() throws Exception {
+ validation = new StringTypeValidation();
+ }
+
+ @Test
+ public void key() {
+ assertThat(validation.key()).isEqualTo("STRING");
+ }
+
+ @Test
+ public void not_fail_on_valid_string() {
+ validation.validate("10", null);
+ validation.validate("abc", null);
+ }
+
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java b/sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java
new file mode 100644
index 00000000000..ee62352d167
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/util/TextTypeValidationTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.util;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TextTypeValidationTest {
+
+ TextTypeValidation validation;
+
+ @Before
+ public void setUp() throws Exception {
+ validation = new TextTypeValidation();
+ }
+
+ @Test
+ public void key() {
+ assertThat(validation.key()).isEqualTo("TEXT");
+ }
+
+ @Test
+ public void not_fail_on_valid_text() {
+ validation.validate("10", null);
+ validation.validate("abc", null);
+ }
+
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java b/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java
index 9c0086cb787..00ae724b6fc 100644
--- a/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/util/TypeValidationsTest.java
@@ -21,8 +21,7 @@
package org.sonar.server.util;
import org.junit.Test;
-
-import java.util.NoSuchElementException;
+import org.sonar.server.exceptions.BadRequestException;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
@@ -52,7 +51,9 @@ public class TypeValidationsTest {
typeValidations.validate("10", "Unknown", null);
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(NoSuchElementException.class);
+ assertThat(e).isInstanceOf(BadRequestException.class);
+ BadRequestException badRequestException = (BadRequestException) e;
+ assertThat(badRequestException.getMessage()).isEqualTo("Type 'Unknown' is not valid.");
}
}