From a100aef8cfcc0578e18ef1b5839a75bf0d915423 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 19 Jun 2019 10:49:24 +0200 Subject: [PATCH] SONAR-11850 Don't warn user if properties are inherited --- .../scanner/scan/ProjectReactorBuilder.java | 7 ++++--- .../mediumtest/issues/IssuesMediumTest.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java index 6b4b9a79677..01f181d55f0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.stream.Stream; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -182,7 +183,7 @@ public class ProjectReactorBuilder { workDir = initRootProjectWorkDir(baseDir, moduleProperties); } else { workDir = initModuleWorkDir(baseDir, moduleProperties); - checkUnsupportedIssueExclusions(moduleProperties); + checkUnsupportedIssueExclusions(moduleProperties, parent.properties()); } return ProjectDefinition.create().setProperties(moduleProperties) @@ -191,9 +192,9 @@ public class ProjectReactorBuilder { .setBuildDir(initModuleBuildDir(baseDir, moduleProperties)); } - private void checkUnsupportedIssueExclusions(Map moduleProperties) { + private void checkUnsupportedIssueExclusions(Map moduleProperties, Map parentProps) { UNSUPPORTED_PROPS_FOR_MODULES.stream().forEach(p -> { - if (moduleProperties.containsKey(p)) { + if (moduleProperties.containsKey(p) && !Objects.equals(moduleProperties.get(p), parentProps.get(p))) { warnOnceUnsupportedIssueExclusions( "Specifying issue exclusions at module level is not supported anymore. Configure the property '" + p + "' and any other issue exclusions at project level."); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java index 3fd82bf4afb..683773b6e94 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesMediumTest.java @@ -285,6 +285,27 @@ public class IssuesMediumTest { issues = result.issuesFor(result.inputFile("moduleB/src/sampleB.xoo")); assertThat(issues).hasSize(10); + + + // SONAR-11850 The Maven scanner replicates properties defined on the root module to all modules + logTester.clear(); + result = tester.newAnalysis() + .properties(ImmutableMap.builder() + .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) + .put("sonar.projectKey", "com.foo.project") + .put("sonar.modules", "moduleA,moduleB") + .put("sonar.sources", "src") + .put("sonar.scm.disabled", "true") + .put("sonar.issue.ignore.multicriteria", "1") + .put("sonar.issue.ignore.multicriteria.1.ruleKey", "*") + .put("sonar.issue.ignore.multicriteria.1.resourceKey", "*") + .put("moduleA.sonar.issue.ignore.multicriteria", "1") + .put("moduleA.sonar.issue.ignore.multicriteria.1.ruleKey", "*") + .put("moduleA.sonar.issue.ignore.multicriteria.1.resourceKey", "*") + .build()) + .execute(); + + assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); } @Test -- 2.39.5