diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-09-06 16:34:06 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:59 +0200 |
commit | 39c110298f71325ce73d584e5034acc904c32c40 (patch) | |
tree | 09da55bd5ec1affaa68d7d97dfd588e2a3d41efe /sonar-scanner-engine/src/main/java/org/sonar/scanner | |
parent | 579aa0457917229ed583c782563552ae957e121d (diff) | |
download | sonarqube-39c110298f71325ce73d584e5034acc904c32c40.tar.gz sonarqube-39c110298f71325ce73d584e5034acc904c32c40.zip |
SONAR-9701 Don't publish coverage, scm and source of unchanged files
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner')
10 files changed, 41 insertions, 40 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java index b90ab462a6e..6e7bf1a508c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java @@ -28,7 +28,6 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.bootstrap.AbstractAnalysisMode; import org.sonar.scanner.bootstrap.GlobalProperties; import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; @Immutable public class DefaultAnalysisMode extends AbstractAnalysisMode { @@ -50,13 +49,12 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode { // make sure analysis is consistent with global properties boolean globalPreview = isIssues(globalProps); boolean analysisPreview = isIssues(analysisProps); - boolean shortLivingBranch = branchConfig.branchType() == BranchType.SHORT; if (!globalPreview && analysisPreview) { throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it"); } - load(globalProps, analysisProps, shortLivingBranch); + load(globalProps, analysisProps, branchConfig.isShortLivingBranch()); } private void load(Map<String, String> globalProps, Map<String, String> analysisProps, boolean isShortLivingBranch) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java index 1ce8033e270..af5bddfc8f5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java @@ -19,8 +19,9 @@ */ package org.sonar.scanner.cpd; -import static com.google.common.collect.FluentIterable.from; - +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; @@ -29,7 +30,6 @@ 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.InputComponent; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputComponent; @@ -46,13 +46,10 @@ import org.sonar.scanner.protocol.output.ScannerReport.Duplicate; import org.sonar.scanner.protocol.output.ScannerReport.Duplication; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; import org.sonar.scanner.scan.filesystem.InputComponentStore; import org.sonar.scanner.util.ProgressReport; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Predicate; +import static com.google.common.collect.FluentIterable.from; /** * Runs on the root module, at the end of the project analysis. @@ -86,7 +83,7 @@ public class CpdExecutor { } public void execute() { - if (branchConfiguration.branchType() == BranchType.SHORT) { + if (branchConfiguration.isShortLivingBranch()) { LOG.info("Skipping CPD calculation for short living branch"); return; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index 84275b0d0e2..c8dd7a3097b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -45,7 +45,6 @@ import org.sonar.scanner.protocol.output.ScannerReport.Issue; import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; /** * Adds components and analysis metadata to output report @@ -65,10 +64,6 @@ public class ComponentsPublisher implements ReportPublisherStep { this.branchConfiguration = branchConfiguration; } - private boolean isShortLivingBranch() { - return branchConfiguration.branchType() == BranchType.SHORT; - } - @Override public void publish(ScannerReportWriter writer) { this.reader = new ScannerReportReader(writer.getFileStructure().root()); @@ -175,7 +170,7 @@ public class ComponentsPublisher implements ReportPublisherStep { } private boolean shouldSkipComponent(DefaultInputComponent component, Collection<InputComponent> children) { - if (component instanceof InputModule && children.isEmpty() && isShortLivingBranch()) { + if (component instanceof InputModule && children.isEmpty() && branchConfiguration.isShortLivingBranch()) { // no children on a module in short branch analysis -> skip it (except root) return !moduleHierarchy.isRoot((InputModule) component); } else if (component instanceof InputDir && children.isEmpty()) { @@ -188,7 +183,7 @@ public class ComponentsPublisher implements ReportPublisherStep { } else if (component instanceof DefaultInputFile) { // skip files not marked for publishing DefaultInputFile inputFile = (DefaultInputFile) component; - return !inputFile.isPublished() || (isShortLivingBranch() && inputFile.status() == Status.SAME); + return !inputFile.isPublished() || (branchConfiguration.isShortLivingBranch() && inputFile.status() == Status.SAME); } return false; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java index f6a2626d8d3..2a4152c6174 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java @@ -40,6 +40,10 @@ public interface BranchConfiguration { */ BranchType branchType(); + default boolean isShortLivingBranch() { + return branchType() == BranchType.SHORT; + } + /** * The name of the branch. */ diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index 060b7d21026..edbb9bfd689 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -253,12 +253,14 @@ public class ProjectScanContainer extends ComponentContainer { } private static String toDisplayName(BranchConfiguration.BranchType branchType) { - if (branchType == BranchConfiguration.BranchType.LONG) { - return "long living"; - } else if (branchType == BranchConfiguration.BranchType.SHORT) { - return "short living"; + switch (branchType) { + case LONG: + return "long living"; + case SHORT: + return "short living"; + default: + throw new UnsupportedOperationException("unknown branch type: " + branchType); } - throw new UnsupportedOperationException("unknown branch type: " + branchType); } private void scanRecursively(InputModuleHierarchy tree, DefaultInputModule module) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java index 0138e851c68..3c50e847b28 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java @@ -44,6 +44,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.FileExtensionPredicate; import org.sonar.api.scan.filesystem.PathResolver; +import org.sonar.scanner.scan.BranchConfiguration; /** * Store of all files and dirs. This cache is shared amongst all project modules. Inclusion and @@ -65,10 +66,12 @@ public class InputComponentStore { private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create(); private final InputModule root; private final AnalysisMode mode; + private final BranchConfiguration branchConfiguration; - public InputComponentStore(DefaultInputModule root, AnalysisMode mode) { + public InputComponentStore(DefaultInputModule root, AnalysisMode mode, BranchConfiguration branchConfiguration) { this.root = root; this.mode = mode; + this.branchConfiguration = branchConfiguration; this.put(root); } @@ -80,7 +83,7 @@ public class InputComponentStore { return inputFileCache.values().stream() .map(f -> (DefaultInputFile) f) .filter(DefaultInputFile::isPublished) - .filter(f -> !mode.isIncremental() || f.status() != Status.SAME)::iterator; + .filter(f -> (!mode.isIncremental() && !branchConfiguration.isShortLivingBranch()) || f.status() != Status.SAME)::iterator; } public Iterable<InputFile> allFiles() { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java index 2225f245207..f8e55b011de 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java @@ -22,13 +22,14 @@ package org.sonar.scanner.scan.filesystem; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; +import org.sonar.scanner.scan.BranchConfiguration; public class InputComponentStoreProvider extends ProviderAdapter { private InputComponentStore store; - public InputComponentStore provide(InputModuleHierarchy hierarchy, AnalysisMode mode) { + public InputComponentStore provide(InputModuleHierarchy hierarchy, AnalysisMode mode, BranchConfiguration branchConfiguration) { if (store == null) { - store = new InputComponentStore(hierarchy.root(), mode); + store = new InputComponentStore(hierarchy.root(), mode, branchConfiguration); } return store; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java index 5e12f1e821a..6fd503098b9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java @@ -23,6 +23,7 @@ import com.google.common.base.Preconditions; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -62,10 +63,10 @@ class DefaultBlameOutput implements BlameOutput { public synchronized void blameResult(InputFile file, List<BlameLine> lines) { Preconditions.checkNotNull(file); Preconditions.checkNotNull(lines); - Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file.relativePath()); + Preconditions.checkArgument(allFilesToBlame.contains(file), "It was not expected to blame file %s", file); if (lines.size() != file.lines()) { - LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file.relativePath(), file.lines()); + LOG.debug("Ignoring blame result since provider returned {} blame lines but file {} has {} lines", lines.size(), file, file.lines()); return; } @@ -93,8 +94,8 @@ class DefaultBlameOutput implements BlameOutput { } private static void validateLine(BlameLine line, int lineId, InputFile file) { - Preconditions.checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file.relativePath(), lineId); - Preconditions.checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file.relativePath(), lineId); + Preconditions.checkArgument(StringUtils.isNotBlank(line.revision()), "Blame revision is blank for file %s at line %s", file, lineId); + Preconditions.checkArgument(line.date() != null, "Blame date is null for file %s at line %s", file, lineId); } private static void addChangeset(Builder scmBuilder, BlameLine line) { @@ -112,7 +113,7 @@ class DefaultBlameOutput implements BlameOutput { if (inputString == null) { return ""; } - return inputString.toLowerCase(); + return inputString.toLowerCase(Locale.US); } public void finish(boolean success) { @@ -120,7 +121,7 @@ class DefaultBlameOutput implements BlameOutput { if (success && !allFilesToBlame.isEmpty()) { LOG.warn("Missing blame information for the following files:"); for (InputFile f : allFilesToBlame) { - LOG.warn(" * " + f.absolutePath()); + LOG.warn(" * " + f); } LOG.warn("This may lead to missing/broken features in SonarQube"); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java index 27c185fe545..50cf4958c5f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java @@ -37,6 +37,7 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter; import org.sonar.scanner.report.ReportPublisher; import org.sonar.scanner.repository.FileData; import org.sonar.scanner.repository.ProjectRepositories; +import org.sonar.scanner.scan.BranchConfiguration; import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; import org.sonar.scanner.scan.filesystem.ModuleInputComponentStore; @@ -52,14 +53,16 @@ public final class ScmPublisher { private final ModuleInputComponentStore componentStore; private final DefaultModuleFileSystem fs; private final ScannerReportWriter writer; + private final BranchConfiguration branchConfiguration; public ScmPublisher(DefaultInputModule inputModule, ScmConfiguration configuration, ProjectRepositories projectRepositories, - ModuleInputComponentStore componentStore, DefaultModuleFileSystem fs, ReportPublisher reportPublisher) { + ModuleInputComponentStore componentStore, DefaultModuleFileSystem fs, ReportPublisher reportPublisher, BranchConfiguration branchConfiguration) { this.inputModule = inputModule; this.configuration = configuration; this.projectRepositories = projectRepositories; this.componentStore = componentStore; this.fs = fs; + this.branchConfiguration = branchConfiguration; this.writer = reportPublisher.getWriter(); } @@ -100,7 +103,7 @@ public final class ScmPublisher { } if (configuration.forceReloadAll() || f.status() != Status.SAME) { addIfNotEmpty(filesToBlame, f); - } else { + } else if (!branchConfiguration.isShortLivingBranch()) { // File status is SAME so that mean fileData exists FileData fileData = projectRepositories.fileData(inputModule.definition().getKeyWithBranch(), inputFile.getModuleRelativePath()); if (StringUtils.isEmpty(fileData.revision())) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java index f6575cfea60..db2e7f8e014 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java @@ -20,9 +20,7 @@ package org.sonar.scanner.sensor; import java.io.Serializable; - import javax.annotation.concurrent.ThreadSafe; - import org.sonar.api.SonarRuntime; import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.fs.FileSystem; @@ -49,7 +47,6 @@ import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.utils.Version; import org.sonar.scanner.scan.BranchConfiguration; -import org.sonar.scanner.scan.BranchConfiguration.BranchType; import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError; import org.sonar.scanner.sensor.noop.NoOpNewCoverage; import org.sonar.scanner.sensor.noop.NoOpNewCpdTokens; @@ -151,7 +148,7 @@ public class DefaultSensorContext implements SensorContext { @Override public NewCoverage newCoverage() { - if (branchConfiguration.branchType() == BranchType.SHORT) { + if (branchConfiguration.isShortLivingBranch()) { return NO_OP_NEW_COVERAGE; } return new DefaultCoverage(sensorStorage); @@ -159,7 +156,7 @@ public class DefaultSensorContext implements SensorContext { @Override public NewCpdTokens newCpdTokens() { - if (analysisMode.isIssues() || branchConfiguration.branchType() == BranchType.SHORT) { + if (analysisMode.isIssues() || branchConfiguration.isShortLivingBranch()) { return NO_OP_NEW_CPD_TOKENS; } return new DefaultCpdTokens(config, sensorStorage); |