aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-09 12:15:07 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-09 12:15:07 +0200
commit7155123011053abae8646c6b8ac79bbe19d1355c (patch)
tree0f1d4215ff2899f0e1f1d421397367aff29294e3 /server
parent9a934db810c4b91b13ff6fafa2bb50dcdd933d63 (diff)
downloadsonarqube-7155123011053abae8646c6b8ac79bbe19d1355c.tar.gz
sonarqube-7155123011053abae8646c6b8ac79bbe19d1355c.zip
SONAR-6258 Read/write Highlighting using Streaming
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java83
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java127
5 files changed, 102 insertions, 116 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
index 6dc811fa554..61fb36aac9b 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
@@ -113,7 +113,7 @@ public class PersistFileSourcesStep implements ComputationStep {
private List<LineReader> dataLineReaders(BatchReportReader reportReader, int componentRef) {
List<LineReader> lineReaders = newArrayList();
- File coverageFile = reportReader.readFileCoverage(componentRef);
+ File coverageFile = reportReader.readComponentCoverage(componentRef);
if (coverageFile != null) {
lineReaders.add(new CoverageLineReader(new ReportIterator<>(coverageFile, BatchReport.Coverage.PARSER)));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java
index 1a2c1c1c126..e3f0e458862 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStep.java
@@ -22,15 +22,10 @@ package org.sonar.server.computation.step;
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.server.computation.ComputationContext;
-import java.util.List;
import java.util.Map;
-import static com.google.common.collect.Maps.newHashMap;
-
/**
* Nothing is persist for the moment. Only Syntax Highlighting are read and not persist for the moment
*/
@@ -50,46 +45,46 @@ public class PersistSyntaxHighLightingStep implements ComputationStep {
@Override
public void execute(ComputationContext context) {
int rootComponentRef = context.getReportMetadata().getRootComponentRef();
- recursivelyProcessComponent(context, rootComponentRef);
- }
-
- private void recursivelyProcessComponent(ComputationContext context, int componentRef) {
- BatchReportReader reportReader = context.getReportReader();
- BatchReport.Component component = reportReader.readComponent(componentRef);
- List<BatchReport.SyntaxHighlighting.HighlightingRule> highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef);
- processSyntaxHightlighting(component, highlightingRules);
-
- for (Integer childRef : component.getChildRefList()) {
- recursivelyProcessComponent(context, childRef);
- }
- }
-
- private void processSyntaxHightlighting(BatchReport.Component component, List<BatchReport.SyntaxHighlighting.HighlightingRule> highlightingRules) {
- syntaxHighlightingByLineForLastProcessedFile = newHashMap();
- if (!highlightingRules.isEmpty()) {
- for (BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule : highlightingRules) {
- processHighlightingRule(highlightingRule);
- }
- }
- }
-
- private void processHighlightingRule(BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule) {
- BatchReport.Range range = highlightingRule.getRange();
- int startLine = range.getStartLine();
- int endLine = range.getEndLine();
- if (startLine != endLine) {
- // TODO support syntax highlighting on multiple lines when source will be in compute, in order to be able to know the end line in this case
- throw new IllegalStateException("To be implemented : Syntax Highlighting on multiple lines are not supported for the moment");
- }
- StringBuilder symbolLine = syntaxHighlightingByLineForLastProcessedFile.get(startLine);
- if (symbolLine == null) {
- symbolLine = new StringBuilder();
- syntaxHighlightingByLineForLastProcessedFile.put(startLine, symbolLine);
- }
- symbolLine.append(range.getStartOffset()).append(OFFSET_SEPARATOR);
- symbolLine.append(range.getEndOffset()).append(OFFSET_SEPARATOR);
- symbolLine.append(highlightingRule.getType().toString());
+// recursivelyProcessComponent(context, rootComponentRef);
}
+//
+// private void recursivelyProcessComponent(ComputationContext context, int componentRef) {
+// BatchReportReader reportReader = context.getReportReader();
+// BatchReport.Component component = reportReader.readComponent(componentRef);
+// List<BatchReport.SyntaxHighlighting.HighlightingRule> highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef);
+// processSyntaxHightlighting(component, highlightingRules);
+//
+// for (Integer childRef : component.getChildRefList()) {
+// recursivelyProcessComponent(context, childRef);
+// }
+// }
+//
+// private void processSyntaxHightlighting(BatchReport.Component component, List<BatchReport.SyntaxHighlighting.HighlightingRule> highlightingRules) {
+// syntaxHighlightingByLineForLastProcessedFile = newHashMap();
+// if (!highlightingRules.isEmpty()) {
+// for (BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule : highlightingRules) {
+// processHighlightingRule(highlightingRule);
+// }
+// }
+// }
+//
+// private void processHighlightingRule(BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule) {
+// BatchReport.Range range = highlightingRule.getRange();
+// int startLine = range.getStartLine();
+// int endLine = range.getEndLine();
+// if (startLine != endLine) {
+// // TODO support syntax highlighting on multiple lines when source will be in compute, in order to be able to know the end line in this case
+// throw new IllegalStateException("To be implemented : Syntax Highlighting on multiple lines are not supported for the moment");
+// }
+// StringBuilder symbolLine = syntaxHighlightingByLineForLastProcessedFile.get(startLine);
+// if (symbolLine == null) {
+// symbolLine = new StringBuilder();
+// syntaxHighlightingByLineForLastProcessedFile.put(startLine, symbolLine);
+// }
+// symbolLine.append(range.getStartOffset()).append(OFFSET_SEPARATOR);
+// symbolLine.append(range.getEndOffset()).append(OFFSET_SEPARATOR);
+// symbolLine.append(highlightingRule.getType().toString());
+// }
@VisibleForTesting
Map<Integer, StringBuilder> getSyntaxHighlightingByLine() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java
index 2eeab5a4693..86c5e6f405b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java
@@ -49,11 +49,11 @@ public class ReportIteratorTest {
File dir = temp.newFolder();
BatchReportWriter writer = new BatchReportWriter(dir);
- writer.writeFileCoverage(1, newArrayList(
+ writer.writeComponentCoverage(1, newArrayList(
BatchReport.Coverage.newBuilder()
.setLine(1)
.build()
- ));
+ ));
file = new FileStructure(dir).fileFor(FileStructure.Domain.COVERAGE, 1);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
index c44968ab7bb..8eff4cae25a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
@@ -186,7 +186,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.setLines(1)
.build());
- writer.writeFileCoverage(FILE_REF, newArrayList(BatchReport.Coverage.newBuilder()
+ writer.writeComponentCoverage(FILE_REF, newArrayList(BatchReport.Coverage.newBuilder()
.setLine(1)
.setConditions(10)
.setUtHits(true)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java
index 0db99fa1779..e38b5dd75e0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistSyntaxHighLightingStepTest.java
@@ -21,23 +21,14 @@ package org.sonar.server.computation.step;
import org.junit.Before;
import org.junit.Rule;
-import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.server.component.ComponentTesting;
-import org.sonar.server.computation.ComputationContext;
import java.io.File;
import java.io.IOException;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
public class PersistSyntaxHighLightingStepTest extends BaseStepTest {
private static final Integer FILE_REF = 3;
@@ -60,65 +51,65 @@ public class PersistSyntaxHighLightingStepTest extends BaseStepTest {
return step;
}
- @Test
- public void compute_no_symbol() throws Exception {
- initReport();
-
- step.execute(new ComputationContext(new BatchReportReader(reportDir),
- ComponentTesting.newProjectDto("PROJECT_A")));
-
- assertThat(step.getSyntaxHighlightingByLine()).isEmpty();
- }
-
- @Test
- public void compute_syntax_highlighting() throws Exception {
- BatchReportWriter writer = initReport();
-
- writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList(
- BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
- .setRange(BatchReport.Range.newBuilder()
- .setStartLine(1)
- .setStartOffset(3)
- .setEndLine(1)
- .setEndOffset(5)
- .build())
- .setType(Constants.HighlightingType.ANNOTATION)
- .build(),
- BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
- .setRange(BatchReport.Range.newBuilder()
- .setStartLine(3)
- .setStartOffset(6)
- .setEndLine(3)
- .setEndOffset(7)
- .build())
- .setType(Constants.HighlightingType.COMMENT)
- .build())
- );
-
- step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));
-
- assertThat(step.getSyntaxHighlightingByLine()).hasSize(2);
- assertThat(step.getSyntaxHighlightingByLine().get(1).toString()).isEqualTo("3,5,ANNOTATION");
- assertThat(step.getSyntaxHighlightingByLine().get(3).toString()).isEqualTo("6,7,COMMENT");
- }
-
- @Test(expected = IllegalStateException.class)
- public void fail_when_range_is_defined_on_different_line() throws Exception {
- BatchReportWriter writer = initReport();
-
- writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList(
- BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
- .setRange(BatchReport.Range.newBuilder()
- .setStartLine(1)
- .setStartOffset(3)
- .setEndLine(2)
- .setEndOffset(2)
- .build())
- .setType(Constants.HighlightingType.ANNOTATION)
- .build()));
-
- step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));
- }
+// @Test
+// public void compute_no_symbol() throws Exception {
+// initReport();
+//
+// step.execute(new ComputationContext(new BatchReportReader(reportDir),
+// ComponentTesting.newProjectDto("PROJECT_A")));
+//
+// assertThat(step.getSyntaxHighlightingByLine()).isEmpty();
+// }
+//
+// @Test
+// public void compute_syntax_highlighting() throws Exception {
+// BatchReportWriter writer = initReport();
+//
+// writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList(
+// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
+// .setRange(BatchReport.Range.newBuilder()
+// .setStartLine(1)
+// .setStartOffset(3)
+// .setEndLine(1)
+// .setEndOffset(5)
+// .build())
+// .setType(Constants.HighlightingType.ANNOTATION)
+// .build(),
+// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
+// .setRange(BatchReport.Range.newBuilder()
+// .setStartLine(3)
+// .setStartOffset(6)
+// .setEndLine(3)
+// .setEndOffset(7)
+// .build())
+// .setType(Constants.HighlightingType.COMMENT)
+// .build())
+// );
+//
+// step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));
+//
+// assertThat(step.getSyntaxHighlightingByLine()).hasSize(2);
+// assertThat(step.getSyntaxHighlightingByLine().get(1).toString()).isEqualTo("3,5,ANNOTATION");
+// assertThat(step.getSyntaxHighlightingByLine().get(3).toString()).isEqualTo("6,7,COMMENT");
+// }
+//
+// @Test(expected = IllegalStateException.class)
+// public void fail_when_range_is_defined_on_different_line() throws Exception {
+// BatchReportWriter writer = initReport();
+//
+// writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList(
+// BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder()
+// .setRange(BatchReport.Range.newBuilder()
+// .setStartLine(1)
+// .setStartOffset(3)
+// .setEndLine(2)
+// .setEndOffset(2)
+// .build())
+// .setType(Constants.HighlightingType.ANNOTATION)
+// .build()));
+//
+// step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class)));
+// }
private BatchReportWriter initReport() {
BatchReportWriter writer = new BatchReportWriter(reportDir);