aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2015-07-09 15:50:59 +0200
committerJenkins CI <ci@sonarsource.com>2015-07-09 15:50:59 +0200
commit0bdf27c47c0bd9c5f642fd397be58f7d4ddd3a1a (patch)
tree92afa12539f2b3a5fbcdd3b43e080f2728dd6aab /sonar-batch/src
parent726c1fa0cfb2d0e27df0ed3de1dbed6ffdaf2377 (diff)
parentca253b85929fa9c372e285b617a7c8991d89698b (diff)
downloadsonarqube-0bdf27c47c0bd9c5f642fd397be58f7d4ddd3a1a.tar.gz
sonarqube-0bdf27c47c0bd9c5f642fd397be58f7d4ddd3a1a.zip
Automatic merge from branch-5.1
* origin/branch-5.1: SONAR-6706 org.sonar.api.rules.ActiveRule.getRule().getTemplate() is always null on batch
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java23
2 files changed, 25 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
index f890761ba37..7ab4959321d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/RulesProfileProvider.java
@@ -20,20 +20,18 @@
package org.sonar.batch.rule;
import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.DefaultActiveRules;
import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
-import java.util.Collection;
-import java.util.Map;
-
/**
* Ensures backward-compatibility with extensions that use {@link org.sonar.api.profiles.RulesProfile}.
*/
@@ -75,9 +73,15 @@ public class RulesProfileProvider extends ProviderAdapter {
// TODO deprecatedProfile.setVersion(qProfile.version());
deprecatedProfile.setName(qProfile.getName());
deprecatedProfile.setLanguage(qProfile.getLanguage());
- for (org.sonar.api.batch.rule.ActiveRule activeRule : ((DefaultActiveRules) activeRules).findByLanguage(qProfile.getLanguage())) {
+ for (org.sonar.api.batch.rule.ActiveRule activeRule : activeRules.findByLanguage(qProfile.getLanguage())) {
Rule rule = Rule.create(activeRule.ruleKey().repository(), activeRule.ruleKey().rule());
rule.setConfigKey(activeRule.internalKey());
+
+ // SONAR-6706
+ if (activeRule.templateRuleKey() != null) {
+ rule.setTemplate(Rule.create(activeRule.ruleKey().repository(), activeRule.templateRuleKey()));
+ }
+
ActiveRule deprecatedActiveRule = deprecatedProfile.activateRule(rule,
RulePriority.valueOf(activeRule.severity()));
for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java
index bfa14cf91bc..092bfb42250 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/RulesProfileProviderTest.java
@@ -19,13 +19,12 @@
*/
package org.sonar.batch.rule;
+import java.util.Arrays;
import org.junit.Test;
-import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;
-
-import java.util.Arrays;
+import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@@ -35,7 +34,6 @@ import static org.mockito.Mockito.when;
public class RulesProfileProviderTest {
ModuleQProfiles qProfiles = mock(ModuleQProfiles.class);
- ActiveRules activeRules = new ActiveRulesBuilder().build();
Settings settings = new Settings();
RulesProfileProvider provider = new RulesProfileProvider();
@@ -44,7 +42,7 @@ public class RulesProfileProviderTest {
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
- RulesProfile profile = provider.provide(qProfiles, activeRules, settings);
+ RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
// merge of all profiles
assertThat(profile).isNotNull().isInstanceOf(RulesProfileWrapper.class);
@@ -66,12 +64,23 @@ public class RulesProfileProviderTest {
QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
when(qProfiles.findByLanguage("java")).thenReturn(qProfile);
- RulesProfile profile = provider.provide(qProfiles, activeRules, settings);
+ RulesProfile profile = provider.provide(qProfiles, new ActiveRulesBuilder().build(), settings);
// no merge, directly the old hibernate profile
assertThat(profile).isNotNull();
assertThat(profile.getLanguage()).isEqualTo("java");
assertThat(profile.getName()).isEqualTo("Sonar way");
- ;
+ }
+
+ @Test
+ public void support_rule_templates() {
+ QProfile qProfile = new QProfile().setKey("java-sw").setName("Sonar way").setLanguage("java");
+ when(qProfiles.findAll()).thenReturn(Arrays.asList(qProfile));
+ ActiveRulesBuilder activeRulesBuilder = new ActiveRulesBuilder();
+ activeRulesBuilder.create(RuleKey.of("java", "S001")).setTemplateRuleKey("T001").setLanguage("java").activate();
+
+ RulesProfile profile = provider.provide(qProfiles, activeRulesBuilder.build(), settings);
+
+ assertThat(profile.getActiveRule("java", "S001").getRule().getTemplate().getKey()).isEqualTo("T001");
}
}