From d8bd692a3fe6b1742252550f58e1d2ca09de139c Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 21 Mar 2016 11:34:03 +0100 Subject: [PATCH] SONAR-7487 Drop support of properties sonar.skippedModules and sonar.includedModules --- .../src/test/java/it/Category3Suite.java | 14 +- .../src/test/java/it/analysis/BatchTest.java | 59 ++------ .../it/analysis/ProjectExclusionsTest.java | 139 ------------------ .../core/config/ExclusionProperties.java | 28 +--- .../java/org/sonar/api/CoreProperties.java | 13 -- .../scan/ImmutableProjectReactorProvider.java | 7 +- .../sonar/batch/scan/ProjectExclusions.java | 94 ------------ .../batch/scan/ProjectScanContainer.java | 1 - .../batch/scan/ProjectExclusionsTest.java | 122 --------------- 9 files changed, 29 insertions(+), 448 deletions(-) delete mode 100644 it/it-tests/src/test/java/it/analysis/ProjectExclusionsTest.java delete mode 100644 sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectExclusions.java delete mode 100644 sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectExclusionsTest.java diff --git a/it/it-tests/src/test/java/it/Category3Suite.java b/it/it-tests/src/test/java/it/Category3Suite.java index 8576080b5cb..9a4d76d0ed3 100644 --- a/it/it-tests/src/test/java/it/Category3Suite.java +++ b/it/it-tests/src/test/java/it/Category3Suite.java @@ -20,7 +20,18 @@ package it; import com.sonar.orchestrator.Orchestrator; -import it.analysis.*; +import it.analysis.BatchTest; +import it.analysis.ExtensionLifecycleTest; +import it.analysis.IssueJsonReportTest; +import it.analysis.IssuesModeTest; +import it.analysis.LinksTest; +import it.analysis.MavenTest; +import it.analysis.MultiLanguageTest; +import it.analysis.ProjectBuilderTest; +import it.analysis.ProjectProvisioningTest; +import it.analysis.ReportDumpTest; +import it.analysis.SettingsEncryptionTest; +import it.analysis.TempFolderTest; import it.measure.DecimalScaleMetricTest; import org.junit.ClassRule; import org.junit.runner.RunWith; @@ -36,7 +47,6 @@ import static util.ItUtils.xooPlugin; LinksTest.class, MavenTest.class, ProjectBuilderTest.class, - ProjectExclusionsTest.class, TempFolderTest.class, MultiLanguageTest.class, IssueJsonReportTest.class, diff --git a/it/it-tests/src/test/java/it/analysis/BatchTest.java b/it/it-tests/src/test/java/it/analysis/BatchTest.java index b69a4dd2abf..bf15ee6468f 100644 --- a/it/it-tests/src/test/java/it/analysis/BatchTest.java +++ b/it/it-tests/src/test/java/it/analysis/BatchTest.java @@ -20,13 +20,20 @@ package it.analysis; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.BuildFailureException; import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import it.Category3Suite; +import java.io.File; +import java.io.IOException; +import java.util.Date; import org.apache.commons.io.FileUtils; -import org.junit.*; +import org.junit.Assume; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; @@ -36,10 +43,6 @@ import org.sonar.wsclient.services.PropertyUpdateQuery; import org.sonar.wsclient.services.Resource; import org.sonar.wsclient.services.ResourceQuery; import util.ItUtils; - -import java.io.File; -import java.io.IOException; -import java.util.Date; import util.QaOnly; import static org.assertj.core.api.Assertions.assertThat; @@ -89,34 +92,6 @@ public class BatchTest { assertThat(r.getMeasureIntValue("violations")).isEqualTo(61); } - /** - * SONAR-2907 - */ - @Test - public void branch_should_load_own_settings_from_database() { - orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample"); - orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line"); - scan("shared/xoo-multi-modules-sample"); - assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b")).isNotNull(); - - Sonar sonar = orchestrator.getServer().getAdminWsClient(); - // The parameter skippedModule considers key after first colon - sonar.update(new PropertyUpdateQuery("sonar.skippedModules", "multi-modules-sample:module_b", - "com.sonarsource.it.samples:multi-modules-sample")); - - try { - scan("shared/xoo-multi-modules-sample"); - assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b")).isNull(); - - scan("shared/xoo-multi-modules-sample", - "sonar.branch", "mybranch"); - - assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b:mybranch")).isNotNull(); - } finally { - sonar.delete(new PropertyDeleteQuery("sonar.skippedModules", "com.sonarsource.it.samples:multi-modules-sample")); - } - } - // SONAR-4680 @Test public void module_should_load_own_settings_from_database() { @@ -172,20 +147,6 @@ public class BatchTest { assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = project"); } - /** - * SONAR-3116 - */ - @Test - @Category(QaOnly.class) - public void should_not_exclude_root_module() { - orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample"); - orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line"); - - thrown.expect(BuildFailureException.class); - scan("shared/xoo-multi-modules-sample", - "sonar.skippedModules", "multi-modules-sample"); - } - /** * SONAR-3024 */ @@ -329,7 +290,7 @@ public class BatchTest { File cache = new File(userHome, "cache"); assertThat(cache).exists().isDirectory(); - int cachedFiles = FileUtils.listFiles(cache, new String[]{"jar"}, true).size(); + int cachedFiles = FileUtils.listFiles(cache, new String[] {"jar"}, true).size(); assertThat(cachedFiles).isGreaterThan(5); assertThat(result.getLogs()).contains("User cache: " + cache.getAbsolutePath()); assertThat(result.getLogs()).contains("Download sonar-xoo-plugin-"); diff --git a/it/it-tests/src/test/java/it/analysis/ProjectExclusionsTest.java b/it/it-tests/src/test/java/it/analysis/ProjectExclusionsTest.java deleted file mode 100644 index 81c5d1a5b85..00000000000 --- a/it/it-tests/src/test/java/it/analysis/ProjectExclusionsTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package it.analysis; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.MavenBuild; -import it.Category3Suite; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.wsclient.services.Resource; -import org.sonar.wsclient.services.ResourceQuery; -import util.ItUtils; -import util.QaOnly; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -@Category(QaOnly.class) -public class ProjectExclusionsTest { - @ClassRule - public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR; - - @Before - public void deleteProjectData() { - orchestrator.resetData(); - } - - /** - * This use-case was a bug in 2.8-RC2. It failed when both the properties sonar.branch and sonar.skippedModules - * were set on the same multi-modules project. - */ - @Test - public void shouldSupportMixOfBranchAndSkippedModules() { - MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample")) - .setGoals("clean verify", "sonar:sonar") - .setProperty("sonar.dynamicAnalysis", "false") - .setProperty("sonar.branch", "mybranch") - .setProperty("sonar.skippedModules", "module_b"); - - orchestrator.executeBuild(build); - - assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample:mybranch")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a:mybranch").getId()); - assertNotNull(getResource("com.sonarsource.it.samples:module_a1:mybranch").getId()); - assertNotNull(getResource("com.sonarsource.it.samples:module_a2:mybranch").getId()); - - assertNull(getResource("com.sonarsource.it.samples:module_b:mybranch")); - assertNull(getResource("com.sonarsource.it.samples:module_b1:mybranch")); - assertNull(getResource("com.sonarsource.it.samples:module_b2:mybranch")); - } - - /** - * Black list - */ - @Test - public void shouldExcludeModuleAndItsChildren() { - MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample")) - .setGoals("clean verify", "sonar:sonar") - .setProperty("sonar.dynamicAnalysis", "false") - .setProperty("sonar.skippedModules", "module_b"); - - orchestrator.executeBuild(build); - - assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a1")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a2")); - - // excluded project and its children - assertNull(getResource("com.sonarsource.it.samples:module_b")); - assertNull(getResource("com.sonarsource.it.samples:module_b1")); - assertNull(getResource("com.sonarsource.it.samples:module_b2")); - } - - /** - * Exhaustive white list - */ - @Test - public void shouldIncludeModules() { - MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample")) - .setGoals("clean verify", "sonar:sonar") - .setProperty("sonar.dynamicAnalysis", "false") - .setProperty("sonar.includedModules", "multi-modules-sample,module_a,module_a1"); - - orchestrator.executeBuild(build); - - assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a1")); - - assertNull(getResource("com.sonarsource.it.samples:module_a2")); - assertNull(getResource("com.sonarsource.it.samples:module_b")); - assertNull(getResource("com.sonarsource.it.samples:module_b1")); - assertNull(getResource("com.sonarsource.it.samples:module_b2")); - } - - @Test - public void rootModuleShouldBeOptionalInListOfIncludedModules() { - MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample")) - .setCleanSonarGoals() - .setProperty("sonar.dynamicAnalysis", "false") - // the root module 'multi-modules-sample' is not declared - .setProperty("sonar.includedModules", "module_a,module_a1"); - - orchestrator.executeBuild(build); - - assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a")); - assertNotNull(getResource("com.sonarsource.it.samples:module_a1")); - - assertNull(getResource("com.sonarsource.it.samples:module_a2")); - assertNull(getResource("com.sonarsource.it.samples:module_b")); - assertNull(getResource("com.sonarsource.it.samples:module_b1")); - assertNull(getResource("com.sonarsource.it.samples:module_b2")); - } - - private Resource getResource(String key) { - return orchestrator.getServer().getWsClient().find(ResourceQuery.create(key)); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java b/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java index cf4299bd61f..4d8f859185d 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java +++ b/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java @@ -71,31 +71,13 @@ public class ExclusionProperties { .index(1) .build(), - PropertyDefinition.builder(CoreProperties.CORE_SKIPPED_MODULES_PROPERTY) - .name("Exclude Modules") - .description("Maven artifact ids of modules to exclude.") - .multiValues(true) - .category(CoreProperties.CATEGORY_EXCLUSIONS) - .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) - .onlyOnQualifiers(Qualifiers.PROJECT) - .index(0) - .build(), - PropertyDefinition.builder(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY) - .name("Include Modules") - .description("Maven artifact ids of modules to include.") - .multiValues(true) - .category(CoreProperties.CATEGORY_EXCLUSIONS) - .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) - .onlyOnQualifiers(Qualifiers.PROJECT) - .index(1) - .build(), PropertyDefinition.builder(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY) .name("Source File Exclusions") .multiValues(true) .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) .onQualifiers(Qualifiers.PROJECT) - .index(2) + .index(0) .build(), PropertyDefinition.builder(CoreProperties.PROJECT_INCLUSIONS_PROPERTY) @@ -104,7 +86,7 @@ public class ExclusionProperties { .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) .onQualifiers(Qualifiers.PROJECT) - .index(3) + .index(1) .build(), PropertyDefinition.builder(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY) .name("Test File Exclusions") @@ -112,7 +94,7 @@ public class ExclusionProperties { .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) .onQualifiers(Qualifiers.PROJECT) - .index(4) + .index(2) .build(), PropertyDefinition.builder(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY) .name("Test File Inclusions") @@ -120,9 +102,9 @@ public class ExclusionProperties { .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS) .onQualifiers(Qualifiers.PROJECT) - .index(5) + .index(3) .build() - ); + ); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 71895ffded4..fc1bd8ad073 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -206,19 +206,6 @@ public interface CoreProperties { String CORE_VIOLATION_LOCALE_DEFAULT_VALUE = "en"; - /** - * @deprecated since 4.3. See http://jira.sonarsource.com/browse/SONAR-5109 - */ - @Deprecated - String CORE_SKIPPED_MODULES_PROPERTY = "sonar.skippedModules"; - - /** - * @since 4.0 - * @deprecated since 4.3. See http://jira.sonarsource.com/browse/SONAR-5109 - */ - @Deprecated - String CORE_INCLUDED_MODULES_PROPERTY = "sonar.includedModules"; - String CORE_FORCE_AUTHENTICATION_PROPERTY = "sonar.forceAuthentication"; boolean CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE = false; String CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY = "sonar.allowUsersToSignUp"; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java index ecf58a88482..3a90eb145ae 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ImmutableProjectReactorProvider.java @@ -26,15 +26,12 @@ public class ImmutableProjectReactorProvider extends ProviderAdapter { private ImmutableProjectReactor singleton; - public ImmutableProjectReactor provide(ProjectReactor reactor, ProjectBuildersExecutor projectBuildersExecutor, ProjectExclusions exclusions, ProjectReactorValidator validator) { + public ImmutableProjectReactor provide(ProjectReactor reactor, ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator) { if (singleton == null) { // 1 Apply project builders projectBuildersExecutor.execute(reactor); - // 2 Apply project exclusions - exclusions.apply(reactor); - - // 3 Validate final reactor + // 2 Validate final reactor validator.validate(reactor); singleton = new ImmutableProjectReactor(reactor.getRoot()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectExclusions.java deleted file mode 100644 index 0bea9a81309..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectExclusions.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.Settings; - -/** - * Exclude the sub-projects as defined by the properties sonar.skippedModules and sonar.includedModules - * - * @since 2.12 - */ -public class ProjectExclusions { - - private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class); - - private Settings settings; - - public ProjectExclusions(Settings settings) { - this.settings = settings; - } - - public void apply(ProjectReactor reactor) { - if (!reactor.getProjects().isEmpty() && StringUtils.isNotBlank(reactor.getProjects().get(0).getKey())) { - LOG.info("Apply project exclusions"); - - if (settings.hasKey(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY)) { - LOG.warn("'sonar.includedModules' property is deprecated since version 4.3 and should not be used anymore."); - } - if (settings.hasKey(CoreProperties.CORE_SKIPPED_MODULES_PROPERTY)) { - LOG.warn("'sonar.skippedModules' property is deprecated since version 4.3 and should not be used anymore."); - } - - for (ProjectDefinition project : reactor.getProjects()) { - if (isExcluded(key(project), project == reactor.getRoot())) { - exclude(project); - } - } - } - } - - private boolean isExcluded(String projectKey, boolean isRoot) { - String[] includedKeys = settings.getStringArray(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY); - boolean excluded = false; - if (!isRoot && includedKeys.length > 0) { - excluded = !ArrayUtils.contains(includedKeys, projectKey); - } - String skippedModulesProperty = CoreProperties.CORE_SKIPPED_MODULES_PROPERTY; - if (!excluded) { - String[] excludedKeys = settings.getStringArray(skippedModulesProperty); - excluded = ArrayUtils.contains(excludedKeys, projectKey); - } - if (excluded && isRoot) { - throw new IllegalArgumentException("The root project can't be excluded. Please check the parameters " + skippedModulesProperty + " and sonar.includedModules."); - } - return excluded; - } - - private void exclude(ProjectDefinition project) { - LOG.info(String.format("Exclude project: %s [%s]", project.getName(), project.getKey())); - project.remove(); - } - - static String key(ProjectDefinition project) { - String key = project.getKey(); - if (key.contains(":")) { - return StringUtils.substringAfter(key, ":"); - } - return key; - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index ff8108e4871..867547e0bdd 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -149,7 +149,6 @@ public class ProjectScanContainer extends ComponentContainer { PhasesTimeProfiler.class, ResourceTypes.class, DefaultProjectTree.class, - ProjectExclusions.class, ProjectReactorValidator.class, new AnalysisWSLoaderProvider(), CodeColorizers.class, diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectExclusionsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectExclusionsTest.java deleted file mode 100644 index 4f9b403a94e..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/batch/scan/ProjectExclusionsTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan; - -import org.junit.Test; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.config.Settings; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ProjectExclusionsTest { - - ProjectReactor newReactor(String rootKey, String... moduleKeys) { - ProjectDefinition root = ProjectDefinition.create().setKey(rootKey); - for (String moduleKey : moduleKeys) { - ProjectDefinition module = ProjectDefinition.create().setKey(moduleKey); - root.addSubProject(module); - } - return new ProjectReactor(root); - } - - @Test - public void testSkippedModules() { - Settings settings = new Settings(); - settings.setProperty("sonar.skippedModules", "sub1,sub3"); - - ProjectReactor reactor = newReactor("root", "sub1", "sub2"); - - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - - assertThat(reactor.getProject("root")).isNotNull(); - assertThat(reactor.getProject("sub1")).isNull(); - assertThat(reactor.getProject("sub2")).isNotNull(); - } - - @Test - public void testNoSkippedModules() { - Settings settings = new Settings(); - ProjectReactor reactor = newReactor("root", "sub1", "sub2"); - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - - assertThat(reactor.getProject("root")).isNotNull(); - assertThat(reactor.getProject("sub1")).isNotNull(); - assertThat(reactor.getProject("sub2")).isNotNull(); - } - - @Test - public void testIncludedModules() { - Settings settings = new Settings(); - settings.setProperty("sonar.includedModules", "sub1"); - ProjectReactor reactor = newReactor("root", "sub1", "sub2"); - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - - assertThat(reactor.getProject("root")).isNotNull(); - assertThat(reactor.getProject("sub1")).isNotNull(); - assertThat(reactor.getProject("sub2")).isNull(); - } - - @Test - public void shouldBeExcludedIfParentIsExcluded() { - ProjectDefinition sub11 = ProjectDefinition.create().setKey("sub11"); - ProjectDefinition sub1 = ProjectDefinition.create().setKey("sub1").addSubProject(sub11); - ProjectDefinition root = ProjectDefinition.create().setKey("root").addSubProject(sub1); - - Settings settings = new Settings(); - settings.setProperty("sonar.skippedModules", "sub1"); - - ProjectReactor reactor = new ProjectReactor(root); - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - - assertThat(reactor.getProject("root")).isNotNull(); - assertThat(reactor.getProject("sub1")).isNull(); - assertThat(reactor.getProject("sub11")).isNull(); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailIfExcludingRoot() { - Settings settings = new Settings(); - settings.setProperty("sonar.skippedModules", "sub1,root"); - - ProjectReactor reactor = newReactor("root", "sub1", "sub2"); - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - } - - @Test - public void shouldIgnoreMavenGroupId() { - ProjectReactor reactor = newReactor("org.apache.struts:struts", "org.apache.struts:struts-core", "org.apache.struts:struts-taglib"); - - Settings settings = new Settings(); - settings.setProperty("sonar.skippedModules", "struts-taglib"); - - ProjectExclusions exclusions = new ProjectExclusions(settings); - exclusions.apply(reactor); - - assertThat(reactor.getProject("org.apache.struts:struts")).isNotNull(); - assertThat(reactor.getProject("org.apache.struts:struts-core")).isNotNull(); - assertThat(reactor.getProject("org.apache.struts:struts-taglib")).isNull(); - } -} -- 2.39.5