aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStore.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/InputComponentStoreProvider.java5
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java7
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java26
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java2
23 files changed, 81 insertions, 65 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);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java
index b8bdfa48233..0d0ead878ab 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java
@@ -49,7 +49,6 @@ import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
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 static org.assertj.core.api.Assertions.assertThat;
@@ -91,7 +90,7 @@ public class CpdExecutorTest {
index = new SonarCpdBlockIndex(publisher, settings);
DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
- componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class));
+ componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig);
reader = new ScannerReportReader(outputDir);
@@ -102,7 +101,7 @@ public class CpdExecutorTest {
@Test
public void skipIfShortBranch() {
- when(branchConfig.branchType()).thenReturn(BranchType.SHORT);
+ when(branchConfig.isShortLivingBranch()).thenReturn(true);
index = mock(SonarCpdBlockIndex.class);
executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
index bf4b0f4f310..58d9133dddc 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
@@ -42,8 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BranchMediumTest {
+ private static final String PROJECT_KEY = "sample";
+ private static final String FILE_PATH = "HelloJava.xoo";
+ private static final String FILE_CONTENT = "xoooo";
private File baseDir;
- private final String relativePath = "HelloJava.xoo";
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -58,24 +60,31 @@ public class BranchMediumTest {
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
- Path filepath = baseDir.toPath().resolve(relativePath);
- Files.write(filepath, "xoooo".getBytes());
+ Path filepath = baseDir.toPath().resolve(FILE_PATH);
+ Files.write(filepath, FILE_CONTENT.getBytes());
String md5sum = new FileMetadata()
- .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, relativePath)
+ .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, FILE_PATH)
.hash();
- tester.addFileData("sample", relativePath, new FileData(md5sum, null));
+ tester.addFileData(PROJECT_KEY, FILE_PATH, new FileData(md5sum, "1.1"));
}
@Test
public void should_skip_report_for_unchanged_files_in_short_branch() {
// sanity check, normally report gets generated
TaskResult result = getResult(tester);
- assertThat(getResult(tester).getReportComponent(result.inputFile(relativePath).key())).isNotNull();
+ assertThat(getResult(tester).getReportComponent(result.inputFile(FILE_PATH).key())).isNotNull();
+ int fileId = 2;
+ assertThat(result.getReportReader().readChangesets(fileId)).isNotNull();
+ assertThat(result.getReportReader().hasCoverage(fileId)).isTrue();
+ assertThat(result.getReportReader().readFileSource(fileId)).isNotNull();
// file is skipped for short branches (no report, no coverage, no duplications)
TaskResult result2 = getResult(tester.setBranchType(BranchConfiguration.BranchType.SHORT));
- assertThat(result2.getReportComponent(result2.inputFile(relativePath).key())).isNull();
+ assertThat(result2.getReportComponent(result2.inputFile(FILE_PATH).key())).isNull();
+ assertThat(result2.getReportReader().readChangesets(fileId)).isNull();
+ assertThat(result2.getReportReader().hasCoverage(fileId)).isFalse();
+ assertThat(result.getReportReader().readFileSource(fileId)).isNull();
}
@Test
@@ -100,8 +109,9 @@ public class BranchMediumTest {
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
.put("sonar.projectBaseDir", baseDir.getAbsolutePath())
- .put("sonar.projectKey", "sample")
+ .put("sonar.projectKey", PROJECT_KEY)
.put("sonar.sources", ".")
+ .put("sonar.scm.provider", "xoo")
.build())
.execute();
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
index fbf81aa0c7e..2fc4af185a3 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
@@ -31,7 +31,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.utils.PathUtils;
import org.sonar.api.utils.log.LogTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester.TaskBuilder;
@@ -180,7 +179,7 @@ public class ScmMediumTest {
assertThat(fileWithoutBlameScm).isNull();
assertThat(logTester.logs()).containsSubsequence("2 files to be analyzed", "1/2 files analyzed", MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES,
- " * " + PathUtils.sanitize(xooFileWithoutBlame.toPath().toString()));
+ " * src/sample_no_blame.xoo");
}
// SONAR-6397
@@ -239,7 +238,7 @@ public class ScmMediumTest {
// 5 .xoo files + 3 .scm files, but only 4 marked for publishing. 1 file is SAME so not included in the total
assertThat(logTester.logs()).containsSubsequence("8 files indexed");
assertThat(logTester.logs()).containsSubsequence("4 files to be analyzed", "3/4 files analyzed");
- assertThat(logTester.logs()).containsSubsequence(MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES, " * " + noBlameScmOnServer.getPath().replaceAll("\\\\", "/"));
+ assertThat(logTester.logs()).containsSubsequence(MISSING_BLAME_INFORMATION_FOR_THE_FOLLOWING_FILES, " * src/no_blame_scm_on_server.xoo");
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
index 8d0eb0085da..f39cafcadb7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.java
@@ -33,6 +33,7 @@ import org.sonar.api.batch.rule.Severity;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
+import org.sonar.scanner.scan.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,7 +55,7 @@ public class DefaultPostJobContextTest {
public void setUp() throws IOException {
issueCache = mock(IssueCache.class);
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder());
- componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class));
+ componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
settings = new MapSettings();
analysisMode = mock(AnalysisMode.class);
context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
index 5b0406bdfc1..a03afd14359 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
@@ -313,7 +313,7 @@ public class ComponentsPublisherTest {
@Test
public void skip_unchanged_components_in_short_branches() throws IOException {
- when(branchConfiguration.branchType()).thenReturn(BranchType.SHORT);
+ when(branchConfiguration.isShortLivingBranch()).thenReturn(true);
ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java
index 76ce5527497..f2a0e614bae 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java
@@ -35,6 +35,7 @@ import org.sonar.core.util.CloseableIterator;
import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage;
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.filesystem.InputComponentStore;
import org.sonar.scanner.scan.measure.MeasureCache;
@@ -58,7 +59,7 @@ public class CoveragePublisherTest {
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
- InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class));
+ InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java
index 3e5c7d507e5..31a60b633c8 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MeasuresPublisherTest.java
@@ -39,6 +39,7 @@ import org.sonar.scanner.deprecated.test.TestPlanBuilder;
import org.sonar.scanner.protocol.output.ScannerReport;
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.filesystem.InputComponentStore;
import org.sonar.scanner.scan.measure.MeasureCache;
@@ -69,7 +70,7 @@ public class MeasuresPublisherTest {
String moduleKey = "foo";
inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
- InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class));
+ InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java
index 60b51e5a8f2..b859b3962e8 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/SourcePublisherTest.java
@@ -33,6 +33,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
+import org.sonar.scanner.scan.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import static org.assertj.core.api.Assertions.assertThat;
@@ -62,7 +63,7 @@ public class SourcePublisherTest {
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir);
analysisMode = mock(AnalysisMode.class);
- InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode);
+ InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode, mock(BranchConfiguration.class));
componentStore.put(inputFile);
publisher = new SourcePublisher(componentStore);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java
index a11e500c302..e9d075d327e 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java
@@ -38,7 +38,7 @@ public class ModuleIndexerTest {
private InputComponentStore componentStore;
public void createIndexer(DefaultInputModule rootModule) {
- componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class));
+ componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
tree = new DefaultComponentTree();
moduleHierarchy = mock(DefaultInputModuleHierarchy.class);
indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java
index 8d3f530c25f..aacfb609f52 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java
@@ -36,6 +36,7 @@ import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.scanner.scan.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -59,7 +60,7 @@ public class InputComponentStoreTest {
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
- InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class));
+ InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
cache.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java")
@@ -103,7 +104,7 @@ public class InputComponentStoreTest {
static class InputComponentStoreTester extends InputComponentStore {
InputComponentStoreTester() throws IOException {
- super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class));
+ super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class), mock(BranchConfiguration.class));
}
InputFile addFile(String moduleKey, String relpath, String language) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
index 0911d7436c7..9856377a92c 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleInputComponentStoreTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
+import org.sonar.scanner.scan.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -48,7 +49,7 @@ public class ModuleInputComponentStoreTest {
@Before
public void setUp() throws IOException {
DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
- componentStore = new InputComponentStore(root, mock(AnalysisMode.class));
+ componentStore = new InputComponentStore(root, mock(AnalysisMode.class), mock(BranchConfiguration.class));
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java
index 148dabfdab9..4b005062ddb 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java
@@ -48,6 +48,7 @@ import org.sonar.api.platform.Server;
import org.sonar.api.rule.RuleKey;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
+import org.sonar.scanner.scan.BranchConfiguration;
import org.sonar.scanner.scan.DefaultComponentTree;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
@@ -83,7 +84,7 @@ public class JSONReportTest {
DefaultComponentTree inputComponentTree = new DefaultComponentTree();
ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts");
DefaultInputModule rootModule = new DefaultInputModule(def, 1);
- InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class));
+ InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.class), mock(BranchConfiguration.class));
DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
inputComponentTree.index(moduleA, rootModule);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
index 92c62a33436..aa62800ee91 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
@@ -91,7 +91,7 @@ public class DefaultSensorContextTest {
@Test
public void shouldSkipDupsAndCoverageOnShortBranches() {
- when(branchConfig.branchType()).thenReturn(BranchConfiguration.BranchType.SHORT);
+ when(branchConfig.isShortLivingBranch()).thenReturn(true);
assertThat(adaptor.newCpdTokens()).isEqualTo(DefaultSensorContext.NO_OP_NEW_CPD_TOKENS);
assertThat(adaptor.newCoverage()).isEqualTo(DefaultSensorContext.NO_OP_NEW_COVERAGE);
}