summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-01-15 15:26:05 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-01-15 15:27:07 +0100
commit003d198ddc733d7b2358973752193033b8be182d (patch)
tree7c3f77c005948e3c913cd92572a3848989df8ebe /sonar-batch
parente76cc6071c7cc54916ccc50aa045ecdbde95ff45 (diff)
downloadsonarqube-003d198ddc733d7b2358973752193033b8be182d.tar.gz
sonarqube-003d198ddc733d7b2358973752193033b8be182d.zip
SONAR-3024 Use new resource key in json report
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java10
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json4
7 files changed, 11 insertions, 51 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java
index ba4a29ac6f8..8542eb6476e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelector.java
@@ -31,6 +31,4 @@ abstract class ComponentSelector {
abstract Set<String> componentKeys();
- abstract String getDeprecatedKey(String componentKey);
-
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
index 6fd9bb07c76..b384130468c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
@@ -37,6 +37,6 @@ public class ComponentSelectorFactory implements BatchComponent {
if (mode.isIncremental()) {
return new IncrementalComponentSelector(fileCache);
}
- return new DefaultComponentSelector(fileCache);
+ return new DefaultComponentSelector();
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java
index a90b4df7bf4..5b7223ad200 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/DefaultComponentSelector.java
@@ -19,35 +19,17 @@
*/
package org.sonar.batch.scan.report;
-import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.sonar.api.issue.Issue;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-import org.sonar.api.scan.filesystem.internal.InputFile;
-import org.sonar.batch.scan.filesystem.InputFileCache;
-import java.util.Map;
import java.util.Set;
class DefaultComponentSelector extends ComponentSelector {
- private final InputFileCache cache;
- private final Map<String, String> componentKeys = Maps.newHashMap();
private final Set<String> componentKeysWithIssue = Sets.newHashSet();
- DefaultComponentSelector(InputFileCache cache) {
- this.cache = cache;
- }
-
@Override
void init() {
- for (InputFile inputFile : cache.all()) {
- String componentKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY);
- String componentDeprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY);
- if (componentKey != null) {
- componentKeys.put(componentKey, componentDeprecatedKey);
- }
- }
}
@Override
@@ -60,9 +42,4 @@ class DefaultComponentSelector extends ComponentSelector {
Set<String> componentKeys() {
return componentKeysWithIssue;
}
-
- @Override
- String getDeprecatedKey(String componentKey) {
- return componentKeys.get(componentKey);
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java
index 0c54d1bbfa3..0317edf8b0b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IncrementalComponentSelector.java
@@ -19,19 +19,18 @@
*/
package org.sonar.batch.scan.report;
-import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.sonar.api.issue.Issue;
import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
import org.sonar.api.scan.filesystem.internal.InputFile;
import org.sonar.batch.scan.filesystem.InputFileCache;
-import java.util.Map;
import java.util.Set;
class IncrementalComponentSelector extends ComponentSelector {
private final InputFileCache cache;
- private final Map<String, String> componentKeys = Maps.newHashMap();
+ private final Set<String> componentKeys = Sets.newHashSet();
IncrementalComponentSelector(InputFileCache cache) {
this.cache = cache;
@@ -43,9 +42,8 @@ class IncrementalComponentSelector extends ComponentSelector {
String status = inputFile.attribute(InputFile.ATTRIBUTE_STATUS);
if (status != null && !InputFile.STATUS_SAME.equals(status)) {
String componentKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY);
- String componentDeprecatedKey = inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY);
if (componentKey != null) {
- componentKeys.put(componentKey, componentDeprecatedKey);
+ componentKeys.add(componentKey);
}
}
}
@@ -53,16 +51,11 @@ class IncrementalComponentSelector extends ComponentSelector {
@Override
boolean register(Issue issue) {
- return componentKeys.keySet().contains(issue.componentKey());
+ return componentKeys.contains(issue.componentKey());
}
@Override
Set<String> componentKeys() {
- return componentKeys.keySet();
- }
-
- @Override
- String getDeprecatedKey(String componentKey) {
- return componentKeys.get(componentKey);
+ return componentKeys;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
index b0d46450130..5ae50e5e4bd 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
@@ -145,7 +145,7 @@ public class JsonReport implements BatchComponent {
json
.beginObject()
.name("key").value(issue.key())
- .name("component").value(componentSelector.getDeprecatedKey(issue.componentKey()))
+ .name("component").value(issue.componentKey())
.name("line").value(issue.line())
.name("message").value(issue.message())
.name("severity").value(issue.severity())
@@ -183,7 +183,7 @@ public class JsonReport implements BatchComponent {
for (String componentKey : componentSelector.componentKeys()) {
json
.beginObject()
- .name("key").value(componentSelector.getDeprecatedKey(componentKey))
+ .name("key").value(componentKey)
.endObject();
}
json.endArray();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
index 5a09dfdbff4..3ed7a9ebfaf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
@@ -34,14 +34,11 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
-import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
-import org.sonar.api.scan.filesystem.internal.InputFile;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.core.user.DefaultUser;
import org.sonar.test.TestUtils;
@@ -85,12 +82,7 @@ public class JsonReportTest {
mode = mock(AnalysisMode.class);
when(mode.isPreview()).thenReturn(true);
userFinder = mock(UserFinder.class);
- InputFileCache inputFileCache = mock(InputFileCache.class);
- InputFile inputFile = mock(InputFile.class);
- when(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_KEY)).thenReturn("struts:/src/main/java/org/apache/struts/Action.java");
- when(inputFile.attribute(DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY)).thenReturn("struts:org.apache.struts.Action");
- when(inputFileCache.all()).thenReturn(Arrays.asList(inputFile));
- jsonReport = new JsonReport(settings, fileSystem, server, ruleFinder, issueCache, mock(EventBus.class), new DefaultComponentSelector(inputFileCache), mode, userFinder);
+ jsonReport = new JsonReport(settings, fileSystem, server, ruleFinder, issueCache, mock(EventBus.class), new DefaultComponentSelector(), mode, userFinder);
}
@Test
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
index 8d539f907f9..62bf4da8a75 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
@@ -1,7 +1,7 @@
{"version": "3.6", "issues": [
{
"key": "200",
- "component": "struts:org.apache.struts.Action",
+ "component": "struts:/src/main/java/org/apache/struts/Action.java",
"line": 1,
"message": "There are 2 cycles",
"severity": "MINOR",
@@ -16,7 +16,7 @@
}
], "components": [
{
- "key": "struts:org.apache.struts.Action"
+ "key": "struts:/src/main/java/org/apache/struts/Action.java"
}
], "rules": [
{