aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java9
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/ActiveRulesProvider.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java15
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java2
12 files changed, 41 insertions, 19 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
index 144a34b292b..6c1992ac1e2 100644
--- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
@@ -26,12 +26,13 @@ import java.util.Map;
public class ActiveRule {
private final String repositoryKey, ruleKey;
- private final String severity, internalKey, language;
+ private final String name, severity, internalKey, language;
private final Map<String, String> params = new HashMap<String, String>();
- public ActiveRule(String repositoryKey, String ruleKey, String severity, String internalKey, String language) {
+ public ActiveRule(String repositoryKey, String ruleKey, String name, String severity, String internalKey, String language) {
this.repositoryKey = repositoryKey;
this.ruleKey = ruleKey;
+ this.name = name;
this.severity = severity;
this.internalKey = internalKey;
this.language = language;
@@ -45,6 +46,10 @@ public class ActiveRule {
return ruleKey;
}
+ public String name() {
+ return name;
+ }
+
public String severity() {
return severity;
}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
index 831f5e12cef..328939ca23d 100644
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
@@ -38,7 +38,7 @@ public class ProjectReferentialsTest {
ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984")));
ref.addSettings("foo", new HashMap<String, String>());
ref.settings("foo").put("prop", "value");
- ref.addActiveRule(new ActiveRule("repo", "rule", "MAJOR", "rule", "java"));
+ ref.addActiveRule(new ActiveRule("repo", "rule", "Rule", "MAJOR", "rule", "java"));
ref.setTimestamp(10);
System.out.println(ref.toJson());
@@ -46,7 +46,7 @@ public class ProjectReferentialsTest {
.assertEquals(
"{timestamp:10,"
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
- + "activeRules:[{repositoryKey:repo,ruleKey:rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
+ + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
+ "settingsByModule:{foo:{prop:value}}}",
ref.toJson(), true);
}
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();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java
index 3e3d18651e9..d24fa2eed84 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java
@@ -22,6 +22,7 @@ package org.sonar.api.batch.rule;
import org.sonar.api.rule.RuleKey;
import javax.annotation.CheckForNull;
+
import java.util.Map;
/**
@@ -33,6 +34,12 @@ public interface ActiveRule {
RuleKey ruleKey();
/**
+ * Name of the rule.
+ * @since 4.5
+ */
+ String name();
+
+ /**
* Non-null severity.
* @see org.sonar.api.rule.Severity
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java
index 5eeea77687d..b37fc6a8890 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java
@@ -24,16 +24,19 @@ import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.rule.RuleKey;
import javax.annotation.concurrent.Immutable;
+
import java.util.Map;
@Immutable
class DefaultActiveRule implements ActiveRule {
private final RuleKey ruleKey;
+ private final String name;
private final String severity, internalKey, language;
private final Map<String, String> params;
DefaultActiveRule(NewActiveRule newActiveRule) {
this.severity = newActiveRule.severity;
+ this.name = newActiveRule.name;
this.internalKey = newActiveRule.internalKey;
this.ruleKey = newActiveRule.ruleKey;
this.params = ImmutableMap.copyOf(newActiveRule.params);
@@ -46,6 +49,11 @@ class DefaultActiveRule implements ActiveRule {
}
@Override
+ public String name() {
+ return name;
+ }
+
+ @Override
public String severity() {
return severity;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java
index dd4b53d5953..3f20d89bf3f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewActiveRule.java
@@ -33,6 +33,7 @@ import java.util.Map;
*/
public class NewActiveRule {
final RuleKey ruleKey;
+ String name;
String severity = Severity.defaultSeverity();
Map<String, String> params = new HashMap<String, String>();
String internalKey, language;
@@ -43,6 +44,11 @@ public class NewActiveRule {
this.ruleKey = ruleKey;
}
+ public NewActiveRule setName(String name) {
+ this.name = name;
+ return this;
+ }
+
public NewActiveRule setSeverity(@Nullable String severity) {
this.severity = StringUtils.defaultIfBlank(severity, Severity.defaultSeverity());
return this;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java
index 584b1ea7663..3d2ac27b8a1 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/ActiveRulesBuilderTest.java
@@ -40,6 +40,7 @@ public class ActiveRulesBuilderTest {
public void build_rules() throws Exception {
ActiveRules activeRules = new ActiveRulesBuilder()
.create(RuleKey.of("squid", "S0001"))
+ .setName("My Rule")
.setSeverity(Severity.CRITICAL)
.setInternalKey("__S0001__")
.setParam("min", "20")
@@ -58,6 +59,7 @@ public class ActiveRulesBuilderTest {
ActiveRule squid1 = activeRules.find(RuleKey.of("squid", "S0001"));
assertThat(squid1.ruleKey().repository()).isEqualTo("squid");
assertThat(squid1.ruleKey().rule()).isEqualTo("S0001");
+ assertThat(squid1.name()).isEqualTo("My Rule");
assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL);
assertThat(squid1.internalKey()).isEqualTo("__S0001__");
assertThat(squid1.params()).hasSize(1);