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 6dc811fa5547..61fb36aac9b4 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 @@ private static LineIterator sourceLinesIterator(File file) { private List dataLineReaders(BatchReportReader reportReader, int componentRef) { List 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 1a2c1c1c1265..e3f0e458862e 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 @@ 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 String[] supportedProjectQualifiers() { @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 highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef); - processSyntaxHightlighting(component, highlightingRules); - - for (Integer childRef : component.getChildRefList()) { - recursivelyProcessComponent(context, childRef); - } - } - - private void processSyntaxHightlighting(BatchReport.Component component, List 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 highlightingRules = reportReader.readComponentSyntaxHighlighting(componentRef); +// processSyntaxHightlighting(component, highlightingRules); +// +// for (Integer childRef : component.getChildRefList()) { +// recursivelyProcessComponent(context, childRef); +// } +// } +// +// private void processSyntaxHightlighting(BatchReport.Component component, List 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 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 2eeab5a46939..86c5e6f405ba 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 void setUp() throws Exception { 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 c44968ab7bb5..8eff4cae25ae 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 void persist_coverage() throws Exception { .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 0db99fa17796..e38b5dd75e0e 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 @@ 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 @@ protected ComputationStep step() throws IOException { 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); diff --git a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java index 064899e2b243..4b04e4ff9e2e 100644 --- a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java +++ b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java @@ -19649,6 +19649,7 @@ public interface CoverageOrBuilder extends * *
    * Only FILE component has coverage information
+   * TODO rename it LineCoverage ?
    * 
*/ public static final class Coverage extends @@ -20051,6 +20052,7 @@ protected Builder newBuilderForType( * *
      * Only FILE component has coverage information
+     * TODO rename it LineCoverage ?
      * 
*/ public static final class Builder extends @@ -20479,60 +20481,34 @@ public interface SyntaxHighlightingOrBuilder extends com.google.protobuf.MessageOrBuilder { /** - * optional int32 file_ref = 1; + * optional .Range range = 1; */ - boolean hasFileRef(); - /** - * optional int32 file_ref = 1; - */ - int getFileRef(); - + boolean hasRange(); /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .Range range = 1; */ - java.util.List - getHighlightingRuleList(); + org.sonar.batch.protocol.output.BatchReport.Range getRange(); /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .Range range = 1; */ - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index); + org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder(); + /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .HighlightingType type = 2; */ - int getHighlightingRuleCount(); + boolean hasType(); /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .HighlightingType type = 2; */ - java.util.List - getHighlightingRuleOrBuilderList(); - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
- */ - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( - int index); + org.sonar.batch.protocol.Constants.HighlightingType getType(); } /** * Protobuf type {@code SyntaxHighlighting} + * + *
+   * Must be sorted by line and start offset
+   * TODO rename it SyntaxHighlightingRule ?
+   * 
*/ public static final class SyntaxHighlighting extends com.google.protobuf.GeneratedMessage implements @@ -20550,763 +20526,142 @@ public static SyntaxHighlighting getDefaultInstance() { return defaultInstance; } - public SyntaxHighlighting getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SyntaxHighlighting( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - bitField0_ |= 0x00000001; - fileRef_ = input.readInt32(); - break; - } - case 18: { - if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - highlightingRule_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000002; - } - highlightingRule_.add(input.readMessage(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.PARSER, extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { - highlightingRule_ = java.util.Collections.unmodifiableList(highlightingRule_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public SyntaxHighlighting parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SyntaxHighlighting(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public interface HighlightingRuleOrBuilder extends - // @@protoc_insertion_point(interface_extends:SyntaxHighlighting.HighlightingRule) - com.google.protobuf.MessageOrBuilder { - - /** - * optional .Range range = 1; - */ - boolean hasRange(); - /** - * optional .Range range = 1; - */ - org.sonar.batch.protocol.output.BatchReport.Range getRange(); - /** - * optional .Range range = 1; - */ - org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder(); - - /** - * optional .HighlightingType type = 2; - */ - boolean hasType(); - /** - * optional .HighlightingType type = 2; - */ - org.sonar.batch.protocol.Constants.HighlightingType getType(); - } - /** - * Protobuf type {@code SyntaxHighlighting.HighlightingRule} - */ - public static final class HighlightingRule extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:SyntaxHighlighting.HighlightingRule) - HighlightingRuleOrBuilder { - // Use HighlightingRule.newBuilder() to construct. - private HighlightingRule(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private HighlightingRule(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final HighlightingRule defaultInstance; - public static HighlightingRule getDefaultInstance() { - return defaultInstance; - } - - public HighlightingRule getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private HighlightingRule( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - org.sonar.batch.protocol.output.BatchReport.Range.Builder subBuilder = null; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - subBuilder = range_.toBuilder(); - } - range_ = input.readMessage(org.sonar.batch.protocol.output.BatchReport.Range.PARSER, extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom(range_); - range_ = subBuilder.buildPartial(); - } - bitField0_ |= 0x00000001; - break; - } - case 16: { - int rawValue = input.readEnum(); - org.sonar.batch.protocol.Constants.HighlightingType value = org.sonar.batch.protocol.Constants.HighlightingType.valueOf(rawValue); - if (value == null) { - unknownFields.mergeVarintField(2, rawValue); - } else { - bitField0_ |= 0x00000002; - type_ = value; - } - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public HighlightingRule parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new HighlightingRule(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - private int bitField0_; - public static final int RANGE_FIELD_NUMBER = 1; - private org.sonar.batch.protocol.output.BatchReport.Range range_; - /** - * optional .Range range = 1; - */ - public boolean hasRange() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional .Range range = 1; - */ - public org.sonar.batch.protocol.output.BatchReport.Range getRange() { - return range_; - } - /** - * optional .Range range = 1; - */ - public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { - return range_; - } - - public static final int TYPE_FIELD_NUMBER = 2; - private org.sonar.batch.protocol.Constants.HighlightingType type_; - /** - * optional .HighlightingType type = 2; - */ - public boolean hasType() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional .HighlightingType type = 2; - */ - public org.sonar.batch.protocol.Constants.HighlightingType getType() { - return type_; - } - - private void initFields() { - range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); - type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeMessage(1, range_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - output.writeEnum(2, type_.getNumber()); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, range_); - } - if (((bitField0_ & 0x00000002) == 0x00000002)) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(2, type_.getNumber()); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code SyntaxHighlighting.HighlightingRule} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:SyntaxHighlighting.HighlightingRule) - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable - .ensureFieldAccessorsInitialized( - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder.class); - } - - // Construct using org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getRangeFieldBuilder(); - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - if (rangeBuilder_ == null) { - range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); - } else { - rangeBuilder_.clear(); - } - bitField0_ = (bitField0_ & ~0x00000001); - type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; - bitField0_ = (bitField0_ & ~0x00000002); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_HighlightingRule_descriptor; - } - - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getDefaultInstanceForType() { - return org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance(); - } - - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule build() { - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule buildPartial() { - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule result = new org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - if (rangeBuilder_ == null) { - result.range_ = range_; - } else { - result.range_ = rangeBuilder_.build(); - } - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { - to_bitField0_ |= 0x00000002; - } - result.type_ = type_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule) { - return mergeFrom((org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule other) { - if (other == org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()) return this; - if (other.hasRange()) { - mergeRange(other.getRange()); - } - if (other.hasType()) { - setType(other.getType()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - return true; - } + public SyntaxHighlighting getDefaultInstanceForType() { + return defaultInstance; + } - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private SyntaxHighlighting( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; } - } - return this; - } - private int bitField0_; - - private org.sonar.batch.protocol.output.BatchReport.Range range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); - private com.google.protobuf.SingleFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> rangeBuilder_; - /** - * optional .Range range = 1; - */ - public boolean hasRange() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional .Range range = 1; - */ - public org.sonar.batch.protocol.output.BatchReport.Range getRange() { - if (rangeBuilder_ == null) { - return range_; - } else { - return rangeBuilder_.getMessage(); - } - } - /** - * optional .Range range = 1; - */ - public Builder setRange(org.sonar.batch.protocol.output.BatchReport.Range value) { - if (rangeBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); + case 10: { + org.sonar.batch.protocol.output.BatchReport.Range.Builder subBuilder = null; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + subBuilder = range_.toBuilder(); + } + range_ = input.readMessage(org.sonar.batch.protocol.output.BatchReport.Range.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(range_); + range_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000001; + break; } - range_ = value; - onChanged(); - } else { - rangeBuilder_.setMessage(value); - } - bitField0_ |= 0x00000001; - return this; - } - /** - * optional .Range range = 1; - */ - public Builder setRange( - org.sonar.batch.protocol.output.BatchReport.Range.Builder builderForValue) { - if (rangeBuilder_ == null) { - range_ = builderForValue.build(); - onChanged(); - } else { - rangeBuilder_.setMessage(builderForValue.build()); - } - bitField0_ |= 0x00000001; - return this; - } - /** - * optional .Range range = 1; - */ - public Builder mergeRange(org.sonar.batch.protocol.output.BatchReport.Range value) { - if (rangeBuilder_ == null) { - if (((bitField0_ & 0x00000001) == 0x00000001) && - range_ != org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance()) { - range_ = - org.sonar.batch.protocol.output.BatchReport.Range.newBuilder(range_).mergeFrom(value).buildPartial(); - } else { - range_ = value; + case 16: { + int rawValue = input.readEnum(); + org.sonar.batch.protocol.Constants.HighlightingType value = org.sonar.batch.protocol.Constants.HighlightingType.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(2, rawValue); + } else { + bitField0_ |= 0x00000002; + type_ = value; + } + break; } - onChanged(); - } else { - rangeBuilder_.mergeFrom(value); - } - bitField0_ |= 0x00000001; - return this; - } - /** - * optional .Range range = 1; - */ - public Builder clearRange() { - if (rangeBuilder_ == null) { - range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); - onChanged(); - } else { - rangeBuilder_.clear(); - } - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - /** - * optional .Range range = 1; - */ - public org.sonar.batch.protocol.output.BatchReport.Range.Builder getRangeBuilder() { - bitField0_ |= 0x00000001; - onChanged(); - return getRangeFieldBuilder().getBuilder(); - } - /** - * optional .Range range = 1; - */ - public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { - if (rangeBuilder_ != null) { - return rangeBuilder_.getMessageOrBuilder(); - } else { - return range_; - } - } - /** - * optional .Range range = 1; - */ - private com.google.protobuf.SingleFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> - getRangeFieldBuilder() { - if (rangeBuilder_ == null) { - rangeBuilder_ = new com.google.protobuf.SingleFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder>( - getRange(), - getParentForChildren(), - isClean()); - range_ = null; - } - return rangeBuilder_; - } - - private org.sonar.batch.protocol.Constants.HighlightingType type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; - /** - * optional .HighlightingType type = 2; - */ - public boolean hasType() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional .HighlightingType type = 2; - */ - public org.sonar.batch.protocol.Constants.HighlightingType getType() { - return type_; - } - /** - * optional .HighlightingType type = 2; - */ - public Builder setType(org.sonar.batch.protocol.Constants.HighlightingType value) { - if (value == null) { - throw new NullPointerException(); } - bitField0_ |= 0x00000002; - type_ = value; - onChanged(); - return this; } - /** - * optional .HighlightingType type = 2; - */ - public Builder clearType() { - bitField0_ = (bitField0_ & ~0x00000002); - type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:SyntaxHighlighting.HighlightingRule) + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_descriptor; + } - static { - defaultInstance = new HighlightingRule(true); - defaultInstance.initFields(); + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_SyntaxHighlighting_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.class, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public SyntaxHighlighting parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SyntaxHighlighting(input, extensionRegistry); } + }; - // @@protoc_insertion_point(class_scope:SyntaxHighlighting.HighlightingRule) + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; } private int bitField0_; - public static final int FILE_REF_FIELD_NUMBER = 1; - private int fileRef_; + public static final int RANGE_FIELD_NUMBER = 1; + private org.sonar.batch.protocol.output.BatchReport.Range range_; /** - * optional int32 file_ref = 1; + * optional .Range range = 1; */ - public boolean hasFileRef() { + public boolean hasRange() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * optional int32 file_ref = 1; - */ - public int getFileRef() { - return fileRef_; - } - - public static final int HIGHLIGHTING_RULE_FIELD_NUMBER = 2; - private java.util.List highlightingRule_; - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
- */ - public java.util.List getHighlightingRuleList() { - return highlightingRule_; - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .Range range = 1; */ - public java.util.List - getHighlightingRuleOrBuilderList() { - return highlightingRule_; + public org.sonar.batch.protocol.output.BatchReport.Range getRange() { + return range_; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .Range range = 1; */ - public int getHighlightingRuleCount() { - return highlightingRule_.size(); + public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { + return range_; } + + public static final int TYPE_FIELD_NUMBER = 2; + private org.sonar.batch.protocol.Constants.HighlightingType type_; /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .HighlightingType type = 2; */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index) { - return highlightingRule_.get(index); + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-     * Rule must be sorted by line and start offset
-     * 
+ * optional .HighlightingType type = 2; */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( - int index) { - return highlightingRule_.get(index); + public org.sonar.batch.protocol.Constants.HighlightingType getType() { + return type_; } private void initFields() { - fileRef_ = 0; - highlightingRule_ = java.util.Collections.emptyList(); + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -21322,10 +20677,10 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeInt32(1, fileRef_); + output.writeMessage(1, range_); } - for (int i = 0; i < highlightingRule_.size(); i++) { - output.writeMessage(2, highlightingRule_.get(i)); + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeEnum(2, type_.getNumber()); } getUnknownFields().writeTo(output); } @@ -21338,11 +20693,11 @@ public int getSerializedSize() { size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream - .computeInt32Size(1, fileRef_); + .computeMessageSize(1, range_); } - for (int i = 0; i < highlightingRule_.size(); i++) { + if (((bitField0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, highlightingRule_.get(i)); + .computeEnumSize(2, type_.getNumber()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; @@ -21424,6 +20779,11 @@ protected Builder newBuilderForType( } /** * Protobuf type {@code SyntaxHighlighting} + * + *
+     * Must be sorted by line and start offset
+     * TODO rename it SyntaxHighlightingRule ?
+     * 
*/ public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder implements @@ -21453,7 +20813,7 @@ private Builder( } private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getHighlightingRuleFieldBuilder(); + getRangeFieldBuilder(); } } private static Builder create() { @@ -21462,14 +20822,14 @@ private static Builder create() { public Builder clear() { super.clear(); - fileRef_ = 0; - bitField0_ = (bitField0_ & ~0x00000001); - if (highlightingRuleBuilder_ == null) { - highlightingRule_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); + if (rangeBuilder_ == null) { + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); } else { - highlightingRuleBuilder_.clear(); + rangeBuilder_.clear(); } + bitField0_ = (bitField0_ & ~0x00000001); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + bitField0_ = (bitField0_ & ~0x00000002); return this; } @@ -21501,16 +20861,15 @@ public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting buildParti if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } - result.fileRef_ = fileRef_; - if (highlightingRuleBuilder_ == null) { - if (((bitField0_ & 0x00000002) == 0x00000002)) { - highlightingRule_ = java.util.Collections.unmodifiableList(highlightingRule_); - bitField0_ = (bitField0_ & ~0x00000002); - } - result.highlightingRule_ = highlightingRule_; + if (rangeBuilder_ == null) { + result.range_ = range_; } else { - result.highlightingRule_ = highlightingRuleBuilder_.build(); + result.range_ = rangeBuilder_.build(); + } + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; } + result.type_ = type_; result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -21527,34 +20886,11 @@ public Builder mergeFrom(com.google.protobuf.Message other) { public Builder mergeFrom(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting other) { if (other == org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.getDefaultInstance()) return this; - if (other.hasFileRef()) { - setFileRef(other.getFileRef()); + if (other.hasRange()) { + mergeRange(other.getRange()); } - if (highlightingRuleBuilder_ == null) { - if (!other.highlightingRule_.isEmpty()) { - if (highlightingRule_.isEmpty()) { - highlightingRule_ = other.highlightingRule_; - bitField0_ = (bitField0_ & ~0x00000002); - } else { - ensureHighlightingRuleIsMutable(); - highlightingRule_.addAll(other.highlightingRule_); - } - onChanged(); - } - } else { - if (!other.highlightingRule_.isEmpty()) { - if (highlightingRuleBuilder_.isEmpty()) { - highlightingRuleBuilder_.dispose(); - highlightingRuleBuilder_ = null; - highlightingRule_ = other.highlightingRule_; - bitField0_ = (bitField0_ & ~0x00000002); - highlightingRuleBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getHighlightingRuleFieldBuilder() : null; - } else { - highlightingRuleBuilder_.addAllMessages(other.highlightingRule_); - } - } + if (other.hasType()) { + setType(other.getType()); } this.mergeUnknownFields(other.getUnknownFields()); return this; @@ -21583,348 +20919,155 @@ public Builder mergeFrom( } private int bitField0_; - private int fileRef_ ; + private org.sonar.batch.protocol.output.BatchReport.Range range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> rangeBuilder_; /** - * optional int32 file_ref = 1; + * optional .Range range = 1; */ - public boolean hasFileRef() { + public boolean hasRange() { return ((bitField0_ & 0x00000001) == 0x00000001); } /** - * optional int32 file_ref = 1; - */ - public int getFileRef() { - return fileRef_; - } - /** - * optional int32 file_ref = 1; - */ - public Builder setFileRef(int value) { - bitField0_ |= 0x00000001; - fileRef_ = value; - onChanged(); - return this; - } - /** - * optional int32 file_ref = 1; - */ - public Builder clearFileRef() { - bitField0_ = (bitField0_ & ~0x00000001); - fileRef_ = 0; - onChanged(); - return this; - } - - private java.util.List highlightingRule_ = - java.util.Collections.emptyList(); - private void ensureHighlightingRuleIsMutable() { - if (!((bitField0_ & 0x00000002) == 0x00000002)) { - highlightingRule_ = new java.util.ArrayList(highlightingRule_); - bitField0_ |= 0x00000002; - } - } - - private com.google.protobuf.RepeatedFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder> highlightingRuleBuilder_; - - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public java.util.List getHighlightingRuleList() { - if (highlightingRuleBuilder_ == null) { - return java.util.Collections.unmodifiableList(highlightingRule_); - } else { - return highlightingRuleBuilder_.getMessageList(); - } - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public int getHighlightingRuleCount() { - if (highlightingRuleBuilder_ == null) { - return highlightingRule_.size(); - } else { - return highlightingRuleBuilder_.getCount(); - } - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule getHighlightingRule(int index) { - if (highlightingRuleBuilder_ == null) { - return highlightingRule_.get(index); + public org.sonar.batch.protocol.output.BatchReport.Range getRange() { + if (rangeBuilder_ == null) { + return range_; } else { - return highlightingRuleBuilder_.getMessage(index); + return rangeBuilder_.getMessage(); } } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder setHighlightingRule( - int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { - if (highlightingRuleBuilder_ == null) { + public Builder setRange(org.sonar.batch.protocol.output.BatchReport.Range value) { + if (rangeBuilder_ == null) { if (value == null) { throw new NullPointerException(); } - ensureHighlightingRuleIsMutable(); - highlightingRule_.set(index, value); - onChanged(); - } else { - highlightingRuleBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public Builder setHighlightingRule( - int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { - if (highlightingRuleBuilder_ == null) { - ensureHighlightingRuleIsMutable(); - highlightingRule_.set(index, builderForValue.build()); + range_ = value; onChanged(); } else { - highlightingRuleBuilder_.setMessage(index, builderForValue.build()); + rangeBuilder_.setMessage(value); } + bitField0_ |= 0x00000001; return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder addHighlightingRule(org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { - if (highlightingRuleBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureHighlightingRuleIsMutable(); - highlightingRule_.add(value); + public Builder setRange( + org.sonar.batch.protocol.output.BatchReport.Range.Builder builderForValue) { + if (rangeBuilder_ == null) { + range_ = builderForValue.build(); onChanged(); } else { - highlightingRuleBuilder_.addMessage(value); + rangeBuilder_.setMessage(builderForValue.build()); } + bitField0_ |= 0x00000001; return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder addHighlightingRule( - int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule value) { - if (highlightingRuleBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); + public Builder mergeRange(org.sonar.batch.protocol.output.BatchReport.Range value) { + if (rangeBuilder_ == null) { + if (((bitField0_ & 0x00000001) == 0x00000001) && + range_ != org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance()) { + range_ = + org.sonar.batch.protocol.output.BatchReport.Range.newBuilder(range_).mergeFrom(value).buildPartial(); + } else { + range_ = value; } - ensureHighlightingRuleIsMutable(); - highlightingRule_.add(index, value); - onChanged(); - } else { - highlightingRuleBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public Builder addHighlightingRule( - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { - if (highlightingRuleBuilder_ == null) { - ensureHighlightingRuleIsMutable(); - highlightingRule_.add(builderForValue.build()); onChanged(); } else { - highlightingRuleBuilder_.addMessage(builderForValue.build()); + rangeBuilder_.mergeFrom(value); } + bitField0_ |= 0x00000001; return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder addHighlightingRule( - int index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder builderForValue) { - if (highlightingRuleBuilder_ == null) { - ensureHighlightingRuleIsMutable(); - highlightingRule_.add(index, builderForValue.build()); + public Builder clearRange() { + if (rangeBuilder_ == null) { + range_ = org.sonar.batch.protocol.output.BatchReport.Range.getDefaultInstance(); onChanged(); } else { - highlightingRuleBuilder_.addMessage(index, builderForValue.build()); + rangeBuilder_.clear(); } + bitField0_ = (bitField0_ & ~0x00000001); return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder addAllHighlightingRule( - java.lang.Iterable values) { - if (highlightingRuleBuilder_ == null) { - ensureHighlightingRuleIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, highlightingRule_); - onChanged(); - } else { - highlightingRuleBuilder_.addAllMessages(values); - } - return this; + public org.sonar.batch.protocol.output.BatchReport.Range.Builder getRangeBuilder() { + bitField0_ |= 0x00000001; + onChanged(); + return getRangeFieldBuilder().getBuilder(); } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder clearHighlightingRule() { - if (highlightingRuleBuilder_ == null) { - highlightingRule_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); + public org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder getRangeOrBuilder() { + if (rangeBuilder_ != null) { + return rangeBuilder_.getMessageOrBuilder(); } else { - highlightingRuleBuilder_.clear(); + return range_; } - return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .Range range = 1; */ - public Builder removeHighlightingRule(int index) { - if (highlightingRuleBuilder_ == null) { - ensureHighlightingRuleIsMutable(); - highlightingRule_.remove(index); - onChanged(); - } else { - highlightingRuleBuilder_.remove(index); + private com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder> + getRangeFieldBuilder() { + if (rangeBuilder_ == null) { + rangeBuilder_ = new com.google.protobuf.SingleFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Range, org.sonar.batch.protocol.output.BatchReport.Range.Builder, org.sonar.batch.protocol.output.BatchReport.RangeOrBuilder>( + getRange(), + getParentForChildren(), + isClean()); + range_ = null; } - return this; + return rangeBuilder_; } + + private org.sonar.batch.protocol.Constants.HighlightingType type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .HighlightingType type = 2; */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder getHighlightingRuleBuilder( - int index) { - return getHighlightingRuleFieldBuilder().getBuilder(index); + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .HighlightingType type = 2; */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder getHighlightingRuleOrBuilder( - int index) { - if (highlightingRuleBuilder_ == null) { - return highlightingRule_.get(index); } else { - return highlightingRuleBuilder_.getMessageOrBuilder(index); - } + public org.sonar.batch.protocol.Constants.HighlightingType getType() { + return type_; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .HighlightingType type = 2; */ - public java.util.List - getHighlightingRuleOrBuilderList() { - if (highlightingRuleBuilder_ != null) { - return highlightingRuleBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(highlightingRule_); + public Builder setType(org.sonar.batch.protocol.Constants.HighlightingType value) { + if (value == null) { + throw new NullPointerException(); } + bitField0_ |= 0x00000002; + type_ = value; + onChanged(); + return this; } /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder addHighlightingRuleBuilder() { - return getHighlightingRuleFieldBuilder().addBuilder( - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()); - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
- */ - public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder addHighlightingRuleBuilder( - int index) { - return getHighlightingRuleFieldBuilder().addBuilder( - index, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.getDefaultInstance()); - } - /** - * repeated .SyntaxHighlighting.HighlightingRule highlighting_rule = 2; - * - *
-       * Rule must be sorted by line and start offset
-       * 
+ * optional .HighlightingType type = 2; */ - public java.util.List - getHighlightingRuleBuilderList() { - return getHighlightingRuleFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder> - getHighlightingRuleFieldBuilder() { - if (highlightingRuleBuilder_ == null) { - highlightingRuleBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< - org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule.Builder, org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRuleOrBuilder>( - highlightingRule_, - ((bitField0_ & 0x00000002) == 0x00000002), - getParentForChildren(), - isClean()); - highlightingRule_ = null; - } - return highlightingRuleBuilder_; + public Builder clearType() { + bitField0_ = (bitField0_ & ~0x00000002); + type_ = org.sonar.batch.protocol.Constants.HighlightingType.ANNOTATION; + onChanged(); + return this; } // @@protoc_insertion_point(builder_scope:SyntaxHighlighting) @@ -22028,11 +21171,6 @@ public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Highlighti private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_SyntaxHighlighting_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_SyntaxHighlighting_HighlightingRule_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -22107,13 +21245,10 @@ public org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.Highlighti "nditions\030\002 \001(\005\022\017\n\007ut_hits\030\003 \001(\010\022\017\n\007it_hi" + "ts\030\004 \001(\010\022\035\n\025ut_covered_conditions\030\005 \001(\005\022" + "\035\n\025it_covered_conditions\030\006 \001(\005\022\"\n\032overal" + - "l_covered_conditions\030\007 \001(\005\"\263\001\n\022SyntaxHig" + - "hlighting\022\020\n\010file_ref\030\001 \001(\005\022?\n\021highlight" + - "ing_rule\030\002 \003(\0132$.SyntaxHighlighting.High" + - "lightingRule\032J\n\020HighlightingRule\022\025\n\005rang" + - "e\030\001 \001(\0132\006.Range\022\037\n\004type\030\002 \001(\0162\021.Highligh", - "tingTypeB#\n\037org.sonar.batch.protocol.out" + - "putH\001" + "l_covered_conditions\030\007 \001(\005\"L\n\022SyntaxHigh" + + "lighting\022\025\n\005range\030\001 \001(\0132\006.Range\022\037\n\004type\030" + + "\002 \001(\0162\021.HighlightingTypeB#\n\037org.sonar.ba" + + "tch.protocol.outputH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { @@ -22235,12 +21370,6 @@ public com.google.protobuf.ExtensionRegistry assignDescriptors( internal_static_SyntaxHighlighting_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_SyntaxHighlighting_descriptor, - new java.lang.String[] { "FileRef", "HighlightingRule", }); - internal_static_SyntaxHighlighting_HighlightingRule_descriptor = - internal_static_SyntaxHighlighting_descriptor.getNestedTypes().get(0); - internal_static_SyntaxHighlighting_HighlightingRule_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_SyntaxHighlighting_HighlightingRule_descriptor, new java.lang.String[] { "Range", "Type", }); org.sonar.batch.protocol.Constants.getDescriptor(); } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java index 90720f6e5e16..fa11aa19b1bc 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java @@ -115,18 +115,17 @@ public boolean hasSyntaxHighlighting(int componentRef) { return file.exists(); } - public List readComponentSyntaxHighlighting(int componentRef) { - File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, componentRef); - if (file.exists() && file.isFile()) { - // all the highlighting are loaded in memory - BatchReport.SyntaxHighlighting syntaxHighlighting = ProtobufUtil.readFile(file, BatchReport.SyntaxHighlighting.PARSER); - return syntaxHighlighting.getHighlightingRuleList(); + @CheckForNull + public File readComponentSyntaxHighlighting(int fileRef) { + File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, fileRef); + if (doesFileExists(file)) { + return file; } - return Collections.emptyList(); + return null; } @CheckForNull - public File readFileCoverage(int fileRef) { + public File readComponentCoverage(int fileRef) { File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE, fileRef); if (doesFileExists(file)) { return file; diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java index 86ec1c53f6ee..8011382f086f 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportWriter.java @@ -105,15 +105,12 @@ public void writeComponentSymbols(int componentRef, Iterable highlightingRules) { - BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); - builder.setFileRef(componentRef); - builder.addAllHighlightingRule(highlightingRules); + public void writeComponentSyntaxHighlighting(int componentRef, Iterable syntaxHighlightingRules) { File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, componentRef); - ProtobufUtil.writeToFile(builder.build(), file); + ProtobufUtil.writeMessagesToFile(syntaxHighlightingRules, file); } - public void writeFileCoverage(int componentRef, Iterable coverageList) { + public void writeComponentCoverage(int componentRef, Iterable coverageList) { File file = fileStructure.fileFor(FileStructure.Domain.COVERAGE, componentRef); ProtobufUtil.writeMessagesToFile(coverageList, file); } diff --git a/sonar-batch-protocol/src/main/protobuf/batch_report.proto b/sonar-batch-protocol/src/main/protobuf/batch_report.proto index 52c746be7a06..3ab4bfc463f8 100644 --- a/sonar-batch-protocol/src/main/protobuf/batch_report.proto +++ b/sonar-batch-protocol/src/main/protobuf/batch_report.proto @@ -213,6 +213,7 @@ message Symbols { } // Only FILE component has coverage information +// TODO rename it LineCoverage ? message Coverage { optional int32 line = 1; @@ -225,14 +226,10 @@ message Coverage { optional int32 overall_covered_conditions = 7; } +// Must be sorted by line and start offset +// TODO rename it SyntaxHighlightingRule ? message SyntaxHighlighting { - optional int32 file_ref = 1; - // Rule must be sorted by line and start offset - repeated HighlightingRule highlighting_rule = 2; - - message HighlightingRule { - optional Range range = 1; - optional HighlightingType type = 2; - } + optional Range range = 1; + optional HighlightingType type = 2; } diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java index 184e1209804a..4d785ba153f3 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java @@ -109,24 +109,31 @@ public void read_syntax_highlighting() throws Exception { BatchReportWriter writer = new BatchReportWriter(dir); writer.writeMetadata(BatchReport.Metadata.newBuilder() - .setRootComponentRef(1).build()); + .setRootComponentRef(1) + .build()); writer.writeComponent(BatchReport.Component.newBuilder() .setRef(1).build()); - BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule = BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() - .setRange(BatchReport.Range.newBuilder() - .setStartLine(1) - .setEndLine(1) - .build()) - .setType(Constants.HighlightingType.ANNOTATION) - .build(); - writer.writeComponentSyntaxHighlighting(1, Arrays.asList(highlightingRule)); + writer.writeComponentSyntaxHighlighting(1, Arrays.asList( + BatchReport.SyntaxHighlighting.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setEndLine(10) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build() + )); - BatchReportReader sut = new BatchReportReader(dir); - assertThat(sut.readComponentSyntaxHighlighting(1)).hasSize(1); - assertThat(sut.readComponentSyntaxHighlighting(1).get(0).getRange()).isNotNull(); - assertThat(sut.readComponentSyntaxHighlighting(1).get(0).getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); + sut = new BatchReportReader(dir); + + try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(dir).readComponentSyntaxHighlighting(1))) { + BatchReport.SyntaxHighlighting syntaxHighlighting = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream); + assertThat(syntaxHighlighting.getRange()).isNotNull(); + assertThat(syntaxHighlighting.getRange().getStartLine()).isEqualTo(1); + assertThat(syntaxHighlighting.getRange().getEndLine()).isEqualTo(10); + assertThat(syntaxHighlighting.getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); + } } @Test @@ -174,7 +181,7 @@ public void read_coverage() throws Exception { writer.writeComponent(BatchReport.Component.newBuilder() .setRef(1).build()); - writer.writeFileCoverage(1, Arrays.asList( + writer.writeComponentCoverage(1, Arrays.asList( BatchReport.Coverage.newBuilder() .setLine(1) .setConditions(1) @@ -196,7 +203,7 @@ public void read_coverage() throws Exception { sut = new BatchReportReader(dir); - try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(dir).readFileCoverage(1))) { + try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(dir).readComponentCoverage(1))) { BatchReport.Coverage coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream); assertThat(coverage.getLine()).isEqualTo(1); assertThat(coverage.getConditions()).isEqualTo(1); @@ -264,18 +271,18 @@ public void empty_list_if_no_symbol_found() throws Exception { } @Test - public void empty_list_if_no_highlighting_found() throws Exception { - assertThat(sut.readComponentSyntaxHighlighting(123)).isEmpty(); + public void return_null_if_no_highlighting_found() throws Exception { + assertThat(sut.readComponentSyntaxHighlighting(123)).isNull(); } @Test public void return_null_if_no_coverage_found() throws Exception { - assertThat(sut.readFileCoverage(123)).isNull(); + assertThat(sut.readComponentCoverage(123)).isNull(); } @Test public void return_null_if_no_source_found() throws Exception { - assertThat(sut.readFileCoverage(123)).isNull(); + assertThat(sut.readComponentCoverage(123)).isNull(); } /** diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java index b0d666a52d72..c58ecbb67dfe 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportWriterTest.java @@ -277,24 +277,20 @@ public void write_syntax_highlighting() throws Exception { File dir = temp.newFolder(); BatchReportWriter writer = new BatchReportWriter(dir); + // no data yet assertThat(writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1)).isFalse(); - BatchReport.SyntaxHighlighting.HighlightingRule highlightingRule = BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() - .setRange(BatchReport.Range.newBuilder() - .setStartLine(1) - .setEndLine(1) - .build()) - .setType(Constants.HighlightingType.ANNOTATION) - .build(); - writer.writeComponentSyntaxHighlighting(1, Arrays.asList(highlightingRule)); + writer.writeComponentSyntaxHighlighting(1, Arrays.asList( + BatchReport.SyntaxHighlighting.newBuilder() + .setRange(BatchReport.Range.newBuilder() + .setStartLine(1) + .setEndLine(1) + .build()) + .setType(Constants.HighlightingType.ANNOTATION) + .build() + )); assertThat(writer.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1)).isTrue(); - File file = writer.getFileStructure().fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTING, 1); - assertThat(file).exists().isFile(); - BatchReport.SyntaxHighlighting syntaxHighlighting = ProtobufUtil.readFile(file, BatchReport.SyntaxHighlighting.PARSER); - assertThat(syntaxHighlighting.getFileRef()).isEqualTo(1); - assertThat(syntaxHighlighting.getHighlightingRuleList()).hasSize(1); - assertThat(syntaxHighlighting.getHighlightingRule(0).getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); } @Test @@ -305,7 +301,7 @@ public void write_coverage() throws Exception { // no data yet assertThat(writer.hasComponentData(FileStructure.Domain.COVERAGE, 1)).isFalse(); - writer.writeFileCoverage(1, Arrays.asList( + writer.writeComponentCoverage(1, Arrays.asList( BatchReport.Coverage.newBuilder() .setLine(1) .setConditions(1) @@ -315,7 +311,7 @@ public void write_coverage() throws Exception { .setItCoveredConditions(1) .setOverallCoveredConditions(1) .build() - )); + )); assertThat(writer.hasComponentData(FileStructure.Domain.COVERAGE, 1)).isTrue(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index 8a0184be3e37..8a1447acdee8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -21,6 +21,7 @@ import com.google.common.base.CharMatcher; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; import org.sonar.api.batch.fs.internal.DefaultInputFile; @@ -30,12 +31,13 @@ import org.sonar.api.measures.Measure; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; +import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; import org.sonar.batch.protocol.output.BatchReport.Scm; import org.sonar.batch.protocol.output.BatchReport.Scm.Changeset; import org.sonar.batch.protocol.output.BatchReport.Symbols; -import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule; -import org.sonar.batch.protocol.output.*; +import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting; +import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.report.BatchReportUtils; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.scan.measure.MeasureCache; @@ -43,7 +45,9 @@ import org.sonar.server.source.db.FileSourceDb; import org.sonar.server.source.db.FileSourceDb.Data.Builder; +import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.*; /** @@ -196,20 +200,34 @@ static interface MeasureOperation { void applyHighlighting(DefaultInputFile inputFile, FileSourceDb.Data.Builder to) { BatchReportReader reader = new BatchReportReader(reportPublisher.getReportDir()); - List highlightingRules = reader.readComponentSyntaxHighlighting(resourceCache.get(inputFile).batchId()); - if (highlightingRules.isEmpty()) { + File highlightingFile = reader.readComponentSyntaxHighlighting(resourceCache.get(inputFile).batchId()); + if (highlightingFile == null) { return; } StringBuilder[] highlightingPerLine = new StringBuilder[inputFile.lines()]; RuleItemWriter ruleItemWriter = new RuleItemWriter(); int currentLineIdx = 1; - for (HighlightingRule rule : highlightingRules) { - while (currentLineIdx < inputFile.lines() && rule.getRange().getStartLine() > currentLineIdx) { - // This rule starts on another line so advance - currentLineIdx++; + + InputStream inputStream = null; + try { + inputStream = FileUtils.openInputStream(highlightingFile); + BatchReport.SyntaxHighlighting rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream); + while (rule != null) { + while (currentLineIdx < inputFile.lines() && rule.getRange().getStartLine() > currentLineIdx) { + // This rule starts on another line so advance + currentLineIdx++; + } + // Now we know current rule starts on current line + writeDataPerLine(inputFile.originalLineOffsets(), rule, rule.getRange(), highlightingPerLine, ruleItemWriter); + + // Get next element + rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream); } - // Now we know current rule starts on current line - writeDataPerLine(inputFile.originalLineOffsets(), rule, rule.getRange(), highlightingPerLine, ruleItemWriter); + + } catch (Exception e) { + throw new IllegalStateException("Can't read syntax highlighting for " + inputFile.absolutePath()); + } finally { + IOUtils.closeQuietly(inputStream); } for (int i = 0; i < highlightingPerLine.length; i++) { StringBuilder sb = highlightingPerLine[i]; @@ -294,9 +312,9 @@ private static interface RangeItemWriter { void writeItem(StringBuilder currentLineSb, long startLineOffset, long endLineOffset, G item); } - private static class RuleItemWriter implements RangeItemWriter { + private static class RuleItemWriter implements RangeItemWriter { @Override - public void writeItem(StringBuilder currentLineSb, long startLineOffset, long endLineOffset, HighlightingRule item) { + public void writeItem(StringBuilder currentLineSb, long startLineOffset, long endLineOffset, SyntaxHighlighting item) { if (currentLineSb.length() > 0) { currentLineSb.append(';'); } 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 423f430c14f2..6dff11809b9f 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 @@ -20,6 +20,8 @@ package org.sonar.batch.mediumtest; import com.google.common.collect.Lists; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,12 +42,12 @@ import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.Cache.Entry; import org.sonar.batch.issue.IssueCache; +import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Component; import org.sonar.batch.protocol.output.BatchReport.Metadata; import org.sonar.batch.protocol.output.BatchReport.Range; import org.sonar.batch.protocol.output.BatchReport.Symbols.Symbol; -import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule; -import org.sonar.batch.protocol.output.*; +import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.report.BatchReportUtils; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.scan.ProjectScanContainer; @@ -55,6 +57,8 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import java.io.File; +import java.io.InputStream; import java.io.Serializable; import java.util.*; @@ -189,21 +193,33 @@ public List duplicationsFor(InputFile inputFile) { /** * Get highlighting types at a given position in an inputfile - * @param charIndex 0-based offset in file + * @param lineOffset 0-based offset in file */ public List highlightingTypeFor(InputFile file, int line, int lineOffset) { int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef(); - List syntaxHighlightingRules = getReportReader().readComponentSyntaxHighlighting(ref); - if (syntaxHighlightingRules.isEmpty()) { + File highlightingFile = reader.readComponentSyntaxHighlighting(ref); + if (highlightingFile == null) { return Collections.emptyList(); } TextPointer pointer = file.newPointer(line, lineOffset); List result = new ArrayList(); - for (HighlightingRule sortedRule : syntaxHighlightingRules) { - TextRange ruleRange = toRange(file, sortedRule.getRange()); - if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) { - result.add(BatchReportUtils.toBatchType(sortedRule.getType())); + InputStream inputStream = null; + try { + inputStream = FileUtils.openInputStream(highlightingFile); + BatchReport.SyntaxHighlighting rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream); + while (rule != null) { + 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()); + } finally { + IOUtils.closeQuietly(inputStream); } return result; } @@ -214,8 +230,8 @@ private static TextRange toRange(InputFile file, Range reportRange) { /** * Get list of all start positions of a symbol in an inputfile - * @param symbolStartOffset 0-based start offset for the symbol in file - * @param symbolEndOffset 0-based end offset for the symbol in file + * @param symbolStartLine 0-based start offset for the symbol in file + * @param symbolStartLineOffset 0-based end offset for the symbol in file */ @CheckForNull public List symbolReferencesFor(InputFile file, int symbolStartLine, int symbolStartLineOffset) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java index 6bc33a24c6e1..617e4d1b943f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/CoveragePublisher.java @@ -91,7 +91,7 @@ public void apply(String value, Coverage.Builder builder) { } }); - writer.writeFileCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), new Function() { + writer.writeComponentCoverage(resource.batchId(), Iterables.transform(coveragePerLine.values(), new Function() { @Override public Coverage apply(Builder input) { return input.build(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java index 5aec595a9f74..99cdf8bbb701 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java @@ -58,7 +58,6 @@ import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; -import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.report.BatchReportUtils; import org.sonar.batch.report.ReportPublisher; @@ -226,12 +225,12 @@ public void store(DefaultHighlighting highlighting) { BatchReportWriter writer = reportPublisher.getWriter(); DefaultInputFile inputFile = (DefaultInputFile) highlighting.inputFile(); writer.writeComponentSyntaxHighlighting(resourceCache.get(inputFile).batchId(), - Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new Function() { - private HighlightingRule.Builder builder = HighlightingRule.newBuilder(); + Iterables.transform(highlighting.getSyntaxHighlightingRuleSet(), new Function() { + private BatchReport.SyntaxHighlighting.Builder builder = BatchReport.SyntaxHighlighting.newBuilder(); private Range.Builder rangeBuilder = Range.newBuilder(); @Override - public HighlightingRule apply(SyntaxHighlightingRule input) { + public BatchReport.SyntaxHighlighting apply(SyntaxHighlightingRule input) { builder.clear(); rangeBuilder.clear(); builder.setRange(rangeBuilder.setStartLine(input.range().start().line()) diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java index 50a2554aa374..3d003ecc8a3a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java @@ -35,11 +35,12 @@ import org.sonar.api.measures.Metric; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.protocol.Constants.HighlightingType; -import org.sonar.batch.protocol.output.*; +import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Range; import org.sonar.batch.protocol.output.BatchReport.Scm; import org.sonar.batch.protocol.output.BatchReport.Scm.Changeset; -import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting.HighlightingRule; +import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting; +import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.server.source.db.FileSourceDb; @@ -315,8 +316,8 @@ public void applyHighlighting_nested_rules_and_multiple_lines() throws Exception assertThat(data.getLines(2).getHighlighting()).isEqualTo("0,9,c;1,8,k"); } - private HighlightingRule newRule(int startLine, int startOffset, int endLine, int endOffset, HighlightingType type) { - return BatchReport.SyntaxHighlighting.HighlightingRule.newBuilder() + private SyntaxHighlighting newRule(int startLine, int startOffset, int endLine, int endOffset, HighlightingType type) { + return BatchReport.SyntaxHighlighting.newBuilder() .setRange(Range.newBuilder().setStartLine(startLine).setStartOffset(startOffset).setEndLine(endLine).setEndOffset(endOffset).build()) .setType(type) .build(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java index 96ce8e035e75..0455bf55dba6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java @@ -91,7 +91,6 @@ public void computeSyntaxHighlightingOnTempProject() throws IOException { assertThat(result.highlightingTypeFor(file, 1, 9)).containsExactly(TypeOfText.STRING); assertThat(result.highlightingTypeFor(file, 2, 0)).containsExactly(TypeOfText.KEYWORD); assertThat(result.highlightingTypeFor(file, 2, 8)).isEmpty(); - } @Test 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 3e3c4cf284d7..f799843baba0 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 @@ -95,7 +95,7 @@ public void publishCoverage() throws Exception { publisher.publish(writer); - try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(outputDir).readFileCoverage(2))) { + try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(outputDir).readComponentCoverage(2))) { assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder() .setLine(2) .setUtHits(true)