]> source.dussan.org Git - sonarqube.git/commitdiff
No op for highlighting and symbol references in issues mode 507/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 15 Sep 2015 14:50:12 +0000 (16:50 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 17 Sep 2015 14:48:24 +0000 (16:48 +0200)
17 files changed:
sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java
sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java
sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/source/DefaultHighlightableTest.java
sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolTableTest.java
sonar-batch/src/test/java/org/sonar/batch/source/DefaultSymbolizableTest.java
sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlighting.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/highlighting/internal/DefaultHighlightingTest.java

index a4f7c8c8b2eabfa289c9c444cf10c0fc6672334d..04b5724b2c39d717aad86cc8ea53b81deebdf2aa 100644 (file)
@@ -76,9 +76,9 @@ public class TaskResult implements org.sonar.batch.mediumtest.ScanTaskObserver {
       issues.add(issue);
     }
 
+    ReportPublisher reportPublisher = container.getComponentByType(ReportPublisher.class);
+    reader = new BatchReportReader(reportPublisher.getReportDir());
     if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
-      ReportPublisher reportPublisher = container.getComponentByType(ReportPublisher.class);
-      reader = new BatchReportReader(reportPublisher.getReportDir());
       Metadata readMetadata = getReportReader().readMetadata();
       int rootComponentRef = readMetadata.getRootComponentRef();
       storeReportComponents(rootComponentRef, null, readMetadata.hasBranch() ? readMetadata.getBranch() : null);
index 57197abc0a1fd81c41d1bc7a5ddf0fcc2d61f2d8..cb58332f96cdd4d9771de32480b1d6d088c591c1 100644 (file)
  */
 package org.sonar.batch.sensor;
 
+import java.io.Serializable;
 import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.batch.sensor.coverage.NewCoverage;
@@ -28,6 +30,7 @@ import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
 import org.sonar.api.batch.sensor.duplication.NewDuplication;
 import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
+import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import org.sonar.api.batch.sensor.issue.NewIssue;
@@ -36,10 +39,29 @@ import org.sonar.api.batch.sensor.measure.NewMeasure;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.config.Settings;
 
-import java.io.Serializable;
-
 public class DefaultSensorContext implements SensorContext {
 
+  private static final NoOpNewHighlighting NO_OP_NEW_HIGHLIGHTING = new NoOpNewHighlighting();
+
+  private static final class NoOpNewHighlighting implements NewHighlighting {
+    @Override
+    public void save() {
+      // Do nothing
+    }
+
+    @Override
+    public NewHighlighting onFile(InputFile inputFile) {
+      // Do nothing
+      return this;
+    }
+
+    @Override
+    public NewHighlighting highlight(int startOffset, int endOffset, TypeOfText typeOfText) {
+      // Do nothing
+      return this;
+    }
+  }
+
   private final Settings settings;
   private final FileSystem fs;
   private final ActiveRules activeRules;
@@ -86,6 +108,9 @@ public class DefaultSensorContext implements SensorContext {
 
   @Override
   public NewHighlighting newHighlighting() {
+    if (analysisMode.isIssues()) {
+      return NO_OP_NEW_HIGHLIGHTING;
+    }
     return new DefaultHighlighting(sensorStorage);
   }
 
index e03531d243e812dfd50fd52ad4f0eff4dff8e6b1..6d38bbb320be12ad1ac84a0e6ae9d51d628b3cd2 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.batch.source;
 
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
@@ -30,21 +31,40 @@ import org.sonar.api.source.Highlightable;
  */
 public class DefaultHighlightable implements Highlightable {
 
+  private static final HighlightingBuilder NO_OP_BUILDER = new NoOpHighlightingBuilder();
   private final DefaultInputFile inputFile;
   private final SensorStorage sensorStorage;
+  private final AnalysisMode analysisMode;
 
-  public DefaultHighlightable(DefaultInputFile inputFile, SensorStorage sensorStorage) {
+  public DefaultHighlightable(DefaultInputFile inputFile, SensorStorage sensorStorage, AnalysisMode analysisMode) {
     this.inputFile = inputFile;
     this.sensorStorage = sensorStorage;
+    this.analysisMode = analysisMode;
   }
 
   @Override
   public HighlightingBuilder newHighlighting() {
+    if (analysisMode.isIssues()) {
+      return NO_OP_BUILDER;
+    }
     DefaultHighlighting defaultHighlighting = new DefaultHighlighting(sensorStorage);
     defaultHighlighting.onFile(inputFile);
     return new DefaultHighlightingBuilder(defaultHighlighting);
   }
 
+  private static final class NoOpHighlightingBuilder implements HighlightingBuilder {
+    @Override
+    public HighlightingBuilder highlight(int startOffset, int endOffset, String typeOfText) {
+      // Do nothing
+      return this;
+    }
+
+    @Override
+    public void done() {
+      // Do nothing
+    }
+  }
+
   private static class DefaultHighlightingBuilder implements HighlightingBuilder {
 
     private final DefaultHighlighting defaultHighlighting;
index e2bbf13bfa891b43ffd5505e0b57d7d3e94e8408..ce9766e0859d4f700927dc3524bf9ff384a89cfe 100644 (file)
 
 package org.sonar.batch.source;
 
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import org.sonar.api.batch.fs.TextRange;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.source.Symbol;
 import org.sonar.api.source.Symbolizable;
 
-import java.util.*;
-
 public class DefaultSymbolTable implements Symbolizable.SymbolTable {
 
   private Map<Symbol, Set<TextRange>> referencesBySymbol;
@@ -55,6 +60,25 @@ public class DefaultSymbolTable implements Symbolizable.SymbolTable {
 
   public static class Builder implements Symbolizable.SymbolTableBuilder {
 
+    private static final FakeSymbol FAKE_SYMBOL = new FakeSymbol();
+
+    private static final class FakeSymbol implements Symbol {
+      @Override
+      public String getFullyQualifiedName() {
+        return null;
+      }
+
+      @Override
+      public int getDeclarationStartOffset() {
+        return 0;
+      }
+
+      @Override
+      public int getDeclarationEndOffset() {
+        return 0;
+      }
+    }
+
     private final Map<Symbol, Set<TextRange>> referencesBySymbol = new LinkedHashMap<>();
     private final DefaultInputFile inputFile;
 
index f65cb609c21e51c97b3ab6a71fe6e65f2057af36..5089a9cca47c49651bb96883839c3563ddbe3e2e 100644 (file)
 
 package org.sonar.batch.source;
 
+import java.util.Collections;
+import java.util.List;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.source.Symbol;
 import org.sonar.api.source.Symbolizable;
 import org.sonar.batch.sensor.DefaultSensorStorage;
 
 public class DefaultSymbolizable implements Symbolizable {
 
+  private static final NoOpSymbolTableBuilder NO_OP_SYMBOL_TABLE_BUILDER = new NoOpSymbolTableBuilder();
+  private static final NoOpSymbolTable NO_OP_SYMBOL_TABLE = new NoOpSymbolTable();
+  private static final NoOpSymbol NO_OP_SYMBOL = new NoOpSymbol();
+
+  private static final class NoOpSymbolTableBuilder implements SymbolTableBuilder {
+    @Override
+    public Symbol newSymbol(int fromOffset, int toOffset) {
+      return NO_OP_SYMBOL;
+    }
+
+    @Override
+    public void newReference(Symbol symbol, int fromOffset) {
+      // Do nothing
+    }
+
+    @Override
+    public SymbolTable build() {
+      return NO_OP_SYMBOL_TABLE;
+    }
+  }
+
+  private static final class NoOpSymbolTable implements SymbolTable {
+    @Override
+    public List<Symbol> symbols() {
+      return Collections.emptyList();
+    }
+
+    @Override
+    public List<Integer> references(Symbol symbol) {
+      return Collections.emptyList();
+    }
+  }
+
+  private static final class NoOpSymbol implements Symbol {
+    @Override
+    public String getFullyQualifiedName() {
+      return null;
+    }
+
+    @Override
+    public int getDeclarationStartOffset() {
+      return 0;
+    }
+
+    @Override
+    public int getDeclarationEndOffset() {
+      return 0;
+    }
+  }
+
   private final DefaultInputFile inputFile;
   private final DefaultSensorStorage sensorStorage;
+  private final AnalysisMode analysisMode;
 
-  public DefaultSymbolizable(DefaultInputFile inputFile, DefaultSensorStorage sensorStorage) {
+  public DefaultSymbolizable(DefaultInputFile inputFile, DefaultSensorStorage sensorStorage, AnalysisMode analysisMode) {
     this.inputFile = inputFile;
     this.sensorStorage = sensorStorage;
+    this.analysisMode = analysisMode;
   }
 
   @Override
   public SymbolTableBuilder newSymbolTableBuilder() {
+    if (analysisMode.isIssues()) {
+      return NO_OP_SYMBOL_TABLE_BUILDER;
+    }
     return new DefaultSymbolTable.Builder(inputFile);
   }
 
   @Override
   public void setSymbolTable(SymbolTable symbolTable) {
+    if (analysisMode.isIssues()) {
+      // No need for symbols in issues mode
+      return;
+    }
     sensorStorage.store(inputFile, ((DefaultSymbolTable) symbolTable).getReferencesBySymbol());
   }
 }
index 067b96d882e4cc36a0231ee8dc6316f65fc70ad6..69acf876cd9fc3e3eac8231d12c0079ec4491b26 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.batch.source;
 
 import javax.annotation.CheckForNull;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -30,10 +31,12 @@ import org.sonar.batch.index.BatchComponent;
 public class HighlightableBuilder extends PerspectiveBuilder<Highlightable> {
 
   private final SensorStorage sensorStorage;
+  private final AnalysisMode analysisMode;
 
-  public HighlightableBuilder(SensorStorage sensorStorage) {
+  public HighlightableBuilder(SensorStorage sensorStorage, AnalysisMode analysisMode) {
     super(Highlightable.class);
     this.sensorStorage = sensorStorage;
+    this.analysisMode = analysisMode;
   }
 
   @CheckForNull
@@ -41,7 +44,7 @@ public class HighlightableBuilder extends PerspectiveBuilder<Highlightable> {
   public Highlightable loadPerspective(Class<Highlightable> perspectiveClass, BatchComponent component) {
     if (component.isFile()) {
       InputFile path = (InputFile) component.inputComponent();
-      return new DefaultHighlightable((DefaultInputFile) path, sensorStorage);
+      return new DefaultHighlightable((DefaultInputFile) path, sensorStorage, analysisMode);
     }
     return null;
   }
index fc377e0d8209ec0d3a85560f227dcdf6d551a113..48d7033a6b525092df04f0de090c55ed36034bbb 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.batch.source;
 
 import javax.annotation.CheckForNull;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.source.Symbolizable;
@@ -31,10 +32,12 @@ import org.sonar.batch.sensor.DefaultSensorStorage;
 public class SymbolizableBuilder extends PerspectiveBuilder<Symbolizable> {
 
   private final DefaultSensorStorage sensorStorage;
+  private final AnalysisMode analysisMode;
 
-  public SymbolizableBuilder(DefaultSensorStorage sensorStorage) {
+  public SymbolizableBuilder(DefaultSensorStorage sensorStorage, AnalysisMode analysisMode) {
     super(Symbolizable.class);
     this.sensorStorage = sensorStorage;
+    this.analysisMode = analysisMode;
   }
 
   @CheckForNull
@@ -42,7 +45,7 @@ public class SymbolizableBuilder extends PerspectiveBuilder<Symbolizable> {
   public Symbolizable loadPerspective(Class<Symbolizable> perspectiveClass, BatchComponent component) {
     if (component.isFile()) {
       InputFile path = (InputFile) component.inputComponent();
-      return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage);
+      return new DefaultSymbolizable((DefaultInputFile) path, sensorStorage, analysisMode);
     }
     return null;
   }
index 5dcc1d57af955c05c63449f831561fd3254c062f..bb0ad02c6590632ec2b5c2d060181a1d66a3925c 100644 (file)
@@ -71,7 +71,6 @@ public class HighlightingMediumTest {
 
     TaskResult result = tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
-        .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
         .put("sonar.projectName", "Foo Project")
@@ -112,7 +111,6 @@ public class HighlightingMediumTest {
     long start = System.currentTimeMillis();
     TaskResult result = tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
-        .put("sonar.task", "scan")
         .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
         .put("sonar.projectKey", "com.foo.project")
         .put("sonar.projectName", "Foo Project")
index 83b5c18433a42ab3c5c19a9954125ae992c06f77..47d0589c0c3f8e1e48483debaa7ddf70581a9693 100644 (file)
  */
 package org.sonar.batch.mediumtest.issuesmode;
 
-import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
-
 import com.google.common.collect.ImmutableMap;
-
 import java.io.File;
+import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
-
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
@@ -45,9 +42,11 @@ import org.sonar.batch.mediumtest.BatchMediumTester;
 import org.sonar.batch.mediumtest.TaskResult;
 import org.sonar.batch.protocol.Constants.Severity;
 import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
 import org.sonar.batch.scan.report.ConsoleReport;
 import org.sonar.xoo.XooPlugin;
 import org.sonar.xoo.rule.XooRulesDefinition;
+
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class IssueModeAndReportsMediumTest {
@@ -156,7 +155,8 @@ public class IssueModeAndReportsMediumTest {
     int openIssues = 0;
     int resolvedIssue = 0;
     for (Issue issue : result.trackedIssues()) {
-      System.out.println(issue.message() + " " + issue.key() + " " + issue.ruleKey() + " " + issue.isNew() + " " + issue.resolution() + " " + issue.componentKey() + " " + issue.line());
+      System.out
+        .println(issue.message() + " " + issue.key() + " " + issue.ruleKey() + " " + issue.isNew() + " " + issue.resolution() + " " + issue.componentKey() + " " + issue.line());
       if (issue.isNew()) {
         newIssues++;
       } else if (issue.resolution() != null) {
@@ -165,7 +165,7 @@ public class IssueModeAndReportsMediumTest {
         openIssues++;
       }
     }
-    System.out.println("new: " + newIssues + " open: " +  openIssues + " resolved " + resolvedIssue);
+    System.out.println("new: " + newIssues + " open: " + openIssues + " resolved " + resolvedIssue);
     assertThat(newIssues).isEqualTo(16);
     assertThat(openIssues).isEqualTo(3);
     assertThat(resolvedIssue).isEqualTo(1);
@@ -263,4 +263,32 @@ public class IssueModeAndReportsMediumTest {
     }
   }
 
+  @Test
+  public void noSyntaxHighlightingInIssuesMode() throws IOException {
+
+    File baseDir = temp.newFolder();
+    File srcDir = new File(baseDir, "src");
+    srcDir.mkdir();
+
+    File xooFile = new File(srcDir, "sample.xoo");
+    File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
+    FileUtils.write(xooFile, "Sample xoo\ncontent plop");
+    FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k");
+
+    TaskResult result = tester.newTask()
+      .properties(ImmutableMap.<String, String>builder()
+        .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+        .put("sonar.projectKey", "com.foo.project")
+        .put("sonar.projectName", "Foo Project")
+        .put("sonar.projectVersion", "1.0-SNAPSHOT")
+        .put("sonar.projectDescription", "Description of Foo Project")
+        .put("sonar.sources", "src")
+        .build())
+      .start();
+
+    assertThat(result.getReportReader().hasSyntaxHighlighting(1)).isFalse();
+    assertThat(result.getReportReader().hasSyntaxHighlighting(2)).isFalse();
+    assertThat(result.getReportReader().hasSyntaxHighlighting(3)).isFalse();
+  }
+
 }
index 4ef06e4a0e5a10a3f15ac7ae65eaf35818327c83..5cf546a7be42ccffebb12b083476d29a3bdeba14 100644 (file)
  */
 package org.sonar.batch.source;
 
+import java.io.StringReader;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.ArgumentCaptor;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 
-import java.io.StringReader;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -44,7 +44,7 @@ public class DefaultHighlightableTest {
     SensorStorage sensorStorage = mock(SensorStorage.class);
     DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.php")
       .initMetadata(new FileMetadata().readMetadata(new StringReader("azerty\nbla bla")));
-    DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage);
+    DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage, mock(AnalysisMode.class));
     highlightablePerspective.newHighlighting().highlight(0, 6, "k").highlight(7, 10, "cppd").done();
 
     ArgumentCaptor<DefaultHighlighting> argCaptor = ArgumentCaptor.forClass(DefaultHighlighting.class);
index 385ce1bbd6a89f2f0a2055343a435b2d9c452e7f..465c26fbf67431f27ec42138c39bd2babbbc8425 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.batch.source;
 
 import com.google.common.base.Strings;
+import java.io.StringReader;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -30,8 +31,6 @@ import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.api.source.Symbol;
 import org.sonar.api.source.Symbolizable;
 
-import java.io.StringReader;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class DefaultSymbolTableTest {
index 21803da6c85bead1e8c379ceb6fa634d094f013c..7423d81b77a8e8790aa5cb0c3e435c9eb3fa8f61 100644 (file)
 package org.sonar.batch.source;
 
 import com.google.common.base.Strings;
+import java.io.StringReader;
+import java.util.Map;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.api.source.Symbol;
 import org.sonar.api.source.Symbolizable;
 import org.sonar.batch.sensor.DefaultSensorStorage;
 
-import java.io.StringReader;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
@@ -46,7 +46,7 @@ public class DefaultSymbolizableTest {
     DefaultInputFile inputFile = new DefaultInputFile("foo", "src/Foo.php")
       .initMetadata(new FileMetadata().readMetadata(new StringReader(Strings.repeat("azerty\n", 20))));
 
-    DefaultSymbolizable symbolPerspective = new DefaultSymbolizable(inputFile, sensorStorage);
+    DefaultSymbolizable symbolPerspective = new DefaultSymbolizable(inputFile, sensorStorage, mock(AnalysisMode.class));
     Symbolizable.SymbolTableBuilder symbolTableBuilder = symbolPerspective.newSymbolTableBuilder();
     Symbol firstSymbol = symbolTableBuilder.newSymbol(4, 8);
     symbolTableBuilder.newReference(firstSymbol, 12);
index 2b3d0cc4abf451864159ce944ff54ad26d55820d..2ec6988e950378abbdee954fb502497768789cf5 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.batch.source;
 
 import org.junit.Test;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
@@ -39,7 +40,7 @@ public class HighlightableBuilderTest {
     Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
     BatchComponent component = new BatchComponent(1, file, null).setInputComponent(new DefaultInputFile("foo", "foo.c"));
 
-    HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class));
+    HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class), mock(AnalysisMode.class));
     Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
 
     assertThat(perspective).isNotNull().isInstanceOf(DefaultHighlightable.class);
@@ -49,7 +50,7 @@ public class HighlightableBuilderTest {
   public void project_should_not_be_highlightable() {
     BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null).setInputComponent(new DefaultInputModule("struts"));
 
-    HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class));
+    HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class), mock(AnalysisMode.class));
     Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
 
     assertThat(perspective).isNull();
index 2bc3f32368f702f2c7669ce6ace3896102817cbd..76d0f64b6912dafc0f1850df4acf8285b96b8cd7 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.batch.source;
 
 import org.junit.Test;
+import org.sonar.api.batch.AnalysisMode;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.component.Perspective;
@@ -41,7 +42,7 @@ public class SymbolizableBuilderTest {
     Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
     BatchComponent component = new BatchComponent(1, file, null).setInputComponent(new DefaultInputFile("foo", "foo.c"));
 
-    SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(mock(DefaultSensorStorage.class));
+    SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(mock(DefaultSensorStorage.class), mock(AnalysisMode.class));
     Perspective perspective = perspectiveBuilder.loadPerspective(Symbolizable.class, component);
 
     assertThat(perspective).isInstanceOf(Symbolizable.class);
@@ -51,7 +52,7 @@ public class SymbolizableBuilderTest {
   public void project_should_not_be_highlightable() {
     BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null).setInputComponent(new DefaultInputModule("struts"));
 
-    SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class));
+    SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class), mock(AnalysisMode.class));
     Perspective perspective = builder.loadPerspective(Symbolizable.class, component);
 
     assertThat(perspective).isNull();
index 50019d5eadd140b651f23f7be0ba4509587cc248..9a99185d4afd864dc57178ec71767f1f45bfe747 100644 (file)
@@ -27,6 +27,9 @@ package org.sonar.api.batch;
 public interface AnalysisMode {
   boolean isPreview();
 
+  /**
+   * @since 5.2
+   */
   boolean isIssues();
 
   boolean isPublish();
index 1f1333a65bf2aa8fc9472927273c7fbf7330d4ef..faf3f7536ec7f34347458f18fb1312bbb9847936 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
-import javax.annotation.Nullable;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
@@ -36,14 +35,10 @@ import org.sonar.api.batch.sensor.internal.SensorStorage;
 
 public class DefaultHighlighting extends DefaultStorable implements NewHighlighting {
 
+  private final List<SyntaxHighlightingRule> syntaxHighlightingRules;
   private DefaultInputFile inputFile;
-  private List<SyntaxHighlightingRule> syntaxHighlightingRules;
 
-  public DefaultHighlighting() {
-    this(null);
-  }
-
-  public DefaultHighlighting(@Nullable SensorStorage storage) {
+  public DefaultHighlighting(SensorStorage storage) {
     super(storage);
     syntaxHighlightingRules = new ArrayList<>();
   }
index acd24d674cb10ded14389dd9f5f9c00ed07feb7b..76378512ff5b670a6266c2263b695f36cec36671 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.api.batch.sensor.highlighting.internal;
 
+import java.util.Collection;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -29,8 +30,6 @@ import org.sonar.api.batch.fs.internal.DefaultTextPointer;
 import org.sonar.api.batch.fs.internal.DefaultTextRange;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 
-import java.util.Collection;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.sonar.api.batch.sensor.highlighting.TypeOfText.COMMENT;