aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-11-02 17:38:18 +0100
committerDavid Gageot <david@gageot.net>2012-11-02 17:43:25 +0100
commit50b20cf3336aaa5c26a116bd467f5cbb32420caa (patch)
tree37d45f8d722906123b3df0c90f1d639dc9cc7625 /sonar-batch
parent175c0e69eec53fa8cf17da39a6dfa4691325073b (diff)
downloadsonarqube-50b20cf3336aaa5c26a116bd467f5cbb32420caa.tar.gz
sonarqube-50b20cf3336aaa5c26a116bd467f5cbb32420caa.zip
SONAR-3895 Fix rule name
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java15
2 files changed, 22 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java b/sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java
index 3d25d1fb163..c292007b318 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/local/DryRunExporter.java
@@ -29,10 +29,12 @@ import org.sonar.api.batch.SensorContext;
import org.sonar.api.platform.Server;
import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.resources.Resource;
+import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.bootstrap.DryRun;
import org.sonar.batch.index.DefaultIndex;
+import org.sonar.core.i18n.RuleI18nManager;
import java.io.BufferedWriter;
import java.io.File;
@@ -41,6 +43,7 @@ import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
/**
* @since 3.4
@@ -52,12 +55,14 @@ public class DryRunExporter implements BatchComponent {
private final DefaultIndex sonarIndex;
private final ProjectFileSystem projectFileSystem;
private final Server server;
+ private final RuleI18nManager ruleI18nManager;
- public DryRunExporter(DryRun dryRun, DefaultIndex sonarIndex, ProjectFileSystem projectFileSystem, Server server) {
+ public DryRunExporter(DryRun dryRun, DefaultIndex sonarIndex, ProjectFileSystem projectFileSystem, Server server, RuleI18nManager ruleI18nManager) {
this.dryRun = dryRun;
this.sonarIndex = sonarIndex;
this.projectFileSystem = projectFileSystem;
this.server = server;
+ this.ruleI18nManager = ruleI18nManager;
}
public void execute(SensorContext context) {
@@ -110,7 +115,8 @@ public class DryRunExporter implements BatchComponent {
.name("message").value(violation.getMessage())
.name("severity").value(violation.getSeverity().name())
.name("rule_key").value(violation.getRule().getKey())
- .name("rule_name").value(violation.getRule().getName())
+ .name("rule_repository").value(violation.getRule().getRepositoryKey())
+ .name("rule_name").value(name(violation.getRule()))
.endObject();
}
@@ -127,6 +133,10 @@ public class DryRunExporter implements BatchComponent {
}
}
+ private String name(Rule rule) {
+ return ruleI18nManager.getName(rule.getRepositoryKey(), rule.getKey(), Locale.getDefault());
+ }
+
@VisibleForTesting
List<Violation> getViolations(Resource resource) {
return sonarIndex.getViolations(resource);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java b/sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java
index 35a5ce2f4bd..733893f9860 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/local/DryRunExporterTest.java
@@ -32,12 +32,14 @@ import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
import org.sonar.batch.bootstrap.DryRun;
import org.sonar.batch.index.DefaultIndex;
+import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.java.api.JavaClass;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
+import java.util.Locale;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
@@ -56,13 +58,14 @@ public class DryRunExporterTest {
Violation violation = mock(Violation.class);
ProjectFileSystem projectFileSystem = mock(ProjectFileSystem.class);
Server server = mock(Server.class);
+ RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
@org.junit.Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Before
public void setUp() {
- dryRunExporter = spy(new DryRunExporter(dryRun, sonarIndex, projectFileSystem, server));
+ dryRunExporter = spy(new DryRunExporter(dryRun, sonarIndex, projectFileSystem, server, ruleI18nManager));
}
@Test
@@ -79,8 +82,9 @@ public class DryRunExporterTest {
when(violation.getResource()).thenReturn(resource);
when(violation.getLineId()).thenReturn(1);
when(violation.getMessage()).thenReturn("VIOLATION");
- when(violation.getRule()).thenReturn(Rule.create("pmd", "RULE_KEY").setName("RULE_NAME"));
+ when(violation.getRule()).thenReturn(Rule.create("pmd", "RULE_KEY"));
when(violation.getSeverity()).thenReturn(RulePriority.INFO);
+ when(ruleI18nManager.getName("pmd", "RULE_KEY", Locale.getDefault())).thenReturn("RULE_NAME");
doReturn(Arrays.asList(violation)).when(dryRunExporter).getViolations(resource);
StringWriter output = new StringWriter();
@@ -89,7 +93,7 @@ public class DryRunExporterTest {
assertThat(json)
.isEqualTo(
- "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"line\":1,\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_name\":\"RULE_NAME\"}]}}");
+ "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"line\":1,\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\"}]}}");
}
@Test
@@ -99,8 +103,9 @@ public class DryRunExporterTest {
when(violation.getResource()).thenReturn(resource);
when(violation.getLineId()).thenReturn(null);
when(violation.getMessage()).thenReturn("VIOLATION");
- when(violation.getRule()).thenReturn(Rule.create("pmd", "RULE_KEY").setName("RULE_NAME"));
+ when(violation.getRule()).thenReturn(Rule.create("pmd", "RULE_KEY"));
when(violation.getSeverity()).thenReturn(RulePriority.INFO);
+ when(ruleI18nManager.getName("pmd", "RULE_KEY", Locale.getDefault())).thenReturn("RULE_NAME");
doReturn(Arrays.asList(violation)).when(dryRunExporter).getViolations(resource);
StringWriter output = new StringWriter();
@@ -108,7 +113,7 @@ public class DryRunExporterTest {
String json = output.toString();
assertThat(json).isEqualTo(
- "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_name\":\"RULE_NAME\"}]}}");
+ "{\"version\":\"3.4\",\"violations_per_resource\":{\"KEY\":[{\"message\":\"VIOLATION\",\"severity\":\"INFO\",\"rule_key\":\"RULE_KEY\",\"rule_repository\":\"pmd\",\"rule_name\":\"RULE_NAME\"}]}}");
}
@Test