diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2019-01-04 17:19:38 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-01-16 09:43:11 +0100 |
commit | 48459e1f797c63fac0e299158ecf651c57b62709 (patch) | |
tree | bce052cdb348026ab1020dd87bb47c0ab898ec83 /sonar-scanner-engine | |
parent | 505300a3c10164c805c5d8c8e9745f2f1d29fdf0 (diff) | |
download | sonarqube-48459e1f797c63fac0e299158ecf651c57b62709.tar.gz sonarqube-48459e1f797c63fac0e299158ecf651c57b62709.zip |
SONAR-11508 Missing global server settings in module settings
Diffstat (limited to 'sonar-scanner-engine')
3 files changed, 80 insertions, 4 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java index 7e19c53af74..fd409e22d6b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleConfigurationProvider.java @@ -27,15 +27,19 @@ import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.scanner.bootstrap.GlobalConfiguration; +import org.sonar.scanner.bootstrap.GlobalServerSettings; public class ModuleConfigurationProvider extends ProviderAdapter { private ModuleConfiguration moduleConfiguration; - public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, ProjectServerSettings projectServerSettings) { + public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, GlobalServerSettings globalServerSettings, + ProjectServerSettings projectServerSettings) { if (moduleConfiguration == null) { - Map<String, String> settings = new LinkedHashMap<>(projectServerSettings.properties()); + Map<String, String> settings = new LinkedHashMap<>(); + settings.putAll(globalServerSettings.properties()); + settings.putAll(projectServerSettings.properties()); addScannerSideProperties(settings, module.definition()); moduleConfiguration = new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), settings); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java index dfad08dfcf7..788ee0d5887 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java @@ -42,6 +42,7 @@ import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.bootstrap.GlobalConfiguration; +import org.sonar.scanner.bootstrap.GlobalServerSettings; import org.sonar.scanner.scan.ModuleConfiguration; import org.sonar.scanner.scan.ModuleConfigurationProvider; import org.sonar.scanner.scan.ProjectServerSettings; @@ -58,17 +59,19 @@ public class ProjectFileIndexer { private final InputComponentStore componentStore; private final InputModuleHierarchy inputModuleHierarchy; private final GlobalConfiguration globalConfig; + private final GlobalServerSettings globalServerSettings; private final ProjectServerSettings projectServerSettings; private final FileIndexer fileIndexer; private ProgressReport progressReport; public ProjectFileIndexer(InputComponentStore componentStore, ProjectExclusionFilters exclusionFilters, - InputModuleHierarchy inputModuleHierarchy, GlobalConfiguration globalConfig, ProjectServerSettings projectServerSettings, + InputModuleHierarchy inputModuleHierarchy, GlobalConfiguration globalConfig, GlobalServerSettings globalServerSettings, ProjectServerSettings projectServerSettings, FileIndexer fileIndexer, ProjectCoverageAndDuplicationExclusions projectCoverageAndDuplicationExclusions) { this.componentStore = componentStore; this.inputModuleHierarchy = inputModuleHierarchy; this.globalConfig = globalConfig; + this.globalServerSettings = globalServerSettings; this.projectServerSettings = projectServerSettings; this.fileIndexer = fileIndexer; this.projectExclusionFilters = exclusionFilters; @@ -102,7 +105,7 @@ public class ProjectFileIndexer { private void index(DefaultInputModule module, AtomicInteger excludedByPatternsCount) { // Emulate creation of module level settings - ModuleConfiguration moduleConfig = new ModuleConfigurationProvider().provide(globalConfig, module, projectServerSettings); + ModuleConfiguration moduleConfig = new ModuleConfigurationProvider().provide(globalConfig, module, globalServerSettings, projectServerSettings); ModuleExclusionFilters moduleExclusionFilters = new ModuleExclusionFilters(moduleConfig); ModuleCoverageAndDuplicationExclusions moduleCoverageAndDuplicationExclusions = new ModuleCoverageAndDuplicationExclusions(moduleConfig); if (componentStore.allModules().size() > 1) { 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 d00a5cf3951..0cbd92f80ab 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 @@ -33,6 +33,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.utils.MessageException; @@ -639,6 +640,74 @@ public class FileSystemMediumTest { } @Test + public void support_global_server_side_exclusions_for_multi_module_project() throws IOException { + File baseDir = temp.getRoot(); + File baseDirModuleA = new File(baseDir, "moduleA"); + File baseDirModuleB = new File(baseDir, "moduleB"); + File srcDirA = new File(baseDirModuleA, "src"); + srcDirA.mkdirs(); + File srcDirB = new File(baseDirModuleB, "src"); + srcDirB.mkdirs(); + + File xooFileA = new File(srcDirA, "sample.xoo"); + FileUtils.write(xooFileA, "Sample xoo\ncontent", StandardCharsets.UTF_8); + + File xooFileB = new File(srcDirB, "sample.xoo"); + FileUtils.write(xooFileB, "Sample xoo\ncontent", StandardCharsets.UTF_8); + + tester.addGlobalServerSettings(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*.xoo"); + + AnalysisResult result = tester.newAnalysis() + .properties(ImmutableMap.<String, String>builder() + .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) + .put("sonar.projectKey", "com.foo.project") + .put("sonar.sources", "src") + .put("sonar.modules", "moduleA,moduleB") + .build()) + .execute(); + + InputFile fileA = result.inputFile("moduleA/src/sample.xoo"); + assertThat(fileA).isNull(); + + InputFile fileB = result.inputFile("moduleB/src/sample.xoo"); + assertThat(fileB).isNull(); + } + + @Test + public void support_global_server_side_global_exclusions_for_multi_module_project() throws IOException { + File baseDir = temp.getRoot(); + File baseDirModuleA = new File(baseDir, "moduleA"); + File baseDirModuleB = new File(baseDir, "moduleB"); + File srcDirA = new File(baseDirModuleA, "src"); + srcDirA.mkdirs(); + File srcDirB = new File(baseDirModuleB, "src"); + srcDirB.mkdirs(); + + File xooFileA = new File(srcDirA, "sample.xoo"); + FileUtils.write(xooFileA, "Sample xoo\ncontent", StandardCharsets.UTF_8); + + File xooFileB = new File(srcDirB, "sample.xoo"); + FileUtils.write(xooFileB, "Sample xoo\ncontent", StandardCharsets.UTF_8); + + tester.addGlobalServerSettings(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY, "**/*.xoo"); + + AnalysisResult result = tester.newAnalysis() + .properties(ImmutableMap.<String, String>builder() + .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) + .put("sonar.projectKey", "com.foo.project") + .put("sonar.sources", "src") + .put("sonar.modules", "moduleA,moduleB") + .build()) + .execute(); + + InputFile fileA = result.inputFile("moduleA/src/sample.xoo"); + assertThat(fileA).isNull(); + + InputFile fileB = result.inputFile("moduleB/src/sample.xoo"); + assertThat(fileB).isNull(); + } + + @Test public void warn_user_for_outdated_server_side_inherited_exclusions_for_multi_module_project() throws IOException { File baseDir = temp.getRoot(); File baseDirModuleA = new File(baseDir, "moduleA"); |