diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-01 14:43:55 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 14:58:16 +0200 |
commit | e6b28c1ba4e7627f4599590ddfcc21875843ce87 (patch) | |
tree | 76d3344308689e5f448ba160f3f4bd90649344cf /sonar-scanner-engine/src/test | |
parent | ef26b6a20f4a813079538b60f97dba53dc4108c1 (diff) | |
download | sonarqube-e6b28c1ba4e7627f4599590ddfcc21875843ce87.tar.gz sonarqube-e6b28c1ba4e7627f4599590ddfcc21875843ce87.zip |
Store project relative path inside DefaultIndexedFile
Diffstat (limited to 'sonar-scanner-engine/src/test')
7 files changed, 49 insertions, 16 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java index c7774c750e9..111ddeebfc5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdSettingsTest.java @@ -19,19 +19,18 @@ */ package org.sonar.scanner.cpd; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.util.Optional; - import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; import org.sonar.api.config.Configuration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class CpdSettingsTest { private CpdSettings cpdSettings; private Configuration configuration; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index a61330e3657..5f2add6955a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -712,4 +712,23 @@ public class FileSystemMediumTest { assertThat(result.inputFiles()).hasSize(1); } + + @Test + public void detectDuplicatedFilesInDifferentModules() throws IOException { + File srcDir = new File(baseDir, "module1/src"); + srcDir.mkdir(); + + File xooFile = new File(srcDir, "sample.xoo"); + FileUtils.write(xooFile, "Sample xoo\ncontent"); + + TaskResult result = tester.newTask() + .properties(builder + .put("sonar.sources", "module1/src") + .put("sonar.modules", "module1") + .put("module1.sonar.sources", "src") + .build()) + .execute(); + + assertThat(result.inputFiles()).hasSize(1); + } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/CoverageExclusionsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/CoverageExclusionsTest.java index 166964fcdc7..a6d208b35bb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/CoverageExclusionsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/CoverageExclusionsTest.java @@ -26,7 +26,6 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.core.config.ExclusionProperties; -import org.sonar.scanner.phases.CoverageExclusions; import static org.assertj.core.api.Assertions.assertThat; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java index 2a68b02aa16..d56d2be32ed 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/phases/SensorsExecutorTest.java @@ -30,11 +30,11 @@ import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.InputModuleHierarchy; +import org.sonar.api.batch.fs.internal.SensorStrategy; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.resources.Project; import org.sonar.scanner.bootstrap.ScannerExtensionDictionnary; import org.sonar.scanner.events.EventBus; -import org.sonar.scanner.sensor.SensorStrategy; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index 24fa9205c37..1b59e69bd18 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -19,9 +19,6 @@ */ package org.sonar.scanner.scan; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -32,6 +29,9 @@ import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; import org.sonar.scanner.analysis.DefaultAnalysisMode; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class ProjectReactorValidatorTest { @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java index a4c6a32b6dd..6611f15302b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/InputFileBuilderTest.java @@ -30,7 +30,9 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DefaultInputModule; +import org.sonar.api.batch.fs.internal.SensorStrategy; import org.sonar.api.config.internal.MapSettings; +import org.sonar.scanner.scan.DefaultInputModuleHierarchy; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -44,13 +46,19 @@ public class InputFileBuilderTest { private Path workDir; private InputFileBuilder builder; + private SensorStrategy sensorStrategy; + @Before public void setUp() throws IOException { baseDir = temp.newFolder().toPath(); workDir = temp.newFolder().toPath(); - DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create() + DefaultInputModule root = new DefaultInputModule(ProjectDefinition.create() .setBaseDir(baseDir.toFile()) .setWorkDir(workDir.toFile()) + .setKey("root"), 0); + DefaultInputModule module = new DefaultInputModule(ProjectDefinition.create() + .setBaseDir(baseDir.resolve("module1").toFile()) + .setWorkDir(workDir.toFile()) .setKey("module1"), 0); MetadataGenerator metadataGenerator = mock(MetadataGenerator.class); @@ -58,17 +66,25 @@ public class InputFileBuilderTest { MapSettings settings = new MapSettings(); ModuleFileSystemInitializer moduleFileSystemInitializer = mock(ModuleFileSystemInitializer.class); when(moduleFileSystemInitializer.defaultEncoding()).thenReturn(StandardCharsets.UTF_8); - builder = new InputFileBuilder(module, metadataGenerator, idGenerator, settings.asConfig(), moduleFileSystemInitializer); + sensorStrategy = new SensorStrategy(); + builder = new InputFileBuilder(module, metadataGenerator, idGenerator, settings.asConfig(), moduleFileSystemInitializer, new DefaultInputModuleHierarchy(root), + sensorStrategy); } @Test public void testBuild() { - Path filePath = baseDir.resolve("src/File1.xoo"); - DefaultInputFile inputFile = builder.create(Type.MAIN, "src/File1.xoo", null); + Path filePath = baseDir.resolve("module1/src/File1.xoo"); + DefaultInputFile inputFile = builder.create(Type.MAIN, filePath, null); assertThat(inputFile.moduleKey()).isEqualTo("module1"); assertThat(inputFile.absolutePath()).isEqualTo(filePath.toString().replaceAll("\\\\", "/")); + assertThat(inputFile.relativePath()).isEqualTo("src/File1.xoo"); + assertThat(inputFile.path()).isEqualTo(filePath); assertThat(inputFile.key()).isEqualTo("module1:src/File1.xoo"); assertThat(inputFile.isPublished()).isFalse(); + + sensorStrategy.setGlobal(true); + + assertThat(inputFile.relativePath()).isEqualTo("module1/src/File1.xoo"); } } 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 4d2e97d0c23..ff1f957bccf 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 @@ -27,8 +27,8 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.InputFile; 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.sensor.SensorStrategy; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; |