diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-07-31 16:15:44 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 14:58:16 +0200 |
commit | 6cedf507a95545611c31813a427f43291beeadfc (patch) | |
tree | a509e266abbf44baa523e2a19566ccb249389666 /sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java | |
parent | 75e47ba5a19b3d4ab901d2ed7a180714b141d580 (diff) | |
download | sonarqube-6cedf507a95545611c31813a427f43291beeadfc.tar.gz sonarqube-6cedf507a95545611c31813a427f43291beeadfc.zip |
SONAR-9557 Fix coverage exclusions for global sensors
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java new file mode 100644 index 00000000000..97675a88960 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/phases/CoverageExclusions.java @@ -0,0 +1,73 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.scanner.phases; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import java.util.Collection; +import java.util.Iterator; +import javax.annotation.concurrent.Immutable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.CoreProperties; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.config.Configuration; +import org.sonar.api.utils.WildcardPattern; + +@Immutable +public class CoverageExclusions { + private static final Logger LOG = LoggerFactory.getLogger(CoverageExclusions.class); + + private Collection<WildcardPattern> exclusionPatterns; + + public CoverageExclusions(Configuration settings) { + Builder<WildcardPattern> builder = ImmutableList.builder(); + for (String pattern : settings.getStringArray(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY)) { + builder.add(WildcardPattern.create(pattern)); + } + exclusionPatterns = builder.build(); + } + + void log() { + log("Excluded sources for coverage: ", exclusionPatterns); + } + + boolean isExcluded(InputFile file) { + boolean found = false; + Iterator<WildcardPattern> iterator = exclusionPatterns.iterator(); + while (!found && iterator.hasNext()) { + found = iterator.next().match(file.relativePath()); + } + return found; + } + + private static void log(String title, Collection<WildcardPattern> patterns) { + if (!patterns.isEmpty()) { + LOG.info(title); + for (WildcardPattern pattern : patterns) { + LOG.info(" " + pattern); + } + } + } + + public boolean shouldExecute() { + return !exclusionPatterns.isEmpty(); + } +} |