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/cpd/CpdExecutor.java16
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java21
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java3
3 files changed, 5 insertions, 35 deletions
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 f0b923791a0..89e2cd0569c 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
@@ -34,7 +34,6 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.sonar.api.batch.fs.InputComponent;
-import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.utils.log.Logger;
@@ -49,7 +48,6 @@ import org.sonar.scanner.protocol.output.ScannerReport;
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.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import org.sonar.scanner.util.ProgressReport;
@@ -68,24 +66,22 @@ public class CpdExecutor {
private final SonarCpdBlockIndex index;
private final ReportPublisher publisher;
private final InputComponentStore componentStore;
- private final BranchConfiguration branchConfiguration;
private final ProgressReport progressReport;
private final CpdSettings settings;
private final ExecutorService executorService;
private int count = 0;
private int total;
- public CpdExecutor(CpdSettings settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache, BranchConfiguration branchConfiguration) {
- this(settings, index, publisher, inputComponentCache, branchConfiguration, Executors.newSingleThreadExecutor());
+ public CpdExecutor(CpdSettings settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache) {
+ this(settings, index, publisher, inputComponentCache, Executors.newSingleThreadExecutor());
}
public CpdExecutor(CpdSettings settings, SonarCpdBlockIndex index, ReportPublisher publisher, InputComponentStore inputComponentCache,
- BranchConfiguration branchConfiguration, ExecutorService executorService) {
+ ExecutorService executorService) {
this.settings = settings;
this.index = index;
this.publisher = publisher;
this.componentStore = inputComponentCache;
- this.branchConfiguration = branchConfiguration;
this.progressReport = new ProgressReport("CPD computation", TimeUnit.SECONDS.toMillis(10));
this.executorService = executorService;
}
@@ -102,7 +98,7 @@ public class CpdExecutor {
while (it.hasNext()) {
ResourceBlocks resourceBlocks = it.next();
Optional<FileBlocks> fileBlocks = toFileBlocks(resourceBlocks.resourceId(), resourceBlocks.blocks());
- if (!fileBlocks.isPresent() || shouldSkip(fileBlocks.get().getInputFile())) {
+ if (!fileBlocks.isPresent()) {
continue;
}
components.add(fileBlocks.get());
@@ -129,10 +125,6 @@ public class CpdExecutor {
}
}
- private boolean shouldSkip(DefaultInputFile inputFile) {
- return branchConfiguration.isShortOrPullRequest() && inputFile.status() == InputFile.Status.SAME;
- }
-
private static String pluralize(int files) {
return files == 1 ? "file" : "files";
}
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 8acc34a63b3..30b257eb2f6 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
@@ -36,7 +36,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatchers;
-import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
@@ -76,13 +75,11 @@ public class CpdExecutorTest {
private ExecutorService executorService = mock(ExecutorService.class);
private CpdSettings settings = mock(CpdSettings.class);
private ReportPublisher publisher = mock(ReportPublisher.class);
- private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
private SonarCpdBlockIndex index = new SonarCpdBlockIndex(publisher, settings);
private ScannerReportReader reader;
private DefaultInputFile batchComponent1;
private DefaultInputFile batchComponent2;
private DefaultInputFile batchComponent3;
- private DefaultInputFile batchComponent4;
private File baseDir;
private InputComponentStore componentStore;
@@ -94,13 +91,12 @@ public class CpdExecutorTest {
DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
componentStore = new InputComponentStore(inputModule, mock(BranchConfiguration.class));
- executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfiguration, executorService);
+ executor = new CpdExecutor(settings, index, publisher, componentStore, executorService);
reader = new ScannerReportReader(outputDir);
batchComponent1 = createComponent("src/Foo.php", 5);
batchComponent2 = createComponent("src/Foo2.php", 5);
batchComponent3 = createComponent("src/Foo3.php", 5);
- batchComponent4 = createComponent("src/Foo4.php", 5, f -> f.setStatus(InputFile.Status.SAME));
}
@Test
@@ -196,21 +192,6 @@ public class CpdExecutorTest {
}
@Test
- public void should_ignore_unmodified_files_in_SLB() {
- when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
- Block block = Block.builder()
- .setBlockHash(new ByteArray("AAAABBBBCCCC"))
- .setResourceId(batchComponent4.key())
- .build();
- index.insert(batchComponent4, Collections.singletonList(block));
- executor.execute();
-
- verify(executorService).shutdown();
- verifyNoMoreInteractions(executorService);
- readDuplications(batchComponent4, 0);
- }
-
- @Test
public void should_ignore_missing_component() {
Block block = Block.builder()
.setBlockHash(new ByteArray("AAAABBBBCCCC"))
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 ff7a8ff862e..0a4522b29ee 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
@@ -37,7 +37,6 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.Version;
-import org.sonar.scanner.scan.branch.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -58,7 +57,6 @@ public class DefaultSensorContextTest {
private SensorStorage sensorStorage;
private AnalysisMode analysisMode;
private SonarRuntime runtime;
- private BranchConfiguration branchConfig;
@Before
public void prepare() throws Exception {
@@ -68,7 +66,6 @@ public class DefaultSensorContextTest {
when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
settings = new MapSettings();
- branchConfig = mock(BranchConfiguration.class);
sensorStorage = mock(SensorStorage.class);
analysisMode = mock(AnalysisMode.class);
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);