]> source.dussan.org Git - sonarqube.git/commitdiff
Update scanner report to protobuf 3 (imply SONAR-7497) 858/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 22 Mar 2016 09:06:28 +0000 (10:06 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 23 Mar 2016 19:31:30 +0000 (20:31 +0100)
68 files changed:
it/it-tests/src/test/resources/test/TestExecutionTest/expected.json
pom.xml
server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReader.java
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerRawInputFactory.java
server/sonar-server/src/main/java/org/sonar/server/computation/measure/BatchMeasureToMeasure.java
server/sonar-server/src/main/java/org/sonar/server/computation/scm/ReportScmInfo.java
server/sonar-server/src/main/java/org/sonar/server/computation/source/CoverageLineReader.java
server/sonar-server/src/main/java/org/sonar/server/computation/source/HighlightingLineReader.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadDuplicationsFromReportStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadQualityProfilesStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistTestsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/batch/BatchReportReaderRule.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/ComponentImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/TrackerRawInputFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/measure/BatchMeasureToMeasureTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/measure/MeasureRepositoryImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/source/CoverageLineReaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/source/HighlightingLineReaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/source/ReportIteratorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/BuildComponentTreeStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/LoadQualityProfilesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/IssueTransformer.java
sonar-scanner-engine/src/main/java/org/sonar/batch/issue/ModuleIssues.java
sonar-scanner-engine/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/ActiveRulesPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/ComponentsPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/CoveragePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/MeasuresPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/ScannerReportUtils.java
sonar-scanner-engine/src/main/java/org/sonar/batch/report/TestExecutionAndCoveragePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
sonar-scanner-engine/src/test/java/org/sonar/batch/cpd/CpdExecutorTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/issue/DefaultFilterableIssueTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilterTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/report/ActiveRulesPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java
sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java
sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java
sonar-scanner-protocol/src/main/protobuf/constants.proto
sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java
sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java

index 8ad71d649bc7b96c311df5cad8f069ef11e79e40..843d28f52844ce20a88acc850ca95eedc046c2cb 100644 (file)
@@ -4,9 +4,7 @@
       "name": "success",
       "status": "OK",
       "durationInMs": 4,
-      "coveredLines": 0,
-      "message": "",
-      "stacktrace": ""
+      "coveredLines": 0
     },
     {
       "name": "error",
       "status": "FAILURE",
       "durationInMs": 2,
       "coveredLines": 0,
-      "message": "Failure",
-      "stacktrace": ""
+      "message": "Failure"
     },
     {
       "name": "skipped",
       "status": "SKIPPED",
       "coveredLines": 0,
-      "message": "",
-      "stacktrace": ""
+      "durationInMs": 0
     }
   ]
 }
diff --git a/pom.xml b/pom.xml
index ad7bb80b8741f089267c0b6ac8af69b314c9b320..73f97eb7d4d7c602ac6e5ac5e40a1ab426467ab8 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,7 @@
     <orchestrator.version>3.11-build315</orchestrator.version>
     <okhttp.version>2.6.0</okhttp.version>
 
-    <protobuf.version>3.0.0-beta-1</protobuf.version>
+    <protobuf.version>3.0.0-beta-2</protobuf.version>
     <protobuf.compiler>${settings.localRepository}/com/google/protobuf/protoc/${protobuf.version}/protoc-${protobuf.version}-${os.detected.classifier}.exe</protobuf.compiler>
 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
index c5d96e80a3019259452bb75524629447eab86da5..cc2a09d3365e417fd53634e72a4aded6c9fbc265 100644 (file)
@@ -34,8 +34,9 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule;
 import org.sonar.server.computation.batch.BatchReportDirectoryHolderImpl;
@@ -118,7 +119,7 @@ public class PersistFileSourcesStepTest {
       .build());
     ScannerReport.Component.Builder project = ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT);
+      .setType(ComponentType.PROJECT);
 
     List<Component> components = new ArrayList<>();
     for (int fileRef = 2; fileRef <= NUMBER_OF_FILES + 1; fileRef++) {
@@ -152,7 +153,7 @@ public class PersistFileSourcesStepTest {
     }
     writer.writeComponent(ScannerReport.Component.newBuilder()
       .setRef(fileRef)
-      .setType(Constants.ComponentType.FILE)
+      .setType(ComponentType.FILE)
       .setLines(NUMBER_OF_LINES)
       .build());
 
@@ -168,8 +169,8 @@ public class PersistFileSourcesStepTest {
   private static class LineData {
     List<String> lines = new ArrayList<>();
     ScannerReport.Changesets.Builder changesetsBuilder = ScannerReport.Changesets.newBuilder();
-    List<ScannerReport.Coverage> coverages = new ArrayList<>();
-    List<ScannerReport.SyntaxHighlighting> highlightings = new ArrayList<>();
+    List<ScannerReport.LineCoverage> coverages = new ArrayList<>();
+    List<ScannerReport.SyntaxHighlightingRule> highlightings = new ArrayList<>();
     List<ScannerReport.Symbol> symbols = new ArrayList<>();
 
     void generateLineData(int line) {
@@ -182,7 +183,7 @@ public class PersistFileSourcesStepTest {
         .build())
         .addChangesetIndexByLine(line - 1);
 
-      coverages.add(ScannerReport.Coverage.newBuilder()
+      coverages.add(ScannerReport.LineCoverage.newBuilder()
         .setLine(line)
         .setConditions(10)
         .setUtHits(true)
@@ -192,12 +193,12 @@ public class PersistFileSourcesStepTest {
         .setOverallCoveredConditions(4)
         .build());
 
-      highlightings.add(ScannerReport.SyntaxHighlighting.newBuilder()
+      highlightings.add(ScannerReport.SyntaxHighlightingRule.newBuilder()
         .setRange(ScannerReport.TextRange.newBuilder()
           .setStartLine(line).setEndLine(line)
           .setStartOffset(1).setEndOffset(3)
           .build())
-        .setType(Constants.HighlightingType.ANNOTATION)
+        .setType(HighlightingType.ANNOTATION)
         .build());
 
       symbols.add(ScannerReport.Symbol.newBuilder()
index 2941e9fc5d937af5e9f218be946c42107fed4903..84ac8c306e1353794a7b7180863c9b05a948bc3e 100644 (file)
@@ -46,9 +46,9 @@ public interface BatchReportReader {
 
   CloseableIterator<ScannerReport.Symbol> readComponentSymbols(int componentRef);
 
-  CloseableIterator<ScannerReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef);
+  CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef);
 
-  CloseableIterator<ScannerReport.Coverage> readComponentCoverage(int fileRef);
+  CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef);
 
   /**
    * Reads file source line by line. Return an absent optional if the file doest not exist
index c1ae4b7f048c694eb4755f00d7beef0de26002c0..f4d8045840124b4639fd25cf2de2bcfdfac146db 100644 (file)
@@ -110,12 +110,12 @@ public class BatchReportReaderImpl implements BatchReportReader {
   }
 
   @Override
-  public CloseableIterator<ScannerReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) {
+  public CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef) {
     return delegate.readComponentSyntaxHighlighting(fileRef);
   }
 
   @Override
-  public CloseableIterator<ScannerReport.Coverage> readComponentCoverage(int fileRef) {
+  public CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef) {
     return delegate.readComponentCoverage(fileRef);
   }
 
index c1c48346a980d64e442bc36f426261e9ebe50704..32479e48960d5238cf25c21c75b2535a0c05c5b0 100644 (file)
@@ -26,13 +26,14 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Arrays.asList;
+import static org.elasticsearch.common.lang3.StringUtils.trimToNull;
 
 @Immutable
 public class ComponentImpl implements Component {
@@ -125,8 +126,8 @@ public class ComponentImpl implements Component {
     private Builder(ScannerReport.Component component) {
       checkNotNull(component);
       this.type = convertType(component.getType());
-      this.name = checkNotNull(component.getName());
-      this.description = component.hasDescription() ? component.getDescription() : null;
+      this.name = component.getName();
+      this.description = trimToNull(component.getDescription());
       this.reportAttributes = createBatchAttributes(component);
       this.fileAttributes = createFileAttributes(component);
     }
@@ -157,24 +158,24 @@ public class ComponentImpl implements Component {
 
     private static ReportAttributes createBatchAttributes(ScannerReport.Component component) {
       return ReportAttributes.newBuilder(component.getRef())
-        .setVersion(component.hasVersion() ? component.getVersion() : null)
-        .setPath(component.hasPath() ? component.getPath() : null)
+        .setVersion(trimToNull(component.getVersion()))
+        .setPath(trimToNull(component.getPath()))
         .build();
     }
 
     @CheckForNull
     private static FileAttributes createFileAttributes(ScannerReport.Component component) {
-      if (component.getType() != Constants.ComponentType.FILE) {
+      if (component.getType() != ComponentType.FILE) {
         return null;
       }
 
       return new FileAttributes(
-        component.hasIsTest() && component.getIsTest(),
-        component.hasLanguage() ? component.getLanguage() : null);
+        component.getIsTest(),
+        trimToNull(component.getLanguage()));
     }
 
     @VisibleForTesting
-    static Type convertType(Constants.ComponentType type) {
+    static Type convertType(ComponentType type) {
       switch (type) {
         case PROJECT:
           return Type.PROJECT;
@@ -185,7 +186,7 @@ public class ComponentImpl implements Component {
         case FILE:
           return Type.FILE;
         default:
-          throw new IllegalArgumentException("Unsupported Constants.ComponentType value " + type);
+          throw new IllegalArgumentException("Unsupported ComponentType value " + type);
       }
     }
   }
index 63aa189e73db435067e8157e2af519bb20f96ab6..75cdfe284afd874bd176e4fbda002cae11003914 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.core.issue.tracking.LineHashSequence;
 import org.sonar.core.util.CloseableIterator;
 import org.sonar.db.protobuf.DbCommons;
 import org.sonar.db.protobuf.DbIssues;
+import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.Component;
@@ -41,6 +42,7 @@ import org.sonar.server.computation.source.SourceLinesRepository;
 import org.sonar.server.rule.CommonRuleKeys;
 
 import static com.google.common.collect.Lists.newArrayList;
+import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
 
 public class TrackerRawInputFactory {
 
@@ -113,19 +115,20 @@ public class TrackerRawInputFactory {
       DefaultIssue issue = new DefaultIssue();
       init(issue);
       issue.setRuleKey(RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey()));
-      if (reportIssue.hasLine()) {
-        issue.setLine(reportIssue.getLine());
-        issue.setChecksum(lineHashSeq.getHashForLine(reportIssue.getLine()));
+      if (reportIssue.hasTextRange()) {
+        int startLine = reportIssue.getTextRange().getStartLine();
+        issue.setLine(startLine);
+        issue.setChecksum(lineHashSeq.getHashForLine(startLine));
       } else {
         issue.setChecksum("");
       }
-      if (reportIssue.hasMsg()) {
+      if (isNotEmpty(reportIssue.getMsg())) {
         issue.setMessage(reportIssue.getMsg());
       }
-      if (reportIssue.hasSeverity()) {
+      if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) {
         issue.setSeverity(reportIssue.getSeverity().name());
       }
-      if (reportIssue.hasGap()) {
+      if (reportIssue.getGap() != 0) {
         issue.setGap(reportIssue.getGap());
       }
       DbIssues.Locations.Builder dbLocationsBuilder = DbIssues.Locations.newBuilder();
@@ -157,10 +160,10 @@ public class TrackerRawInputFactory {
 
     private DbIssues.Location convertLocation(ScannerReport.IssueLocation source) {
       DbIssues.Location.Builder target = DbIssues.Location.newBuilder();
-      if (source.hasComponentRef() && source.getComponentRef() != component.getReportAttributes().getRef()) {
+      if (source.getComponentRef() != 0 && source.getComponentRef() != component.getReportAttributes().getRef()) {
         target.setComponentId(treeRootHolder.getComponentByRef(source.getComponentRef()).getUuid());
       }
-      if (source.hasMsg()) {
+      if (isNotEmpty(source.getMsg())) {
         target.setMsg(source.getMsg());
       }
       if (source.hasTextRange()) {
@@ -173,18 +176,10 @@ public class TrackerRawInputFactory {
 
     private DbCommons.TextRange.Builder convertTextRange(ScannerReport.TextRange sourceRange) {
       DbCommons.TextRange.Builder targetRange = DbCommons.TextRange.newBuilder();
-      if (sourceRange.hasStartLine()) {
-        targetRange.setStartLine(sourceRange.getStartLine());
-      }
-      if (sourceRange.hasStartOffset()) {
-        targetRange.setStartOffset(sourceRange.getStartOffset());
-      }
-      if (sourceRange.hasEndLine()) {
-        targetRange.setEndLine(sourceRange.getEndLine());
-      }
-      if (sourceRange.hasEndOffset()) {
-        targetRange.setEndOffset(sourceRange.getEndOffset());
-      }
+      targetRange.setStartLine(sourceRange.getStartLine());
+      targetRange.setStartOffset(sourceRange.getStartOffset());
+      targetRange.setEndLine(sourceRange.getEndLine());
+      targetRange.setEndOffset(sourceRange.getEndOffset());
       return targetRange;
     }
   }
index 21797b3b16fab8d0bea9c439b9677dde2f42a904..d238f577d746114e91a559b7d1e2d420fea09fe0 100644 (file)
@@ -23,9 +23,11 @@ import com.google.common.base.Optional;
 import java.util.Objects;
 import javax.annotation.Nullable;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.ValueCase;
 import org.sonar.server.computation.metric.Metric;
 
 import static com.google.common.base.Optional.of;
+import static org.apache.commons.lang.StringUtils.trimToNull;
 
 public class BatchMeasureToMeasure {
 
@@ -36,16 +38,15 @@ public class BatchMeasureToMeasure {
     }
 
     Measure.NewMeasureBuilder builder = Measure.newMeasureBuilder();
-    String data = batchMeasure.hasStringValue() ? batchMeasure.getStringValue() : null;
     switch (metric.getType().getValueType()) {
       case INT:
-        return toIntegerMeasure(builder, batchMeasure, data);
+        return toIntegerMeasure(builder, batchMeasure);
       case LONG:
-        return toLongMeasure(builder, batchMeasure, data);
+        return toLongMeasure(builder, batchMeasure);
       case DOUBLE:
-        return toDoubleMeasure(builder, batchMeasure, data);
+        return toDoubleMeasure(builder, batchMeasure);
       case BOOLEAN:
-        return toBooleanMeasure(builder, batchMeasure, data);
+        return toBooleanMeasure(builder, batchMeasure);
       case STRING:
         return toStringMeasure(builder, batchMeasure);
       case LEVEL:
@@ -57,49 +58,48 @@ public class BatchMeasureToMeasure {
     }
   }
 
-  private static Optional<Measure> toIntegerMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure, @Nullable String data) {
-    if (!batchMeasure.hasIntValue()) {
+  private static Optional<Measure> toIntegerMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    return of(builder.create(batchMeasure.getIntValue(), data));
+    return of(builder.create(batchMeasure.getIntValue().getValue(), trimToNull(batchMeasure.getIntValue().getData())));
   }
 
-  private static Optional<Measure> toLongMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure, @Nullable String data) {
-    if (!batchMeasure.hasLongValue()) {
+  private static Optional<Measure> toLongMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    return of(builder.create(batchMeasure.getLongValue(), data));
+    return of(builder.create(batchMeasure.getLongValue().getValue(), trimToNull(batchMeasure.getLongValue().getData())));
   }
 
-  private static Optional<Measure> toDoubleMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure, @Nullable String data) {
-    if (!batchMeasure.hasDoubleValue()) {
+  private static Optional<Measure> toDoubleMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    return of(builder.create(batchMeasure.getDoubleValue(),
+    return of(builder.create(batchMeasure.getDoubleValue().getValue(),
       // Decimals are not truncated in scanner report, so an arbitrary decimal scale is applied when reading values from report
-      org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE,
-      data));
+      org.sonar.api.measures.Metric.MAX_DECIMAL_SCALE, trimToNull(batchMeasure.getDoubleValue().getData())));
   }
 
-  private static Optional<Measure> toBooleanMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure, @Nullable String data) {
-    if (!batchMeasure.hasBooleanValue()) {
+  private static Optional<Measure> toBooleanMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    return of(builder.create(batchMeasure.getBooleanValue(), data));
+    return of(builder.create(batchMeasure.getBooleanValue().getValue(), trimToNull(batchMeasure.getBooleanValue().getData())));
   }
 
   private static Optional<Measure> toStringMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
-    if (!batchMeasure.hasStringValue()) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    return of(builder.create(batchMeasure.getStringValue()));
+    return of(builder.create(batchMeasure.getStringValue().getValue()));
   }
 
   private static Optional<Measure> toLevelMeasure(Measure.NewMeasureBuilder builder, ScannerReport.Measure batchMeasure) {
-    if (!batchMeasure.hasStringValue()) {
+    if (batchMeasure.getValueCase() == ValueCase.VALUE_NOT_SET) {
       return toNoValueMeasure(builder, batchMeasure);
     }
-    Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue());
+    Optional<Measure.Level> level = Measure.Level.toLevel(batchMeasure.getStringValue().getValue());
     if (!level.isPresent()) {
       return toNoValueMeasure(builder, batchMeasure);
     }
index c60ceb94473be61ce4cd40959d412e7b9ddf587e..e9a5cf0c3dda94163a4e494e51ac0384eb425bb8 100644 (file)
@@ -32,6 +32,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.FluentIterable.from;
 import static java.util.Objects.requireNonNull;
+import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
 
 /**
  * ScmInfo implementation based on the changeset information from the Report
@@ -95,11 +96,11 @@ class ReportScmInfo implements ScmInfo {
     }
 
     private Changeset convert(ScannerReport.Changesets.Changeset changeset, int line) {
-      checkState(changeset.hasRevision(), "Changeset on line %s must have a revision", line);
-      checkState(changeset.hasDate(), "Changeset on line %s must have a date", line);
+      checkState(isNotEmpty(changeset.getRevision()), "Changeset on line %s must have a revision", line);
+      checkState(changeset.getDate() != 0, "Changeset on line %s must have a date", line);
       return builder
         .setRevision(changeset.getRevision())
-        .setAuthor(changeset.hasAuthor() ? changeset.getAuthor() : null)
+        .setAuthor(isNotEmpty(changeset.getAuthor()) ? changeset.getAuthor() : null)
         .setDate(changeset.getDate())
         .build();
     }
index 6a9ac03b364bec175a08bdcbcdcd53114f1d3335..19f8a80d611a849c371526a5d07a5da5566130fd 100644 (file)
@@ -26,16 +26,16 @@ import org.sonar.scanner.protocol.output.ScannerReport;
 
 public class CoverageLineReader implements LineReader {
 
-  private final Iterator<ScannerReport.Coverage> coverageIterator;
-  private ScannerReport.Coverage coverage;
+  private final Iterator<ScannerReport.LineCoverage> coverageIterator;
+  private ScannerReport.LineCoverage coverage;
 
-  public CoverageLineReader(Iterator<ScannerReport.Coverage> coverageIterator) {
+  public CoverageLineReader(Iterator<ScannerReport.LineCoverage> coverageIterator) {
     this.coverageIterator = coverageIterator;
   }
 
   @Override
   public void read(DbFileSources.Line.Builder lineBuilder) {
-    ScannerReport.Coverage reportCoverage = getNextLineCoverageIfMatchLine(lineBuilder.getLine());
+    ScannerReport.LineCoverage reportCoverage = getNextLineCoverageIfMatchLine(lineBuilder.getLine());
     if (reportCoverage != null) {
       processUnitTest(lineBuilder, reportCoverage);
       processIntegrationTest(lineBuilder, reportCoverage);
@@ -44,38 +44,32 @@ public class CoverageLineReader implements LineReader {
     }
   }
 
-  private static void processUnitTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.Coverage reportCoverage) {
-    if (reportCoverage.hasUtHits()) {
-      lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0);
-    }
-    if (reportCoverage.hasConditions() && reportCoverage.hasUtCoveredConditions()) {
+  private static void processUnitTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
+    lineBuilder.setUtLineHits(reportCoverage.getUtHits() ? 1 : 0);
+    if (reportCoverage.getConditions() > 0) {
       lineBuilder.setUtConditions(reportCoverage.getConditions());
       lineBuilder.setUtCoveredConditions(reportCoverage.getUtCoveredConditions());
     }
   }
 
-  private static void processIntegrationTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.Coverage reportCoverage) {
-    if (reportCoverage.hasItHits()) {
-      lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0);
-    }
-    if (reportCoverage.hasConditions() && reportCoverage.hasItCoveredConditions()) {
+  private static void processIntegrationTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
+    lineBuilder.setItLineHits(reportCoverage.getItHits() ? 1 : 0);
+    if (reportCoverage.getConditions() > 0) {
       lineBuilder.setItConditions(reportCoverage.getConditions());
       lineBuilder.setItCoveredConditions(reportCoverage.getItCoveredConditions());
     }
   }
 
-  private static void processOverallTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.Coverage reportCoverage) {
-    if (reportCoverage.hasUtHits() || reportCoverage.hasItHits()) {
-      lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0);
-    }
-    if (reportCoverage.hasConditions() && reportCoverage.hasOverallCoveredConditions()) {
+  private static void processOverallTest(DbFileSources.Line.Builder lineBuilder, ScannerReport.LineCoverage reportCoverage) {
+    lineBuilder.setOverallLineHits((reportCoverage.getUtHits() || reportCoverage.getItHits()) ? 1 : 0);
+    if (reportCoverage.getConditions() > 0) {
       lineBuilder.setOverallConditions(reportCoverage.getConditions());
       lineBuilder.setOverallCoveredConditions(reportCoverage.getOverallCoveredConditions());
     }
   }
 
   @CheckForNull
-  private ScannerReport.Coverage getNextLineCoverageIfMatchLine(int line) {
+  private ScannerReport.LineCoverage getNextLineCoverageIfMatchLine(int line) {
     // Get next element (if exists)
     if (coverage == null && coverageIterator.hasNext()) {
       coverage = coverageIterator.next();
index ac8e167336c38b9c787c91a7f3c3b68295963797..5e465939a2cb26cd6a5784f7111c565b8c348ff6 100644 (file)
@@ -27,8 +27,8 @@ import javax.annotation.CheckForNull;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.db.protobuf.DbFileSources;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.source.RangeOffsetConverter.RangeOffsetConverterException;
 
@@ -43,26 +43,26 @@ public class HighlightingLineReader implements LineReader {
 
   private boolean isHighlightingValid = true;
 
-  private static final Map<Constants.HighlightingType, String> cssClassByType = ImmutableMap.<Constants.HighlightingType, String>builder()
-    .put(Constants.HighlightingType.ANNOTATION, "a")
-    .put(Constants.HighlightingType.CONSTANT, "c")
-    .put(Constants.HighlightingType.COMMENT, "cd")
-    .put(Constants.HighlightingType.CPP_DOC, "cppd")
-    .put(Constants.HighlightingType.STRUCTURED_COMMENT, "j")
-    .put(Constants.HighlightingType.KEYWORD, "k")
-    .put(Constants.HighlightingType.KEYWORD_LIGHT, "h")
-    .put(Constants.HighlightingType.HIGHLIGHTING_STRING, "s")
-    .put(Constants.HighlightingType.PREPROCESS_DIRECTIVE, "p")
+  private static final Map<HighlightingType, String> cssClassByType = ImmutableMap.<HighlightingType, String>builder()
+    .put(HighlightingType.ANNOTATION, "a")
+    .put(HighlightingType.CONSTANT, "c")
+    .put(HighlightingType.COMMENT, "cd")
+    .put(HighlightingType.CPP_DOC, "cppd")
+    .put(HighlightingType.STRUCTURED_COMMENT, "j")
+    .put(HighlightingType.KEYWORD, "k")
+    .put(HighlightingType.KEYWORD_LIGHT, "h")
+    .put(HighlightingType.HIGHLIGHTING_STRING, "s")
+    .put(HighlightingType.PREPROCESS_DIRECTIVE, "p")
     .build();
 
   private final Component file;
-  private final Iterator<ScannerReport.SyntaxHighlighting> lineHighlightingIterator;
+  private final Iterator<ScannerReport.SyntaxHighlightingRule> lineHighlightingIterator;
   private final RangeOffsetConverter rangeOffsetConverter;
-  private final List<ScannerReport.SyntaxHighlighting> highlightingList;
+  private final List<ScannerReport.SyntaxHighlightingRule> highlightingList;
 
-  private ScannerReport.SyntaxHighlighting currentItem;
+  private ScannerReport.SyntaxHighlightingRule currentItem;
 
-  public HighlightingLineReader(Component file, Iterator<ScannerReport.SyntaxHighlighting> lineHighlightingIterator, RangeOffsetConverter rangeOffsetConverter) {
+  public HighlightingLineReader(Component file, Iterator<ScannerReport.SyntaxHighlightingRule> lineHighlightingIterator, RangeOffsetConverter rangeOffsetConverter) {
     this.file = file;
     this.lineHighlightingIterator = lineHighlightingIterator;
     this.rangeOffsetConverter = rangeOffsetConverter;
@@ -87,7 +87,7 @@ public class HighlightingLineReader implements LineReader {
     StringBuilder highlighting = new StringBuilder();
 
     incrementHighlightingListMatchingLine(line);
-    for (Iterator<ScannerReport.SyntaxHighlighting> syntaxHighlightingIterator = highlightingList.iterator(); syntaxHighlightingIterator.hasNext();) {
+    for (Iterator<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingIterator = highlightingList.iterator(); syntaxHighlightingIterator.hasNext();) {
       processHighlighting(syntaxHighlightingIterator, highlighting, lineBuilder);
     }
     if (highlighting.length() > 0) {
@@ -95,9 +95,9 @@ public class HighlightingLineReader implements LineReader {
     }
   }
 
-  private void processHighlighting(Iterator<ScannerReport.SyntaxHighlighting> syntaxHighlightingIterator, StringBuilder highlighting,
+  private void processHighlighting(Iterator<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingIterator, StringBuilder highlighting,
     DbFileSources.Line.Builder lineBuilder) {
-    ScannerReport.SyntaxHighlighting syntaxHighlighting = syntaxHighlightingIterator.next();
+    ScannerReport.SyntaxHighlightingRule syntaxHighlighting = syntaxHighlightingIterator.next();
     int line = lineBuilder.getLine();
     ScannerReport.TextRange range = syntaxHighlighting.getRange();
     if (range.getStartLine() <= line) {
@@ -118,7 +118,7 @@ public class HighlightingLineReader implements LineReader {
     }
   }
 
-  private static String getCssClass(Constants.HighlightingType type) {
+  private static String getCssClass(HighlightingType type) {
     String cssClass = cssClassByType.get(type);
     if (cssClass != null) {
       return cssClass;
@@ -128,7 +128,7 @@ public class HighlightingLineReader implements LineReader {
   }
 
   private void incrementHighlightingListMatchingLine(int line) {
-    ScannerReport.SyntaxHighlighting syntaxHighlighting = getNextHighlightingMatchingLine(line);
+    ScannerReport.SyntaxHighlightingRule syntaxHighlighting = getNextHighlightingMatchingLine(line);
     while (syntaxHighlighting != null) {
       highlightingList.add(syntaxHighlighting);
       this.currentItem = null;
@@ -137,7 +137,7 @@ public class HighlightingLineReader implements LineReader {
   }
 
   @CheckForNull
-  private ScannerReport.SyntaxHighlighting getNextHighlightingMatchingLine(int line) {
+  private ScannerReport.SyntaxHighlightingRule getNextHighlightingMatchingLine(int line) {
     // Get next element (if exists)
     if (currentItem == null && lineHighlightingIterator.hasNext()) {
       currentItem = lineHighlightingIterator.next();
index 1826ff7a3eb0033c9ba8e9312aa62e4716c73de4..ba24979f136e6a271312690d7ada085440cff90b 100644 (file)
@@ -85,8 +85,7 @@ public class LoadDuplicationsFromReportStep implements ComputationStep {
       new Duplication(
         convert(duplication.getOriginPosition(), id),
         from(duplication.getDuplicateList())
-          .transform(new BatchDuplicateToCeDuplicate(file))
-      ));
+          .transform(new BatchDuplicateToCeDuplicate(file))));
   }
 
   private static TextBlock convert(ScannerReport.TextRange textRange) {
@@ -107,7 +106,7 @@ public class LoadDuplicationsFromReportStep implements ComputationStep {
     @Override
     @Nonnull
     public Duplicate apply(@Nonnull ScannerReport.Duplicate input) {
-      if (input.hasOtherFileRef()) {
+      if (input.getOtherFileRef() != 0) {
         checkArgument(input.getOtherFileRef() != file.getReportAttributes().getRef(), "file and otherFile references can not be the same");
         return new InProjectDuplicate(
           treeRootHolder.getComponentByRef(input.getOtherFileRef()),
index 1f93bba907b0cd0f6f4d5acf9dc6a239d3bf242d..711079cde1d545dfd78fa16b29d436cf420a6a72 100644 (file)
@@ -79,10 +79,7 @@ public class LoadQualityProfilesStep implements ComputationStep {
 
   private static ActiveRule convert(ScannerReport.ActiveRule input) {
     RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
-    Map<String, String> params = new HashMap<>();
-    for (ScannerReport.ActiveRule.ActiveRuleParam inputParam : input.getParamList()) {
-      params.put(inputParam.getKey(), inputParam.getValue());
-    }
+    Map<String, String> params = new HashMap<>(input.getParamsByKey());
     return new ActiveRule(key, input.getSeverity().name(), params);
   }
 }
index d34e2c627f50d8745edad571dfbe74b0278907a6..da7885d9086acd7dc40e45b1ff1b506bc99147ee 100644 (file)
 package org.sonar.server.computation.step;
 
 import org.sonar.api.utils.MessageException;
+import org.sonar.ce.queue.CeTask;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder;
 import org.sonar.server.computation.batch.BatchReportReader;
-import org.sonar.ce.queue.CeTask;
 
 import static java.lang.String.format;
+import static org.elasticsearch.common.lang3.StringUtils.isNotEmpty;
 
 /**
  * Feed analysis metadata holder with metadata from the analysis report.
@@ -49,9 +50,9 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
     checkProjectKeyConsistency(reportMetadata);
 
     mutableAnalysisMetadataHolder.setRootComponentRef(reportMetadata.getRootComponentRef());
-    mutableAnalysisMetadataHolder.setBranch(reportMetadata.hasBranch() ? reportMetadata.getBranch() : null);
+    mutableAnalysisMetadataHolder.setBranch(isNotEmpty(reportMetadata.getBranch()) ? reportMetadata.getBranch() : null);
     mutableAnalysisMetadataHolder.setAnalysisDate(reportMetadata.getAnalysisDate());
-    mutableAnalysisMetadataHolder.setCrossProjectDuplicationEnabled(reportMetadata.hasCrossProjectDuplicationActivated() && reportMetadata.getCrossProjectDuplicationActivated());
+    mutableAnalysisMetadataHolder.setCrossProjectDuplicationEnabled(reportMetadata.getCrossProjectDuplicationActivated());
   }
 
   private void checkProjectKeyConsistency(ScannerReport.Metadata reportMetadata) {
@@ -60,20 +61,18 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
     if (componentKey == null) {
       throw MessageException.of(format(
         "Compute Engine task component key is null. Project with UUID %s must have been deleted since report was uploaded. Can not proceed.",
-        ceTask.getComponentUuid()
-        ));
+        ceTask.getComponentUuid()));
     }
     if (!componentKey.equals(reportProjectKey)) {
       throw MessageException.of(format(
         "ProjectKey in report (%s) is not consistent with projectKey under which the report as been submitted (%s)",
         reportProjectKey,
-        componentKey
-        ));
+        componentKey));
     }
   }
 
   private static String projectKeyFromReport(ScannerReport.Metadata reportMetadata) {
-    if (reportMetadata.hasBranch()) {
+    if (isNotEmpty(reportMetadata.getBranch())) {
       return reportMetadata.getProjectKey() + ":" + reportMetadata.getBranch();
     }
     return reportMetadata.getProjectKey();
index 55832544b7d0ccabdd978ed96b303110064a4500..38c9495500206b9279bac9643e7c0f95499fe4f4 100644 (file)
@@ -206,7 +206,7 @@ public class PersistFileSourcesStep implements ComputationStep {
 
     LineReaders(BatchReportReader reportReader, ScmInfoRepository scmInfoRepository, DuplicationRepository duplicationRepository, Component component) {
       int componentRef = component.getReportAttributes().getRef();
-      CloseableIterator<ScannerReport.Coverage> coverageIt = reportReader.readComponentCoverage(componentRef);
+      CloseableIterator<ScannerReport.LineCoverage> coverageIt = reportReader.readComponentCoverage(componentRef);
       closeables.add(coverageIt);
       readers.add(new CoverageLineReader(coverageIt));
 
@@ -219,7 +219,7 @@ public class PersistFileSourcesStep implements ComputationStep {
       }
 
       RangeOffsetConverter rangeOffsetConverter = new RangeOffsetConverter();
-      CloseableIterator<ScannerReport.SyntaxHighlighting> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef);
+      CloseableIterator<ScannerReport.SyntaxHighlightingRule> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef);
       closeables.add(highlightingIt);
       readers.add(new HighlightingLineReader(component, highlightingIt, rangeOffsetConverter));
 
index 98fac5cb3c4a24cad0c8f67a4be71330039cfe59..d6342d40ec99a543fb4dabff51a4c214753718a3 100644 (file)
@@ -32,8 +32,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentLinkDto;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.CrawlerDepthLimit;
@@ -54,12 +54,12 @@ public class PersistProjectLinksStep implements ComputationStep {
   private final TreeRootHolder treeRootHolder;
   private final BatchReportReader reportReader;
 
-  private static final Map<Constants.ComponentLinkType, String> typesConverter = ImmutableMap.of(
-    Constants.ComponentLinkType.HOME, ComponentLinkDto.TYPE_HOME_PAGE,
-    Constants.ComponentLinkType.SCM, ComponentLinkDto.TYPE_SOURCES,
-    Constants.ComponentLinkType.SCM_DEV, ComponentLinkDto.TYPE_SOURCES_DEV,
-    Constants.ComponentLinkType.CI, ComponentLinkDto.TYPE_CI,
-    Constants.ComponentLinkType.ISSUE, ComponentLinkDto.TYPE_ISSUE_TRACKER);
+  private static final Map<ComponentLinkType, String> typesConverter = ImmutableMap.of(
+    ComponentLinkType.HOME, ComponentLinkDto.TYPE_HOME_PAGE,
+    ComponentLinkType.SCM, ComponentLinkDto.TYPE_SOURCES,
+    ComponentLinkType.SCM_DEV, ComponentLinkDto.TYPE_SOURCES_DEV,
+    ComponentLinkType.CI, ComponentLinkDto.TYPE_CI,
+    ComponentLinkType.ISSUE, ComponentLinkDto.TYPE_ISSUE_TRACKER);
 
   public PersistProjectLinksStep(DbClient dbClient, I18n i18n, TreeRootHolder treeRootHolder, BatchReportReader reportReader) {
     this.dbClient = dbClient;
@@ -145,7 +145,7 @@ public class PersistProjectLinksStep implements ComputationStep {
       }
     }
 
-    private String convertType(Constants.ComponentLinkType reportType) {
+    private String convertType(ComponentLinkType reportType) {
       String type = typesConverter.get(reportType);
       if (type != null) {
         return type;
index fec594e8115ee1afbec01623a754fd903298f4bb..8e63a3146724da5db178e9efbbeac264bda3e2f0 100644 (file)
@@ -46,6 +46,7 @@ import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.db.source.FileSourceDto.Type;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.ComponentVisitor;
@@ -191,18 +192,16 @@ public class PersistTestsStep implements ComputationStep {
           DbFileSources.Test.Builder dbTest = DbFileSources.Test.newBuilder();
           dbTest.setUuid(Uuids.create());
           dbTest.setName(batchTest.getName());
-          if (batchTest.hasStacktrace()) {
+          if (!batchTest.getStacktrace().isEmpty()) {
             dbTest.setStacktrace(batchTest.getStacktrace());
           }
-          if (batchTest.hasStatus()) {
+          if (batchTest.getStatus() != TestStatus.UNSET) {
             dbTest.setStatus(DbFileSources.Test.TestStatus.valueOf(batchTest.getStatus().name()));
           }
-          if (batchTest.hasMsg()) {
+          if (!batchTest.getMsg().isEmpty()) {
             dbTest.setMsg(batchTest.getMsg());
           }
-          if (batchTest.hasDurationInMs()) {
-            dbTest.setExecutionTimeMs(batchTest.getDurationInMs());
-          }
+          dbTest.setExecutionTimeMs(batchTest.getDurationInMs());
 
           tests.put(dbTest.getName(), dbTest);
         }
index c265584c865961ed287a3b8a547128462ce5d470..6a8331f348d8a9e68e6abe3b8d0192891b97f736 100644 (file)
@@ -43,10 +43,10 @@ public class BatchReportReaderImplTest {
   private static final ScannerReport.Duplication DUPLICATION = ScannerReport.Duplication.newBuilder().build();
   private static final ScannerReport.CpdTextBlock DUPLICATION_BLOCK = ScannerReport.CpdTextBlock.newBuilder().build();
   private static final ScannerReport.Symbol SYMBOL = ScannerReport.Symbol.newBuilder().build();
-  private static final ScannerReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_1 = ScannerReport.SyntaxHighlighting.newBuilder().build();
-  private static final ScannerReport.SyntaxHighlighting SYNTAX_HIGHLIGHTING_2 = ScannerReport.SyntaxHighlighting.newBuilder().build();
-  private static final ScannerReport.Coverage COVERAGE_1 = ScannerReport.Coverage.newBuilder().build();
-  private static final ScannerReport.Coverage COVERAGE_2 = ScannerReport.Coverage.newBuilder().build();
+  private static final ScannerReport.SyntaxHighlightingRule SYNTAX_HIGHLIGHTING_1 = ScannerReport.SyntaxHighlightingRule.newBuilder().build();
+  private static final ScannerReport.SyntaxHighlightingRule SYNTAX_HIGHLIGHTING_2 = ScannerReport.SyntaxHighlightingRule.newBuilder().build();
+  private static final ScannerReport.LineCoverage COVERAGE_1 = ScannerReport.LineCoverage.newBuilder().build();
+  private static final ScannerReport.LineCoverage COVERAGE_2 = ScannerReport.LineCoverage.newBuilder().build();
   private static final ScannerReport.Test TEST_1 = ScannerReport.Test.newBuilder().setName("1").build();
   private static final ScannerReport.Test TEST_2 = ScannerReport.Test.newBuilder().setName("2").build();
   private static final ScannerReport.CoverageDetail COVERAGE_DETAIL_1 = ScannerReport.CoverageDetail.newBuilder().setTestName("1").build();
@@ -254,7 +254,7 @@ public class BatchReportReaderImplTest {
   public void verify_readComponentSyntaxHighlighting() {
     writer.writeComponentSyntaxHighlighting(COMPONENT_REF, of(SYNTAX_HIGHLIGHTING_1, SYNTAX_HIGHLIGHTING_2));
 
-    CloseableIterator<ScannerReport.SyntaxHighlighting> res = underTest.readComponentSyntaxHighlighting(COMPONENT_REF);
+    CloseableIterator<ScannerReport.SyntaxHighlightingRule> res = underTest.readComponentSyntaxHighlighting(COMPONENT_REF);
     assertThat(res).containsExactly(SYNTAX_HIGHLIGHTING_1, SYNTAX_HIGHLIGHTING_2);
     res.close();
   }
@@ -268,7 +268,7 @@ public class BatchReportReaderImplTest {
   public void verify_readComponentCoverage() {
     writer.writeComponentCoverage(COMPONENT_REF, of(COVERAGE_1, COVERAGE_2));
 
-    CloseableIterator<ScannerReport.Coverage> res = underTest.readComponentCoverage(COMPONENT_REF);
+    CloseableIterator<ScannerReport.LineCoverage> res = underTest.readComponentCoverage(COMPONENT_REF);
     assertThat(res).containsExactly(COVERAGE_1, COVERAGE_2);
     res.close();
   }
index 323e7a85230c4ca7b8002d756ca8d66893c906f7..0c21f1bd677575cbab9d2892d4a1adaa77f186e1 100644 (file)
@@ -45,8 +45,8 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
   private Map<Integer, List<ScannerReport.Duplication>> duplications = new HashMap<>();
   private Map<Integer, List<ScannerReport.CpdTextBlock>> duplicationBlocks = new HashMap<>();
   private Map<Integer, List<ScannerReport.Symbol>> symbols = new HashMap<>();
-  private Map<Integer, List<ScannerReport.SyntaxHighlighting>> syntaxHighlightings = new HashMap<>();
-  private Map<Integer, List<ScannerReport.Coverage>> coverages = new HashMap<>();
+  private Map<Integer, List<ScannerReport.SyntaxHighlightingRule>> syntaxHighlightings = new HashMap<>();
+  private Map<Integer, List<ScannerReport.LineCoverage>> coverages = new HashMap<>();
   private Map<Integer, List<String>> fileSources = new HashMap<>();
   private Map<Integer, List<ScannerReport.Test>> tests = new HashMap<>();
   private Map<Integer, List<ScannerReport.CoverageDetail>> coverageDetails = new HashMap<>();
@@ -201,8 +201,8 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
   }
 
   @Override
-  public CloseableIterator<ScannerReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) {
-    List<ScannerReport.SyntaxHighlighting> res = this.syntaxHighlightings.get(fileRef);
+  public CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef) {
+    List<ScannerReport.SyntaxHighlightingRule> res = this.syntaxHighlightings.get(fileRef);
     if (res == null) {
       return CloseableIterator.emptyCloseableIterator();
     }
@@ -210,14 +210,14 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
     return CloseableIterator.from(res.iterator());
   }
 
-  public BatchReportReaderRule putSyntaxHighlighting(int fileRef, List<ScannerReport.SyntaxHighlighting> syntaxHighlightings) {
+  public BatchReportReaderRule putSyntaxHighlighting(int fileRef, List<ScannerReport.SyntaxHighlightingRule> syntaxHighlightings) {
     this.syntaxHighlightings.put(fileRef, syntaxHighlightings);
     return this;
   }
 
   @Override
-  public CloseableIterator<ScannerReport.Coverage> readComponentCoverage(int fileRef) {
-    List<ScannerReport.Coverage> res = this.coverages.get(fileRef);
+  public CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef) {
+    List<ScannerReport.LineCoverage> res = this.coverages.get(fileRef);
     if (res == null) {
       return CloseableIterator.emptyCloseableIterator();
     }
@@ -225,7 +225,7 @@ public class BatchReportReaderRule implements TestRule, BatchReportReader {
     return CloseableIterator.from(res.iterator());
   }
 
-  public BatchReportReaderRule putCoverage(int fileRef, List<ScannerReport.Coverage> coverages) {
+  public BatchReportReaderRule putCoverage(int fileRef, List<ScannerReport.LineCoverage> coverages) {
     this.coverages.put(fileRef, coverages);
     return this;
   }
index 1427bfb3c9b5fe1d500c6e98855b74f894397686..1a50e60e6c0ad2a3eb644386e3c983b6a0c904b7 100644 (file)
@@ -23,15 +23,18 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 
-import static com.google.common.base.Predicates.equalTo;
+import static com.google.common.base.Predicates.in;
 import static com.google.common.base.Predicates.not;
 import static com.google.common.collect.FluentIterable.from;
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
-import static org.sonar.scanner.protocol.Constants.ComponentType;
-import static org.sonar.scanner.protocol.Constants.ComponentType.FILE;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.DIRECTORY;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNSET;
 import static org.sonar.server.computation.component.ComponentImpl.builder;
 
 public class ComponentImplTest {
@@ -44,7 +47,7 @@ public class ComponentImplTest {
 
   @Test
   public void verify_key_and_uuid() throws Exception {
-    ComponentImpl component = builder(ScannerReport.Component.newBuilder().build()).setKey(KEY).setUuid(UUID).build();
+    ComponentImpl component = builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setKey(KEY).setUuid(UUID).build();
 
     assertThat(component.getKey()).isEqualTo(KEY);
     assertThat(component.getUuid()).isEqualTo(UUID);
@@ -61,47 +64,47 @@ public class ComponentImplTest {
   public void set_key_throws_NPE_if_component_arg_is_Null() {
     thrown.expect(NullPointerException.class);
 
-    builder(ScannerReport.Component.newBuilder().build()).setUuid(null);
+    builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setUuid(null);
   }
 
   @Test
   public void set_uuid_throws_NPE_if_component_arg_is_Null() {
     thrown.expect(NullPointerException.class);
 
-    builder(ScannerReport.Component.newBuilder().build()).setKey(null);
+    builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setKey(null);
   }
 
   @Test
   public void build_without_key_throws_NPE_if_component_arg_is_Null() {
     thrown.expect(NullPointerException.class);
 
-    builder(ScannerReport.Component.newBuilder().build()).setUuid("ABCD").build();
+    builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setUuid("ABCD").build();
   }
 
   @Test
   public void build_without_uuid_throws_NPE_if_component_arg_is_Null() {
     thrown.expect(NullPointerException.class);
 
-    builder(ScannerReport.Component.newBuilder().build()).setKey(KEY).build();
+    builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setKey(KEY).build();
   }
 
   @Test
   public void get_name_from_batch_component() {
     String name = "project";
-    ComponentImpl component = buildSimpleComponent(ScannerReport.Component.newBuilder().setName(name).build());
+    ComponentImpl component = buildSimpleComponent(ScannerReport.Component.newBuilder().setType(FILE).setName(name).build());
     assertThat(component.getName()).isEqualTo(name);
   }
 
   @Test
   public void get_version_from_batch_component() {
     String version = "1.0";
-    ComponentImpl component = buildSimpleComponent(ScannerReport.Component.newBuilder().setVersion(version).build());
+    ComponentImpl component = buildSimpleComponent(ScannerReport.Component.newBuilder().setType(FILE).setVersion(version).build());
     assertThat(component.getReportAttributes().getVersion()).isEqualTo(version);
   }
 
   @Test
   public void getFileAttributes_throws_ISE_if_BatchComponent_does_not_have_type_FILE() {
-    for (ComponentType componentType : from(asList(ComponentType.values())).filter(not(equalTo(FILE)))) {
+    for (ComponentType componentType : from(asList(ComponentType.values())).filter(not(in(asList(FILE, UNSET, UNRECOGNIZED))))) {
       ComponentImpl component = buildSimpleComponent(ScannerReport.Component.newBuilder().setType(componentType).build());
       try {
         component.getFileAttributes();
@@ -129,13 +132,11 @@ public class ComponentImplTest {
 
   @Test
   public void build_with_child() throws Exception {
-    buildSimpleComponent(ScannerReport.Component.newBuilder().build());
-
     ComponentImpl child = builder(ScannerReport.Component.newBuilder().setType(FILE).build())
       .setKey("CHILD_KEY")
       .setUuid("CHILD_UUID")
       .build();
-    ComponentImpl componentImpl = builder(ScannerReport.Component.newBuilder().build())
+    ComponentImpl componentImpl = builder(ScannerReport.Component.newBuilder().setType(DIRECTORY).build())
       .setKey(KEY)
       .setUuid(UUID)
       .addChildren(child)
@@ -150,7 +151,7 @@ public class ComponentImplTest {
 
   @Test
   public void convertType() {
-    for (ComponentType componentType : ComponentType.values()) {
+    for (ComponentType componentType : from(asList(ComponentType.values())).filter(not(in(asList(UNSET, UNRECOGNIZED))))) {
       assertThat(ComponentImpl.Builder.convertType(componentType)).isEqualTo(Component.Type.valueOf(componentType.name()));
     }
   }
@@ -161,7 +162,7 @@ public class ComponentImplTest {
 
   @Test
   public void equals_compares_on_uuid_only() {
-    ComponentImpl.Builder builder = builder(ScannerReport.Component.newBuilder().build()).setUuid(UUID);
+    ComponentImpl.Builder builder = builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setUuid(UUID);
 
     assertThat(builder.setKey("1").build()).isEqualTo(builder.setKey("1").build());
     assertThat(builder.setKey("1").build()).isEqualTo(builder.setKey("2").build());
@@ -169,7 +170,7 @@ public class ComponentImplTest {
 
   @Test
   public void hashCode_is_hashcode_of_uuid() {
-    ComponentImpl.Builder builder = builder(ScannerReport.Component.newBuilder().build()).setUuid(UUID);
+    ComponentImpl.Builder builder = builder(ScannerReport.Component.newBuilder().setType(FILE).build()).setUuid(UUID);
 
     assertThat(builder.setKey("1").build().hashCode()).isEqualTo(builder.setKey("1").build().hashCode());
     assertThat(builder.setKey("1").build().hashCode()).isEqualTo(builder.setKey("2").build().hashCode());
index fc43b2639cfa93036e048f1a6e1e2223e98314e4..83af9b05e8842357f18a955bff0e23031c7cb69a 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.tracking.Input;
 import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -88,7 +89,7 @@ public class TrackerRawInputFactoryTest {
   public void load_issues() throws Exception {
     fileSourceRepository.addLines(FILE_REF, "line 1;", "line 2;");
     ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder()
-      .setLine(2)
+      .setTextRange(TextRange.newBuilder().setStartLine(2).build())
       .setMsg("the message")
       .setRuleRepository("java")
       .setRuleKey("S001")
index ddc18d8c558fe83dd8d3baa9f8f8cd47f180f410..9d02c40974c2d0f74d71ff6edaa835ec20eb0e06 100644 (file)
@@ -25,6 +25,11 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.BoolValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.IntValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.LongValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
 import org.sonar.server.computation.metric.Metric;
 import org.sonar.server.computation.metric.MetricImpl;
 
@@ -70,7 +75,7 @@ public class BatchMeasureToMeasureTest {
 
   @Test
   public void toMeasure_returns_no_value_if_dto_has_invalid_string_value_for_LEVEL_Metric() {
-    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue("trololo").build(), SOME_LEVEL_METRIC);
+    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue("trololo")).build(), SOME_LEVEL_METRIC);
 
     assertThat(measure).isPresent();
     assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
@@ -78,7 +83,7 @@ public class BatchMeasureToMeasureTest {
 
   @Test
   public void toMeasure_returns_no_value_if_dto_has_value_in_wrong_case_for_LEVEL_Metric() {
-    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue("waRn").build(), SOME_LEVEL_METRIC);
+    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue("waRn")).build(), SOME_LEVEL_METRIC);
 
     assertThat(measure).isPresent();
     assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
@@ -92,7 +97,8 @@ public class BatchMeasureToMeasureTest {
   }
 
   private void verify_toMeasure_returns_value_for_LEVEL_Metric(Measure.Level expectedQualityGateStatus) {
-    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue(expectedQualityGateStatus.name()).build(), SOME_LEVEL_METRIC);
+    Optional<Measure> measure =
+      underTest.toMeasure(ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue(expectedQualityGateStatus.name())).build(), SOME_LEVEL_METRIC);
     assertThat(measure).isPresent();
     assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LEVEL);
     assertThat(measure.get().getLevelValue()).isEqualTo(expectedQualityGateStatus);
@@ -101,7 +107,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_for_LEVEL_Metric_maps_QualityGateStatus() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setStringValue(Measure.Level.OK.name())
+      .setStringValue(StringValue.newBuilder().setValue(Measure.Level.OK.name()))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_LEVEL_METRIC);
@@ -120,7 +126,7 @@ public class BatchMeasureToMeasureTest {
 
   private void verify_toMeasure_for_LEVEL_Metric_parses_level_from_data(Measure.Level expectedLevel) {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setStringValue(expectedLevel.name())
+      .setStringValue(StringValue.newBuilder().setValue(expectedLevel.name()))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_LEVEL_METRIC);
@@ -140,8 +146,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_maps_data_and_alert_properties_in_dto_for_Int_Metric() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setIntValue(10)
-      .setStringValue(SOME_DATA)
+      .setIntValue(IntValue.newBuilder().setValue(10).setData(SOME_DATA))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_INT_METRIC);
@@ -162,7 +167,7 @@ public class BatchMeasureToMeasureTest {
 
   @Test
   public void toMeasure_returns_long_part_of_value_in_dto_for_Long_Metric() {
-    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setLongValue(15l).build(), SOME_LONG_METRIC);
+    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setLongValue(LongValue.newBuilder().setValue(15l)).build(), SOME_LONG_METRIC);
 
     assertThat(measure.isPresent()).isTrue();
     assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.LONG);
@@ -172,8 +177,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_maps_data_and_alert_properties_in_dto_for_Long_Metric() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setLongValue(10l)
-      .setStringValue(SOME_DATA)
+      .setLongValue(LongValue.newBuilder().setValue(10l).setData(SOME_DATA))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_LONG_METRIC);
@@ -195,8 +199,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_maps_data_and_alert_properties_in_dto_for_Double_Metric() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setDoubleValue(10.6395d)
-      .setStringValue(SOME_DATA)
+      .setDoubleValue(DoubleValue.newBuilder().setValue(10.6395d).setData(SOME_DATA))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_DOUBLE_METRIC);
@@ -222,7 +225,7 @@ public class BatchMeasureToMeasureTest {
   }
 
   private void verify_toMeasure_returns_false_value_if_dto_has_invalid_value_for_Boolean_metric(boolean expected) {
-    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setBooleanValue(expected).build(), SOME_BOOLEAN_METRIC);
+    Optional<Measure> measure = underTest.toMeasure(ScannerReport.Measure.newBuilder().setBooleanValue(BoolValue.newBuilder().setValue(expected)).build(), SOME_BOOLEAN_METRIC);
 
     assertThat(measure.isPresent()).isTrue();
     assertThat(measure.get().getValueType()).isEqualTo(Measure.ValueType.BOOLEAN);
@@ -232,7 +235,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_maps_data_and_alert_properties_in_dto_for_Boolean_metric() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setBooleanValue(true).setStringValue(SOME_DATA).build();
+      .setBooleanValue(BoolValue.newBuilder().setValue(true).setData(SOME_DATA)).build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_BOOLEAN_METRIC);
 
@@ -253,7 +256,7 @@ public class BatchMeasureToMeasureTest {
   @Test
   public void toMeasure_maps_alert_properties_in_dto_for_String_Metric() {
     ScannerReport.Measure batchMeasure = ScannerReport.Measure.newBuilder()
-      .setStringValue(SOME_DATA)
+      .setStringValue(StringValue.newBuilder().setValue(SOME_DATA))
       .build();
 
     Optional<Measure> measure = underTest.toMeasure(batchMeasure, SOME_STRING_METRIC);
@@ -267,12 +270,12 @@ public class BatchMeasureToMeasureTest {
   @DataProvider
   public static Object[][] all_types_batch_measure_builders() {
     return new Object[][] {
-      {ScannerReport.Measure.newBuilder().setBooleanValue(true), SOME_BOOLEAN_METRIC},
-      {ScannerReport.Measure.newBuilder().setIntValue(1), SOME_INT_METRIC},
-      {ScannerReport.Measure.newBuilder().setLongValue(1), SOME_LONG_METRIC},
-      {ScannerReport.Measure.newBuilder().setDoubleValue(1), SOME_DOUBLE_METRIC},
-      {ScannerReport.Measure.newBuilder().setStringValue("1"), SOME_STRING_METRIC},
-      {ScannerReport.Measure.newBuilder().setStringValue(Measure.Level.OK.name()), SOME_LEVEL_METRIC}
+      {ScannerReport.Measure.newBuilder().setBooleanValue(BoolValue.newBuilder().setValue(true)), SOME_BOOLEAN_METRIC},
+      {ScannerReport.Measure.newBuilder().setIntValue(IntValue.newBuilder().setValue(1)), SOME_INT_METRIC},
+      {ScannerReport.Measure.newBuilder().setLongValue(LongValue.newBuilder().setValue(1)), SOME_LONG_METRIC},
+      {ScannerReport.Measure.newBuilder().setDoubleValue(DoubleValue.newBuilder().setValue(1)), SOME_DOUBLE_METRIC},
+      {ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue("1")), SOME_STRING_METRIC},
+      {ScannerReport.Measure.newBuilder().setStringValue(StringValue.newBuilder().setValue(Measure.Level.OK.name())), SOME_LEVEL_METRIC}
     };
   }
 }
index eae715ca1a414385b8833a5e40a17c1c54a73eb6..8f21d3669aeebe684b3f8db1c26d4240fab955d4 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
 import org.sonar.server.computation.batch.BatchReportReader;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.component.Component;
@@ -216,8 +217,7 @@ public class MeasureRepositoryImplTest {
     Measure.newMeasureBuilder().create(false),
     Measure.newMeasureBuilder().create("sds"),
     Measure.newMeasureBuilder().create(Measure.Level.OK),
-    Measure.newMeasureBuilder().createNoValue()
-    );
+    Measure.newMeasureBuilder().createNoValue());
 
   @DataProvider
   public static Object[][] measures() {
@@ -333,8 +333,7 @@ public class MeasureRepositoryImplTest {
     when(reportMetricValidator.validate(METRIC_KEY_1)).thenReturn(true);
 
     reportReader.putMeasures(FILE_COMPONENT.getReportAttributes().getRef(), ImmutableList.of(
-      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(value).build()
-      ));
+      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(StringValue.newBuilder().setValue(value)).build()));
 
     Optional<Measure> res = underTest.getRawMeasure(FILE_COMPONENT, metric1);
 
@@ -352,9 +351,8 @@ public class MeasureRepositoryImplTest {
     when(reportMetricValidator.validate(METRIC_KEY_2)).thenReturn(false);
 
     reportReader.putMeasures(FILE_COMPONENT.getReportAttributes().getRef(), ImmutableList.of(
-      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue("value1").build(),
-      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_2).setStringValue("value2").build()
-      ));
+      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(StringValue.newBuilder().setValue("value1")).build(),
+      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_2).setStringValue(StringValue.newBuilder().setValue("value2")).build()));
 
     assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1)).isPresent();
     assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric2)).isAbsent();
@@ -364,8 +362,7 @@ public class MeasureRepositoryImplTest {
   public void getRawMeasure_retrieves_added_measure_over_batch_measure() {
     when(reportMetricValidator.validate(METRIC_KEY_1)).thenReturn(true);
     reportReader.putMeasures(FILE_COMPONENT.getReportAttributes().getRef(), ImmutableList.of(
-      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue("some value").build()
-      ));
+      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(StringValue.newBuilder().setValue("some value")).build()));
 
     Measure addedMeasure = SOME_MEASURE;
     underTest.add(FILE_COMPONENT, metric1, addedMeasure);
@@ -380,8 +377,7 @@ public class MeasureRepositoryImplTest {
   public void getRawMeasure_retrieves_measure_from_batch_and_caches_it_locally_so_that_it_can_be_updated() {
     when(reportMetricValidator.validate(METRIC_KEY_1)).thenReturn(true);
     reportReader.putMeasures(FILE_COMPONENT.getReportAttributes().getRef(), ImmutableList.of(
-      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue("some value").build()
-      ));
+      ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(StringValue.newBuilder().setValue("some value")).build()));
 
     Optional<Measure> measure = underTest.getRawMeasure(FILE_COMPONENT, metric1);
 
@@ -409,8 +405,8 @@ public class MeasureRepositoryImplTest {
   public void getRawMeasures_returns_added_measures_over_batch_measures() {
     when(reportMetricValidator.validate(METRIC_KEY_1)).thenReturn(true);
     when(reportMetricValidator.validate(METRIC_KEY_2)).thenReturn(true);
-    ScannerReport.Measure batchMeasure1 = ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue("some value").build();
-    ScannerReport.Measure batchMeasure2 = ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_2).setStringValue("some value").build();
+    ScannerReport.Measure batchMeasure1 = ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_1).setStringValue(StringValue.newBuilder().setValue("some value")).build();
+    ScannerReport.Measure batchMeasure2 = ScannerReport.Measure.newBuilder().setMetricKey(METRIC_KEY_2).setStringValue(StringValue.newBuilder().setValue("some value")).build();
     reportReader.putMeasures(FILE_COMPONENT.getReportAttributes().getRef(), ImmutableList.of(batchMeasure1, batchMeasure2));
 
     Measure addedMeasure = SOME_MEASURE;
index 247105f80044c3b44518d39243bfafaff146b958..1f211b59363b381b9967b76b61c18df62ba958c4 100644 (file)
@@ -31,7 +31,7 @@ public class CoverageLineReaderTest {
 
   @Test
   public void set_coverage() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setConditions(10)
       .setUtHits(true)
@@ -55,7 +55,7 @@ public class CoverageLineReaderTest {
 
   @Test
   public void set_coverage_on_uncovered_lines() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setUtHits(false)
       .setItHits(false)
@@ -72,23 +72,9 @@ public class CoverageLineReaderTest {
     assertThat(lineBuilder.getOverallLineHits()).isEqualTo(0);
   }
 
-  @Test
-  public void set_coverage_without_line_hits() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
-      .setLine(1)
-      .build()).iterator());
-
-    DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
-    computeCoverageLine.read(lineBuilder);
-
-    assertThat(lineBuilder.hasUtLineHits()).isFalse();
-    assertThat(lineBuilder.hasItLineHits()).isFalse();
-    assertThat(lineBuilder.hasOverallLineHits()).isFalse();
-  }
-
   @Test
   public void set_overall_line_hits_with_only_ut() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setUtHits(true)
       .setItHits(false)
@@ -102,7 +88,7 @@ public class CoverageLineReaderTest {
 
   @Test
   public void set_overall_line_hits_with_only_it() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setUtHits(false)
       .setItHits(true)
@@ -116,7 +102,7 @@ public class CoverageLineReaderTest {
 
   @Test
   public void set_overall_line_hits_with_ut_and_it() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.Coverage.newBuilder()
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setUtHits(true)
       .setItHits(true)
@@ -130,7 +116,7 @@ public class CoverageLineReaderTest {
 
   @Test
   public void nothing_to_do_when_no_coverage_info() {
-    CoverageLineReader computeCoverageLine = new CoverageLineReader(Collections.<ScannerReport.Coverage>emptyList().iterator());
+    CoverageLineReader computeCoverageLine = new CoverageLineReader(Collections.<ScannerReport.LineCoverage>emptyList().iterator());
 
     DbFileSources.Line.Builder lineBuilder = DbFileSources.Data.newBuilder().addLinesBuilder().setLine(1);
     computeCoverageLine.read(lineBuilder);
@@ -147,7 +133,7 @@ public class CoverageLineReaderTest {
   @Test
   public void nothing_to_do_when_no_coverage_info_for_current_line() {
     CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(1)
         .setConditions(10)
         .setUtHits(true)
@@ -174,7 +160,7 @@ public class CoverageLineReaderTest {
   @Test
   public void nothing_to_do_when_no_coverage_info_for_next_line() {
     CoverageLineReader computeCoverageLine = new CoverageLineReader(newArrayList(
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(1)
         .setConditions(10)
         .setUtHits(true)
index dea1dd7d97b638375f4a76e05cfc47017213569e..fe2493acb7817069756cd3942ab424cb4ac86a40 100644 (file)
@@ -28,8 +28,8 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.db.protobuf.DbFileSources;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.source.RangeOffsetConverter.RangeOffsetConverterException;
@@ -41,10 +41,10 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.utils.log.LoggerLevel.WARN;
 import static org.sonar.db.protobuf.DbFileSources.Data.newBuilder;
-import static org.sonar.scanner.protocol.Constants.HighlightingType.ANNOTATION;
-import static org.sonar.scanner.protocol.Constants.HighlightingType.COMMENT;
-import static org.sonar.scanner.protocol.Constants.HighlightingType.CONSTANT;
-import static org.sonar.scanner.protocol.Constants.HighlightingType.HIGHLIGHTING_STRING;
+import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.ANNOTATION;
+import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.COMMENT;
+import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.CONSTANT;
+import static org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType.HIGHLIGHTING_STRING;
 import static org.sonar.server.computation.component.ReportComponent.builder;
 
 public class HighlightingLineReaderTest {
@@ -77,7 +77,7 @@ public class HighlightingLineReaderTest {
 
   @Test
   public void nothing_to_read() {
-    HighlightingLineReader highlightingLineReader = newReader(Collections.<TextRange, Constants.HighlightingType>emptyMap());
+    HighlightingLineReader highlightingLineReader = newReader(Collections.<TextRange, HighlightingType>emptyMap());
 
     DbFileSources.Line.Builder lineBuilder = newBuilder().addLinesBuilder().setLine(1);
     highlightingLineReader.read(lineBuilder);
@@ -88,8 +88,7 @@ public class HighlightingLineReaderTest {
   @Test
   public void read_one_line() {
     HighlightingLineReader highlightingLineReader = newReader(of(
-      newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1),
-      ANNOTATION));
+      newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1), ANNOTATION));
 
     highlightingLineReader.read(line1);
 
@@ -101,8 +100,7 @@ public class HighlightingLineReaderTest {
     HighlightingLineReader highlightingLineReader = newReader(of(
       newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1), ANNOTATION,
       newSingleLineTextRangeWithExpectingLabel(LINE_2, RANGE_LABEL_2), COMMENT,
-      newSingleLineTextRangeWithExpectingLabel(LINE_4, RANGE_LABEL_3), CONSTANT
-      ));
+      newSingleLineTextRangeWithExpectingLabel(LINE_4, RANGE_LABEL_3), CONSTANT));
 
     highlightingLineReader.read(line1);
     highlightingLineReader.read(line2);
@@ -118,8 +116,7 @@ public class HighlightingLineReaderTest {
   public void read_many_syntax_highlighting_on_same_line() {
     HighlightingLineReader highlightingLineReader = newReader(of(
       newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1), ANNOTATION,
-      newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_2), COMMENT
-      ));
+      newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_2), COMMENT));
 
     highlightingLineReader.read(line1);
 
@@ -164,8 +161,7 @@ public class HighlightingLineReaderTest {
     HighlightingLineReader highlightingLineReader = newReader(of(
       textRange1, ANNOTATION,
       textRange2, HIGHLIGHTING_STRING,
-      textRange3, COMMENT
-      ));
+      textRange3, COMMENT));
 
     highlightingLineReader.read(line1);
     highlightingLineReader.read(line2);
@@ -202,7 +198,7 @@ public class HighlightingLineReaderTest {
     doThrow(RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(textRange1, LINE_1, DEFAULT_LINE_LENGTH);
 
     HighlightingLineReader highlightingLineReader = newReader(of(
-      textRange1, ANNOTATION,
+      textRange1, HighlightingType.ANNOTATION,
       newSingleLineTextRangeWithExpectingLabel(LINE_2, RANGE_LABEL_1), HIGHLIGHTING_STRING));
 
     highlightingLineReader.read(line1);
@@ -219,8 +215,7 @@ public class HighlightingLineReaderTest {
 
     HighlightingLineReader highlightingLineReader = newReader(of(
       newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1), ANNOTATION,
-      textRange2, HIGHLIGHTING_STRING
-      ));
+      textRange2, HIGHLIGHTING_STRING));
 
     highlightingLineReader.read(line1);
     highlightingLineReader.read(line2);
@@ -241,10 +236,10 @@ public class HighlightingLineReaderTest {
     assertThat(logTester.logs(WARN)).containsOnly("Inconsistency detected in Highlighting data. Highlighting will be ignored for file 'FILE_KEY'");
   }
 
-  private HighlightingLineReader newReader(Map<TextRange, Constants.HighlightingType> textRangeByType) {
-    List<ScannerReport.SyntaxHighlighting> syntaxHighlightingList = new ArrayList<>();
-    for (Map.Entry<TextRange, Constants.HighlightingType> entry : textRangeByType.entrySet()) {
-      syntaxHighlightingList.add(ScannerReport.SyntaxHighlighting.newBuilder()
+  private HighlightingLineReader newReader(Map<TextRange, HighlightingType> textRangeByType) {
+    List<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingList = new ArrayList<>();
+    for (Map.Entry<TextRange, HighlightingType> entry : textRangeByType.entrySet()) {
+      syntaxHighlightingList.add(ScannerReport.SyntaxHighlightingRule.newBuilder()
         .setRange(entry.getKey())
         .setType(entry.getValue())
         .build());
index 33422d738bfc70e42153bf0d400c231651322ceb..9be2fb9c096b1cf459fff9bccd0a518c76db00a3 100644 (file)
  */
 package org.sonar.server.computation.source;
 
+import java.io.File;
+import java.util.NoSuchElementException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import org.sonar.scanner.protocol.output.FileStructure;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.protocol.output.FileStructure;
-import java.io.File;
-import java.util.NoSuchElementException;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +40,7 @@ public class ReportIteratorTest {
 
   File file;
 
-  ReportIterator<ScannerReport.Coverage> underTest;
+  ReportIterator<ScannerReport.LineCoverage> underTest;
 
   @Before
   public void setUp() throws Exception {
@@ -48,10 +48,9 @@ public class ReportIteratorTest {
     ScannerReportWriter writer = new ScannerReportWriter(dir);
 
     writer.writeComponentCoverage(1, newArrayList(
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(1)
-        .build()
-    ));
+        .build()));
 
     file = new FileStructure(dir).fileFor(FileStructure.Domain.COVERAGES, 1);
   }
@@ -65,13 +64,13 @@ public class ReportIteratorTest {
 
   @Test
   public void read_report() {
-    underTest = new ReportIterator<>(file, ScannerReport.Coverage.PARSER);
+    underTest = new ReportIterator<>(file, ScannerReport.LineCoverage.parser());
     assertThat(underTest.next().getLine()).isEqualTo(1);
   }
 
   @Test
   public void do_not_fail_when_calling_has_next_with_iterator_already_closed() {
-    underTest = new ReportIterator<>(file, ScannerReport.Coverage.PARSER);
+    underTest = new ReportIterator<>(file, ScannerReport.LineCoverage.parser());
     assertThat(underTest.next().getLine()).isEqualTo(1);
     assertThat(underTest.hasNext()).isFalse();
 
@@ -81,7 +80,7 @@ public class ReportIteratorTest {
 
   @Test(expected = NoSuchElementException.class)
   public void test_error() throws Exception {
-    underTest = new ReportIterator<>(file, ScannerReport.Coverage.PARSER);
+    underTest = new ReportIterator<>(file, ScannerReport.LineCoverage.parser());
     underTest.next();
 
     // fail !
index e58395b5c9600ed1a1d2b6ab95c8647ec6a52aad..944f401463a17402f714aa057487ef49ea1fa57c 100644 (file)
@@ -33,8 +33,8 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.SnapshotDto;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 import org.sonar.server.computation.analysis.AnalysisMetadataHolderImpl;
 import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder;
 import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule;
@@ -42,17 +42,22 @@ import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.MutableTreeRootHolderRule;
 
+import static com.google.common.base.Predicates.in;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.collect.FluentIterable.from;
+import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject;
-import static org.sonar.scanner.protocol.Constants.ComponentType.DIRECTORY;
-import static org.sonar.scanner.protocol.Constants.ComponentType.FILE;
-import static org.sonar.scanner.protocol.Constants.ComponentType.MODULE;
-import static org.sonar.scanner.protocol.Constants.ComponentType.PROJECT;
-
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.DIRECTORY;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.MODULE;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNSET;
 
 @RunWith(DataProviderRunner.class)
 public class BuildComponentTreeStepTest {
@@ -100,9 +105,9 @@ public class BuildComponentTreeStepTest {
 
   @DataProvider
   public static Object[][] allComponentTypes() {
-    Object[][] res = new Object[Constants.ComponentType.values().length][1];
+    Object[][] res = new Object[ComponentType.values().length - 2][1];
     int i = 0;
-    for (Constants.ComponentType componentType : Constants.ComponentType.values()) {
+    for (ComponentType componentType : from(asList(ComponentType.values())).filter(not(in(asList(UNSET, UNRECOGNIZED))))) {
       res[i][0] = componentType;
       i++;
     }
@@ -111,7 +116,7 @@ public class BuildComponentTreeStepTest {
 
   @Test
   @UseDataProvider("allComponentTypes")
-  public void verify_ref_and_type(Constants.ComponentType componentType) {
+  public void verify_ref_and_type(ComponentType componentType) {
     int componentRef = 1;
     reportReader.putComponent(component(componentRef, componentType));
 
@@ -316,19 +321,19 @@ public class BuildComponentTreeStepTest {
     }
   }
 
-  private static ScannerReport.Component component(int componentRef, Constants.ComponentType componentType, int... children) {
+  private static ScannerReport.Component component(int componentRef, ComponentType componentType, int... children) {
     return component(componentRef, componentType, null, null, children);
   }
 
-  private static ScannerReport.Component componentWithKey(int componentRef, Constants.ComponentType componentType, String key, int... children) {
+  private static ScannerReport.Component componentWithKey(int componentRef, ComponentType componentType, String key, int... children) {
     return component(componentRef, componentType, key, null, children);
   }
 
-  private static ScannerReport.Component componentWithPath(int componentRef, Constants.ComponentType componentType, String path, int... children) {
+  private static ScannerReport.Component componentWithPath(int componentRef, ComponentType componentType, String path, int... children) {
     return component(componentRef, componentType, null, path, children);
   }
 
-  private static ScannerReport.Component component(int componentRef, Constants.ComponentType componentType, @Nullable String key, @Nullable String path, int... children) {
+  private static ScannerReport.Component component(int componentRef, ComponentType componentType, @Nullable String key, @Nullable String path, int... children) {
     ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder()
       .setType(componentType)
       .setRef(componentRef);
index 415867e6294f63a74cd699da48078753462dfc18..7617467a04373f709368b64c2a15581eb92c52d7 100644 (file)
@@ -57,7 +57,7 @@ public class LoadQualityProfilesStepTest {
     ScannerReport.ActiveRule.Builder batch1 = ScannerReport.ActiveRule.newBuilder()
       .setRuleRepository(XOO_X1.repository()).setRuleKey(XOO_X1.rule())
       .setSeverity(Constants.Severity.BLOCKER);
-    batch1.addParamBuilder().setKey("p1").setValue("v1").build();
+    batch1.getMutableParamsByKey().put("p1", "v1");
 
     ScannerReport.ActiveRule.Builder batch2 = ScannerReport.ActiveRule.newBuilder()
       .setRuleRepository(XOO_X2.repository()).setRuleKey(XOO_X2.rule()).setSeverity(Constants.Severity.MAJOR);
index 63b515b4a4441fb59fd0eafe717de040bd63e787..ec17dbd40df60a3d991d699ee7a21439c3913a75 100644 (file)
@@ -31,8 +31,9 @@ import org.sonar.db.DbTester;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.db.source.FileSourceDto.Type;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -51,7 +52,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-
 public class PersistFileSourcesStepTest extends BaseStepTest {
 
   private static final int FILE_REF = 3;
@@ -135,7 +135,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
   public void persist_coverage() {
     initBasicReport(1);
 
-    reportReader.putCoverage(FILE_REF, newArrayList(ScannerReport.Coverage.newBuilder()
+    reportReader.putCoverage(FILE_REF, newArrayList(ScannerReport.LineCoverage.newBuilder()
       .setLine(1)
       .setConditions(10)
       .setUtHits(true)
@@ -193,12 +193,12 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
   public void persist_highlighting() {
     initBasicReport(1);
 
-    reportReader.putSyntaxHighlighting(FILE_REF, newArrayList(ScannerReport.SyntaxHighlighting.newBuilder()
+    reportReader.putSyntaxHighlighting(FILE_REF, newArrayList(ScannerReport.SyntaxHighlightingRule.newBuilder()
       .setRange(ScannerReport.TextRange.newBuilder()
         .setStartLine(1).setEndLine(1)
         .setStartOffset(2).setEndOffset(4)
         .build())
-      .setType(Constants.HighlightingType.ANNOTATION)
+      .setType(HighlightingType.ANNOTATION)
       .build()));
 
     underTest.execute();
@@ -245,8 +245,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
 
     duplicationRepository.add(
       FILE_REF,
-      new Duplication(new TextBlock(1, 2), Arrays.<Duplicate>asList(new InnerDuplicate(new TextBlock(3, 4))))
-      );
+      new Duplication(new TextBlock(1, 2), Arrays.<Duplicate>asList(new InnerDuplicate(new TextBlock(3, 4)))));
 
     underTest.execute();
 
@@ -441,17 +440,17 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
+      .setType(ComponentType.MODULE)
       .addChildRef(FILE_REF)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(FILE_REF)
-      .setType(Constants.ComponentType.FILE)
+      .setType(ComponentType.FILE)
       .build());
 
     for (int i = 1; i <= numberOfLines; i++) {
index 0f7e9671905d434446c637fd76e6e22cbe6b1641..5236ad1c64f2ea98bac47210b7e4e506a24bf5fb 100644 (file)
@@ -26,8 +26,9 @@ import org.junit.Test;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
+import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
@@ -39,7 +40,6 @@ import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-
 public class PersistProjectLinksStepTest extends BaseStepTest {
 
   @Rule
@@ -81,18 +81,18 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
     // project and 1 module
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .addChildRef(2)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.SCM).setHref("https://github.com/SonarSource/sonar").build())
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.SCM_DEV).setHref("scm:git:git@github.com:SonarSource/sonar.git/sonar").build())
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.ISSUE).setHref("http://jira.sonarsource.com/").build())
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.CI).setHref("http://bamboo.ci.codehaus.org/browse/SONAR").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.SCM).setHref("https://github.com/SonarSource/sonar").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.SCM_DEV).setHref("scm:git:git@github.com:SonarSource/sonar.git/sonar").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.ISSUE).setHref("http://jira.sonarsource.com/").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.CI).setHref("http://bamboo.ci.codehaus.org/browse/SONAR").build())
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.SCM).setHref("https://github.com/SonarSource/sonar/server").build())
+      .setType(ComponentType.MODULE)
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.SCM).setHref("https://github.com/SonarSource/sonar/server").build())
       .build());
 
     step.execute();
@@ -108,8 +108,8 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .setType(ComponentType.PROJECT)
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
       .build());
 
     step.execute();
@@ -127,13 +127,13 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.FILE)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .setType(ComponentType.FILE)
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
       .build());
 
     step.execute();
@@ -149,8 +149,8 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .setType(ComponentType.PROJECT)
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
       .build());
 
     step.execute();
@@ -166,7 +166,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .build());
 
     step.execute();
@@ -182,7 +182,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .build());
 
     step.execute();
@@ -198,9 +198,9 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
-      .addLink(ScannerReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .setType(ComponentType.PROJECT)
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
+      .addLink(ScannerReport.ComponentLink.newBuilder().setType(ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
       .build());
 
     try {
index b84689867f5d39a04465bdb1aa45cfdcbe0a69c1..52e49fa5e6e48194c77c41b2849ad7415b9dca6a 100644 (file)
@@ -31,14 +31,14 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail;
+import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.component.ReportComponent;
 import org.sonar.server.computation.component.FileAttributes;
+import org.sonar.server.computation.component.ReportComponent;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
@@ -256,7 +256,7 @@ public class PersistTestsStepTest extends BaseStepTest {
 
   private ScannerReport.Test newTest(int id) {
     return ScannerReport.Test.newBuilder()
-      .setStatus(Constants.TestStatus.FAILURE)
+      .setStatus(TestStatus.FAILURE)
       .setName("name#" + id)
       .setStacktrace("stacktrace#" + id)
       .setMsg("message#" + id)
index 61f1a0265b22de623cedcc7f5f0a5a92b4f7a30e..6078a73df0630dbc35b1774db5806118ac4d3a43 100644 (file)
@@ -32,15 +32,14 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.SnapshotTesting;
-import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 import org.sonar.server.computation.analysis.AnalysisMetadataHolderRule;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.ReportComponent;
 
-
 public class ValidateProjectStepTest {
 
   static long DEFAULT_ANALYSIS_TIME = 1433131200000L; // 2015-06-01
@@ -79,7 +78,7 @@ public class ValidateProjectStepTest {
     analysisMetadataHolder.setBranch(DEFAULT_BRANCH);
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .build());
     treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY + ":origin/master").build());
@@ -96,7 +95,7 @@ public class ValidateProjectStepTest {
     analysisMetadataHolder.setBranch("bran#ch");
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .build());
     treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY + ":bran#ch").build());
@@ -115,13 +114,13 @@ public class ValidateProjectStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(invalidProjectKey)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
+      .setType(ComponentType.MODULE)
       .setKey("Module$Key")
       .build());
     treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(invalidProjectKey).addChildren(
@@ -141,13 +140,13 @@ public class ValidateProjectStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
+      .setType(ComponentType.MODULE)
       .setKey(MODULE_KEY)
       .build());
 
@@ -171,13 +170,13 @@ public class ValidateProjectStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
+      .setType(ComponentType.MODULE)
       .setKey(MODULE_KEY)
       .build());
 
@@ -206,13 +205,13 @@ public class ValidateProjectStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .addChildRef(2)
       .build());
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(2)
-      .setType(Constants.ComponentType.MODULE)
+      .setType(ComponentType.MODULE)
       .setKey(MODULE_KEY)
       .build());
 
@@ -233,7 +232,7 @@ public class ValidateProjectStepTest {
   public void not_fail_if_analysis_date_is_after_last_analysis() {
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .addChildRef(2)
       .build());
@@ -259,7 +258,7 @@ public class ValidateProjectStepTest {
 
     reportReader.putComponent(ScannerReport.Component.newBuilder()
       .setRef(1)
-      .setType(Constants.ComponentType.PROJECT)
+      .setType(ComponentType.PROJECT)
       .setKey(PROJECT_KEY)
       .addChildRef(2)
       .build());
index ee3c07f13023caca3402109e57ac8d80e0b0e80a..1b0d755ce9f83ca31edc8d29e0bd76586c5c1abb 100644 (file)
@@ -394,21 +394,21 @@ public final class CoreMetrics {
   @Deprecated
   public static final Metric<String> CLASS_COMPLEXITY_DISTRIBUTION = new Metric.Builder(CLASS_COMPLEXITY_DISTRIBUTION_KEY, "Classes distribution /complexity",
     Metric.ValueType.DISTRIB)
-    .setDescription("Classes distribution /complexity")
-    .setDirection(Metric.DIRECTION_NONE)
-    .setQualitative(true)
-    .setDomain(DOMAIN_COMPLEXITY)
-    .setHidden(true)
-    .create();
+      .setDescription("Classes distribution /complexity")
+      .setDirection(Metric.DIRECTION_NONE)
+      .setQualitative(true)
+      .setDomain(DOMAIN_COMPLEXITY)
+      .setHidden(true)
+      .create();
 
   public static final String FUNCTION_COMPLEXITY_DISTRIBUTION_KEY = "function_complexity_distribution";
   public static final Metric<String> FUNCTION_COMPLEXITY_DISTRIBUTION = new Metric.Builder(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "Functions distribution /complexity",
     Metric.ValueType.DISTRIB)
-    .setDescription("Functions distribution /complexity")
-    .setDirection(Metric.DIRECTION_NONE)
-    .setQualitative(true)
-    .setDomain(DOMAIN_COMPLEXITY)
-    .create();
+      .setDescription("Functions distribution /complexity")
+      .setDirection(Metric.DIRECTION_NONE)
+      .setQualitative(true)
+      .setDomain(DOMAIN_COMPLEXITY)
+      .create();
 
   public static final String FILE_COMPLEXITY_DISTRIBUTION_KEY = "file_complexity_distribution";
   public static final Metric<String> FILE_COMPLEXITY_DISTRIBUTION = new Metric.Builder(FILE_COMPLEXITY_DISTRIBUTION_KEY, "Files distribution /complexity", Metric.ValueType.DISTRIB)
@@ -915,12 +915,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Integer> NEW_IT_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_IT_UNCOVERED_CONDITIONS_KEY, "Uncovered branches by IT on new code",
     Metric.ValueType.INT)
-    .setDescription("Uncovered branches by Integration Tests on new code")
-    .setDirection(Metric.DIRECTION_WORST)
-    .setDomain(DOMAIN_TESTS)
-    .setBestValue(0.0)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Uncovered branches by Integration Tests on new code")
+      .setDirection(Metric.DIRECTION_WORST)
+      .setDomain(DOMAIN_TESTS)
+      .setBestValue(0.0)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 2.12
@@ -1142,12 +1142,12 @@ public final class CoreMetrics {
   @Deprecated
   public static final Metric<String> OVERALL_COVERAGE_LINE_HITS_DATA = new Metric.Builder(OVERALL_COVERAGE_LINE_HITS_DATA_KEY, "Overall coverage hits by line",
     Metric.ValueType.DATA)
-    .setDescription("Coverage hits by all tests and by line")
-    .setDirection(Metric.DIRECTION_NONE)
-    .setQualitative(false)
-    .setDomain(DOMAIN_TESTS)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Coverage hits by all tests and by line")
+      .setDirection(Metric.DIRECTION_NONE)
+      .setQualitative(false)
+      .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 3.3
@@ -1175,11 +1175,11 @@ public final class CoreMetrics {
    */
   public static final Metric<Integer> NEW_OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(NEW_OVERALL_CONDITIONS_TO_COVER_KEY, "Overall branches to cover on new code",
     Metric.ValueType.INT)
-    .setDescription("New branches to cover by all tests")
-    .setDomain(DOMAIN_TESTS)
-    .setDeleteHistoricalData(true)
-    .setHidden(true)
-    .create();
+      .setDescription("New branches to cover by all tests")
+      .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
+      .setHidden(true)
+      .create();
 
   /**
    * @since 3.3
@@ -1205,12 +1205,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Integer> NEW_OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall uncovered branches on new code",
     Metric.ValueType.INT)
-    .setDescription("New branches that are not covered by any test")
-    .setDirection(Metric.DIRECTION_WORST)
-    .setDomain(DOMAIN_TESTS)
-    .setBestValue(0.0)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("New branches that are not covered by any test")
+      .setDirection(Metric.DIRECTION_WORST)
+      .setDomain(DOMAIN_TESTS)
+      .setBestValue(0.0)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 3.3
@@ -1239,14 +1239,14 @@ public final class CoreMetrics {
    */
   public static final Metric<Double> NEW_OVERALL_BRANCH_COVERAGE = new Metric.Builder(NEW_OVERALL_BRANCH_COVERAGE_KEY, "Overall condition coverage on new code",
     Metric.ValueType.PERCENT)
-    .setDescription("Condition coverage of new/changed code by all tests")
-    .setDirection(Metric.DIRECTION_BETTER)
-    .setQualitative(true)
-    .setDomain(DOMAIN_TESTS)
-    .setWorstValue(0.0)
-    .setBestValue(100.0)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Condition coverage of new/changed code by all tests")
+      .setDirection(Metric.DIRECTION_BETTER)
+      .setQualitative(true)
+      .setDomain(DOMAIN_TESTS)
+      .setWorstValue(0.0)
+      .setBestValue(100.0)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 3.3
@@ -1280,10 +1280,10 @@ public final class CoreMetrics {
   @Deprecated
   public static final Metric<String> OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line",
     Metric.ValueType.DATA)
-    .setDescription("Overall covered branches by all tests and by line")
-    .setDomain(DOMAIN_TESTS)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Overall covered branches by all tests and by line")
+      .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
+      .create();
 
   // --------------------------------------------------------------------------------------------------------------------
   //
@@ -2149,8 +2149,8 @@ public final class CoreMetrics {
   @Deprecated
   public static final transient Metric<String> SCM_LAST_COMMIT_DATETIMES_BY_LINE = new Metric.Builder(SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, "Last commit dates by line",
     Metric.ValueType.DATA)
-    .setDomain(DOMAIN_SCM)
-    .create();
+      .setDomain(DOMAIN_SCM)
+      .create();
 
   // --------------------------------------------------------------------------------------------------------------------
   //
@@ -2279,12 +2279,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> EFFORT_TO_REACH_MAINTAINABILITY_RATING_A = new Metric.Builder(EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY,
     "Effort to reach maintainability rating A", Metric.ValueType.WORK_DUR)
-    .setDomain(DOMAIN_MAINTAINABILITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setQualitative(true)
-    .setBestValue(0.0)
-    .setOptimizedBestValue(true)
-    .create();
+      .setDomain(DOMAIN_MAINTAINABILITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setQualitative(true)
+      .setBestValue(0.0)
+      .setOptimizedBestValue(true)
+      .create();
 
   // --------------------------------------------------------------------------------------------------------------------
   //
@@ -2302,12 +2302,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> RELIABILITY_REMEDIATION_EFFORT = new Metric.Builder(RELIABILITY_REMEDIATION_EFFORT_KEY, "Reliability remediation effort",
     Metric.ValueType.WORK_DUR)
-    .setDomain(DOMAIN_RELIABILITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setOptimizedBestValue(true)
-    .setBestValue(0.0)
-    .setQualitative(true)
-    .create();
+      .setDomain(DOMAIN_RELIABILITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setOptimizedBestValue(true)
+      .setBestValue(0.0)
+      .setQualitative(true)
+      .create();
 
   /**
    * @since 5.5
@@ -2319,14 +2319,14 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> NEW_RELIABILITY_REMEDIATION_EFFORT = new Metric.Builder(NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, "Reliability remediation effort on new code",
     Metric.ValueType.WORK_DUR)
-    .setDescription("Reliability remediation effort of new code")
-    .setDomain(DOMAIN_RELIABILITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setOptimizedBestValue(true)
-    .setBestValue(0.0)
-    .setQualitative(true)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Reliability remediation effort of new code")
+      .setDomain(DOMAIN_RELIABILITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setOptimizedBestValue(true)
+      .setBestValue(0.0)
+      .setQualitative(true)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 5.5
@@ -2354,12 +2354,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> EFFORT_TO_REACH_RELIABILITY_RATING_A = new Metric.Builder(EFFORT_TO_REACH_RELIABILITY_RATING_A_KEY, "Effort to reach reliability rating A",
     Metric.ValueType.WORK_DUR)
-    .setDomain(DOMAIN_RELIABILITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setQualitative(true)
-    .setBestValue(0.0)
-    .setOptimizedBestValue(true)
-    .create();
+      .setDomain(DOMAIN_RELIABILITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setQualitative(true)
+      .setBestValue(0.0)
+      .setOptimizedBestValue(true)
+      .create();
 
   // --------------------------------------------------------------------------------------------------------------------
   //
@@ -2393,14 +2393,14 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> NEW_SECURITY_REMEDIATION_EFFORT = new Metric.Builder(NEW_SECURITY_REMEDIATION_EFFORT_KEY, "Security remediation effort on new code",
     Metric.ValueType.WORK_DUR)
-    .setDescription("Security remediation effort of new code")
-    .setDomain(DOMAIN_SECURITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setOptimizedBestValue(true)
-    .setBestValue(0.0)
-    .setQualitative(true)
-    .setDeleteHistoricalData(true)
-    .create();
+      .setDescription("Security remediation effort of new code")
+      .setDomain(DOMAIN_SECURITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setOptimizedBestValue(true)
+      .setBestValue(0.0)
+      .setQualitative(true)
+      .setDeleteHistoricalData(true)
+      .create();
 
   /**
    * @since 5.5
@@ -2428,12 +2428,12 @@ public final class CoreMetrics {
    */
   public static final Metric<Long> EFFORT_TO_REACH_SECURITY_RATING_A = new Metric.Builder(EFFORT_TO_REACH_SECURITY_RATING_A_KEY, "Effort to reach security rating A",
     Metric.ValueType.WORK_DUR)
-    .setDomain(DOMAIN_SECURITY)
-    .setDirection(Metric.DIRECTION_WORST)
-    .setQualitative(true)
-    .setBestValue(0.0)
-    .setOptimizedBestValue(true)
-    .create();
+      .setDomain(DOMAIN_SECURITY)
+      .setDirection(Metric.DIRECTION_WORST)
+      .setQualitative(true)
+      .setBestValue(0.0)
+      .setOptimizedBestValue(true)
+      .create();
 
   // --------------------------------------------------------------------------------------------------------------------
   //
index 12dac2c19028b7e24a4466ca174dfd32b4f278c6..ec890289ac55795452211d9a6d862559ae6174dc 100644 (file)
@@ -61,12 +61,12 @@ public class DefaultFilterableIssue implements FilterableIssue {
 
   @Override
   public Integer line() {
-    return rawIssue.hasLine() ? rawIssue.getLine() : null;
+    return rawIssue.hasTextRange() ? rawIssue.getTextRange().getStartLine() : null;
   }
 
   @Override
   public Double gap() {
-    return rawIssue.hasGap() ? rawIssue.getGap() : null;
+    return rawIssue.getGap() != 0 ? rawIssue.getGap() : null;
   }
 
   @Override
index 9dfa16d7f7f9b69e1b010d051d950ad45d66b561..3a87023b2d11102e1977a098ffdf6dd2a3889260 100644 (file)
@@ -77,7 +77,7 @@ class DeprecatedIssueAdapterForFilter implements Issue {
 
   @Override
   public Integer line() {
-    return rawIssue.hasLine() ? rawIssue.getLine() : null;
+    return rawIssue.hasTextRange() ? rawIssue.getTextRange().getStartLine() : null;
   }
 
   @Override
@@ -88,7 +88,7 @@ class DeprecatedIssueAdapterForFilter implements Issue {
 
   @Override
   public Double gap() {
-    return rawIssue.hasGap() ? rawIssue.getGap() : null;
+    return rawIssue.getGap() != 0 ? rawIssue.getGap() : null;
   }
 
   @Override
index 8a34253114b6f9f1e47b7eb747c255818ba55db5..c6a2644d1ad2133c7233d999844d3e054e16a93e 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 import javax.annotation.Nullable;
+import org.apache.commons.lang.StringUtils;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.batch.index.BatchComponent;
@@ -93,9 +94,9 @@ public class IssueTransformer {
     issue.setKey(Uuids.createFast());
     issue.setComponentKey(component.key());
     issue.setRuleKey(ruleKey);
-    issue.setGap(rawIssue.hasGap() ? rawIssue.getGap() : null);
+    issue.setGap(rawIssue.getGap() != 0 ? rawIssue.getGap() : null);
     issue.setSeverity(rawIssue.getSeverity().name());
-    issue.setMessage(rawIssue.hasMsg() ? rawIssue.getMsg() : null);
+    issue.setMessage(StringUtils.trimToNull(rawIssue.getMsg()));
     issue.setResolution(null);
     issue.setStatus(Issue.STATUS_OPEN);
     issue.setNew(true);
@@ -103,10 +104,10 @@ public class IssueTransformer {
     if (rawIssue.hasTextRange()) {
       TextRange r = rawIssue.getTextRange();
 
-      issue.setStartLine(r.hasStartLine() ? rawIssue.getTextRange().getStartLine() : null);
-      issue.setStartLineOffset(r.hasStartOffset() ? r.getStartOffset() : null);
-      issue.setEndLine(r.hasEndLine() ? r.getEndLine() : issue.startLine());
-      issue.setEndLineOffset(r.hasEndOffset() ? r.getEndOffset() : null);
+      issue.setStartLine(r.getStartLine());
+      issue.setStartLineOffset(r.getStartOffset());
+      issue.setEndLine(r.getEndLine());
+      issue.setEndLineOffset(r.getEndOffset());
     }
 
     return issue;
index 433c8826f85fa4acb0f9a84848a455c2ad773acf..d120e018acdba691dec2cd64426a17c58cbc34c9 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.batch.report.ReportPublisher;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation;
-import org.sonar.scanner.protocol.output.ScannerReport.IssueLocation.Builder;
 
 /**
  * Initialize the issues raised during scan.
@@ -48,10 +47,6 @@ public class ModuleIssues {
   private final IssueFilters filters;
   private final ReportPublisher reportPublisher;
   private final BatchComponentCache componentCache;
-  private final ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
-  private final Builder locationBuilder = IssueLocation.newBuilder();
-  private final org.sonar.scanner.protocol.output.ScannerReport.TextRange.Builder textRangeBuilder = org.sonar.scanner.protocol.output.ScannerReport.TextRange.newBuilder();
-  private final ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder();
 
   public ModuleIssues(ActiveRules activeRules, Rules rules, IssueFilters filters, ReportPublisher reportPublisher, BatchComponentCache componentCache) {
     this.activeRules = activeRules;
@@ -76,8 +71,9 @@ public class ModuleIssues {
     org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
     Severity severity = overriddenSeverity != null ? Severity.valueOf(overriddenSeverity.name()) : Severity.valueOf(activeRule.severity());
 
-    builder.clear();
-    locationBuilder.clear();
+    ScannerReport.Issue.Builder builder = ScannerReport.Issue.newBuilder();
+    ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
+    ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
     // non-null fields
     builder.setSeverity(severity);
     builder.setRuleRepository(issue.ruleKey().repository());
@@ -88,14 +84,13 @@ public class ModuleIssues {
     locationBuilder.setComponentRef(component.batchId());
     TextRange primaryTextRange = issue.primaryLocation().textRange();
     if (primaryTextRange != null) {
-      builder.setLine(primaryTextRange.start().line());
-      builder.setTextRange(toProtobufTextRange(primaryTextRange));
+      builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
     }
     Double gap = issue.gap();
     if (gap != null) {
       builder.setGap(gap);
     }
-    applyFlows(issue);
+    applyFlows(builder, locationBuilder, textRangeBuilder, issue);
     ScannerReport.Issue rawIssue = builder.build();
 
     if (filters.accept(inputComponent.key(), rawIssue)) {
@@ -105,7 +100,8 @@ public class ModuleIssues {
     return false;
   }
 
-  private void applyFlows(Issue issue) {
+  private void applyFlows(ScannerReport.Issue.Builder builder, ScannerReport.IssueLocation.Builder locationBuilder, ScannerReport.TextRange.Builder textRangeBuilder, Issue issue) {
+    ScannerReport.Flow.Builder flowBuilder = ScannerReport.Flow.newBuilder();
     for (Flow flow : issue.flows()) {
       if (!flow.locations().isEmpty()) {
         flowBuilder.clear();
@@ -118,7 +114,7 @@ public class ModuleIssues {
           }
           TextRange textRange = location.textRange();
           if (textRange != null) {
-            locationBuilder.setTextRange(toProtobufTextRange(textRange));
+            locationBuilder.setTextRange(toProtobufTextRange(textRangeBuilder, textRange));
           }
           flowBuilder.addLocation(locationBuilder.build());
         }
@@ -127,7 +123,7 @@ public class ModuleIssues {
     }
   }
 
-  private org.sonar.scanner.protocol.output.ScannerReport.TextRange toProtobufTextRange(TextRange primaryTextRange) {
+  private ScannerReport.TextRange toProtobufTextRange(ScannerReport.TextRange.Builder textRangeBuilder, TextRange primaryTextRange) {
     textRangeBuilder.clear();
     textRangeBuilder.setStartLine(primaryTextRange.start().line());
     textRangeBuilder.setStartOffset(primaryTextRange.start().lineOffset());
index 5d3d87b540d756744692abec1bf53f2fae83fd79..9edee3c7208aefa5afa3c7e0372e53ea2ceed0ca 100644 (file)
@@ -29,7 +29,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,16 +42,18 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.batch.issue.IssueCache;
 import org.sonar.batch.issue.tracking.TrackedIssue;
-import org.sonar.batch.report.ScannerReportUtils;
 import org.sonar.batch.report.ReportPublisher;
+import org.sonar.batch.report.ScannerReportUtils;
 import org.sonar.batch.scan.ProjectScanContainer;
 import org.sonar.batch.scan.filesystem.InputPathCache;
 import org.sonar.core.util.CloseableIterator;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
 import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
 import org.sonar.scanner.protocol.output.ScannerReport.Symbol;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
+
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
 
 public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
 
@@ -76,22 +77,22 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
     if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
       Metadata readMetadata = getReportReader().readMetadata();
       int rootComponentRef = readMetadata.getRootComponentRef();
-      storeReportComponents(rootComponentRef, null, readMetadata.hasBranch() ? readMetadata.getBranch() : null);
+      storeReportComponents(rootComponentRef, null, readMetadata.getBranch());
     }
 
     storeFs(container);
 
   }
 
-  private void storeReportComponents(int componentRef, String parentModuleKey, @Nullable String branch) {
+  private void storeReportComponents(int componentRef, String parentModuleKey, String branch) {
     Component component = getReportReader().readComponent(componentRef);
-    if (component.hasKey()) {
-      reportComponents.put(component.getKey() + (branch != null ? ":" + branch : ""), component);
+    if (isNotEmpty(component.getKey())) {
+      reportComponents.put(component.getKey() + (isNotEmpty(branch) ? ":" + branch : ""), component);
     } else {
-      reportComponents.put(parentModuleKey + (branch != null ? ":" + branch : "") + ":" + component.getPath(), component);
+      reportComponents.put(parentModuleKey + (isNotEmpty(branch) ? ":" + branch : "") + ":" + component.getPath(), component);
     }
     for (int childId : component.getChildRefList()) {
-      storeReportComponents(childId, component.hasKey() ? component.getKey() : parentModuleKey, branch);
+      storeReportComponents(childId, isNotEmpty(component.getKey()) ? component.getKey() : parentModuleKey, branch);
     }
 
   }
@@ -179,9 +180,9 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
     }
     TextPointer pointer = file.newPointer(line, lineOffset);
     List<TypeOfText> result = new ArrayList<>();
-    try (CloseableIterator<ScannerReport.SyntaxHighlighting> it = reader.readComponentSyntaxHighlighting(ref)) {
+    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(ref)) {
       while (it.hasNext()) {
-        ScannerReport.SyntaxHighlighting rule = it.next();
+        ScannerReport.SyntaxHighlightingRule rule = it.next();
         TextRange ruleRange = toRange(file, rule.getRange());
         if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
           result.add(ScannerReportUtils.toBatchType(rule.getType()));
@@ -243,11 +244,11 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
   }
 
   @CheckForNull
-  public ScannerReport.Coverage coverageFor(InputFile file, int line) {
+  public ScannerReport.LineCoverage coverageFor(InputFile file, int line) {
     int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
-    try (CloseableIterator<ScannerReport.Coverage> it = getReportReader().readComponentCoverage(ref)) {
+    try (CloseableIterator<ScannerReport.LineCoverage> it = getReportReader().readComponentCoverage(ref)) {
       while (it.hasNext()) {
-        ScannerReport.Coverage coverage = it.next();
+        ScannerReport.LineCoverage coverage = it.next();
         if (coverage.getLine() == line) {
           return coverage;
         }
@@ -261,12 +262,12 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
   public ScannerReport.Test testExecutionFor(InputFile testFile, String testName) {
     int ref = reportComponents.get(((DefaultInputFile) testFile).key()).getRef();
     try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readTests(ref))) {
-      ScannerReport.Test test = ScannerReport.Test.PARSER.parseDelimitedFrom(inputStream);
+      ScannerReport.Test test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
       while (test != null) {
         if (test.getName().equals(testName)) {
           return test;
         }
-        test = ScannerReport.Test.PARSER.parseDelimitedFrom(inputStream);
+        test = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
       }
     } catch (Exception e) {
       throw new IllegalStateException(e);
@@ -277,12 +278,12 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
   public ScannerReport.CoverageDetail coveragePerTestFor(InputFile testFile, String testName) {
     int ref = reportComponents.get(((DefaultInputFile) testFile).key()).getRef();
     try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readCoverageDetails(ref))) {
-      ScannerReport.CoverageDetail details = ScannerReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream);
+      ScannerReport.CoverageDetail details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
       while (details != null) {
         if (details.getTestName().equals(testName)) {
           return details;
         }
-        details = ScannerReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream);
+        details = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
       }
     } catch (Exception e) {
       throw new IllegalStateException(e);
index ba5dd00fbac7d07b3ac93eba8007e8a20d066721..571d709971fa6c65ff6453069297439096b7871e 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.batch.report;
 
 import com.google.common.base.Function;
 import com.google.common.collect.FluentIterable;
-import java.util.Map;
 import javax.annotation.Nonnull;
 import org.sonar.api.batch.rule.ActiveRule;
 import org.sonar.api.batch.rule.ActiveRules;
@@ -52,10 +51,7 @@ public class ActiveRulesPublisher implements ReportPublisherStep {
       builder.setRuleRepository(input.ruleKey().repository());
       builder.setRuleKey(input.ruleKey().rule());
       builder.setSeverity(Constants.Severity.valueOf(input.severity()));
-      for (Map.Entry<String, String> entry : input.params().entrySet()) {
-        builder.addParamBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build();
-
-      }
+      builder.getMutableParamsByKey().putAll(input.params());
       return builder.build();
     }
   }
index 0aa66d0bdcad071f3fd31f9175cae80a6921a879..27d46165d227be3b3700a484610c679d274339e2 100644 (file)
@@ -30,11 +30,11 @@ import org.sonar.api.resources.ResourceUtils;
 import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.scan.ImmutableProjectReactor;
-import org.sonar.scanner.protocol.Constants;
-import org.sonar.scanner.protocol.Constants.ComponentLinkType;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink;
+import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 /**
  * Adds components and analysis metadata to output report
@@ -159,15 +159,15 @@ public class ComponentsPublisher implements ReportPublisherStep {
     return ResourceUtils.isProject(r) ? r.getDescription() : null;
   }
 
-  private Constants.ComponentType getType(Resource r) {
+  private ComponentType getType(Resource r) {
     if (ResourceUtils.isFile(r)) {
-      return Constants.ComponentType.FILE;
+      return ComponentType.FILE;
     } else if (ResourceUtils.isDirectory(r)) {
-      return Constants.ComponentType.DIRECTORY;
+      return ComponentType.DIRECTORY;
     } else if (ResourceUtils.isModuleProject(r)) {
-      return Constants.ComponentType.MODULE;
+      return ComponentType.MODULE;
     } else if (ResourceUtils.isRootProject(r)) {
-      return Constants.ComponentType.PROJECT;
+      return ComponentType.PROJECT;
     }
     throw new IllegalArgumentException("Unknown resource type: " + r);
   }
index 1d6b9db71ef56b5b7814085dff775b38e2d6c983..1d8d5fee448864240e9eb4434d95826d561f252b 100644 (file)
@@ -32,9 +32,9 @@ import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.scan.measure.MeasureCache;
+import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage;
+import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage.Builder;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.protocol.output.ScannerReport.Coverage;
-import org.sonar.scanner.protocol.output.ScannerReport.Coverage.Builder;
 
 public class CoveragePublisher implements ReportPublisherStep {
 
@@ -52,48 +52,48 @@ public class CoveragePublisher implements ReportPublisherStep {
       if (!resource.isFile()) {
         continue;
       }
-      Map<Integer, Coverage.Builder> coveragePerLine = new LinkedHashMap<>();
+      Map<Integer, LineCoverage.Builder> coveragePerLine = new LinkedHashMap<>();
 
       int lineCount = ((InputFile) resource.inputComponent()).lines();
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setUtHits(Integer.parseInt(value) > 0);
           }
         });
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.CONDITIONS_BY_LINE_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setConditions(Integer.parseInt(value));
           }
         });
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setUtCoveredConditions(Integer.parseInt(value));
           }
         });
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setItHits(Integer.parseInt(value) > 0);
           }
         });
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setItCoveredConditions(Integer.parseInt(value));
           }
         });
       applyLineMeasure(resource.key(), lineCount, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, coveragePerLine,
         new MeasureOperation() {
           @Override
-          public void apply(String value, Coverage.Builder builder) {
+          public void apply(String value, LineCoverage.Builder builder) {
             builder.setOverallCoveredConditions(Integer.parseInt(value));
           }
         });
@@ -101,7 +101,7 @@ public class CoveragePublisher implements ReportPublisherStep {
     }
   }
 
-  void applyLineMeasure(String inputFileKey, int lineCount, String metricKey, Map<Integer, Coverage.Builder> coveragePerLine, MeasureOperation op) {
+  void applyLineMeasure(String inputFileKey, int lineCount, String metricKey, Map<Integer, LineCoverage.Builder> coveragePerLine, MeasureOperation op) {
     Measure measure = measureCache.byMetric(inputFileKey, metricKey);
     if (measure != null) {
       Map<Integer, String> lineMeasures = KeyValueFormat.parseIntString((String) measure.value());
@@ -110,9 +110,9 @@ public class CoveragePublisher implements ReportPublisherStep {
         if (lineIdx <= lineCount) {
           String value = lineMeasure.getValue();
           if (StringUtils.isNotEmpty(value)) {
-            Coverage.Builder coverageBuilder = coveragePerLine.get(lineIdx);
+            LineCoverage.Builder coverageBuilder = coveragePerLine.get(lineIdx);
             if (coverageBuilder == null) {
-              coverageBuilder = Coverage.newBuilder();
+              coverageBuilder = LineCoverage.newBuilder();
               coverageBuilder.setLine(lineIdx);
               coveragePerLine.put(lineIdx, coverageBuilder);
             }
@@ -124,14 +124,14 @@ public class CoveragePublisher implements ReportPublisherStep {
   }
 
   interface MeasureOperation {
-    void apply(String value, Coverage.Builder builder);
+    void apply(String value, LineCoverage.Builder builder);
   }
 
-  private enum BuildCoverage implements Function<Coverage.Builder, Coverage> {
+  private enum BuildCoverage implements Function<LineCoverage.Builder, LineCoverage> {
     INSTANCE;
 
     @Override
-    public Coverage apply(@Nonnull Builder input) {
+    public LineCoverage apply(@Nonnull Builder input) {
       return input.build();
     }
   }
index 51e8867ddca5679fb0581337718969e2932ea157..b743a841c988730df4c96130da36fba3c71f618d 100644 (file)
@@ -26,13 +26,16 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import org.sonar.api.batch.measure.Metric;
 import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric.ValueType;
 import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.scan.measure.MeasureCache;
 import org.sonar.core.metric.BatchMetrics;
-import org.sonar.scanner.protocol.Constants.MeasureValueType;
 import org.sonar.scanner.protocol.output.ScannerReport;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.BoolValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.IntValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.LongValue;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 import static com.google.common.collect.Iterables.filter;
@@ -63,61 +66,38 @@ public class MeasuresPublisher implements ReportPublisherStep {
 
     private ScannerReport.Measure toReportMeasure(ScannerReport.Measure.Builder builder, Measure measure) {
       builder.clear();
-
-      builder.setValueType(getMeasureValueType(measure.getMetric().getType()));
-      setValueAccordingToType(builder, measure);
-      // Because some numeric measures also have a data (like maintainability rating)
-      String data = measure.getData();
-      if (data != null) {
-        builder.setStringValue(data);
-      }
       builder.setMetricKey(measure.getMetricKey());
+      setValueAccordingToType(builder, measure);
       return builder.build();
     }
 
     private void setValueAccordingToType(ScannerReport.Measure.Builder builder, Measure measure) {
       Serializable value = measure.value();
-      switch (builder.getValueType()) {
-        case BOOLEAN:
-          builder.setBooleanValue((Boolean) value);
-          break;
-        case DOUBLE:
-          builder.setDoubleValue(((Number) value).doubleValue());
-          break;
-        case INT:
-          builder.setIntValue(((Number) value).intValue());
-          break;
-        case LONG:
-          builder.setLongValue(((Number) value).longValue());
-          break;
-        case STRING:
-          builder.setStringValue((String) value);
-          break;
-        default:
-          throw new IllegalStateException("Unknown value type: " + builder.getValueType());
-      }
-    }
-
-    private MeasureValueType getMeasureValueType(ValueType type) {
-      switch (type) {
+      String data = measure.getData() != null ? measure.getData() : "";
+      switch (measure.getMetric().getType()) {
         case INT:
         case RATING:
-          return MeasureValueType.INT;
+          builder.setIntValue(IntValue.newBuilder().setValue(((Number) value).intValue()).setData(data));
+          break;
         case FLOAT:
         case PERCENT:
-          return MeasureValueType.DOUBLE;
+          builder.setDoubleValue(DoubleValue.newBuilder().setValue(((Number) value).doubleValue()).setData(data));
+          break;
         case BOOL:
-          return MeasureValueType.BOOLEAN;
+          builder.setBooleanValue(BoolValue.newBuilder().setValue(((Boolean) value).booleanValue()).setData(data));
+          break;
+        case WORK_DUR:
+        case MILLISEC:
+          builder.setLongValue(LongValue.newBuilder().setValue(((Number) value).longValue()).setData(data));
+          break;
         case STRING:
         case DATA:
         case LEVEL:
         case DISTRIB:
-          return MeasureValueType.STRING;
-        case WORK_DUR:
-        case MILLISEC:
-          return MeasureValueType.LONG;
+          builder.setStringValue(StringValue.newBuilder().setValue((String) value));
+          break;
         default:
-          throw new IllegalStateException("Unknown value type: " + type);
+          throw new IllegalStateException("Unknown metric type: " + measure.getMetric().getType());
       }
     }
 
index b5e026476d3bd0c504d08a839181cdcb37ac7668..020ac34ab4e83d914f9299f2e80e707533e0766f 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.batch.report;
 
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
-import org.sonar.scanner.protocol.Constants.HighlightingType;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 
 public class ScannerReportUtils {
 
index 7561eb1ed1d215d2205231895920c5fa8dbda135..b047337928a24fb93ab04f6c1472492962a0296f 100644 (file)
@@ -34,11 +34,11 @@ import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.test.DefaultTestable;
 import org.sonar.batch.test.TestPlanBuilder;
-import org.sonar.scanner.protocol.Constants.TestStatus;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.protocol.output.ScannerReport.CoverageDetail;
 import org.sonar.scanner.protocol.output.ScannerReport.Test;
+import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 public class TestExecutionAndCoveragePublisher implements ReportPublisherStep {
 
@@ -59,7 +59,7 @@ public class TestExecutionAndCoveragePublisher implements ReportPublisherStep {
       }
       Long durationInMs = testCase.durationInMs();
       if (durationInMs != null) {
-        builder.setDurationInMs(durationInMs);
+        builder.setDurationInMs(durationInMs.longValue());
       }
       String msg = testCase.message();
       if (msg != null) {
index c8de752737bfe83f8ff44a64f452f934ea38eada..ce3ae500bd18189d05499d0ece4a1bde4db4b0d7 100644 (file)
@@ -58,8 +58,8 @@ import org.sonar.batch.cpd.index.SonarCpdBlockIndex;
 import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.issue.ModuleIssues;
-import org.sonar.batch.report.ScannerReportUtils;
 import org.sonar.batch.report.ReportPublisher;
+import org.sonar.batch.report.ScannerReportUtils;
 import org.sonar.batch.scan.measure.MeasureCache;
 import org.sonar.batch.sensor.coverage.CoverageExclusions;
 import org.sonar.batch.source.DefaultSymbol;
@@ -249,12 +249,12 @@ public class DefaultSensorStorage implements SensorStorage {
     }
   }
 
-  private static class BuildSyntaxHighlighting implements Function<SyntaxHighlightingRule, ScannerReport.SyntaxHighlighting> {
-    private ScannerReport.SyntaxHighlighting.Builder builder = ScannerReport.SyntaxHighlighting.newBuilder();
+  private static class BuildSyntaxHighlighting implements Function<SyntaxHighlightingRule, ScannerReport.SyntaxHighlightingRule> {
+    private ScannerReport.SyntaxHighlightingRule.Builder builder = ScannerReport.SyntaxHighlightingRule.newBuilder();
     private ScannerReport.TextRange.Builder rangeBuilder = ScannerReport.TextRange.newBuilder();
 
     @Override
-    public ScannerReport.SyntaxHighlighting apply(@Nonnull SyntaxHighlightingRule input) {
+    public ScannerReport.SyntaxHighlightingRule apply(@Nonnull SyntaxHighlightingRule input) {
       builder.setRange(rangeBuilder.setStartLine(input.range().start().line())
         .setStartOffset(input.range().start().lineOffset())
         .setEndLine(input.range().end().line())
index 6a6c209348f4cdb8baa34298584267f8b8837006..aa25e27b1371e95f99c4366fb935de6433935348 100644 (file)
  */
 package org.sonar.batch.cpd;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -36,16 +42,10 @@ import org.sonar.batch.report.ReportPublisher;
 import org.sonar.core.util.CloseableIterator;
 import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.ClonePart;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
 import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -195,44 +195,44 @@ public class CpdExecutorTest {
     assertDuplication(dups[0], 5, 204, batchComponent2.batchId(), 15, 214);
     assertDuplication(dups[1], 15, 214, batchComponent3.batchId(), 15, 214);
   }
-  
+
   private Duplication[] readDuplications(int expected) {
     assertThat(reader.readComponentDuplications(batchComponent1.batchId())).hasSize(expected);
     Duplication[] duplications = new Duplication[expected];
     CloseableIterator<Duplication> dups = reader.readComponentDuplications(batchComponent1.batchId());
-    
-    for(int i = 0; i< expected; i++) {
+
+    for (int i = 0; i < expected; i++) {
       duplications[i] = dups.next();
     }
     dups.close();
     return duplications;
   }
-  
+
   private void assertDuplicate(Duplicate d, int otherFileRef, int rangeStartLine, int rangeEndLine) {
     assertThat(d.getOtherFileRef()).isEqualTo(otherFileRef);
     assertThat(d.getRange().getStartLine()).isEqualTo(rangeStartLine);
     assertThat(d.getRange().getEndLine()).isEqualTo(rangeEndLine);
   }
-  
+
   private void assertDuplication(Duplication d, int originStartLine, int originEndLine, int numDuplicates) {
     assertThat(d.getOriginPosition().getStartLine()).isEqualTo(originStartLine);
     assertThat(d.getOriginPosition().getEndLine()).isEqualTo(originEndLine);
     assertThat(d.getDuplicateList()).hasSize(numDuplicates);
   }
-  
+
   private void assertDuplication(Duplication d, int originStartLine, int originEndLine, Integer otherFileRef, int rangeStartLine, int rangeEndLine) {
     assertThat(d.getOriginPosition().getStartLine()).isEqualTo(originStartLine);
     assertThat(d.getOriginPosition().getEndLine()).isEqualTo(originEndLine);
     assertThat(d.getDuplicateList()).hasSize(1);
-    if(otherFileRef != null) {
-    assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(otherFileRef);
+    if (otherFileRef != null) {
+      assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(otherFileRef);
     } else {
-      assertThat(d.getDuplicate(0).hasOtherFileRef()).isFalse();
+      assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(0);
     }
     assertThat(d.getDuplicate(0).getRange().getStartLine()).isEqualTo(rangeStartLine);
     assertThat(d.getDuplicate(0).getRange().getEndLine()).isEqualTo(rangeEndLine);
   }
-  
+
   private CloneGroup newCloneGroup(ClonePart... parts) {
     return CloneGroup.builder().setLength(0).setOrigin(parts[0]).setParts(Arrays.asList(parts)).build();
   }
index daded262498975908229e11bc82afb3c26cff0bc..d6b759a4edbdf2787a2dac6866e2914bf1b2a131 100644 (file)
  */
 package org.sonar.batch.issue;
 
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
 import java.util.Date;
-
-import static org.mockito.Mockito.mock;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.resources.Project;
 import org.sonar.scanner.protocol.Constants.Severity;
 import org.sonar.scanner.protocol.output.ScannerReport.Issue;
+import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class DefaultFilterableIssueTest {
   private DefaultFilterableIssue issue;
@@ -48,7 +47,7 @@ public class DefaultFilterableIssueTest {
     Issue.Builder builder = Issue.newBuilder();
 
     builder.setGap(3.0);
-    builder.setLine(30);
+    builder.setTextRange(TextRange.newBuilder().setStartLine(30));
     builder.setSeverity(Severity.MAJOR);
     return builder.build();
   }
index b4818adae0eeca895831547cfb711976c8b68a81..dca0dea2cfea3940ac07d84e4e60635aa3dd7970 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.issue.Issue;
 import org.sonar.api.resources.Project;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.scanner.protocol.Constants.Severity;
+import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
@@ -51,7 +52,7 @@ public class DeprecatedIssueAdapterForFilterTest {
         .setRuleKey("key")
         .setSeverity(Severity.BLOCKER)
         .setMsg("msg")
-        .setLine(1)
+        .setTextRange(TextRange.newBuilder().setStartLine(1))
         .setGap(2.0)
         .build(),
       COMPONENT_KEY);
index e3dac6ed8695083b2ca848fc2204a7ba587a8ea3..68cae60f218c6f069504a7a67a2dba4e1cf6101c 100644 (file)
@@ -91,7 +91,7 @@ public class CoverageMediumTest {
     assertThat(result.coverageFor(file, 2).getOverallCoveredConditions()).isEqualTo(0);
 
     Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue")
+    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
       .contains(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2),
         tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0),
         tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2),
@@ -170,7 +170,7 @@ public class CoverageMediumTest {
     assertThat(result.coverageFor(file, 4)).isNull();
 
     Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue")
+    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
       .contains(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2),
         tuple(CoreMetrics.UNCOVERED_LINES_KEY, 2));
 
index 6613421a4da772ab8ecf7c8ee6fe4e2fd60e08c7..7a349224239933611872fea9bb9ca5a9c8d4ac0c 100644 (file)
@@ -27,7 +27,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
-import org.assertj.core.groups.Tuple;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -48,6 +47,7 @@ import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.lang.CpdTokenizerSensor;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.groups.Tuple.tuple;
 
 @RunWith(Parameterized.class)
 public class CpdMediumTest {
@@ -324,12 +324,10 @@ public class CpdMediumTest {
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
-    assertThat(allMeasures.get("com.foo.project")).extracting("metricKey", "intValue", "doubleValue", "stringValue").containsOnly(
-      Tuple.tuple(CoreMetrics.QUALITY_PROFILES_KEY, 0, 0.0,
-        "[{\"key\":\"Sonar Way\",\"language\":\"xoo\",\"name\":\"Sonar Way\",\"rulesUpdatedAt\":\"2009-02-13T23:31:31+0000\"}]"));
+    assertThat(allMeasures.get("com.foo.project")).extracting("metricKey").containsOnly(CoreMetrics.QUALITY_PROFILES_KEY);
 
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue").containsOnly(
-      Tuple.tuple(CoreMetrics.LINES_KEY, blockCount * 2 + 1));
+    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").containsOnly(
+      tuple(CoreMetrics.LINES_KEY, blockCount * 2 + 1));
 
     List<org.sonar.scanner.protocol.output.ScannerReport.Duplication> duplicationGroups = result.duplicationsFor(result.inputFile("src/sample.xoo"));
     assertThat(duplicationGroups).hasSize(1);
index fa1ff38833def19a0907315aea65006da2483a8d..886647742bfd9e2205ed8b6ca626eef8ca3d6426 100644 (file)
@@ -82,15 +82,15 @@ public class DeprecatedApiMediumTest {
         .build())
       .start();
 
-    assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputFile("src/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
       tuple("Issue created using deprecated API", 1));
-    assertThat(result.issuesFor(result.inputFile("src/package/sample.xoo"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputFile("src/package/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
       tuple("Issue created using deprecated API", 1));
-    assertThat(result.issuesFor(result.inputDir("src"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputDir("src"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0));
-    assertThat(result.issuesFor(result.inputDir("src/package"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputDir("src/package"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0));
 
   }
@@ -118,15 +118,15 @@ public class DeprecatedApiMediumTest {
         .build())
       .start();
 
-    assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
       tuple("Issue created using deprecated API", 1));
-    assertThat(result.issuesFor(result.inputFile("package/sample.xoo"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputFile("package/sample.xoo"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0),
       tuple("Issue created using deprecated API", 1));
-    assertThat(result.issuesFor(result.inputDir(""))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputDir(""))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0));
-    assertThat(result.issuesFor(result.inputDir("package"))).extracting("msg", "line").containsOnly(
+    assertThat(result.issuesFor(result.inputDir("package"))).extracting("msg", "textRange.startLine").containsOnly(
       tuple("Issue created using deprecated API", 0));
 
   }
index 21526ddcfd57eab7198dd9974e64911d79d82f47..dc1ed8f9dce3e517c008a5f8c7675a5170abf7b3 100644 (file)
@@ -39,6 +39,7 @@ import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 
 public class ProjectBuilderMediumTest {
 
@@ -85,15 +86,9 @@ public class ProjectBuilderMediumTest {
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
 
-    boolean foundIssueAtLine1 = false;
-    for (Issue issue : issues) {
-      if (issue.getLine() == 1) {
-        foundIssueAtLine1 = true;
-        assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
-        assertThat(issue.hasGap()).isFalse();
-      }
-    }
-    assertThat(foundIssueAtLine1).isTrue();
+    assertThat(issues)
+      .extracting("msg", "textRange.startLine", "gap")
+      .contains(tuple("This issue is generated on each line", 1, 0.0));
 
   }
 
@@ -140,15 +135,9 @@ public class ProjectBuilderMediumTest {
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
 
-    boolean foundIssueAtLine1 = false;
-    for (Issue issue : issues) {
-      if (issue.getLine() == 1) {
-        foundIssueAtLine1 = true;
-        assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
-        assertThat(issue.hasGap()).isFalse();
-      }
-    }
-    assertThat(foundIssueAtLine1).isTrue();
+    assertThat(issues)
+      .extracting("msg", "textRange.startLine", "gap")
+      .contains(tuple("This issue is generated on each line", 1, 0.0));
   }
 
   private File prepareProject() throws IOException {
index 804a66a7d4d630303b2ae08c1578d21bf7e48fd9..9a30bec50164c63d7c531d3223207dfd97e9e4fe 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 
 public class ChecksMediumTest {
 
@@ -89,22 +90,12 @@ public class ChecksMediumTest {
       .start();
 
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
-    assertThat(issues).hasSize(2);
-
-    boolean foundIssueAtLine1 = false;
-    boolean foundIssueAtLine2 = false;
-    for (Issue issue : issues) {
-      if (issue.getLine() == 1) {
-        foundIssueAtLine1 = true;
-        assertThat(issue.getMsg()).isEqualTo("A template rule");
-      }
-      if (issue.getLine() == 2) {
-        foundIssueAtLine2 = true;
-        assertThat(issue.getMsg()).isEqualTo("Another template rule");
-      }
-    }
-    assertThat(foundIssueAtLine1).isTrue();
-    assertThat(foundIssueAtLine2).isTrue();
+    assertThat(issues)
+      .extracting("msg", "textRange.startLine")
+      .containsOnly(
+        tuple("A template rule", 1),
+        tuple("Another template rule", 2));
+
   }
 
   private LoadedActiveRule createActiveRuleWithParam(String repositoryKey, String ruleKey, @Nullable String templateRuleKey, String name, @Nullable String severity,
index 50823ff4f48dc2bf0f32a8b5e81be3668b116224..69f3099977ee41c4040476c9040afa3715493c6d 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 
 public class IssuesMediumTest {
 
@@ -90,8 +91,7 @@ public class IssuesMediumTest {
     assertThat(issues).hasSize(8 /* lines */);
 
     Issue issue = issues.get(0);
-    assertThat(issue.getTextRange().getStartLine()).isEqualTo(issue.getLine());
-    assertThat(issue.getTextRange().getEndLine()).isEqualTo(issue.getLine());
+    assertThat(issue.getTextRange().getStartLine()).isEqualTo(issue.getTextRange().getStartLine());
   }
 
   @Test
@@ -164,16 +164,9 @@ public class IssuesMediumTest {
 
     List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
     assertThat(issues).hasSize(10);
-
-    boolean foundIssueAtLine1 = false;
-    for (Issue issue : issues) {
-      if (issue.getLine() == 1) {
-        foundIssueAtLine1 = true;
-        assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
-        assertThat(issue.hasGap()).isFalse();
-      }
-    }
-    assertThat(foundIssueAtLine1).isTrue();
+    assertThat(issues)
+      .extracting("msg", "textRange.startLine", "gap")
+      .contains(tuple("This issue is generated on each line", 1, 0.0));
   }
 
   private class IssueRecorder implements IssueListener {
index 7ec0fe90535ad2c67a75d10c7d8e4ae88d6b9130..476266c0868db6e7d2c1c6107b4479e684880cb5 100644 (file)
@@ -73,7 +73,6 @@ public class MultilineIssuesMediumTest {
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Single.xoo"));
     assertThat(issues).hasSize(1);
     Issue issue = issues.get(0);
-    assertThat(issue.getLine()).isEqualTo(6);
     assertThat(issue.getMsg()).isEqualTo("Primary location");
     assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
     assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
@@ -86,7 +85,6 @@ public class MultilineIssuesMediumTest {
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiline.xoo"));
     assertThat(issues).hasSize(1);
     Issue issue = issues.get(0);
-    assertThat(issue.getLine()).isEqualTo(6);
     assertThat(issue.getMsg()).isEqualTo("Primary location");
     assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
     assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
@@ -99,7 +97,6 @@ public class MultilineIssuesMediumTest {
     List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiple.xoo"));
     assertThat(issues).hasSize(1);
     Issue issue = issues.get(0);
-    assertThat(issue.getLine()).isEqualTo(6);
     assertThat(issue.getMsg()).isEqualTo("Primary location");
     assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
     assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
index e9db30c49f43adb7027f1c6ceafac24ff34158ca..b72458e3141037130e099fffa19f89f71070abd8 100644 (file)
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.FileUtils;
-import org.assertj.core.groups.Tuple;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -91,12 +90,11 @@ public class MeasuresMediumTest {
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
-    assertThat(allMeasures.get("com.foo.project")).extracting("metricKey", "intValue", "doubleValue", "stringValue").containsOnly(
-      Tuple.tuple(CoreMetrics.QUALITY_PROFILES_KEY, 0, 0.0,
-        "[{\"key\":\"Sonar Way\",\"language\":\"xoo\",\"name\":\"Sonar Way\",\"rulesUpdatedAt\":\"2009-02-13T23:31:31+0000\"}]"));
+    assertThat(allMeasures.get("com.foo.project")).extracting("metricKey", "stringValue.value").containsOnly(
+      tuple(CoreMetrics.QUALITY_PROFILES_KEY, "[{\"key\":\"Sonar Way\",\"language\":\"xoo\",\"name\":\"Sonar Way\",\"rulesUpdatedAt\":\"2009-02-13T23:31:31+0000\"}]"));
 
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue").containsOnly(
-      Tuple.tuple(CoreMetrics.LINES_KEY, 2));
+    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").containsOnly(
+      tuple(CoreMetrics.LINES_KEY, 2));
   }
 
   @Test
@@ -122,9 +120,9 @@ public class MeasuresMediumTest {
 
     Map<String, List<Measure>> allMeasures = result.allMeasures();
 
-    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue")
+    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value")
       .contains(tuple("lines", 3));
-    assertThat(allMeasures.get("com.foo.project:src/sample.other")).extracting("metricKey", "intValue")
+    assertThat(allMeasures.get("com.foo.project:src/sample.other")).extracting("metricKey", "intValue.value")
       .contains(tuple("lines", 3), tuple("ncloc", 2));
   }
 
index 37c8da1ef0133b0782bbb9ef4c2c6b6c63ae90f8..8481c17d3ff8619b6d5a3213c05303a69a90e2e1 100644 (file)
@@ -36,9 +36,9 @@ import org.sonar.batch.mediumtest.BatchMediumTester;
 import org.sonar.batch.mediumtest.BatchMediumTester.TaskBuilder;
 import org.sonar.batch.repository.FileData;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
-import org.sonar.scanner.protocol.output.ScannerReport.Component;
 import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset;
+import org.sonar.scanner.protocol.output.ScannerReport.Component;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.xoo.XooPlugin;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -101,7 +101,7 @@ public class ScmMediumTest {
     assertThat(fileScm.getChangesetIndexByLineList()).hasSize(5);
 
     Changeset changesetLine1 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(0));
-    assertThat(changesetLine1.hasAuthor()).isFalse();
+    assertThat(changesetLine1.getAuthor()).isEmpty();
 
     Changeset changesetLine2 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(1));
     assertThat(changesetLine2.getAuthor()).isEqualTo("julien");
index cae559f16c58dc255186032bad643520bab6f608..328ba392561000fdfa2ae8bae4324cc43fdf8fe4 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.batch.mediumtest.tests;
 
 import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.IOException;
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -28,12 +30,9 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.batch.mediumtest.BatchMediumTester;
 import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.scanner.protocol.Constants.TestStatus;
+import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 import org.sonar.xoo.XooPlugin;
 
-import java.io.File;
-import java.io.IOException;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class TestExecutionMediumTest {
index 4b912b22d7bc2d9a785034a0827a73adff878c05..eb747ac0a2cb16e0c93f0395f73f275e9de08029 100644 (file)
@@ -25,7 +25,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.Severity;
 import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
 import org.sonar.api.batch.rule.internal.DefaultActiveRules;
 import org.sonar.api.batch.rule.internal.NewActiveRule;
@@ -60,9 +59,9 @@ public class ActiveRulesPublisherTest {
       assertThat(reportAr.getRuleRepository()).isEqualTo("java");
       assertThat(reportAr.getRuleKey()).isEqualTo("S001");
       assertThat(reportAr.getSeverity()).isEqualTo(Constants.Severity.BLOCKER);
-      assertThat(reportAr.getParamCount()).isEqualTo(1);
-      assertThat(reportAr.getParam(0).getKey()).isEqualTo("p1");
-      assertThat(reportAr.getParam(0).getValue()).isEqualTo("v1");
+      assertThat(reportAr.getParamsByKey()).hasSize(1);
+      assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getKey()).isEqualTo("p1");
+      assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getValue()).isEqualTo("v1");
 
       assertThat(readIt.hasNext()).isFalse();
     }
index 0a4ed8d69cd26dbf61a346c8ce7836a17fa0902a..65c54c6f5c6c6683d2ff8ea2b94fd48353aab95e 100644 (file)
@@ -34,11 +34,11 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.scan.ImmutableProjectReactor;
-import org.sonar.scanner.protocol.Constants.ComponentLinkType;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.protocol.output.FileStructure;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
+import org.sonar.scanner.protocol.output.ScannerReport.ComponentLink.ComponentLinkType;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 72c31cf49285fbf442f250055463c4590336f542..1175661f8b9b98a9733d720b4e0967f39ac88ed0 100644 (file)
@@ -33,9 +33,9 @@ import org.sonar.api.resources.Project;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.scan.measure.MeasureCache;
 import org.sonar.core.util.CloseableIterator;
+import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage;
 import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.protocol.output.ScannerReport.Coverage;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
@@ -90,13 +90,13 @@ public class CoveragePublisherTest {
 
     publisher.publish(writer);
 
-    try (CloseableIterator<Coverage> it = new ScannerReportReader(outputDir).readComponentCoverage(2)) {
-      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
+    try (CloseableIterator<LineCoverage> it = new ScannerReportReader(outputDir).readComponentCoverage(2)) {
+      assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
         .setLine(2)
         .setUtHits(true)
         .setItHits(false)
         .build());
-      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
+      assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
         .setLine(3)
         .setUtHits(true)
         .setItHits(false)
@@ -105,7 +105,7 @@ public class CoveragePublisherTest {
         .setItCoveredConditions(1)
         .setOverallCoveredConditions(2)
         .build());
-      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
+      assertThat(it.next()).isEqualTo(LineCoverage.newBuilder()
         .setLine(5)
         .setUtHits(false)
         .setItHits(true)
index d47b94225efbb828568dee4b2d8daee90df11b9d..5cb0d7b8bf24c1c98af0f511f515fe508413384e 100644 (file)
@@ -39,7 +39,7 @@ public class ScannerReportReader {
     if (!fileExists(file)) {
       throw new IllegalStateException("Metadata file is missing in analysis report: " + file);
     }
-    return Protobuf.read(file, ScannerReport.Metadata.PARSER);
+    return Protobuf.read(file, ScannerReport.Metadata.parser());
   }
 
   public CloseableIterator<ScannerReport.ActiveRule> readActiveRules() {
@@ -47,13 +47,13 @@ public class ScannerReportReader {
     if (!fileExists(file)) {
       return emptyCloseableIterator();
     }
-    return Protobuf.readStream(file, ScannerReport.ActiveRule.PARSER);
+    return Protobuf.readStream(file, ScannerReport.ActiveRule.parser());
   }
 
   public CloseableIterator<ScannerReport.Measure> readComponentMeasures(int componentRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.Measure.PARSER);
+      return Protobuf.readStream(file, ScannerReport.Measure.parser());
     }
     return emptyCloseableIterator();
   }
@@ -62,7 +62,7 @@ public class ScannerReportReader {
   public ScannerReport.Changesets readChangesets(int componentRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, componentRef);
     if (fileExists(file)) {
-      return Protobuf.read(file, ScannerReport.Changesets.PARSER);
+      return Protobuf.read(file, ScannerReport.Changesets.parser());
     }
     return null;
   }
@@ -72,13 +72,13 @@ public class ScannerReportReader {
     if (!fileExists(file)) {
       throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file);
     }
-    return Protobuf.read(file, ScannerReport.Component.PARSER);
+    return Protobuf.read(file, ScannerReport.Component.parser());
   }
 
   public CloseableIterator<ScannerReport.Issue> readComponentIssues(int componentRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.Issue.PARSER);
+      return Protobuf.readStream(file, ScannerReport.Issue.parser());
     }
     return emptyCloseableIterator();
   }
@@ -86,7 +86,7 @@ public class ScannerReportReader {
   public CloseableIterator<ScannerReport.Duplication> readComponentDuplications(int componentRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.Duplication.PARSER);
+      return Protobuf.readStream(file, ScannerReport.Duplication.parser());
     }
     return emptyCloseableIterator();
   }
@@ -102,7 +102,7 @@ public class ScannerReportReader {
   public CloseableIterator<ScannerReport.Symbol> readComponentSymbols(int componentRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.Symbol.PARSER);
+      return Protobuf.readStream(file, ScannerReport.Symbol.parser());
     }
     return emptyCloseableIterator();
   }
@@ -112,10 +112,10 @@ public class ScannerReportReader {
     return file.exists();
   }
 
-  public CloseableIterator<ScannerReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) {
+  public CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, fileRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.SyntaxHighlighting.PARSER);
+      return Protobuf.readStream(file, ScannerReport.SyntaxHighlightingRule.parser());
     }
     return emptyCloseableIterator();
   }
@@ -125,10 +125,10 @@ public class ScannerReportReader {
     return file.exists();
   }
 
-  public CloseableIterator<ScannerReport.Coverage> readComponentCoverage(int fileRef) {
+  public CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, fileRef);
     if (fileExists(file)) {
-      return Protobuf.readStream(file, ScannerReport.Coverage.PARSER);
+      return Protobuf.readStream(file, ScannerReport.LineCoverage.parser());
     }
     return emptyCloseableIterator();
   }
index 5cbba578c2a87c7c79048be76371fc6616f0b050..b2da5ba4b569e0817161fbfbfb38bc1a0d44be3a 100644 (file)
@@ -110,13 +110,13 @@ public class ScannerReportWriter {
     return file;
   }
 
-  public File writeComponentSyntaxHighlighting(int componentRef, Iterable<ScannerReport.SyntaxHighlighting> syntaxHighlightingRules) {
+  public File writeComponentSyntaxHighlighting(int componentRef, Iterable<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingRules) {
     File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef);
     Protobuf.writeStream(syntaxHighlightingRules, file, false);
     return file;
   }
 
-  public File writeComponentCoverage(int componentRef, Iterable<ScannerReport.Coverage> coverageList) {
+  public File writeComponentCoverage(int componentRef, Iterable<ScannerReport.LineCoverage> coverageList) {
     File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, componentRef);
     Protobuf.writeStream(coverageList, file, false);
     return file;
index 3768c1ca0d2c214cda5564a482ba942ebaa58bf7..70ea5f477c9b22198bcec78c651610bdc8d4bc6f 100644 (file)
@@ -47,12 +47,13 @@ import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreeSelectionModel;
+import org.apache.commons.lang.StringUtils;
 import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
 import org.sonar.scanner.protocol.output.FileStructure.Domain;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component;
 import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
+import org.sonar.scanner.protocol.output.ScannerReportReader;
 
 public class ScannerReportViewerApp {
 
@@ -179,7 +180,8 @@ public class ScannerReportViewerApp {
   }
 
   private void updateTitle() {
-    frame.setTitle(metadata.getProjectKey() + (metadata.hasBranch() ? (" (" + metadata.getBranch() + ")") : "") + " " + sdf.format(new Date(metadata.getAnalysisDate())));
+    frame.setTitle(metadata.getProjectKey() + (StringUtils.isNotEmpty(metadata.getBranch()) ? (" (" + metadata.getBranch() + ")") : "") + " "
+      + sdf.format(new Date(metadata.getAnalysisDate())));
   }
 
   private void updateDetails(Component component) {
@@ -207,9 +209,9 @@ public class ScannerReportViewerApp {
 
   private void updateCoverage(Component component) {
     coverageEditor.setText("");
-    try (CloseableIterator<ScannerReport.Coverage> it = reader.readComponentCoverage(component.getRef())) {
+    try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) {
       while (it.hasNext()) {
-        ScannerReport.Coverage coverage = it.next();
+        ScannerReport.LineCoverage coverage = it.next();
         coverageEditor.getDocument().insertString(coverageEditor.getDocument().getEndPosition().getOffset(), coverage.toString() + "\n", null);
       }
     } catch (Exception e) {
@@ -236,9 +238,9 @@ public class ScannerReportViewerApp {
 
   private void updateHighlighting(Component component) {
     highlightingEditor.setText("");
-    try (CloseableIterator<ScannerReport.SyntaxHighlighting> it = reader.readComponentSyntaxHighlighting(component.getRef())) {
+    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) {
       while (it.hasNext()) {
-        ScannerReport.SyntaxHighlighting rule = it.next();
+        ScannerReport.SyntaxHighlightingRule rule = it.next();
         highlightingEditor.getDocument().insertString(highlightingEditor.getDocument().getEndPosition().getOffset(), rule.toString() + "\n", null);
       }
     } catch (Exception e) {
index 862b4afa54c780824b2dc1705a53cd5c64787ed7..8be6a361a2d188180aa7848b7a58fb99b0602d47 100644 (file)
 // along with this program; if not, write to the Free Software Foundation,
 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-syntax = "proto2";
+syntax = "proto3";
 
 option java_package = "org.sonar.scanner.protocol";
 
 option optimize_for = SPEED;
 
 enum Severity {
-  INFO = 0;
-  MINOR = 1;
-  MAJOR = 2;
-  CRITICAL = 3;
-  BLOCKER = 4;
+  UNSET_SEVERITY = 0;
+  INFO = 1;
+  MINOR = 2;
+  MAJOR = 3;
+  CRITICAL = 4;
+  BLOCKER = 5;
 }
 
-enum ComponentType {
-  PROJECT = 0;
-  MODULE = 1;
-  DIRECTORY = 2;
-  FILE = 3;
-}
-
-enum MeasureValueType {
-  INT = 0;
-  LONG = 1;
-  DOUBLE = 2;
-  BOOLEAN = 3;
-  STRING = 4;
-}
-
-// temporary enum during development of computation stack
-enum EventCategory {
-  ALERT = 0;
-  PROFILE = 1;
-}
-
-enum ComponentLinkType {
-  HOME = 0;
-  SCM = 1;
-  SCM_DEV = 2;
-  ISSUE = 3;
-  CI = 4;
-}
-
-enum HighlightingType {
-  ANNOTATION = 0;
-  CONSTANT = 1;
-  COMMENT = 2;
-  CPP_DOC = 3;
-  STRUCTURED_COMMENT = 4;
-  KEYWORD = 5;
-  HIGHLIGHTING_STRING = 6;
-  KEYWORD_LIGHT = 7;
-  PREPROCESS_DIRECTIVE = 8;
-}
-
-enum TestStatus {
-  OK = 1;
-  FAILURE = 2;
-  ERROR = 3;
-  SKIPPED = 4;
-}
index 3df7f4343a6a027092605e82bb0cbc4d9b37665d..c7b4964f540d81c1e82e4f87df67c04a504c4d36 100644 (file)
@@ -26,7 +26,7 @@ Notes
     not forward-compatible yet.
 */
 
-syntax = "proto2";
+syntax = "proto3";
 
 import "constants.proto";
 
@@ -35,82 +35,116 @@ option java_package = "org.sonar.scanner.protocol.output";
 option optimize_for = SPEED;
 
 message Metadata {
-  optional int64 analysis_date = 1;
+  int64 analysis_date = 1;
   // TODO should we keep this project_key here or not ? Because it's a duplication of Component.key
-  optional string project_key = 2;
-  optional string branch = 3;
-  optional int32 root_component_ref = 4;
-  optional bool cross_project_duplication_activated = 5;
+  string project_key = 2;
+  string branch = 3;
+  int32 root_component_ref = 4;
+  bool cross_project_duplication_activated = 5;
 }
 
 message ActiveRule {
-  optional string rule_repository = 1;
-  optional string rule_key = 2;
-  optional Severity severity = 3;
-  repeated ActiveRuleParam param = 4;
-
-  // TODO replace by map
-  message ActiveRuleParam {
-    optional string key = 1;
-    optional string value = 2;
-  }
+  string rule_repository = 1;
+  string rule_key = 2;
+  Severity severity = 3;
+  map<string,string> params_by_key = 4;
 }
 
 message ComponentLink {
-  optional ComponentLinkType type = 1;
-  optional string href = 2;
+  ComponentLinkType type = 1;
+  string href = 2;
+  
+  enum ComponentLinkType {
+    UNSET = 0;
+         HOME = 1;
+         SCM = 2;
+         SCM_DEV = 3;
+         ISSUE = 4;
+         CI = 5;
+       }
 }
 
 message Component {
-  optional int32 ref = 1;
-  optional string path = 2;
-  optional string name = 3;
-  optional ComponentType type = 4;
-  optional bool is_test = 5;
-  optional string language = 6;
+  int32 ref = 1;
+  string path = 2;
+  string name = 3;
+  ComponentType type = 4;
+  bool is_test = 5;
+  string language = 6;
   repeated int32 child_ref = 7 [packed = true];
   repeated ComponentLink link = 8;
   // Only available on PROJECT and MODULE types
-  optional string version = 9;
+  string version = 9;
   // Only available on PROJECT and MODULE types
   // TODO rename this property -> batchKey ? moduleKey ?
-  optional string key = 10;
+  string key = 10;
   // Only available on FILE type
-  optional int32 lines = 11;
+  int32 lines = 11;
   // Only available on PROJECT and MODULE types
-  optional string description = 12;
+  string description = 12;
+  
+       enum ComponentType {
+         UNSET = 0;
+         PROJECT = 1;
+         MODULE = 2;
+         DIRECTORY = 3;
+         FILE = 4;
+       }
 }
 
 message Measure {
-  optional MeasureValueType value_type = 1;
-  // all values may be unset for "new_xxx" measures (only variations are populated)
-  optional bool boolean_value = 2;
-  optional int32 int_value = 3;
-  optional int64 long_value = 4;
-  optional double double_value = 5;
-  optional string string_value = 6;
-  optional string metric_key = 7;
+  string metric_key = 1;
+  oneof value {
+         BoolValue boolean_value = 2;
+         IntValue int_value = 3;
+         LongValue long_value = 4;
+         DoubleValue double_value = 5;
+         StringValue string_value = 6;
+  }
+  
+  message BoolValue {
+    bool value = 1;
+    string data = 2;
+  }
+  
+  message IntValue {
+    int32 value = 1;
+    string data = 2;
+  }
+  
+  message LongValue {
+    int64 value = 1;
+    string data = 2;
+  }
+  
+  message DoubleValue {
+    double value = 1;
+    string data = 2;
+  }
+  
+  message StringValue {
+    string value = 1;
+  }
 }
 
 message Issue {
-  optional string rule_repository = 1;
-  optional string rule_key = 2;
+  string rule_repository = 1;
+  string rule_key = 2;
   // Only when issue component is a file. Can also be empty for a file if this is an issue global to the file.
-  //TODO To be removed. Use first line of text_range instead
-  optional int32 line = 3;
-  optional string msg = 4;
-  optional Severity severity = 5;
-  optional double gap = 6;
+  string msg = 3;
+  Severity severity = 4;
+  double gap = 5;
   // Only when issue component is a file. Can also be empty for a file if this is an issue global to the file.
-  optional TextRange text_range = 7;
-  repeated Flow flow = 8;
+  // Will be identical to the first location of the first flow
+  TextRange text_range = 6;
+  repeated Flow flow = 7;
 }
 
 message IssueLocation {
-  optional int32 component_ref = 1;
+  int32 component_ref = 1;
   // Only when component is a file. Can be empty for a file if this is an issue global to the file.
-  optional TextRange text_range = 2;
-  optional string msg = 3;
+  TextRange text_range = 2;
+  string msg = 3;
 }
 
 message Flow {
@@ -118,96 +152,113 @@ message Flow {
 }
 
 message Changesets {
-  optional int32 component_ref = 1;
+  int32 component_ref = 1;
   repeated Changeset changeset = 2;
   // if changesetIndexByLine[5] = 2 then it means that changeset[2] is the last one on line 6
   repeated int32 changesetIndexByLine = 3 [packed = true];
 
   message Changeset {
-    optional string revision = 1;
-    optional string author = 2;
-    optional int64 date = 3;
+    string revision = 1;
+    string author = 2;
+    int64 date = 3;
   }
 }
 
 message Duplicate {
-  // Will be null when duplicate is in the same file
-  optional int32 other_file_ref = 1;
-  optional TextRange range = 2;
+  // Will be 0 when duplicate is in the same file
+  int32 other_file_ref = 1;
+  // Only start_line and end_line are provided since we dont support "precise" duplication location.
+  TextRange range = 2;
 }
 
 message Duplication {
-  // Origin position in current file
-  optional TextRange origin_position = 1;
+  // Origin position in current file. Only start_line and end_line are provided since we dont support "precise" duplication location.
+  TextRange origin_position = 1;
   repeated Duplicate duplicate = 2;
 }
 
 // Used for cross project duplication
 message CpdTextBlock {
-  optional string hash = 1;
-  optional int32 start_line = 2;
-  optional int32 end_line = 3;
-  optional int32 start_token_index = 4;
-  optional int32 end_token_index = 5;
+  string hash = 1;
+  int32 start_line = 2;
+  int32 end_line = 3;
+  int32 start_token_index = 4;
+  int32 end_token_index = 5;
 }
 
 // Lines start at 1 and line offsets start at 0
 message TextRange {
-  // Should never be null
-  optional int32 start_line = 1;
+  int32 start_line = 1;
   // End line (inclusive)
-  optional int32 end_line = 2;
-  // If null it means range starts at the first offset of start line
-  optional int32 start_offset = 3;
-  // If null it means range ends at the last offset of end line
-  optional int32 end_offset = 4;
+  int32 end_line = 2;
+  int32 start_offset = 3;
+  int32 end_offset = 4;
 }
 
 message Symbol {
-  optional TextRange declaration = 1;
+  TextRange declaration = 1;
   repeated TextRange reference = 2;
 }
 
 // Only FILE component has coverage information, and only executable lines should contains this information.
-// TODO rename it LineCoverage ?
-message Coverage {
-  optional int32 line = 1;
+message LineCoverage {
+  int32 line = 1;
 
   // Number of conditions to cover (if set, the value must be greater than 0)
-  optional int32 conditions = 2;
+  int32 conditions = 2;
   // Is the line has been touched by a unit test ? Returning false means that no test has touched this executable line.
-  optional bool ut_hits = 3;
+  bool ut_hits = 3;
   // Is the line has been touched by a integration test ? Returning false means that no test has touched this executable line.
-  optional bool it_hits = 4;
+  bool it_hits = 4;
   // Number of conditions covered by unit tests
-  optional int32 ut_covered_conditions = 5;
+  int32 ut_covered_conditions = 5;
   // Number of conditions covered by integration tests
-  optional int32 it_covered_conditions = 6;
+  int32 it_covered_conditions = 6;
   // Number of conditions covered by overall tests
-  optional int32 overall_covered_conditions = 7;
+  int32 overall_covered_conditions = 7;
 }
 
 // Must be sorted by line and start offset
-// TODO rename it SyntaxHighlightingRule ?
-message SyntaxHighlighting {
-  optional TextRange range = 1;
-  optional HighlightingType type = 2;
+message SyntaxHighlightingRule {
+  TextRange range = 1;
+  HighlightingType type = 2;
+  
+  enum HighlightingType {
+    UNSET = 0;
+         ANNOTATION = 1;
+         CONSTANT = 2;
+         COMMENT = 3;
+         CPP_DOC = 4;
+         STRUCTURED_COMMENT = 5;
+         KEYWORD = 6;
+         HIGHLIGHTING_STRING = 7;
+         KEYWORD_LIGHT = 8;
+         PREPROCESS_DIRECTIVE = 9;
+       }
 }
 
 message Test {
-  optional string name = 1;
-  optional TestStatus status = 2;
-  optional int64 duration_in_ms = 3;
-  optional string stacktrace = 4;
-  optional string msg = 5;
+  string name = 1;
+  TestStatus status = 2;
+  int64 duration_in_ms = 3;
+  string stacktrace = 4;
+  string msg = 5;
+  
+       enum TestStatus {
+         UNSET = 0;
+         OK = 1;
+         FAILURE = 2;
+         ERROR = 3;
+         SKIPPED = 4;
+       }
 }
 
 message CoverageDetail {
-  optional string test_name = 1;
+  string test_name = 1;
   repeated CoveredFile covered_file = 2;
 
   message CoveredFile {
-    optional int32 file_ref = 1;
+    int32 file_ref = 1;
     repeated int32 covered_line = 2 [packed = true];
   }
 }
index ce2a6e86149b657a58f1e08be11707002105fd48..98b7c7ac71dc709d6b3632033fb231658847daeb 100644 (file)
@@ -30,10 +30,9 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.protocol.Constants;
-import org.sonar.scanner.protocol.output.ScannerReportReader;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.protocol.output.FileStructure;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
+import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
@@ -98,7 +97,6 @@ public class ScannerReportReaderTest {
   public void read_issues() {
     ScannerReportWriter writer = new ScannerReportWriter(dir);
     ScannerReport.Issue issue = ScannerReport.Issue.newBuilder()
-      .setLine(50)
       .build();
     writer.writeComponentIssues(1, asList(issue));
 
@@ -115,7 +113,7 @@ public class ScannerReportReaderTest {
   public void read_measures() {
     ScannerReportWriter writer = new ScannerReportWriter(dir);
     ScannerReport.Measure.Builder measure = ScannerReport.Measure.newBuilder()
-      .setStringValue("value_a");
+      .setStringValue(StringValue.newBuilder().setValue("value_a"));
     writer.writeComponentMeasures(1, asList(measure.build()));
 
     assertThat(underTest.readComponentMeasures(1)).hasSize(1);
@@ -211,20 +209,20 @@ public class ScannerReportReaderTest {
       .setRef(1).build());
 
     writer.writeComponentSyntaxHighlighting(1, asList(
-      ScannerReport.SyntaxHighlighting.newBuilder()
+      ScannerReport.SyntaxHighlightingRule.newBuilder()
         .setRange(ScannerReport.TextRange.newBuilder()
           .setStartLine(1)
           .setEndLine(10)
           .build())
-        .setType(Constants.HighlightingType.ANNOTATION)
+        .setType(HighlightingType.ANNOTATION)
         .build()));
 
-    try (CloseableIterator<ScannerReport.SyntaxHighlighting> it = underTest.readComponentSyntaxHighlighting(1)) {
-      ScannerReport.SyntaxHighlighting syntaxHighlighting = it.next();
+    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = underTest.readComponentSyntaxHighlighting(1)) {
+      ScannerReport.SyntaxHighlightingRule syntaxHighlighting = it.next();
       assertThat(syntaxHighlighting.getRange()).isNotNull();
       assertThat(syntaxHighlighting.getRange().getStartLine()).isEqualTo(1);
       assertThat(syntaxHighlighting.getRange().getEndLine()).isEqualTo(10);
-      assertThat(syntaxHighlighting.getType()).isEqualTo(Constants.HighlightingType.ANNOTATION);
+      assertThat(syntaxHighlighting.getType()).isEqualTo(HighlightingType.ANNOTATION);
     }
   }
 
@@ -276,7 +274,7 @@ public class ScannerReportReaderTest {
       .setRef(1).build());
 
     writer.writeComponentCoverage(1, asList(
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(1)
         .setConditions(1)
         .setUtHits(true)
@@ -285,7 +283,7 @@ public class ScannerReportReaderTest {
         .setItCoveredConditions(1)
         .setOverallCoveredConditions(1)
         .build(),
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(2)
         .setConditions(5)
         .setUtHits(false)
@@ -296,8 +294,8 @@ public class ScannerReportReaderTest {
         .build()));
 
     underTest = new ScannerReportReader(dir);
-    try (CloseableIterator<ScannerReport.Coverage> it = new ScannerReportReader(dir).readComponentCoverage(1)) {
-      ScannerReport.Coverage coverage = it.next();
+    try (CloseableIterator<ScannerReport.LineCoverage> it = new ScannerReportReader(dir).readComponentCoverage(1)) {
+      ScannerReport.LineCoverage coverage = it.next();
       assertThat(coverage.getLine()).isEqualTo(1);
       assertThat(coverage.getConditions()).isEqualTo(1);
       assertThat(coverage.getUtHits()).isTrue();
@@ -331,15 +329,15 @@ public class ScannerReportReaderTest {
         .setDurationInMs(60_000)
         .setStacktrace("stacktrace")
         .setMsg("message")
-        .setStatus(Constants.TestStatus.OK)
+        .setStatus(TestStatus.OK)
         .build()));
 
     try (InputStream inputStream = FileUtils.openInputStream(underTest.readTests(1))) {
-      ScannerReport.Test testResult = ScannerReport.Test.PARSER.parseDelimitedFrom(inputStream);
+      ScannerReport.Test testResult = ScannerReport.Test.parser().parseDelimitedFrom(inputStream);
       assertThat(testResult.getDurationInMs()).isEqualTo(60_000);
       assertThat(testResult.getStacktrace()).isEqualTo("stacktrace");
       assertThat(testResult.getMsg()).isEqualTo("message");
-      assertThat(testResult.getStatus()).isEqualTo(Constants.TestStatus.OK);
+      assertThat(testResult.getStatus()).isEqualTo(TestStatus.OK);
     }
   }
 
@@ -360,7 +358,7 @@ public class ScannerReportReaderTest {
         .build()));
 
     try (InputStream inputStream = FileUtils.openInputStream(underTest.readCoverageDetails(1))) {
-      ScannerReport.CoverageDetail coverageDetail = ScannerReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream);
+      ScannerReport.CoverageDetail coverageDetail = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream);
       assertThat(coverageDetail.getTestName()).isEqualTo("test-name");
       assertThat(coverageDetail.getCoveredFile(0).getFileRef()).isEqualTo(2);
       assertThat(coverageDetail.getCoveredFile(0).getCoveredLineList()).containsExactly(1, 2, 3, 5, 7);
index 9a08cd726ac6e7e9cdf2e2cc7816e776351c5685..c55abc01c9b557b60eac11e8ba1a7890b9bd1043 100644 (file)
@@ -28,9 +28,9 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.core.util.CloseableIterator;
 import org.sonar.core.util.Protobuf;
-import org.sonar.scanner.protocol.Constants;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
-import org.sonar.scanner.protocol.output.FileStructure;
+import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
+import org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue;
+import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -64,7 +64,7 @@ public class ScannerReportWriterTest {
       .setRootComponentRef(1);
     underTest.writeMetadata(metadata.build());
 
-    ScannerReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), ScannerReport.Metadata.PARSER);
+    ScannerReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), ScannerReport.Metadata.parser());
     assertThat(read.getAnalysisDate()).isEqualTo(15000000L);
     assertThat(read.getProjectKey()).isEqualTo("PROJECT_A");
     assertThat(read.getRootComponentRef()).isEqualTo(1);
@@ -80,7 +80,7 @@ public class ScannerReportWriterTest {
       .setRef(1)
       .setLanguage("java")
       .setPath("src/Foo.java")
-      .setType(Constants.ComponentType.FILE)
+      .setType(ComponentType.FILE)
       .setIsTest(false)
       .addChildRef(5)
       .addChildRef(42);
@@ -89,10 +89,10 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1);
     assertThat(file).exists().isFile();
-    ScannerReport.Component read = Protobuf.read(file, ScannerReport.Component.PARSER);
+    ScannerReport.Component read = Protobuf.read(file, ScannerReport.Component.parser());
     assertThat(read.getRef()).isEqualTo(1);
     assertThat(read.getChildRefList()).containsOnly(5, 42);
-    assertThat(read.hasName()).isFalse();
+    assertThat(read.getName()).isEmpty();
     assertThat(read.getIsTest()).isFalse();
   }
 
@@ -103,7 +103,6 @@ public class ScannerReportWriterTest {
 
     // write data
     ScannerReport.Issue issue = ScannerReport.Issue.newBuilder()
-      .setLine(50)
       .setMsg("the message")
       .build();
 
@@ -112,7 +111,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
     assertThat(file).exists().isFile();
-    try (CloseableIterator<ScannerReport.Issue> read = Protobuf.readStream(file, ScannerReport.Issue.PARSER)) {
+    try (CloseableIterator<ScannerReport.Issue> read = Protobuf.readStream(file, ScannerReport.Issue.parser())) {
       assertThat(Iterators.size(read)).isEqualTo(1);
     }
   }
@@ -122,9 +121,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse();
 
     ScannerReport.Measure measure = ScannerReport.Measure.newBuilder()
-      .setStringValue("text-value")
-      .setDoubleValue(2.5d)
-      .setValueType(Constants.MeasureValueType.DOUBLE)
+      .setDoubleValue(DoubleValue.newBuilder().setValue(2.5d).setData("text-value"))
       .build();
 
     underTest.writeComponentMeasures(1, asList(measure));
@@ -132,7 +129,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue();
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1);
     assertThat(file).exists().isFile();
-    try (CloseableIterator<ScannerReport.Measure> read = Protobuf.readStream(file, ScannerReport.Measure.PARSER)) {
+    try (CloseableIterator<ScannerReport.Measure> read = Protobuf.readStream(file, ScannerReport.Measure.parser())) {
       assertThat(Iterators.size(read)).isEqualTo(1);
     }
   }
@@ -155,7 +152,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isTrue();
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGESETS, 1);
     assertThat(file).exists().isFile();
-    ScannerReport.Changesets read = Protobuf.read(file, ScannerReport.Changesets.PARSER);
+    ScannerReport.Changesets read = Protobuf.read(file, ScannerReport.Changesets.parser());
     assertThat(read.getComponentRef()).isEqualTo(1);
     assertThat(read.getChangesetCount()).isEqualTo(1);
     assertThat(read.getChangesetList()).hasSize(1);
@@ -184,7 +181,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isTrue();
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATIONS, 1);
     assertThat(file).exists().isFile();
-    try (CloseableIterator<ScannerReport.Duplication> duplications = Protobuf.readStream(file, ScannerReport.Duplication.PARSER)) {
+    try (CloseableIterator<ScannerReport.Duplication> duplications = Protobuf.readStream(file, ScannerReport.Duplication.parser())) {
       ScannerReport.Duplication dup = duplications.next();
       assertThat(dup.getOriginPosition()).isNotNull();
       assertThat(dup.getDuplicateList()).hasSize(1);
@@ -244,7 +241,7 @@ public class ScannerReportWriterTest {
 
     File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1);
     assertThat(file).exists().isFile();
-    try (CloseableIterator<ScannerReport.Symbol> read = Protobuf.readStream(file, ScannerReport.Symbol.PARSER)) {
+    try (CloseableIterator<ScannerReport.Symbol> read = Protobuf.readStream(file, ScannerReport.Symbol.parser())) {
       assertThat(read).hasSize(1);
     }
   }
@@ -255,12 +252,12 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isFalse();
 
     underTest.writeComponentSyntaxHighlighting(1, asList(
-      ScannerReport.SyntaxHighlighting.newBuilder()
+      ScannerReport.SyntaxHighlightingRule.newBuilder()
         .setRange(ScannerReport.TextRange.newBuilder()
           .setStartLine(1)
           .setEndLine(1)
           .build())
-        .setType(Constants.HighlightingType.ANNOTATION)
+        .setType(HighlightingType.ANNOTATION)
         .build()));
 
     assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isTrue();
@@ -272,7 +269,7 @@ public class ScannerReportWriterTest {
     assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isFalse();
 
     underTest.writeComponentCoverage(1, asList(
-      ScannerReport.Coverage.newBuilder()
+      ScannerReport.LineCoverage.newBuilder()
         .setLine(1)
         .setConditions(1)
         .setUtHits(true)