]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6684 remove unused measure fields from report
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 22 Jul 2015 21:27:12 +0000 (23:27 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 23 Jul 2015 08:18:17 +0000 (10:18 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java
sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/BatchReportReader.java
sonar-batch-protocol/src/main/protobuf/batch_report.proto
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/BatchReportReaderTest.java
sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java

index 775d500d59523972c9096fe6d0e84ff917e295af..687967057330243439234dfbaca3196d974b1103 100644 (file)
@@ -26,7 +26,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
 import java.util.NoSuchElementException;
 import javax.annotation.CheckForNull;
 import org.apache.commons.io.FileUtils;
@@ -89,36 +88,13 @@ public class BatchReportReaderImpl implements BatchReportReader {
   }
 
   @Override
-  @CheckForNull
   public CloseableIterator<BatchReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) {
-    File file = delegate.readComponentSyntaxHighlighting(fileRef);
-    if (file == null) {
-      return CloseableIterator.emptyCloseableIterator();
-    }
-
-    try {
-      return new ParserCloseableIterator<>(BatchReport.SyntaxHighlighting.PARSER, FileUtils.openInputStream(file));
-    } catch (IOException e) {
-      Throwables.propagate(e);
-      // actually never reached
-      return CloseableIterator.emptyCloseableIterator();
-    }
+    return delegate.readComponentSyntaxHighlighting(fileRef);
   }
 
   @Override
   public CloseableIterator<BatchReport.Coverage> readComponentCoverage(int fileRef) {
-    File file = delegate.readComponentCoverage(fileRef);
-    if (file == null) {
-      return CloseableIterator.emptyCloseableIterator();
-    }
-
-    try {
-      return new ParserCloseableIterator<>(BatchReport.Coverage.PARSER, FileUtils.openInputStream(file));
-    } catch (IOException e) {
-      Throwables.propagate(e);
-      // actually never reached
-      return CloseableIterator.emptyCloseableIterator();
-    }
+    return delegate.readComponentCoverage(fileRef);
   }
 
   @Override
index f3ffae7e8fe4de88dd8831c985556980d563a160..d22e5eb0b6eee543c3ea2b5231f39fce8fb8c64f 100644 (file)
@@ -5508,86 +5508,6 @@ public final class BatchReport {
      */
     com.google.protobuf.ByteString
         getMetricKeyBytes();
-
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    boolean hasDescription();
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    java.lang.String getDescription();
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    com.google.protobuf.ByteString
-        getDescriptionBytes();
-
-    /**
-     * <code>optional double variation_value_1 = 14;</code>
-     */
-    boolean hasVariationValue1();
-    /**
-     * <code>optional double variation_value_1 = 14;</code>
-     */
-    double getVariationValue1();
-
-    /**
-     * <code>optional double variation_value_2 = 15;</code>
-     */
-    boolean hasVariationValue2();
-    /**
-     * <code>optional double variation_value_2 = 15;</code>
-     */
-    double getVariationValue2();
-
-    /**
-     * <code>optional double variation_value_3 = 16;</code>
-     */
-    boolean hasVariationValue3();
-    /**
-     * <code>optional double variation_value_3 = 16;</code>
-     */
-    double getVariationValue3();
-
-    /**
-     * <code>optional double variation_value_4 = 17;</code>
-     */
-    boolean hasVariationValue4();
-    /**
-     * <code>optional double variation_value_4 = 17;</code>
-     */
-    double getVariationValue4();
-
-    /**
-     * <code>optional double variation_value_5 = 18;</code>
-     */
-    boolean hasVariationValue5();
-    /**
-     * <code>optional double variation_value_5 = 18;</code>
-     */
-    double getVariationValue5();
-
-    /**
-     * <code>optional int32 person_id = 20;</code>
-     */
-    boolean hasPersonId();
-    /**
-     * <code>optional int32 person_id = 20;</code>
-     */
-    int getPersonId();
   }
   /**
    * Protobuf type {@code Measure}
@@ -5684,42 +5604,6 @@ public final class BatchReport {
               metricKey_ = bs;
               break;
             }
-            case 74: {
-              com.google.protobuf.ByteString bs = input.readBytes();
-              bitField0_ |= 0x00000080;
-              description_ = bs;
-              break;
-            }
-            case 113: {
-              bitField0_ |= 0x00000100;
-              variationValue1_ = input.readDouble();
-              break;
-            }
-            case 121: {
-              bitField0_ |= 0x00000200;
-              variationValue2_ = input.readDouble();
-              break;
-            }
-            case 129: {
-              bitField0_ |= 0x00000400;
-              variationValue3_ = input.readDouble();
-              break;
-            }
-            case 137: {
-              bitField0_ |= 0x00000800;
-              variationValue4_ = input.readDouble();
-              break;
-            }
-            case 145: {
-              bitField0_ |= 0x00001000;
-              variationValue5_ = input.readDouble();
-              break;
-            }
-            case 160: {
-              bitField0_ |= 0x00002000;
-              personId_ = input.readInt32();
-              break;
-            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -5927,150 +5811,6 @@ public final class BatchReport {
       }
     }
 
-    public static final int DESCRIPTION_FIELD_NUMBER = 9;
-    private java.lang.Object description_;
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    public boolean hasDescription() {
-      return ((bitField0_ & 0x00000080) == 0x00000080);
-    }
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    public java.lang.String getDescription() {
-      java.lang.Object ref = description_;
-      if (ref instanceof java.lang.String) {
-        return (java.lang.String) ref;
-      } else {
-        com.google.protobuf.ByteString bs = 
-            (com.google.protobuf.ByteString) ref;
-        java.lang.String s = bs.toStringUtf8();
-        if (bs.isValidUtf8()) {
-          description_ = s;
-        }
-        return s;
-      }
-    }
-    /**
-     * <code>optional string description = 9;</code>
-     *
-     * <pre>
-     * temporary fields during development of computation stack
-     * </pre>
-     */
-    public com.google.protobuf.ByteString
-        getDescriptionBytes() {
-      java.lang.Object ref = description_;
-      if (ref instanceof java.lang.String) {
-        com.google.protobuf.ByteString b = 
-            com.google.protobuf.ByteString.copyFromUtf8(
-                (java.lang.String) ref);
-        description_ = b;
-        return b;
-      } else {
-        return (com.google.protobuf.ByteString) ref;
-      }
-    }
-
-    public static final int VARIATION_VALUE_1_FIELD_NUMBER = 14;
-    private double variationValue1_;
-    /**
-     * <code>optional double variation_value_1 = 14;</code>
-     */
-    public boolean hasVariationValue1() {
-      return ((bitField0_ & 0x00000100) == 0x00000100);
-    }
-    /**
-     * <code>optional double variation_value_1 = 14;</code>
-     */
-    public double getVariationValue1() {
-      return variationValue1_;
-    }
-
-    public static final int VARIATION_VALUE_2_FIELD_NUMBER = 15;
-    private double variationValue2_;
-    /**
-     * <code>optional double variation_value_2 = 15;</code>
-     */
-    public boolean hasVariationValue2() {
-      return ((bitField0_ & 0x00000200) == 0x00000200);
-    }
-    /**
-     * <code>optional double variation_value_2 = 15;</code>
-     */
-    public double getVariationValue2() {
-      return variationValue2_;
-    }
-
-    public static final int VARIATION_VALUE_3_FIELD_NUMBER = 16;
-    private double variationValue3_;
-    /**
-     * <code>optional double variation_value_3 = 16;</code>
-     */
-    public boolean hasVariationValue3() {
-      return ((bitField0_ & 0x00000400) == 0x00000400);
-    }
-    /**
-     * <code>optional double variation_value_3 = 16;</code>
-     */
-    public double getVariationValue3() {
-      return variationValue3_;
-    }
-
-    public static final int VARIATION_VALUE_4_FIELD_NUMBER = 17;
-    private double variationValue4_;
-    /**
-     * <code>optional double variation_value_4 = 17;</code>
-     */
-    public boolean hasVariationValue4() {
-      return ((bitField0_ & 0x00000800) == 0x00000800);
-    }
-    /**
-     * <code>optional double variation_value_4 = 17;</code>
-     */
-    public double getVariationValue4() {
-      return variationValue4_;
-    }
-
-    public static final int VARIATION_VALUE_5_FIELD_NUMBER = 18;
-    private double variationValue5_;
-    /**
-     * <code>optional double variation_value_5 = 18;</code>
-     */
-    public boolean hasVariationValue5() {
-      return ((bitField0_ & 0x00001000) == 0x00001000);
-    }
-    /**
-     * <code>optional double variation_value_5 = 18;</code>
-     */
-    public double getVariationValue5() {
-      return variationValue5_;
-    }
-
-    public static final int PERSON_ID_FIELD_NUMBER = 20;
-    private int personId_;
-    /**
-     * <code>optional int32 person_id = 20;</code>
-     */
-    public boolean hasPersonId() {
-      return ((bitField0_ & 0x00002000) == 0x00002000);
-    }
-    /**
-     * <code>optional int32 person_id = 20;</code>
-     */
-    public int getPersonId() {
-      return personId_;
-    }
-
     private void initFields() {
       valueType_ = org.sonar.batch.protocol.Constants.MeasureValueType.INT;
       booleanValue_ = false;
@@ -6079,13 +5819,6 @@ public final class BatchReport {
       doubleValue_ = 0D;
       stringValue_ = "";
       metricKey_ = "";
-      description_ = "";
-      variationValue1_ = 0D;
-      variationValue2_ = 0D;
-      variationValue3_ = 0D;
-      variationValue4_ = 0D;
-      variationValue5_ = 0D;
-      personId_ = 0;
     }
     private byte memoizedIsInitialized = -1;
     public final boolean isInitialized() {
@@ -6121,27 +5854,6 @@ public final class BatchReport {
       if (((bitField0_ & 0x00000040) == 0x00000040)) {
         output.writeBytes(7, getMetricKeyBytes());
       }
-      if (((bitField0_ & 0x00000080) == 0x00000080)) {
-        output.writeBytes(9, getDescriptionBytes());
-      }
-      if (((bitField0_ & 0x00000100) == 0x00000100)) {
-        output.writeDouble(14, variationValue1_);
-      }
-      if (((bitField0_ & 0x00000200) == 0x00000200)) {
-        output.writeDouble(15, variationValue2_);
-      }
-      if (((bitField0_ & 0x00000400) == 0x00000400)) {
-        output.writeDouble(16, variationValue3_);
-      }
-      if (((bitField0_ & 0x00000800) == 0x00000800)) {
-        output.writeDouble(17, variationValue4_);
-      }
-      if (((bitField0_ & 0x00001000) == 0x00001000)) {
-        output.writeDouble(18, variationValue5_);
-      }
-      if (((bitField0_ & 0x00002000) == 0x00002000)) {
-        output.writeInt32(20, personId_);
-      }
       getUnknownFields().writeTo(output);
     }
 
@@ -6179,34 +5891,6 @@ public final class BatchReport {
         size += com.google.protobuf.CodedOutputStream
           .computeBytesSize(7, getMetricKeyBytes());
       }
-      if (((bitField0_ & 0x00000080) == 0x00000080)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeBytesSize(9, getDescriptionBytes());
-      }
-      if (((bitField0_ & 0x00000100) == 0x00000100)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeDoubleSize(14, variationValue1_);
-      }
-      if (((bitField0_ & 0x00000200) == 0x00000200)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeDoubleSize(15, variationValue2_);
-      }
-      if (((bitField0_ & 0x00000400) == 0x00000400)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeDoubleSize(16, variationValue3_);
-      }
-      if (((bitField0_ & 0x00000800) == 0x00000800)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeDoubleSize(17, variationValue4_);
-      }
-      if (((bitField0_ & 0x00001000) == 0x00001000)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeDoubleSize(18, variationValue5_);
-      }
-      if (((bitField0_ & 0x00002000) == 0x00002000)) {
-        size += com.google.protobuf.CodedOutputStream
-          .computeInt32Size(20, personId_);
-      }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
@@ -6338,20 +6022,6 @@ public final class BatchReport {
         bitField0_ = (bitField0_ & ~0x00000020);
         metricKey_ = "";
         bitField0_ = (bitField0_ & ~0x00000040);
-        description_ = "";
-        bitField0_ = (bitField0_ & ~0x00000080);
-        variationValue1_ = 0D;
-        bitField0_ = (bitField0_ & ~0x00000100);
-        variationValue2_ = 0D;
-        bitField0_ = (bitField0_ & ~0x00000200);
-        variationValue3_ = 0D;
-        bitField0_ = (bitField0_ & ~0x00000400);
-        variationValue4_ = 0D;
-        bitField0_ = (bitField0_ & ~0x00000800);
-        variationValue5_ = 0D;
-        bitField0_ = (bitField0_ & ~0x00001000);
-        personId_ = 0;
-        bitField0_ = (bitField0_ & ~0x00002000);
         return this;
       }
 
@@ -6408,34 +6078,6 @@ public final class BatchReport {
           to_bitField0_ |= 0x00000040;
         }
         result.metricKey_ = metricKey_;
-        if (((from_bitField0_ & 0x00000080) == 0x00000080)) {
-          to_bitField0_ |= 0x00000080;
-        }
-        result.description_ = description_;
-        if (((from_bitField0_ & 0x00000100) == 0x00000100)) {
-          to_bitField0_ |= 0x00000100;
-        }
-        result.variationValue1_ = variationValue1_;
-        if (((from_bitField0_ & 0x00000200) == 0x00000200)) {
-          to_bitField0_ |= 0x00000200;
-        }
-        result.variationValue2_ = variationValue2_;
-        if (((from_bitField0_ & 0x00000400) == 0x00000400)) {
-          to_bitField0_ |= 0x00000400;
-        }
-        result.variationValue3_ = variationValue3_;
-        if (((from_bitField0_ & 0x00000800) == 0x00000800)) {
-          to_bitField0_ |= 0x00000800;
-        }
-        result.variationValue4_ = variationValue4_;
-        if (((from_bitField0_ & 0x00001000) == 0x00001000)) {
-          to_bitField0_ |= 0x00001000;
-        }
-        result.variationValue5_ = variationValue5_;
-        if (((from_bitField0_ & 0x00002000) == 0x00002000)) {
-          to_bitField0_ |= 0x00002000;
-        }
-        result.personId_ = personId_;
         result.bitField0_ = to_bitField0_;
         onBuilt();
         return result;
@@ -6477,29 +6119,6 @@ public final class BatchReport {
           metricKey_ = other.metricKey_;
           onChanged();
         }
-        if (other.hasDescription()) {
-          bitField0_ |= 0x00000080;
-          description_ = other.description_;
-          onChanged();
-        }
-        if (other.hasVariationValue1()) {
-          setVariationValue1(other.getVariationValue1());
-        }
-        if (other.hasVariationValue2()) {
-          setVariationValue2(other.getVariationValue2());
-        }
-        if (other.hasVariationValue3()) {
-          setVariationValue3(other.getVariationValue3());
-        }
-        if (other.hasVariationValue4()) {
-          setVariationValue4(other.getVariationValue4());
-        }
-        if (other.hasVariationValue5()) {
-          setVariationValue5(other.getVariationValue5());
-        }
-        if (other.hasPersonId()) {
-          setPersonId(other.getPersonId());
-        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
@@ -6858,298 +6477,6 @@ public final class BatchReport {
         return this;
       }
 
-      private java.lang.Object description_ = "";
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public boolean hasDescription() {
-        return ((bitField0_ & 0x00000080) == 0x00000080);
-      }
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public java.lang.String getDescription() {
-        java.lang.Object ref = description_;
-        if (!(ref instanceof java.lang.String)) {
-          com.google.protobuf.ByteString bs =
-              (com.google.protobuf.ByteString) ref;
-          java.lang.String s = bs.toStringUtf8();
-          if (bs.isValidUtf8()) {
-            description_ = s;
-          }
-          return s;
-        } else {
-          return (java.lang.String) ref;
-        }
-      }
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public com.google.protobuf.ByteString
-          getDescriptionBytes() {
-        java.lang.Object ref = description_;
-        if (ref instanceof String) {
-          com.google.protobuf.ByteString b = 
-              com.google.protobuf.ByteString.copyFromUtf8(
-                  (java.lang.String) ref);
-          description_ = b;
-          return b;
-        } else {
-          return (com.google.protobuf.ByteString) ref;
-        }
-      }
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public Builder setDescription(
-          java.lang.String value) {
-        if (value == null) {
-    throw new NullPointerException();
-  }
-  bitField0_ |= 0x00000080;
-        description_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public Builder clearDescription() {
-        bitField0_ = (bitField0_ & ~0x00000080);
-        description_ = getDefaultInstance().getDescription();
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional string description = 9;</code>
-       *
-       * <pre>
-       * temporary fields during development of computation stack
-       * </pre>
-       */
-      public Builder setDescriptionBytes(
-          com.google.protobuf.ByteString value) {
-        if (value == null) {
-    throw new NullPointerException();
-  }
-  bitField0_ |= 0x00000080;
-        description_ = value;
-        onChanged();
-        return this;
-      }
-
-      private double variationValue1_ ;
-      /**
-       * <code>optional double variation_value_1 = 14;</code>
-       */
-      public boolean hasVariationValue1() {
-        return ((bitField0_ & 0x00000100) == 0x00000100);
-      }
-      /**
-       * <code>optional double variation_value_1 = 14;</code>
-       */
-      public double getVariationValue1() {
-        return variationValue1_;
-      }
-      /**
-       * <code>optional double variation_value_1 = 14;</code>
-       */
-      public Builder setVariationValue1(double value) {
-        bitField0_ |= 0x00000100;
-        variationValue1_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional double variation_value_1 = 14;</code>
-       */
-      public Builder clearVariationValue1() {
-        bitField0_ = (bitField0_ & ~0x00000100);
-        variationValue1_ = 0D;
-        onChanged();
-        return this;
-      }
-
-      private double variationValue2_ ;
-      /**
-       * <code>optional double variation_value_2 = 15;</code>
-       */
-      public boolean hasVariationValue2() {
-        return ((bitField0_ & 0x00000200) == 0x00000200);
-      }
-      /**
-       * <code>optional double variation_value_2 = 15;</code>
-       */
-      public double getVariationValue2() {
-        return variationValue2_;
-      }
-      /**
-       * <code>optional double variation_value_2 = 15;</code>
-       */
-      public Builder setVariationValue2(double value) {
-        bitField0_ |= 0x00000200;
-        variationValue2_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional double variation_value_2 = 15;</code>
-       */
-      public Builder clearVariationValue2() {
-        bitField0_ = (bitField0_ & ~0x00000200);
-        variationValue2_ = 0D;
-        onChanged();
-        return this;
-      }
-
-      private double variationValue3_ ;
-      /**
-       * <code>optional double variation_value_3 = 16;</code>
-       */
-      public boolean hasVariationValue3() {
-        return ((bitField0_ & 0x00000400) == 0x00000400);
-      }
-      /**
-       * <code>optional double variation_value_3 = 16;</code>
-       */
-      public double getVariationValue3() {
-        return variationValue3_;
-      }
-      /**
-       * <code>optional double variation_value_3 = 16;</code>
-       */
-      public Builder setVariationValue3(double value) {
-        bitField0_ |= 0x00000400;
-        variationValue3_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional double variation_value_3 = 16;</code>
-       */
-      public Builder clearVariationValue3() {
-        bitField0_ = (bitField0_ & ~0x00000400);
-        variationValue3_ = 0D;
-        onChanged();
-        return this;
-      }
-
-      private double variationValue4_ ;
-      /**
-       * <code>optional double variation_value_4 = 17;</code>
-       */
-      public boolean hasVariationValue4() {
-        return ((bitField0_ & 0x00000800) == 0x00000800);
-      }
-      /**
-       * <code>optional double variation_value_4 = 17;</code>
-       */
-      public double getVariationValue4() {
-        return variationValue4_;
-      }
-      /**
-       * <code>optional double variation_value_4 = 17;</code>
-       */
-      public Builder setVariationValue4(double value) {
-        bitField0_ |= 0x00000800;
-        variationValue4_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional double variation_value_4 = 17;</code>
-       */
-      public Builder clearVariationValue4() {
-        bitField0_ = (bitField0_ & ~0x00000800);
-        variationValue4_ = 0D;
-        onChanged();
-        return this;
-      }
-
-      private double variationValue5_ ;
-      /**
-       * <code>optional double variation_value_5 = 18;</code>
-       */
-      public boolean hasVariationValue5() {
-        return ((bitField0_ & 0x00001000) == 0x00001000);
-      }
-      /**
-       * <code>optional double variation_value_5 = 18;</code>
-       */
-      public double getVariationValue5() {
-        return variationValue5_;
-      }
-      /**
-       * <code>optional double variation_value_5 = 18;</code>
-       */
-      public Builder setVariationValue5(double value) {
-        bitField0_ |= 0x00001000;
-        variationValue5_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional double variation_value_5 = 18;</code>
-       */
-      public Builder clearVariationValue5() {
-        bitField0_ = (bitField0_ & ~0x00001000);
-        variationValue5_ = 0D;
-        onChanged();
-        return this;
-      }
-
-      private int personId_ ;
-      /**
-       * <code>optional int32 person_id = 20;</code>
-       */
-      public boolean hasPersonId() {
-        return ((bitField0_ & 0x00002000) == 0x00002000);
-      }
-      /**
-       * <code>optional int32 person_id = 20;</code>
-       */
-      public int getPersonId() {
-        return personId_;
-      }
-      /**
-       * <code>optional int32 person_id = 20;</code>
-       */
-      public Builder setPersonId(int value) {
-        bitField0_ |= 0x00002000;
-        personId_ = value;
-        onChanged();
-        return this;
-      }
-      /**
-       * <code>optional int32 person_id = 20;</code>
-       */
-      public Builder clearPersonId() {
-        bitField0_ = (bitField0_ & ~0x00002000);
-        personId_ = 0;
-        onChanged();
-        return this;
-      }
-
       // @@protoc_insertion_point(builder_scope:Measure)
     }
 
@@ -17744,46 +17071,42 @@ public final class BatchReport {
       "(\010\022\020\n\010language\030\006 \001(\t\022\025\n\tchild_ref\030\007 \003(\005B" +
       "\002\020\001\022\034\n\004link\030\010 \003(\0132\016.ComponentLink\022\017\n\007ver" +
       "sion\030\t \001(\t\022\013\n\003key\030\n \001(\t\022\r\n\005lines\030\013 \001(\005\022\023" +
-      "\n\013description\030\014 \001(\t\"\335\002\n\007Measure\022%\n\nvalue" +
+      "\n\013description\030\014 \001(\t\"\256\001\n\007Measure\022%\n\nvalue" +
       "_type\030\001 \001(\0162\021.MeasureValueType\022\025\n\rboolea" +
       "n_value\030\002 \001(\010\022\021\n\tint_value\030\003 \001(\005\022\022\n\nlong" +
       "_value\030\004 \001(\003\022\024\n\014double_value\030\005 \001(\001\022\024\n\014st" +
-      "ring_value\030\006 \001(\t\022\022\n\nmetric_key\030\007 \001(\t\022\023\n\013",
-      "description\030\t \001(\t\022\031\n\021variation_value_1\030\016" +
-      " \001(\001\022\031\n\021variation_value_2\030\017 \001(\001\022\031\n\021varia" +
-      "tion_value_3\030\020 \001(\001\022\031\n\021variation_value_4\030" +
-      "\021 \001(\001\022\031\n\021variation_value_5\030\022 \001(\001\022\021\n\tpers" +
-      "on_id\030\024 \001(\005\"\242\001\n\005Issue\022\027\n\017rule_repository" +
-      "\030\001 \001(\t\022\020\n\010rule_key\030\002 \001(\t\022\014\n\004line\030\003 \001(\005\022\013" +
-      "\n\003msg\030\004 \001(\t\022\033\n\010severity\030\005 \001(\0162\t.Severity" +
-      "\022\013\n\003tag\030\006 \003(\t\022\025\n\reffort_to_fix\030\007 \001(\001\022\022\n\n" +
-      "attributes\030\010 \001(\t\"\254\001\n\nChangesets\022\025\n\rcompo" +
-      "nent_ref\030\001 \001(\005\022(\n\tchangeset\030\002 \003(\0132\025.Chan",
-      "gesets.Changeset\022 \n\024changesetIndexByLine" +
-      "\030\003 \003(\005B\002\020\001\032;\n\tChangeset\022\020\n\010revision\030\001 \001(" +
-      "\t\022\016\n\006author\030\002 \001(\t\022\014\n\004date\030\003 \001(\003\"R\n\tDupli" +
-      "cate\022\026\n\016other_file_ref\030\001 \001(\005\022\025\n\005range\030\002 " +
-      "\001(\0132\006.Range\022\026\n\016other_file_key\030\003 \001(\t\"M\n\013D" +
-      "uplication\022\037\n\017origin_position\030\001 \001(\0132\006.Ra" +
-      "nge\022\035\n\tduplicate\030\002 \003(\0132\n.Duplicate\"W\n\005Ra" +
-      "nge\022\022\n\nstart_line\030\001 \001(\005\022\020\n\010end_line\030\002 \001(" +
-      "\005\022\024\n\014start_offset\030\003 \001(\005\022\022\n\nend_offset\030\004 " +
-      "\001(\005\"@\n\006Symbol\022\033\n\013declaration\030\001 \001(\0132\006.Ran",
-      "ge\022\031\n\treference\030\002 \003(\0132\006.Range\"\260\001\n\010Covera" +
-      "ge\022\014\n\004line\030\001 \001(\005\022\022\n\nconditions\030\002 \001(\005\022\017\n\007" +
-      "ut_hits\030\003 \001(\010\022\017\n\007it_hits\030\004 \001(\010\022\035\n\025ut_cov" +
-      "ered_conditions\030\005 \001(\005\022\035\n\025it_covered_cond" +
-      "itions\030\006 \001(\005\022\"\n\032overall_covered_conditio" +
-      "ns\030\007 \001(\005\"L\n\022SyntaxHighlighting\022\025\n\005range\030" +
-      "\001 \001(\0132\006.Range\022\037\n\004type\030\002 \001(\0162\021.Highlighti" +
-      "ngType\"j\n\004Test\022\014\n\004name\030\001 \001(\t\022\033\n\006status\030\002" +
-      " \001(\0162\013.TestStatus\022\026\n\016duration_in_ms\030\003 \001(" +
-      "\003\022\022\n\nstacktrace\030\004 \001(\t\022\013\n\003msg\030\005 \001(\t\"\221\001\n\016C",
-      "overageDetail\022\021\n\ttest_name\030\001 \001(\t\0221\n\014cove" +
-      "red_file\030\002 \003(\0132\033.CoverageDetail.CoveredF" +
-      "ile\0329\n\013CoveredFile\022\020\n\010file_ref\030\001 \001(\005\022\030\n\014" +
-      "covered_line\030\002 \003(\005B\002\020\001B#\n\037org.sonar.batc" +
-      "h.protocol.outputH\001"
+      "ring_value\030\006 \001(\t\022\022\n\nmetric_key\030\007 \001(\t\"\242\001\n",
+      "\005Issue\022\027\n\017rule_repository\030\001 \001(\t\022\020\n\010rule_" +
+      "key\030\002 \001(\t\022\014\n\004line\030\003 \001(\005\022\013\n\003msg\030\004 \001(\t\022\033\n\010" +
+      "severity\030\005 \001(\0162\t.Severity\022\013\n\003tag\030\006 \003(\t\022\025" +
+      "\n\reffort_to_fix\030\007 \001(\001\022\022\n\nattributes\030\010 \001(" +
+      "\t\"\254\001\n\nChangesets\022\025\n\rcomponent_ref\030\001 \001(\005\022" +
+      "(\n\tchangeset\030\002 \003(\0132\025.Changesets.Changese" +
+      "t\022 \n\024changesetIndexByLine\030\003 \003(\005B\002\020\001\032;\n\tC" +
+      "hangeset\022\020\n\010revision\030\001 \001(\t\022\016\n\006author\030\002 \001" +
+      "(\t\022\014\n\004date\030\003 \001(\003\"R\n\tDuplicate\022\026\n\016other_f" +
+      "ile_ref\030\001 \001(\005\022\025\n\005range\030\002 \001(\0132\006.Range\022\026\n\016",
+      "other_file_key\030\003 \001(\t\"M\n\013Duplication\022\037\n\017o" +
+      "rigin_position\030\001 \001(\0132\006.Range\022\035\n\tduplicat" +
+      "e\030\002 \003(\0132\n.Duplicate\"W\n\005Range\022\022\n\nstart_li" +
+      "ne\030\001 \001(\005\022\020\n\010end_line\030\002 \001(\005\022\024\n\014start_offs" +
+      "et\030\003 \001(\005\022\022\n\nend_offset\030\004 \001(\005\"@\n\006Symbol\022\033" +
+      "\n\013declaration\030\001 \001(\0132\006.Range\022\031\n\treference" +
+      "\030\002 \003(\0132\006.Range\"\260\001\n\010Coverage\022\014\n\004line\030\001 \001(" +
+      "\005\022\022\n\nconditions\030\002 \001(\005\022\017\n\007ut_hits\030\003 \001(\010\022\017" +
+      "\n\007it_hits\030\004 \001(\010\022\035\n\025ut_covered_conditions" +
+      "\030\005 \001(\005\022\035\n\025it_covered_conditions\030\006 \001(\005\022\"\n",
+      "\032overall_covered_conditions\030\007 \001(\005\"L\n\022Syn" +
+      "taxHighlighting\022\025\n\005range\030\001 \001(\0132\006.Range\022\037" +
+      "\n\004type\030\002 \001(\0162\021.HighlightingType\"j\n\004Test\022" +
+      "\014\n\004name\030\001 \001(\t\022\033\n\006status\030\002 \001(\0162\013.TestStat" +
+      "us\022\026\n\016duration_in_ms\030\003 \001(\003\022\022\n\nstacktrace" +
+      "\030\004 \001(\t\022\013\n\003msg\030\005 \001(\t\"\221\001\n\016CoverageDetail\022\021" +
+      "\n\ttest_name\030\001 \001(\t\0221\n\014covered_file\030\002 \003(\0132" +
+      "\033.CoverageDetail.CoveredFile\0329\n\013CoveredF" +
+      "ile\022\020\n\010file_ref\030\001 \001(\005\022\030\n\014covered_line\030\002 " +
+      "\003(\005B\002\020\001B#\n\037org.sonar.batch.protocol.outp",
+      "utH\001"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
         new com.google.protobuf.Descriptors.FileDescriptor.    InternalDescriptorAssigner() {
@@ -17833,7 +17156,7 @@ public final class BatchReport {
     internal_static_Measure_fieldAccessorTable = new
       com.google.protobuf.GeneratedMessage.FieldAccessorTable(
         internal_static_Measure_descriptor,
-        new java.lang.String[] { "ValueType", "BooleanValue", "IntValue", "LongValue", "DoubleValue", "StringValue", "MetricKey", "Description", "VariationValue1", "VariationValue2", "VariationValue3", "VariationValue4", "VariationValue5", "PersonId", });
+        new java.lang.String[] { "ValueType", "BooleanValue", "IntValue", "LongValue", "DoubleValue", "StringValue", "MetricKey", });
     internal_static_Issue_descriptor =
       getDescriptor().getMessageTypes().get(5);
     internal_static_Issue_fieldAccessorTable = new
index 9cc90da20c59d9211813eb6f5323f16b27e05505..4846bb0e1e988233890c633efc0a3ecca31382e8 100644 (file)
@@ -24,6 +24,8 @@ import javax.annotation.CheckForNull;
 import org.sonar.core.util.CloseableIterator;
 import org.sonar.core.util.Protobuf;
 
+import static org.sonar.core.util.CloseableIterator.emptyCloseableIterator;
+
 public class BatchReportReader {
 
   private final FileStructure fileStructure;
@@ -43,7 +45,7 @@ public class BatchReportReader {
   public CloseableIterator<BatchReport.ActiveRule> readActiveRules() {
     File file = fileStructure.activeRules();
     if (!fileExists(file)) {
-      return CloseableIterator.emptyCloseableIterator();
+      return emptyCloseableIterator();
     }
     return Protobuf.readStream(file, BatchReport.ActiveRule.PARSER);
   }
@@ -53,7 +55,7 @@ public class BatchReportReader {
     if (fileExists(file)) {
       return Protobuf.readStream(file, BatchReport.Measure.PARSER);
     }
-    return CloseableIterator.emptyCloseableIterator();
+    return emptyCloseableIterator();
   }
 
   @CheckForNull
@@ -78,7 +80,7 @@ public class BatchReportReader {
     if (fileExists(file)) {
       return Protobuf.readStream(file, BatchReport.Issue.PARSER);
     }
-    return CloseableIterator.emptyCloseableIterator();
+    return emptyCloseableIterator();
   }
 
   public CloseableIterator<BatchReport.Duplication> readComponentDuplications(int componentRef) {
@@ -86,7 +88,7 @@ public class BatchReportReader {
     if (fileExists(file)) {
       return Protobuf.readStream(file, BatchReport.Duplication.PARSER);
     }
-    return CloseableIterator.emptyCloseableIterator();
+    return emptyCloseableIterator();
   }
 
   public CloseableIterator<BatchReport.Symbol> readComponentSymbols(int componentRef) {
@@ -94,7 +96,7 @@ public class BatchReportReader {
     if (fileExists(file)) {
       return Protobuf.readStream(file, BatchReport.Symbol.PARSER);
     }
-    return CloseableIterator.emptyCloseableIterator();
+    return emptyCloseableIterator();
   }
 
   public boolean hasSyntaxHighlighting(int componentRef) {
@@ -102,22 +104,20 @@ public class BatchReportReader {
     return file.exists();
   }
 
-  @CheckForNull
-  public File readComponentSyntaxHighlighting(int fileRef) {
+  public CloseableIterator<BatchReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, fileRef);
     if (fileExists(file)) {
-      return file;
+      return Protobuf.readStream(file, BatchReport.SyntaxHighlighting.PARSER);
     }
-    return null;
+    return emptyCloseableIterator();
   }
 
-  @CheckForNull
-  public File readComponentCoverage(int fileRef) {
+  public CloseableIterator<BatchReport.Coverage> readComponentCoverage(int fileRef) {
     File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, fileRef);
     if (fileExists(file)) {
-      return file;
+      return Protobuf.readStream(file, BatchReport.Coverage.PARSER);
     }
-    return null;
+    return emptyCloseableIterator();
   }
 
   public File readFileSource(int fileRef) {
index 3520f5bee01cb4220daf6c8c548c2bfde57f7ba7..444d3f9031030d9cf500904808087fc08f412f1b 100644 (file)
@@ -94,15 +94,6 @@ message Measure {
   optional double double_value = 5;
   optional string string_value = 6;
   optional string metric_key = 7;
-
-  // temporary fields during development of computation stack
-  optional string description = 9;
-  optional double variation_value_1 = 14;
-  optional double variation_value_2 = 15;
-  optional double variation_value_3 = 16;
-  optional double variation_value_4 = 17;
-  optional double variation_value_5 = 18;
-  optional int32 person_id = 20;
 }
 
 message Issue {
index 9250a23042ee6c5f3a266a320854a82e77a1768b..283933d18bfb63f90284252c4b1b9de2480a2f03 100644 (file)
 package org.sonar.batch.protocol.output;
 
 import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.InputStream;
+import java.util.Arrays;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.batch.protocol.Constants;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Arrays;
+import org.sonar.core.util.CloseableIterator;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -42,12 +42,12 @@ public class BatchReportReaderTest {
 
   File dir;
 
-  BatchReportReader sut;
+  BatchReportReader underTest;
 
   @Before
   public void setUp() throws Exception {
     dir = temp.newFolder();
-    sut = new BatchReportReader(dir);
+    underTest = new BatchReportReader(dir);
   }
 
   @Test
@@ -59,7 +59,7 @@ public class BatchReportReaderTest {
       .setRootComponentRef(1);
     writer.writeMetadata(metadata.build());
 
-    BatchReport.Metadata readMetadata = sut.readMetadata();
+    BatchReport.Metadata readMetadata = underTest.readMetadata();
     assertThat(readMetadata.getAnalysisDate()).isEqualTo(15000000L);
     assertThat(readMetadata.getProjectKey()).isEqualTo("PROJECT_A");
     assertThat(readMetadata.getRootComponentRef()).isEqualTo(1);
@@ -67,7 +67,7 @@ public class BatchReportReaderTest {
 
   @Test(expected = IllegalStateException.class)
   public void fail_if_missing_metadata_file() {
-    sut.readMetadata();
+    underTest.readMetadata();
   }
 
   @Test
@@ -78,12 +78,12 @@ public class BatchReportReaderTest {
       .setPath("src/main/java/Foo.java");
     writer.writeComponent(component.build());
 
-    assertThat(sut.readComponent(1).getPath()).isEqualTo("src/main/java/Foo.java");
+    assertThat(underTest.readComponent(1).getPath()).isEqualTo("src/main/java/Foo.java");
   }
 
   @Test(expected = IllegalStateException.class)
   public void fail_if_missing_file_on_component() {
-    sut.readComponent(UNKNOWN_COMPONENT_REF);
+    underTest.readComponent(UNKNOWN_COMPONENT_REF);
   }
 
   @Test
@@ -94,13 +94,13 @@ public class BatchReportReaderTest {
       .build();
     writer.writeComponentIssues(1, Arrays.asList(issue));
 
-    assertThat(sut.readComponentIssues(1)).hasSize(1);
-    assertThat(sut.readComponentIssues(200)).isEmpty();
+    assertThat(underTest.readComponentIssues(1)).hasSize(1);
+    assertThat(underTest.readComponentIssues(200)).isEmpty();
   }
 
   @Test
   public void empty_list_if_no_issue_found() {
-    assertThat(sut.readComponentIssues(UNKNOWN_COMPONENT_REF)).isEmpty();
+    assertThat(underTest.readComponentIssues(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -110,12 +110,12 @@ public class BatchReportReaderTest {
       .setStringValue("value_a");
     writer.writeComponentMeasures(1, Arrays.asList(measure.build()));
 
-    assertThat(sut.readComponentMeasures(1)).hasSize(1);
+    assertThat(underTest.readComponentMeasures(1)).hasSize(1);
   }
 
   @Test
   public void empty_list_if_no_measure_found() {
-    assertThat(sut.readComponentMeasures(UNKNOWN_COMPONENT_REF)).isEmpty();
+    assertThat(underTest.readComponentMeasures(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -126,13 +126,13 @@ public class BatchReportReaderTest {
       .addChangeset(BatchReport.Changesets.Changeset.newBuilder().setDate(123_456_789).setAuthor("jack.daniels").setRevision("123-456-789"));
     writer.writeComponentChangesets(scm.build());
 
-    assertThat(sut.readChangesets(1).getChangesetList()).hasSize(1);
-    assertThat(sut.readChangesets(1).getChangeset(0).getDate()).isEqualTo(123_456_789L);
+    assertThat(underTest.readChangesets(1).getChangesetList()).hasSize(1);
+    assertThat(underTest.readChangesets(1).getChangeset(0).getDate()).isEqualTo(123_456_789L);
   }
 
   @Test
   public void null_if_no_changeset_found() {
-    assertThat(sut.readChangesets(UNKNOWN_COMPONENT_REF)).isNull();
+    assertThat(underTest.readChangesets(UNKNOWN_COMPONENT_REF)).isNull();
   }
 
   @Test
@@ -165,7 +165,7 @@ public class BatchReportReaderTest {
 
   @Test
   public void empty_list_if_no_duplication_found() {
-    assertThat(sut.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty();
+    assertThat(underTest.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -184,11 +184,10 @@ public class BatchReportReaderTest {
           .setEndLine(10)
           .build())
         .setType(Constants.HighlightingType.ANNOTATION)
-        .build()
-    ));
+        .build()));
 
-    try (InputStream inputStream = FileUtils.openInputStream(sut.readComponentSyntaxHighlighting(1))) {
-      BatchReport.SyntaxHighlighting syntaxHighlighting = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream);
+    try (CloseableIterator<BatchReport.SyntaxHighlighting> it = underTest.readComponentSyntaxHighlighting(1)) {
+      BatchReport.SyntaxHighlighting syntaxHighlighting = it.next();
       assertThat(syntaxHighlighting.getRange()).isNotNull();
       assertThat(syntaxHighlighting.getRange().getStartLine()).isEqualTo(1);
       assertThat(syntaxHighlighting.getRange().getEndLine()).isEqualTo(10);
@@ -197,8 +196,8 @@ public class BatchReportReaderTest {
   }
 
   @Test
-  public void return_null_if_no_highlighting_found() {
-    assertThat(sut.readComponentSyntaxHighlighting(UNKNOWN_COMPONENT_REF)).isNull();
+  public void return_empty_if_no_highlighting_found() {
+    assertThat(underTest.readComponentSyntaxHighlighting(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -225,13 +224,13 @@ public class BatchReportReaderTest {
         .build())
       .build()));
 
-    sut = new BatchReportReader(dir);
-    assertThat(sut.readComponentSymbols(1)).hasSize(1);
+    underTest = new BatchReportReader(dir);
+    assertThat(underTest.readComponentSymbols(1)).hasSize(1);
   }
 
   @Test
   public void empty_list_if_no_symbol_found() {
-    assertThat(sut.readComponentSymbols(UNKNOWN_COMPONENT_REF)).isEmpty();
+    assertThat(underTest.readComponentSymbols(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -263,10 +262,9 @@ public class BatchReportReaderTest {
         .setOverallCoveredConditions(5)
         .build()));
 
-    sut = new BatchReportReader(dir);
-
-    try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(dir).readComponentCoverage(1))) {
-      BatchReport.Coverage coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
+    underTest = new BatchReportReader(dir);
+    try (CloseableIterator<BatchReport.Coverage> it = new BatchReportReader(dir).readComponentCoverage(1)) {
+      BatchReport.Coverage coverage = it.next();
       assertThat(coverage.getLine()).isEqualTo(1);
       assertThat(coverage.getConditions()).isEqualTo(1);
       assertThat(coverage.getUtHits()).isTrue();
@@ -274,21 +272,12 @@ public class BatchReportReaderTest {
       assertThat(coverage.getUtCoveredConditions()).isEqualTo(1);
       assertThat(coverage.getItCoveredConditions()).isEqualTo(1);
       assertThat(coverage.getOverallCoveredConditions()).isEqualTo(1);
-
-      coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
-      assertThat(coverage.getLine()).isEqualTo(2);
-      assertThat(coverage.getConditions()).isEqualTo(5);
-      assertThat(coverage.getUtHits()).isFalse();
-      assertThat(coverage.getItHits()).isFalse();
-      assertThat(coverage.getUtCoveredConditions()).isEqualTo(4);
-      assertThat(coverage.getItCoveredConditions()).isEqualTo(5);
-      assertThat(coverage.getOverallCoveredConditions()).isEqualTo(5);
     }
   }
 
   @Test
-  public void return_null_if_no_coverage_found() {
-    assertThat(sut.readComponentCoverage(UNKNOWN_COMPONENT_REF)).isNull();
+  public void return_empty_iterator_if_no_coverage_found() {
+    assertThat(underTest.readComponentCoverage(UNKNOWN_COMPONENT_REF)).isEmpty();
   }
 
   @Test
@@ -312,7 +301,7 @@ public class BatchReportReaderTest {
         .setStatus(Constants.TestStatus.OK)
         .build()));
 
-    try (InputStream inputStream = FileUtils.openInputStream(sut.readTests(1))) {
+    try (InputStream inputStream = FileUtils.openInputStream(underTest.readTests(1))) {
       BatchReport.Test testResult = BatchReport.Test.PARSER.parseDelimitedFrom(inputStream);
       assertThat(testResult.getDurationInMs()).isEqualTo(60_000);
       assertThat(testResult.getStacktrace()).isEqualTo("stacktrace");
@@ -323,7 +312,7 @@ public class BatchReportReaderTest {
 
   @Test
   public void null_if_no_test_found() {
-    assertThat(sut.readTests(UNKNOWN_COMPONENT_REF)).isNull();
+    assertThat(underTest.readTests(UNKNOWN_COMPONENT_REF)).isNull();
   }
 
   @Test
@@ -333,13 +322,11 @@ public class BatchReportReaderTest {
       BatchReport.CoverageDetail.newBuilder()
         .setTestName("test-name")
         .addCoveredFile(BatchReport.CoverageDetail.CoveredFile.newBuilder()
-            .addAllCoveredLine(Arrays.asList(1, 2, 3, 5, 7))
-            .setFileRef(2)
-        )
-        .build()
-    ));
+          .addAllCoveredLine(Arrays.asList(1, 2, 3, 5, 7))
+          .setFileRef(2))
+        .build()));
 
-    try (InputStream inputStream = FileUtils.openInputStream(sut.readCoverageDetails(1))) {
+    try (InputStream inputStream = FileUtils.openInputStream(underTest.readCoverageDetails(1))) {
       BatchReport.CoverageDetail coverageDetail = BatchReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream);
       assertThat(coverageDetail.getTestName()).isEqualTo("test-name");
       assertThat(coverageDetail.getCoveredFile(0).getFileRef()).isEqualTo(2);
@@ -349,7 +336,7 @@ public class BatchReportReaderTest {
 
   @Test
   public void null_if_no_coverage_detail_found() {
-    assertThat(sut.readCoverageDetails(UNKNOWN_COMPONENT_REF)).isNull();
+    assertThat(underTest.readCoverageDetails(UNKNOWN_COMPONENT_REF)).isNull();
   }
 
 }
index c937a7fc32a71fc32bec08cebe7bfad899ae7ac4..589f2bbe5f2c11cfbe2a8304fd4c7c4d6f741867 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.batch.mediumtest;
 import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
-import java.io.File;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -34,7 +33,6 @@ import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.AnalysisMode;
@@ -197,29 +195,21 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
    */
   public List<TypeOfText> highlightingTypeFor(InputFile file, int line, int lineOffset) {
     int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
-    File highlightingFile = reader.readComponentSyntaxHighlighting(ref);
-    if (highlightingFile == null) {
+    if (!reader.hasSyntaxHighlighting(ref)) {
       return Collections.emptyList();
     }
     TextPointer pointer = file.newPointer(line, lineOffset);
     List<TypeOfText> result = new ArrayList<>();
-    InputStream inputStream = null;
-    try {
-      inputStream = FileUtils.openInputStream(highlightingFile);
-      BatchReport.SyntaxHighlighting rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream);
-      while (rule != null) {
+    try (CloseableIterator<BatchReport.SyntaxHighlighting> it = reader.readComponentSyntaxHighlighting(ref)) {
+      while (it.hasNext()) {
+        BatchReport.SyntaxHighlighting rule = it.next();
         TextRange ruleRange = toRange(file, rule.getRange());
         if (ruleRange.start().compareTo(pointer) <= 0 && ruleRange.end().compareTo(pointer) > 0) {
           result.add(BatchReportUtils.toBatchType(rule.getType()));
         }
-        // Get next element
-        rule = BatchReport.SyntaxHighlighting.PARSER.parseDelimitedFrom(inputStream);
       }
-
     } catch (Exception e) {
       throw new IllegalStateException("Can't read syntax highlighting for " + file.absolutePath(), e);
-    } finally {
-      IOUtils.closeQuietly(inputStream);
     }
     return result;
   }
@@ -250,13 +240,12 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
   @CheckForNull
   public BatchReport.Coverage coverageFor(InputFile file, int line) {
     int ref = reportComponents.get(((DefaultInputFile) file).key()).getRef();
-    try (InputStream inputStream = FileUtils.openInputStream(getReportReader().readComponentCoverage(ref))) {
-      BatchReport.Coverage coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
-      while (coverage != null) {
+    try (CloseableIterator<BatchReport.Coverage> it = getReportReader().readComponentCoverage(ref)) {
+      while (it.hasNext()) {
+        BatchReport.Coverage coverage = it.next();
         if (coverage.getLine() == line) {
           return coverage;
         }
-        coverage = BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream);
       }
     } catch (Exception e) {
       throw new IllegalStateException(e);
index c257614fe7c9b07edd563b82192ba912fc65c6ac..e143fd3e3d0de254ed553ab1af0a2c3618e01176 100644 (file)
 package org.sonar.batch.report;
 
 import java.io.File;
-import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
-import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -34,11 +32,11 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.api.measures.Measure;
 import org.sonar.api.resources.Project;
 import org.sonar.batch.index.BatchComponentCache;
-import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReport.Coverage;
 import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.batch.protocol.output.BatchReportWriter;
 import org.sonar.batch.scan.measure.MeasureCache;
+import org.sonar.core.util.CloseableIterator;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.anyString;
@@ -93,13 +91,13 @@ public class CoveragePublisherTest {
 
     publisher.publish(writer);
 
-    try (InputStream inputStream = FileUtils.openInputStream(new BatchReportReader(outputDir).readComponentCoverage(2))) {
-      assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+    try (CloseableIterator<Coverage> it = new BatchReportReader(outputDir).readComponentCoverage(2)) {
+      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
         .setLine(2)
         .setUtHits(true)
         .setItHits(false)
         .build());
-      assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
         .setLine(3)
         .setUtHits(true)
         .setItHits(false)
@@ -108,13 +106,12 @@ public class CoveragePublisherTest {
         .setItCoveredConditions(1)
         .setOverallCoveredConditions(2)
         .build());
-      assertThat(BatchReport.Coverage.PARSER.parseDelimitedFrom(inputStream)).isEqualTo(Coverage.newBuilder()
+      assertThat(it.next()).isEqualTo(Coverage.newBuilder()
         .setLine(5)
         .setUtHits(false)
         .setItHits(true)
         .build());
-
     }
-  }
 
+  }
 }