aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-09-03 18:17:36 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-09-10 16:24:34 +0200
commit2cefd460a1366f37c720c01964e00bac4b577c03 (patch)
tree7c27a29635b63b9f08a82c5be23fadc099a4f3a0 /sonar-batch
parentfb5b91248d6e42717f66f23c79d40c91996d1194 (diff)
downloadsonarqube-2cefd460a1366f37c720c01964e00bac4b577c03.tar.gz
sonarqube-2cefd460a1366f37c720c01964e00bac4b577c03.zip
SONAR-6052 Drop secondary locations and rename execution flow -> flow
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java52
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java57
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo4
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo4
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo2
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo2
8 files changed, 55 insertions, 80 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java
index e3f416a9ef9..7bfbf6d81d2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueBuilderWrapper.java
@@ -84,14 +84,8 @@ public class DeprecatedIssueBuilderWrapper implements Issuable.IssueBuilder {
}
@Override
- public IssueBuilder addLocation(NewIssueLocation location) {
- newIssue.addLocation(location);
- return this;
- }
-
- @Override
- public IssueBuilder addExecutionFlow(Iterable<NewIssueLocation> flowLocations) {
- newIssue.addExecutionFlow(flowLocations);
+ public IssueBuilder addFlow(Iterable<NewIssueLocation> flowLocations) {
+ newIssue.addFlow(flowLocations);
return this;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java
index d1d2efdf8f1..83287731be0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueWrapper.java
@@ -72,12 +72,12 @@ public class DeprecatedIssueWrapper implements Issue {
@Override
public String message() {
- return newIssue.locations().get(0).message();
+ return newIssue.primaryLocation().message();
}
@Override
public Integer line() {
- TextRange textRange = newIssue.locations().get(0).textRange();
+ TextRange textRange = newIssue.primaryLocation().textRange();
return textRange != null ? textRange.start().line() : null;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 4363a59853b..9db7fd69fde 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -27,7 +27,7 @@ import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.batch.rule.Rules;
import org.sonar.api.batch.sensor.issue.Issue;
-import org.sonar.api.batch.sensor.issue.Issue.ExecutionFlow;
+import org.sonar.api.batch.sensor.issue.Issue.Flow;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.utils.MessageException;
@@ -52,7 +52,7 @@ public class ModuleIssues {
private final BatchReport.Issue.Builder builder = BatchReport.Issue.newBuilder();
private final Builder locationBuilder = IssueLocation.newBuilder();
private final org.sonar.batch.protocol.output.BatchReport.TextRange.Builder textRangeBuilder = org.sonar.batch.protocol.output.BatchReport.TextRange.newBuilder();
- private final BatchReport.ExecutionFlow.Builder flowBuilder = BatchReport.ExecutionFlow.newBuilder();
+ private final BatchReport.Flow.Builder flowBuilder = BatchReport.Flow.newBuilder();
public ModuleIssues(ActiveRules activeRules, Rules rules, IssueFilters filters, ReportPublisher reportPublisher, BatchComponentCache componentCache) {
this.activeRules = activeRules;
@@ -89,17 +89,15 @@ public class ModuleIssues {
locationBuilder.setComponentRef(component.batchId());
TextRange primaryTextRange = issue.primaryLocation().textRange();
- applyTextRange(primaryTextRange);
if (primaryTextRange != null) {
builder.setLine(primaryTextRange.start().line());
+ builder.setTextRange(toProtobufTextRange(primaryTextRange));
}
- builder.setPrimaryLocation(locationBuilder.build());
Double effortToFix = issue.effortToFix();
if (effortToFix != null) {
builder.setEffortToFix(effortToFix);
}
- applyAdditionalLocations(issue);
- applyExecutionFlows(issue);
+ applyFlows(issue);
BatchReport.Issue rawIssue = builder.build();
if (filters.accept(inputComponent.key(), rawIssue)) {
@@ -109,45 +107,33 @@ public class ModuleIssues {
return false;
}
- private void applyAdditionalLocations(Issue issue) {
- for (org.sonar.api.batch.sensor.issue.IssueLocation additionalLocation : issue.locations()) {
- locationBuilder.clear();
- locationBuilder.setComponentRef(componentCache.get(additionalLocation.inputComponent()).batchId());
- String message = additionalLocation.message();
- if (message != null) {
- locationBuilder.setMsg(message);
- }
- applyTextRange(additionalLocation.textRange());
- builder.addAdditionalLocation(locationBuilder.build());
- }
- }
-
- private void applyExecutionFlows(Issue issue) {
- for (ExecutionFlow executionFlow : issue.executionFlows()) {
+ private void applyFlows(Issue issue) {
+ for (Flow flow : issue.flows()) {
flowBuilder.clear();
- for (org.sonar.api.batch.sensor.issue.IssueLocation location : executionFlow.locations()) {
+ for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) {
locationBuilder.clear();
locationBuilder.setComponentRef(componentCache.get(location.inputComponent()).batchId());
String message = location.message();
if (message != null) {
locationBuilder.setMsg(message);
}
- applyTextRange(location.textRange());
+ TextRange textRange = location.textRange();
+ if (textRange != null) {
+ locationBuilder.setTextRange(toProtobufTextRange(textRange));
+ }
flowBuilder.addLocation(locationBuilder.build());
}
- builder.addExecutionFlow(flowBuilder.build());
+ builder.addFlow(flowBuilder.build());
}
}
- private void applyTextRange(TextRange primaryTextRange) {
- if (primaryTextRange != null) {
- textRangeBuilder.clear();
- textRangeBuilder.setStartLine(primaryTextRange.start().line());
- textRangeBuilder.setStartOffset(primaryTextRange.start().lineOffset());
- textRangeBuilder.setEndLine(primaryTextRange.end().line());
- textRangeBuilder.setEndOffset(primaryTextRange.end().lineOffset());
- locationBuilder.setTextRange(textRangeBuilder.build());
- }
+ private org.sonar.batch.protocol.output.BatchReport.TextRange toProtobufTextRange(TextRange primaryTextRange) {
+ textRangeBuilder.clear();
+ textRangeBuilder.setStartLine(primaryTextRange.start().line());
+ textRangeBuilder.setStartOffset(primaryTextRange.start().lineOffset());
+ textRangeBuilder.setEndLine(primaryTextRange.end().line());
+ textRangeBuilder.setEndOffset(primaryTextRange.end().lineOffset());
+ return textRangeBuilder.build();
}
private Rule validateRule(Issue issue) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
index 48db6fb0aae..3c452e5f53c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
@@ -29,7 +29,7 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.TaskResult;
import org.sonar.batch.protocol.input.ActiveRule;
-import org.sonar.batch.protocol.output.BatchReport.ExecutionFlow;
+import org.sonar.batch.protocol.output.BatchReport.Flow;
import org.sonar.batch.protocol.output.BatchReport.Issue;
import org.sonar.batch.protocol.output.BatchReport.IssueLocation;
import org.sonar.xoo.XooPlugin;
@@ -76,12 +76,10 @@ public class MultilineIssuesMediumTest {
Issue issue = issues.get(0);
assertThat(issue.getLine()).isEqualTo(6);
assertThat(issue.getMsg()).isEqualTo("Primary location");
- IssueLocation primaryLocation = issue.getPrimaryLocation();
- assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
- assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
- assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
- assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(6);
- assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(52);
+ assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
+ assertThat(issue.getTextRange().getEndLine()).isEqualTo(6);
+ assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50);
}
@Test
@@ -91,47 +89,44 @@ public class MultilineIssuesMediumTest {
Issue issue = issues.get(0);
assertThat(issue.getLine()).isEqualTo(6);
assertThat(issue.getMsg()).isEqualTo("Primary location");
- IssueLocation primaryLocation = issue.getPrimaryLocation();
- assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
- assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
- assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
- assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(7);
- assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(23);
+ assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
+ assertThat(issue.getTextRange().getEndLine()).isEqualTo(7);
+ assertThat(issue.getTextRange().getEndOffset()).isEqualTo(23);
}
@Test
- public void testMultipleIssueLocation() throws Exception {
+ public void testFlowWithSingleLocation() throws Exception {
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiple.xoo"));
assertThat(issues).hasSize(1);
Issue issue = issues.get(0);
assertThat(issue.getLine()).isEqualTo(6);
assertThat(issue.getMsg()).isEqualTo("Primary location");
- IssueLocation primaryLocation = issue.getPrimaryLocation();
- assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
- assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
- assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
- assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(6);
- assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(52);
-
- assertThat(issue.getAdditionalLocationList()).hasSize(1);
- IssueLocation additionalLocation = issue.getAdditionalLocation(0);
- assertThat(additionalLocation.getMsg()).isEqualTo("Location #2");
+ assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
+ assertThat(issue.getTextRange().getEndLine()).isEqualTo(6);
+ assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50);
+
+ assertThat(issue.getFlowList()).hasSize(1);
+ Flow flow = issue.getFlow(0);
+ assertThat(flow.getLocationList()).hasSize(1);
+ IssueLocation additionalLocation = flow.getLocation(0);
+ assertThat(additionalLocation.getMsg()).isEqualTo("Flow step #1");
assertThat(additionalLocation.getTextRange().getStartLine()).isEqualTo(7);
- assertThat(additionalLocation.getTextRange().getStartOffset()).isEqualTo(25);
+ assertThat(additionalLocation.getTextRange().getStartOffset()).isEqualTo(26);
assertThat(additionalLocation.getTextRange().getEndLine()).isEqualTo(7);
- assertThat(additionalLocation.getTextRange().getEndOffset()).isEqualTo(52);
+ assertThat(additionalLocation.getTextRange().getEndOffset()).isEqualTo(53);
}
@Test
- public void testExecutionFlows() throws Exception {
+ public void testFlowsWithMultipleElements() throws Exception {
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/WithFlow.xoo"));
assertThat(issues).hasSize(1);
Issue issue = issues.get(0);
- assertThat(issue.getExecutionFlowList()).hasSize(1);
-
- ExecutionFlow executionFlow = issue.getExecutionFlow(0);
- assertThat(executionFlow.getLocationList()).hasSize(2);
+ assertThat(issue.getFlowList()).hasSize(1);
+ Flow flow = issue.getFlow(0);
+ assertThat(flow.getLocationList()).hasSize(2);
// TODO more assertions
}
}
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo
index 4043133acfd..6e8a35f20a5 100644
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo
@@ -3,7 +3,7 @@ package hello;
public class HelloJava {
public static void main(String[] args) {
- {xoo-start-issue:1:1}System.out
- .println("Hello"){xoo-end-issue:1:1};
+ {xoo-start-issue:1}System.out
+ .println("Hello"){xoo-end-issue:1};
}
} \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo
index c3840bf283a..b6b1b8369a4 100644
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo
@@ -3,7 +3,7 @@ package hello;
public class HelloJava {
public static void main(String[] args) {
- {xoo-start-issue:1:1}System.out.println("Hello"){xoo-end-issue:1:1};
- {xoo-start-issue:1:2}System.out.println("World"){xoo-end-issue:1:2};
+ {xoo-start-issue:1}System.out.println("Hello"){xoo-end-issue:1};
+ {xoo-start-flow:1:1:1}System.out.println("World"){xoo-end-flow:1:1:1};
}
} \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo
index 0b815e09295..fc664425a99 100644
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo
@@ -3,6 +3,6 @@ package hello;
public class HelloJava {
public static void main(String[] args) {
- {xoo-start-issue:1:1}System.out.println("Hello"){xoo-end-issue:1:1};
+ {xoo-start-issue:1}System.out.println("Hello"){xoo-end-issue:1};
}
} \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo
index 31e11c695e9..9dc4685fe84 100644
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/WithFlow.xoo
@@ -5,7 +5,7 @@ public class HelloJava {
public static void main(String[] args) {
{xoo-start-flow:1:1:1}if (true){xoo-end-flow:1:1:1} {
{xoo-start-flow:1:1:2}if (true){xoo-end-flow:1:1:2} {
- {xoo-start-issue:1:1}if (true){xoo-end-issue:1:1} {
+ {xoo-start-issue:1}if (true){xoo-end-issue:1} {
System.out.println("Hello");
}
}