Browse Source

fix activation of rule parameters with default value

tags/2.6
simonbrandhof 13 years ago
parent
commit
76453df999

+ 26
- 7
sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java View File

@@ -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) {

+ 3
- 0
sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb View File

@@ -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!

+ 2
- 2
sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb View File

@@ -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>

+ 1
- 1
sonar-server/src/main/webapp/WEB-INF/app/views/rules_configuration/new.html.erb View File

@@ -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'} %>


Loading…
Cancel
Save