diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-23 20:55:46 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-07-23 20:56:27 +0200 |
commit | e4fdef49e36d269ef5365a3056af67c8c3d5aceb (patch) | |
tree | dcec45821e3d24e946eb13c1f80f8bebcf17804f /sonar-batch | |
parent | 0a123014a0781a516b580d4fa9ce76532f23071f (diff) | |
download | sonarqube-e4fdef49e36d269ef5365a3056af67c8c3d5aceb.tar.gz sonarqube-e4fdef49e36d269ef5365a3056af67c8c3d5aceb.zip |
SONAR-5417 Add rule name to active rule
Diffstat (limited to 'sonar-batch')
6 files changed, 9 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java index 3ca6ff97634..4405eb259e8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java @@ -96,7 +96,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad } else { internalKey = rule.getConfigKey(); } - ActiveRule activeRule = new ActiveRule(rule.ruleKey().repository(), rule.ruleKey().rule(), activeDto.getSeverityString(), internalKey, rule.getLanguage()); + ActiveRule activeRule = new ActiveRule(rule.ruleKey().repository(), rule.ruleKey().rule(), rule.getName(), activeDto.getSeverityString(), internalKey, rule.getLanguage()); // load parameter values for (ActiveRuleParamDto paramDto : paramDtosByActiveRuleId.get(activeDto.getId())) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java index 9b6b009d3df..a539b744073 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java @@ -48,6 +48,7 @@ public class ActiveRulesProvider extends ProviderAdapter { ActiveRulesBuilder builder = new ActiveRulesBuilder(); for (ActiveRule activeRule : ref.activeRules()) { NewActiveRule newActiveRule = builder.create(RuleKey.of(activeRule.repositoryKey(), activeRule.ruleKey())); + newActiveRule.setName(activeRule.name()); newActiveRule.setSeverity(activeRule.severity()); newActiveRule.setLanguage(activeRule.language()); newActiveRule.setInternalKey(activeRule.internalKey()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java index c2119b18d02..f54dab6af55 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.issue.IssueBuilder; @@ -129,22 +128,16 @@ public class DefaultSensorContext implements SensorContext { resourceKey = def.getKey(); } RuleKey ruleKey = issue.ruleKey(); - // TODO we need a Rule referential on batch side - Rule rule = null; - // Rule rule = rules.find(ruleKey); - // if (rule == null) { - // throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey)); - // } ActiveRule activeRule = activeRules.find(ruleKey); if (activeRule == null) { // rule does not exist or is not enabled -> ignore the issue return false; } - if (/* Strings.isNullOrEmpty(rule.name()) && */Strings.isNullOrEmpty(issue.message())) { + if (Strings.isNullOrEmpty(activeRule.name()) && Strings.isNullOrEmpty(issue.message())) { throw MessageException.of(String.format("The rule '%s' has no name and the related issue has no message.", ruleKey)); } - updateIssue((DefaultIssue) issue, activeRule, rule); + updateIssue((DefaultIssue) issue, activeRule); if (issueFilters.accept(SensorContextAdaptor.toDefaultIssue(def.getKey(), resourceKey, issue), null)) { issueCache.put(def.getKey(), resourceKey, (DefaultIssue) issue); @@ -154,9 +147,9 @@ public class DefaultSensorContext implements SensorContext { return false; } - private void updateIssue(DefaultIssue issue, ActiveRule activeRule, Rule rule) { + private void updateIssue(DefaultIssue issue, ActiveRule activeRule) { if (Strings.isNullOrEmpty(issue.message())) { - issue.setMessage(rule.name()); + issue.setMessage(activeRule.name()); } if (issue.severity() == null) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java index ace6681869b..674f472d0b5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java @@ -50,7 +50,7 @@ public class FileSystemMediumTest { public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") - .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "MAJOR", "xoo", "xoo")) + .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "One issue per line", "MAJOR", "xoo", "xoo")) .bootstrapProperties(ImmutableMap.of("sonar.analysis.mode", "sensor")) .build(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java index 3fec3ccb251..875e7e6d510 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java @@ -45,7 +45,7 @@ public class IssuesMediumTest { public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") - .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "MAJOR", "OneIssuePerLine.internal", "xoo")) + .activateRule(new ActiveRule("xoo", "OneIssuePerLine", "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo")) .bootstrapProperties(ImmutableMap.of("sonar.analysis.mode", "sensor")) .build(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java index bbd1aefd719..fdf6b15e857 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java @@ -44,7 +44,7 @@ public class IssuesOnDirMediumTest { public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way") - .activateRule(new ActiveRule("xoo", "OneIssueOnDirPerFile", "MINOR", "xoo", "xoo")) + .activateRule(new ActiveRule("xoo", "OneIssueOnDirPerFile", "One issue per line", "MINOR", "xoo", "xoo")) .bootstrapProperties(ImmutableMap.of("sonar.analysis.mode", "sensor")) .build(); |