]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5576 Display coverage exclusions in logs
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 2 Sep 2014 15:25:02 +0000 (17:25 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 2 Sep 2014 15:25:37 +0000 (17:25 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CoverageMeasurementFilter.java
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index eeda60396a926e582ec89132dd22c26c2052eb0d..e236c6298ed34fb305573796f6ef43d2dffb8a18 100644 (file)
@@ -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<Metric> coverageMetrics;
   private Collection<WildcardPattern> resourcePatterns;
 
   public CoverageMeasurementFilter(Settings settings,
-                                   CoverageDecorator coverageDecorator,
-                                   LineCoverageDecorator lineCoverageDecorator,
-                                   BranchCoverageDecorator branchCoverageDecorator) {
+    CoverageDecorator coverageDecorator,
+    LineCoverageDecorator lineCoverageDecorator,
+    BranchCoverageDecorator branchCoverageDecorator) {
     this.settings = settings;
     this.coverageMetrics = ImmutableSet.<Metric>builder()
       .addAll(coverageDecorator.generatedMetrics())
@@ -81,9 +86,19 @@ public class CoverageMeasurementFilter implements MeasurementFilter {
   @VisibleForTesting
   final void initPatterns() {
     Builder<WildcardPattern> 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<WildcardPattern> patterns) {
+    if (!patterns.isEmpty()) {
+      LOG.info(title);
+      for (WildcardPattern pattern : patterns) {
+        LOG.info("  " + pattern);
+      }
+    }
   }
 }
index ced596ed9dd6832774efdd7d2144699f42fa5f3e..e3ff5fe20e96c7f63c68f523615108524d4d20a3 100644 (file)
@@ -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);
       }
     }
   }
index 47756b864d626a781ec5b623e21ba5dea9d4ef85..8b4df1a53f479a680cc5fc311cb21aa48117181d 100644 (file)
@@ -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()
-    );
+      );
   }
 }
index b73e0a0ecee69433ce0410ff4e782e93a9882ac6..7016d777d8a4b62bdc6dde82df436e7b266aed1a 100644 (file)
@@ -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
    */