import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.BatchSide;
+import org.sonar.api.batch.ScannerSide;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
*
* @since 6.0
*/
-@BatchSide
+@ScannerSide
@ServerSide
@ComputeEngineSide
@SonarLintSide
return moduleKey;
}
+ @Override
public Charset charset() {
return charset;
}
checkInputFileNotNull();
TextRange newRange;
try {
- // TODO remove when SONAR-7664 is implemented
- Preconditions.checkArgument(startOffset < endOffset, "start offset should be strictly before end offset");
newRange = inputFile.newRange(startOffset, endOffset);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to highlight file " + inputFile, e);
* Allow to redirect batch logs to a custom output. By defaults logs are written to System.out
* @since 5.2
*/
+@FunctionalInterface
public interface LogOutput {
void log(String formattedMessage, Level level);
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.log.Logger;
import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
import org.sonar.scanner.report.ReportPublisher;
import org.sonar.scanner.util.ProgressReport;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
import static com.google.common.collect.FluentIterable.from;
/**
* @since 3.7
*/
+@FunctionalInterface
public interface BatchStepHandler extends EventHandler {
/**
return bucket;
}
- public boolean isExcluded(@Nullable Resource reference) {
- return false;
- }
-
- public boolean isIndexed(@Nullable Resource reference, boolean acceptExcluded) {
- return getBucket(reference) != null;
- }
-
private Bucket getBucket(@Nullable Resource reference) {
if (reference == null) {
return null;
*/
package org.sonar.scanner.issue.ignore.scanner;
+import java.nio.charset.Charset;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.api.resources.Project;
import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
-import java.nio.charset.Charset;
public final class IssueExclusionsLoader {
this.fileSystem = fileSystem;
}
- public boolean shouldExecuteOnProject(Project project) {
+ public boolean shouldExecute() {
return inclusionPatternInitializer.hasConfiguredPatterns()
|| exclusionPatternInitializer.hasConfiguredPatterns();
}
*/
package org.sonar.scanner.mediumtest;
+import org.sonar.api.ExtensionPoint;
import org.sonar.api.batch.ScannerSide;
import org.sonar.scanner.scan.ProjectScanContainer;
-import org.sonar.api.ExtensionPoint;
@ScannerSide
@ExtensionPoint
+@FunctionalInterface
public interface ScanTaskObserver {
void scanTaskCompleted(ProjectScanContainer container);
protected abstract void executeOnRoot();
private void initIssueExclusions() {
- String stepName = "Init issue exclusions";
- eventBus.fireEvent(new BatchStepEvent(stepName, true));
- issueExclusionsLoader.execute();
- eventBus.fireEvent(new BatchStepEvent(stepName, false));
+ if (issueExclusionsLoader.shouldExecute()) {
+ String stepName = "Init issue exclusions";
+ eventBus.fireEvent(new BatchStepEvent(stepName, true));
+ issueExclusionsLoader.execute();
+ eventBus.fireEvent(new BatchStepEvent(stepName, false));
+ }
}
private void indexFs() {
/**
* Adds a sub-part of data to output report
*/
+@FunctionalInterface
public interface ReportPublisherStep {
void publish(ScannerReportWriter writer);
import static org.sonar.core.util.stream.Collectors.toList;
-/**
- * FIXME Waiting for the list of all server rules on batch side this is implemented by redirecting on ActiveRules. This is not correct
- * since there is a difference between a rule that doesn't exists and a rule that is not activated in project quality profile.
- *
- */
public class RuleFinderCompatibility implements RuleFinder {
private final Rules rules;
import org.sonar.scanner.DefaultProjectTree;
import org.sonar.scanner.bootstrap.BatchExtensionDictionnary;
import org.sonar.scanner.bootstrap.ExtensionInstaller;
-import org.sonar.scanner.bootstrap.ExtensionMatcher;
import org.sonar.scanner.bootstrap.ExtensionUtils;
import org.sonar.scanner.deprecated.DeprecatedSensorContext;
import org.sonar.scanner.deprecated.perspectives.BatchPerspectives;
private void addExtensions() {
ExtensionInstaller installer = getComponentByType(ExtensionInstaller.class);
- installer.install(this, new ExtensionMatcher() {
- @Override
- public boolean accept(Object extension) {
- return ExtensionUtils.isScannerSide(extension) && ExtensionUtils.isInstantiationStrategy(extension, InstantiationStrategy.PER_PROJECT);
- }
- });
+ installer.install(this, e -> ExtensionUtils.isScannerSide(e) && ExtensionUtils.isInstantiationStrategy(e, InstantiationStrategy.PER_PROJECT));
}
@Override
int newIssues = r.totalNewIssues;
if (newIssues > 0) {
sb.append(StringUtils.leftPad("+" + newIssues, LEFT_PAD)).append(" issue" + (newIssues > 1 ? "s" : "")).append("\n\n");
- printNewIssues(sb, r.newBlockerIssues, Severity.BLOCKER, "blocker");
- printNewIssues(sb, r.newCriticalIssues, Severity.CRITICAL, "critical");
- printNewIssues(sb, r.newMajorIssues, Severity.MAJOR, "major");
- printNewIssues(sb, r.newMinorIssues, Severity.MINOR, "minor");
- printNewIssues(sb, r.newInfoIssues, Severity.INFO, "info");
+ printNewIssues(sb, r.newBlockerIssues, "blocker");
+ printNewIssues(sb, r.newCriticalIssues, "critical");
+ printNewIssues(sb, r.newMajorIssues, "major");
+ printNewIssues(sb, r.newMinorIssues, "minor");
+ printNewIssues(sb, r.newInfoIssues, "info");
} else {
sb.append(" No new issue").append("\n");
}
}
- private static void printNewIssues(StringBuilder sb, int issueCount, String severity, String severityLabel) {
+ private static void printNewIssues(StringBuilder sb, int issueCount, String severityLabel) {
if (issueCount > 0) {
sb.append(StringUtils.leftPad("+" + issueCount, LEFT_PAD)).append(" ").append(severityLabel).append("\n");
}
package org.sonar.scanner.scan.report;
import com.google.common.collect.Maps;
-
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
-
import org.sonar.api.batch.rule.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.scanner.index.BatchComponent;
public void addIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) {
addResource(resource);
getSummary().addIssue(issue, rule, severity);
- resourceReportsByResource.get(resource).addIssue(issue, rule, RulePriority.valueOf(issue.severity()));
+ resourceReportsByResource.get(resource).addIssue(issue, rule, severity);
}
- public void addResolvedIssueOnResource(BatchComponent resource, TrackedIssue issue, Rule rule, RulePriority severity) {
+ public void addResolvedIssueOnResource(BatchComponent resource, Rule rule, RulePriority severity) {
addResource(resource);
- getSummary().addResolvedIssue(issue, rule, severity);
- resourceReportsByResource.get(resource).addResolvedIssue(rule, RulePriority.valueOf(issue.severity()));
+ getSummary().addResolvedIssue(rule, severity);
+ resourceReportsByResource.get(resource).addResolvedIssue(rule, severity);
}
private void addResource(BatchComponent resource) {
package org.sonar.scanner.scan.report;
import javax.annotation.CheckForNull;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.ScannerSide;
continue;
}
if (issue.resolution() != null) {
- issuesReport.addResolvedIssueOnResource(resource, issue, rule, severity);
+ issuesReport.addResolvedIssueOnResource(resource, rule, severity);
} else {
issuesReport.addIssueOnResource(resource, issue, rule, severity);
}
return totalByRuleKey;
}
- public void addResolvedIssue(TrackedIssue issue, Rule rule, RulePriority severity) {
+ public void addResolvedIssue(Rule rule, RulePriority severity) {
ReportRuleKey reportRuleKey = new ReportRuleKey(rule, severity);
initMaps(reportRuleKey);
total.incrementResolvedIssuesCount();
import org.sonar.api.batch.ScannerSide;
@ScannerSide
+@FunctionalInterface
public interface Reporter {
void execute();
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
-import org.sonar.scanner.FakeJava;
import org.sonar.scanner.DefaultProjectTree;
-import org.sonar.scanner.index.BatchComponentCache;
-import org.sonar.scanner.index.DefaultIndex;
+import org.sonar.scanner.FakeJava;
import org.sonar.scanner.scan.measure.MeasureCache;
import org.sonar.scanner.sensor.DefaultSensorStorage;
Directory reference = Directory.create("src/org/foo");
assertThat(index.getResource(reference).getName()).isEqualTo("src/org/foo");
- assertThat(index.isIndexed(reference, true)).isTrue();
- assertThat(index.isExcluded(reference)).isFalse();
assertThat(index.getChildren(reference)).hasSize(1);
assertThat(index.getParent(reference)).isInstanceOf(Project.class);
}
File fileRef = File.create("src/org/foo/Bar.java", null, false);
assertThat(index.getResource(fileRef).getKey()).isEqualTo("src/org/foo/Bar.java");
assertThat(index.getResource(fileRef).getLanguage().getKey()).isEqualTo("java");
- assertThat(index.isIndexed(fileRef, true)).isTrue();
- assertThat(index.isExcluded(fileRef)).isFalse();
assertThat(index.getChildren(fileRef)).isEmpty();
assertThat(index.getParent(fileRef)).isInstanceOf(Directory.class);
}
assertThat(index.index(file, directory)).isFalse();
File fileRef = File.create("src/org/foo/Bar.java", null, false);
- assertThat(index.isIndexed(directory, true)).isFalse();
- assertThat(index.isIndexed(fileRef, true)).isFalse();
- assertThat(index.isExcluded(fileRef)).isFalse();
assertThat(index.getChildren(fileRef)).isEmpty();
assertThat(index.getParent(fileRef)).isNull();
}
Resource dir = Directory.create("src/org/foo");
index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
- assertThat(index.isIndexed(dir, true)).isFalse();
assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull();
}
*/
package org.sonar.scanner.issue.ignore.scanner;
+import java.io.File;
+import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
import org.sonar.scanner.issue.ignore.pattern.PatternMatcher;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsRegexpScanner;
-import java.io.File;
-import java.io.IOException;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
public void shouldExecute() {
when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
- assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+ assertThat(scanner.shouldExecute()).isTrue();
when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
- assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+ assertThat(scanner.shouldExecute()).isTrue();
when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(true);
- assertThat(scanner.shouldExecuteOnProject(null)).isTrue();
+ assertThat(scanner.shouldExecute()).isTrue();
when(exclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
when(inclusionPatternInitializer.hasConfiguredPatterns()).thenReturn(false);
- assertThat(scanner.shouldExecuteOnProject(null)).isFalse();
+ assertThat(scanner.shouldExecute()).isFalse();
}