From 39f52452ee8a3d414dd9f2a4dee3dfffdb082c1d Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 2 Sep 2014 17:25:02 +0200 Subject: [PATCH] SONAR-5576 Display coverage exclusions in logs --- .../sensors/CoverageMeasurementFilter.java | 23 +++++++++++++++---- .../scan/filesystem/ExclusionFilters.java | 8 ++++--- .../core/config/ExclusionProperties.java | 4 ++-- .../java/org/sonar/api/CoreProperties.java | 5 +++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java index eeda60396a9..e236c6298ed 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java @@ -23,6 +23,9 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.ImmutableSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; @@ -35,14 +38,16 @@ import java.util.Iterator; public class CoverageMeasurementFilter implements MeasurementFilter { + private static final Logger LOG = LoggerFactory.getLogger(CoverageMeasurementFilter.class); + private final Settings settings; private final ImmutableSet coverageMetrics; private Collection resourcePatterns; public CoverageMeasurementFilter(Settings settings, - CoverageDecorator coverageDecorator, - LineCoverageDecorator lineCoverageDecorator, - BranchCoverageDecorator branchCoverageDecorator) { + CoverageDecorator coverageDecorator, + LineCoverageDecorator lineCoverageDecorator, + BranchCoverageDecorator branchCoverageDecorator) { this.settings = settings; this.coverageMetrics = ImmutableSet.builder() .addAll(coverageDecorator.generatedMetrics()) @@ -81,9 +86,19 @@ public class CoverageMeasurementFilter implements MeasurementFilter { @VisibleForTesting final void initPatterns() { Builder builder = ImmutableList.builder(); - for (String pattern : settings.getStringArray("sonar.coverage.exclusions")) { + for (String pattern : settings.getStringArray(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY)) { builder.add(WildcardPattern.create(pattern)); } resourcePatterns = builder.build(); + log("Excluded sources for coverage: ", resourcePatterns); + } + + private void log(String title, Collection patterns) { + if (!patterns.isEmpty()) { + LOG.info(title); + for (WildcardPattern pattern : patterns) { + LOG.info(" " + pattern); + } + } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java index ced596ed9dd..e3ff5fe20e9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java @@ -28,6 +28,9 @@ import org.sonar.api.batch.fs.internal.PathPattern; import org.sonar.api.scan.filesystem.FileExclusions; public class ExclusionFilters implements BatchComponent { + + private static final Logger LOG = LoggerFactory.getLogger(ExclusionFilters.class); + private final FileExclusions exclusionSettings; private PathPattern[] mainInclusions; @@ -52,10 +55,9 @@ public class ExclusionFilters implements BatchComponent { private void log(String title, PathPattern[] patterns) { if (patterns.length > 0) { - Logger log = LoggerFactory.getLogger(ExclusionFilters.class); - log.info(title); + LOG.info(title); for (PathPattern pattern : patterns) { - log.info(" " + pattern); + LOG.info(" " + pattern); } } } 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 47756b864d6..8b4df1a53f4 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 @@ -37,7 +37,7 @@ public class ExclusionProperties { return ImmutableList.of( // COVERAGE - PropertyDefinition.builder("sonar.coverage.exclusions") + PropertyDefinition.builder(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY) .category(CoreProperties.CATEGORY_EXCLUSIONS) .subCategory(CoreProperties.SUBCATEGORY_COVERAGE_EXCLUSIONS) .type(PropertyType.STRING) @@ -110,6 +110,6 @@ public class ExclusionProperties { .onlyOnQualifiers(Qualifiers.PROJECT) .index(1) .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 b73e0a0ecee..7016d777d8a 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 @@ -159,7 +159,7 @@ public interface CoreProperties { String PROJECT_DATE_PROPERTY = "sonar.projectDate"; /** - * @deprecated since 4.2 project are now multi-language + * @deprecated since 4.2 projects are now multi-language */ @Deprecated String PROJECT_LANGUAGE_PROPERTY = "sonar.language"; @@ -174,6 +174,9 @@ public interface CoreProperties { String PROJECT_INCLUSIONS_PROPERTY = "sonar.inclusions"; String PROJECT_EXCLUSIONS_PROPERTY = "sonar.exclusions"; + /* Coverage exclusions */ + String PROJECT_COVERAGE_EXCLUSIONS_PROPERTY = "sonar.coverage.exclusions"; + /** * @since 3.3 */ -- 2.39.5