aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-07-22 23:27:12 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-07-23 10:18:17 +0200
commitbc7d7e83a24b7cd42f7060a0472b76094cf69f45 (patch)
tree007f3ac960a1516e2c0429d9c89934938c819f76 /sonar-batch
parenta6a852b3d4cd872070216a0aed34e1df48dc175c (diff)
downloadsonarqube-bc7d7e83a24b7cd42f7060a0472b76094cf69f45.tar.gz
sonarqube-bc7d7e83a24b7cd42f7060a0472b76094cf69f45.zip
SONAR-6684 remove unused measure fields from report
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java25
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java15
2 files changed, 13 insertions, 27 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
index c937a7fc32a..589f2bbe5f2 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
@@ -22,7 +22,6 @@ package org.sonar.batch.mediumtest;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
@@ -34,7 +33,6 @@ import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.AnalysisMode;
@@ -197,29 +195,21 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
*/
public List<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
- File highlightingFile = reader.readComponentSyntaxHighlighting(ref);
- if (highlightingFile == null) {
+ if (!reader.hasSyntaxHighlighting(ref)) {
return Collections.emptyList();
}
TextPointer pointer = file.newPointer(line, lineOffset);
List<TypeOfText> result = new ArrayList<>();
- InputStream inputStream = null;
- try {
- inputStream = FileUtils.openInputStream(highlightingFile);
- BatchReport.SyntaxHighlighting rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream);
- while (rule != null) {
+ try (CloseableIterator<BatchReport.SyntaxHighlighting> it = reader.readComponentSyntaxHighlighting(ref)) {
+ while (it.hasNext()) {
+ BatchReport.SyntaxHighlighting rule = it.next();
TextRange ruleRange = toRange(file, rule.getRange());
if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
result.add(BatchReportUtils.toBatchType(rule.getType()));
}
- // Get next element
- rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream);
}
-
} catch (Exception e) {
throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e);
- } finally {
- IOUtils.closeQuietly(inputStream);
}
return result;
}
@@ -250,13 +240,12 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
@CheckForNull
public BatchReport.Coverage coverageFor(InputFile file, int line) {
int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
- try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readComponentCoverage(ref))) {
- BatchReport.Coverage coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
- while (coverage != null) {
+ try (CloseableIterator<BatchReport.Coverage> it = getReportReader().readComponentCoverage(ref)) {
+ while (it.hasNext()) {
+ BatchReport.Coverage coverage = it.next();
if (coverage.getLine() == line) {
return coverage;
}
- coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
}
} catch (Exception e) {
throw new IllegalStateException(e);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
index c257614fe7c..e143fd3e3d0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
@@ -20,11 +20,9 @@
package org.sonar.batch.report;
import java.io.File;
-import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
-import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -34,11 +32,11 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
import org.sonar.batch.index.BatchComponentCache;
-import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.Coverage;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.scan.measure.MeasureCache;
+import org.sonar.core.util.CloseableIterator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
@@ -93,13 +91,13 @@ public class CoveragePublisherTest {
publisher.publish(writer);
- try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(outputDir).readComponentCoverage(2))) {
- assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+ try (CloseableIterator<Coverage> it = new BatchReportReader(outputDir).readComponentCoverage(2)) {
+ assertThat(it.next()).isEqualTo(Coverage.newBuilder()
.setLine(2)
.setUtHits(true)
.setItHits(false)
.build());
- assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+ assertThat(it.next()).isEqualTo(Coverage.newBuilder()
.setLine(3)
.setUtHits(true)
.setItHits(false)
@@ -108,13 +106,12 @@ public class CoveragePublisherTest {
.setItCoveredConditions(1)
.setOverallCoveredConditions(2)
.build());
- assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+ assertThat(it.next()).isEqualTo(Coverage.newBuilder()
.setLine(5)
.setUtHits(false)
.setItHits(true)
.build());
-
}
- }
+ }
}