aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-07-25 17:48:43 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-07 11:44:06 +0200
commiteacbf52a96ed3dca7652dd4f34dd604d8f9c14a2 (patch)
treefdd3c0b13ba40320ee9f953b71448ec90fa48ac5 /sonar-scanner-engine/src/test/java/org/sonar/scanner
parent84c8b435975e605d532cc3dfb81dddcb830aa79c (diff)
downloadsonarqube-eacbf52a96ed3dca7652dd4f34dd604d8f9c14a2.tar.gz
sonarqube-eacbf52a96ed3dca7652dd4f34dd604d8f9c14a2.zip
SONAR-9607 Do not copy unchanged source files in scanner report
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/DefaultPostJobContextTest.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.java32
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleIndexerTest.java3
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputComponentStoreTest.java8
-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/source/ZeroCoverageSensorTest.java2
10 files changed, 52 insertions, 10 deletions
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 e3407fc6fe0..71d060e2f46 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
@@ -30,6 +30,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+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.fs.internal.DefaultInputModule;
@@ -85,7 +86,7 @@ public class CpdExecutorTest {
index = new SonarCpdBlockIndex(publisher, settings);
DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
- componentStore = new InputComponentStore(inputModule);
+ componentStore = new InputComponentStore(inputModule, mock(AnalysisMode.class));
executor = new CpdExecutor(settings, index, publisher, componentStore);
reader = new ScannerReportReader(outputDir);
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 d1bcef89d99..8d0eb0085da 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
@@ -54,7 +54,7 @@ public class DefaultPostJobContextTest {
public void setUp() throws IOException {
issueCache = mock(IssueCache.class);
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder());
- componentStore = new InputComponentStore(rootModule);
+ componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.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/CoveragePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CoveragePublisherTest.java
index 794345ebdf7..76ce5527497 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
@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+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.fs.internal.TestInputFileBuilder;
@@ -57,7 +58,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);
+ InputComponentStore componentCache = new InputComponentStore(rootModule, mock(AnalysisMode.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 224d3533423..3e5c7d507e5 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
@@ -28,6 +28,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+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.fs.internal.TestInputFileBuilder;
@@ -68,7 +69,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);
+ InputComponentStore componentCache = new InputComponentStore(inputModule, mock(AnalysisMode.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 8745a546aed..60b51e5a8f2 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
@@ -27,6 +27,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
@@ -34,6 +36,8 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class SourcePublisherTest {
@@ -43,6 +47,7 @@ public class SourcePublisherTest {
private File sourceFile;
private ScannerReportWriter writer;
private DefaultInputFile inputFile;
+ private AnalysisMode analysisMode;
@Before
public void prepare() throws IOException {
@@ -56,7 +61,8 @@ public class SourcePublisherTest {
.build();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir);
- InputComponentStore componentStore = new InputComponentStore(rootModule);
+ analysisMode = mock(AnalysisMode.class);
+ InputComponentStore componentStore = new InputComponentStore(rootModule, analysisMode);
componentStore.put(inputFile);
publisher = new SourcePublisher(componentStore);
@@ -114,4 +120,28 @@ public class SourcePublisherTest {
File out = writer.getSourceFile(inputFile.batchId());
assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
}
+
+ @Test
+ public void publishChangedSourceInIncrementalMode() throws Exception {
+ when(analysisMode.isIncremental()).thenReturn(true);
+ FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);
+ inputFile.setStatus(Status.CHANGED);
+
+ publisher.publish(writer);
+
+ File out = writer.getSourceFile(inputFile.batchId());
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
+ }
+
+ @Test
+ public void dontPublishUnchangedSourceInIncrementalMode() throws Exception {
+ when(analysisMode.isIncremental()).thenReturn(true);
+ FileUtils.write(sourceFile, "foo", StandardCharsets.ISO_8859_1);
+ inputFile.setStatus(Status.SAME);
+
+ publisher.publish(writer);
+
+ File out = writer.getSourceFile(inputFile.batchId());
+ assertThat(out).doesNotExist();
+ }
}
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 c25b4ce33f1..a11e500c302 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
@@ -21,6 +21,7 @@ package org.sonar.scanner.scan;
import java.util.Arrays;
import org.junit.Test;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -37,7 +38,7 @@ public class ModuleIndexerTest {
private InputComponentStore componentStore;
public void createIndexer(DefaultInputModule rootModule) {
- componentStore = new InputComponentStore(rootModule);
+ componentStore = new InputComponentStore(rootModule, mock(AnalysisMode.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 097d9b918b4..777af5ef52b 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
@@ -27,6 +27,7 @@ import java.util.List;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
@@ -37,6 +38,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class InputComponentStoreTest {
@ClassRule
@@ -57,7 +59,7 @@ public class InputComponentStoreTest {
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
- InputComponentStore cache = new InputComponentStore(rootModule);
+ InputComponentStore cache = new InputComponentStore(rootModule, mock(AnalysisMode.class));
cache.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java")
@@ -101,7 +103,11 @@ public class InputComponentStoreTest {
static class InputComponentStoreTester extends InputComponentStore {
InputComponentStoreTester() throws IOException {
+<<<<<<< HEAD
super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()));
+=======
+ super(new PathResolver(), TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(AnalysisMode.class));
+>>>>>>> SONAR-9607 Do not copy unchanged source files in scanner report
}
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 ff1f957bccf..0911d7436c7 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
@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -47,7 +48,7 @@ public class ModuleInputComponentStoreTest {
@Before
public void setUp() throws IOException {
DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
- componentStore = new InputComponentStore(root);
+ componentStore = new InputComponentStore(root, mock(AnalysisMode.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 876fcb13286..148dabfdab9 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
@@ -31,6 +31,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -82,7 +83,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);
+ InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(AnalysisMode.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/source/ZeroCoverageSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java
index 3b30721750f..09a347f71dc 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/source/ZeroCoverageSensorTest.java
@@ -38,7 +38,7 @@ public class ZeroCoverageSensorTest {
public void dontForceCoverageInIncrementalMode() {
AnalysisMode analysisMode = mock(AnalysisMode.class);
when(analysisMode.isIncremental()).thenReturn(true);
- ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, null, analysisMode);
+ ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisMode);
zeroCoverageSensor.execute(null);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Incremental mode: not forcing coverage to zero");
}