aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-09-15 16:50:12 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-09-17 16:48:24 +0200
commitce60ac8d2e137f33bb111668e54e78c195c73d79 (patch)
tree7a99ab075ee9c85ec71cfa5ee65c2aed794feb04 /sonar-batch/src/main
parent0d1b0b7a200c12d6f966cf1d7e7ec23d3db30760 (diff)
downloadsonarqube-ce60ac8d2e137f33bb111668e54e78c195c73d79.tar.gz
sonarqube-ce60ac8d2e137f33bb111668e54e78c195c73d79.zip
No op for highlighting and symbol references in issues mode
Diffstat (limited to 'sonar-batch/src/main')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java29
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java22
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java65
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java7
7 files changed, 150 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
index a4f7c8c8b2e..04b5724b2c3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java
@@ -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);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
index 57197abc0a1..cb58332f96c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java
@@ -19,8 +19,10 @@
*/
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);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java
index e03531d243e..6d38bbb320b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultHighlightable.java
@@ -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;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
index e2bbf13bfa8..ce9766e0859 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolTable.java
@@ -20,13 +20,18 @@
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;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
index f65cb609c21..5089a9cca47 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/DefaultSymbolizable.java
@@ -20,27 +20,90 @@
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());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java
index 067b96d882e..69acf876cd9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/HighlightableBuilder.java
@@ -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;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java
index fc377e0d820..48d7033a6b5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/source/SymbolizableBuilder.java
@@ -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;
}