diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-20 16:44:22 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-20 16:44:22 +0000 |
commit | 76453df999839a38672dfaf3689a6d06bb1b2bcd (patch) | |
tree | c5eaa2a5ac9e0245a7a44e6f2192eb7e1a8c4f50 /sonar-server | |
parent | f6eae0b6e62b99a5538e733e3f3961c00c24e967 (diff) | |
download | sonarqube-76453df999839a38672dfaf3689a6d06bb1b2bcd.tar.gz sonarqube-76453df999839a38672dfaf3689a6d06bb1b2bcd.zip |
fix activation of rule parameters with default value
Diffstat (limited to 'sonar-server')
4 files changed, 32 insertions, 10 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java index 0e07aa95b0a..ad5ee2559d2 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java @@ -25,8 +25,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseSession; import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.ActiveRuleParam; +import org.sonar.api.rules.*; import org.sonar.api.utils.TimeProfiler; import org.sonar.api.utils.ValidationMessages; import org.sonar.jpa.session.DatabaseSessionFactory; @@ -43,17 +42,20 @@ public final class RegisterProvidedProfiles { private DatabaseSessionFactory sessionFactory; private List<ProfileDefinition> definitions = new ArrayList<ProfileDefinition>(); private DeprecatedProfiles deprecatedProfiles = null; + private RuleFinder ruleFinder; - public RegisterProvidedProfiles(DatabaseSessionFactory sessionFactory, + public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory, DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore, ProfileDefinition[] definitions) { + this.ruleFinder = ruleFinder; this.sessionFactory = sessionFactory; this.definitions.addAll(Arrays.asList(definitions)); this.deprecatedProfiles = deprecatedBridge; } - public RegisterProvidedProfiles(DatabaseSessionFactory sessionFactory, + public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory, DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) { + this.ruleFinder = ruleFinder; this.sessionFactory = sessionFactory; this.deprecatedProfiles = deprecatedBridge; } @@ -117,9 +119,13 @@ public final class RegisterProvidedProfiles { RulesProfile persistedProfile = findOrCreate(profile.getName(), profile.getLanguage(), session); for (ActiveRule activeRule : profile.getActiveRules()) { - ActiveRule persistedRule = persistedProfile.activateRule(activeRule.getRule(), activeRule.getPriority()); - for (ActiveRuleParam param : activeRule.getActiveRuleParams()) { - persistedRule.setParameter(param.getKey(), param.getValue()); + Rule rule = getPersistedRule(activeRule); + ActiveRule persistedRule = persistedProfile.activateRule(rule, activeRule.getPriority()); + for (RuleParam param : rule.getParams()) { + String value = StringUtils.defaultString(activeRule.getParameter(param.getKey()), param.getDefaultValue()); + if (value != null) { + persistedRule.setParameter(param.getKey(), value); + } } } @@ -130,6 +136,19 @@ public final class RegisterProvidedProfiles { } + Rule getPersistedRule(ActiveRule activeRule) { + Rule rule = activeRule.getRule(); + if (rule!=null && rule.getId()==null) { + if (rule.getKey()!=null) { + rule = ruleFinder.findByKey(rule.getRepositoryKey(), rule.getKey()); + + } else if (rule.getConfigKey()!=null) { + rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(rule.getRepositoryKey()).withConfigKey(rule.getConfigKey())); + } + } + return rule; + } + private RulesProfile findOrCreate(String name, String language, DatabaseSession session) { RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", name, "language", language); if (profile == null) { 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 55695f47760..36fedc05dd6 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 @@ -98,6 +98,9 @@ class RulesConfigurationController < ApplicationController # activate the rule
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)
+ end
end
active_rule.failure_level=Sonar::RulePriority.id(priority)
active_rule.save!
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb index 6205dc9c149..166236e6481 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb @@ -32,7 +32,7 @@ <% if administrator? %> <ul style="float: right" class="horizontal"> <li class="marginleft10 add"> - <a href="#" onClick="$('create-form-<%= language.getKey() -%>').show();return false;" id="create-link-<%= language.getKey() -%>">Create</a> + <a href="#" onClick="$('create-form-<%= language.getKey() -%>').show();$('create-form-<%= language.getKey() -%>-name').focus();return false;" id="create-link-<%= language.getKey() -%>">Create</a> </li> </ul> <% end %> @@ -45,7 +45,7 @@ <table class="spaced width100"> <tr> <td width="1%" nowrap>Name: </td> - <td><input type="text" name="name"></input></td> + <td><input type="text" name="name" id="create-form-<%= language.getKey()-%>-name"></input></td> </tr> <% importers.to_a.sort{|x,y| x.getName() <=> y.getName()}.each do |importer| %> <tr> 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 8875c042957..9eacb5dfcf6 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 @@ -1,4 +1,4 @@ -<h1 class="marginbottom10"><%= link_to 'Quality profiles', profiles_path %> / <%= h @profile.language -%> / <%= h @profile.name %></h1> +<h1 class="marginbottom10"><%= link_to 'Quality profiles', :controller => 'profiles', :action => 'index' -%> / <%= h @profile.language -%> / <%= h @profile.name %></h1> <%= render :partial => 'profiles/tabs', :locals => {:new_tab => 'New rule'} %> |