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);
*/
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;
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;
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;
@Override
public NewHighlighting newHighlighting() {
+ if (analysisMode.isIssues()) {
+ return NO_OP_NEW_HIGHLIGHTING;
+ }
return new DefaultHighlighting(sensorStorage);
}
*/
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;
*/
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;
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;
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;
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());
}
}
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;
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
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;
}
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;
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
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;
}
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")
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")
*/
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;
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 {
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) {
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);
}
}
+ @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();
+ }
+
}
*/
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;
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);
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;
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 {
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;
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);
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;
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);
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();
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;
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);
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();
public interface AnalysisMode {
boolean isPreview();
+ /**
+ * @since 5.2
+ */
boolean isIssues();
boolean isPublish();
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;
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<>();
}
*/
package org.sonar.api.batch.sensor.highlighting.internal;
+import java.util.Collection;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
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;