From 5debbecc152bf7aff83601e6a39d4247c8f522df Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 17 Feb 2014 11:51:16 +0100 Subject: [PATCH] Ensure that JavaSquidSensor is executed after exclusions initialization --- .../core/issue/ignore/IgnoreIssuesPlugin.java | 8 ++++---- ...pScanner.java => IgnoreIssuesRegexpScanner.java} | 6 +++--- ...eScanner.java => IgnoreIssuesSourceScanner.java} | 13 ++++++++----- ...Test.java => IgnoreIssuesRegexpScannerTest.java} | 6 +++--- ...Test.java => IgnoreIssuesSourceScannerTest.java} | 8 ++++---- 5 files changed, 22 insertions(+), 19 deletions(-) rename plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/{RegexpScanner.java => IgnoreIssuesRegexpScanner.java} (96%) rename plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/{SourceScanner.java => IgnoreIssuesSourceScanner.java} (86%) rename plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/{RegexpScannerTest.java => IgnoreIssuesRegexpScannerTest.java} (97%) rename plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/{SourceScannerTest.java => IgnoreIssuesSourceScannerTest.java} (96%) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/IgnoreIssuesPlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/IgnoreIssuesPlugin.java index 248c13853ff..c39060a912c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/IgnoreIssuesPlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/IgnoreIssuesPlugin.java @@ -23,8 +23,8 @@ package org.sonar.plugins.core.issue.ignore; import com.google.common.collect.ImmutableList; import org.sonar.plugins.core.issue.ignore.pattern.ExclusionPatternInitializer; import org.sonar.plugins.core.issue.ignore.pattern.InclusionPatternInitializer; -import org.sonar.plugins.core.issue.ignore.scanner.RegexpScanner; -import org.sonar.plugins.core.issue.ignore.scanner.SourceScanner; +import org.sonar.plugins.core.issue.ignore.scanner.IgnoreIssuesRegexpScanner; +import org.sonar.plugins.core.issue.ignore.scanner.IgnoreIssuesSourceScanner; import java.util.List; @@ -41,8 +41,8 @@ public final class IgnoreIssuesPlugin { extensions.add( InclusionPatternInitializer.class, ExclusionPatternInitializer.class, - RegexpScanner.class, - SourceScanner.class, + IgnoreIssuesRegexpScanner.class, + IgnoreIssuesSourceScanner.class, EnforceIssuesFilter.class, IgnoreIssuesFilter.class); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScanner.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScanner.java similarity index 96% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScanner.java rename to plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScanner.java index b479000d013..d6fa2d26fa6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScanner.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScanner.java @@ -37,9 +37,9 @@ import java.nio.charset.Charset; import java.util.List; import java.util.Set; -public class RegexpScanner implements BatchExtension { +public class IgnoreIssuesRegexpScanner implements BatchExtension { - private static final Logger LOG = LoggerFactory.getLogger(RegexpScanner.class); + private static final Logger LOG = LoggerFactory.getLogger(IgnoreIssuesRegexpScanner.class); private ExclusionPatternInitializer exclusionPatternInitializer; private List allFilePatterns; @@ -51,7 +51,7 @@ public class RegexpScanner implements BatchExtension { private List lineExclusions; private LineExclusion currentLineExclusion; - public RegexpScanner(ExclusionPatternInitializer patternsInitializer) { + public IgnoreIssuesRegexpScanner(ExclusionPatternInitializer patternsInitializer) { this.exclusionPatternInitializer = patternsInitializer; lineExclusions = Lists.newArrayList(); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScanner.java similarity index 86% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java rename to plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScanner.java index 23a61888fee..f88696d7128 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScanner.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScanner.java @@ -20,30 +20,33 @@ package org.sonar.plugins.core.issue.ignore.scanner; -import org.sonar.api.scan.filesystem.InputFile; - +import org.sonar.api.batch.DependedUpon; import org.sonar.api.batch.Phase; import org.sonar.api.batch.Sensor; import org.sonar.api.batch.SensorContext; import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.FileQuery; +import org.sonar.api.scan.filesystem.InputFile; import org.sonar.api.scan.filesystem.internal.DefaultInputFile; import org.sonar.api.utils.SonarException; import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; +import org.sonar.java.api.JavaUtils; import org.sonar.plugins.core.issue.ignore.pattern.ExclusionPatternInitializer; import org.sonar.plugins.core.issue.ignore.pattern.InclusionPatternInitializer; import java.nio.charset.Charset; @Phase(name = Phase.Name.PRE) -public final class SourceScanner implements Sensor { +// Issue Exclusions must be computed before JavaSquidSensor is executed and creates issues +@DependedUpon(value = JavaUtils.BARRIER_BEFORE_SQUID) +public final class IgnoreIssuesSourceScanner implements Sensor { - private final RegexpScanner regexpScanner; + private final IgnoreIssuesRegexpScanner regexpScanner; private final ExclusionPatternInitializer exclusionPatternInitializer; private final InclusionPatternInitializer inclusionPatternInitializer; private final DefaultModuleFileSystem fileSystem; - public SourceScanner(RegexpScanner regexpScanner, ExclusionPatternInitializer exclusionPatternInitializer, InclusionPatternInitializer inclusionPatternInitializer, + public IgnoreIssuesSourceScanner(IgnoreIssuesRegexpScanner regexpScanner, ExclusionPatternInitializer exclusionPatternInitializer, InclusionPatternInitializer inclusionPatternInitializer, DefaultModuleFileSystem fileSystem) { this.regexpScanner = regexpScanner; this.exclusionPatternInitializer = exclusionPatternInitializer; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScannerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScannerTest.java similarity index 97% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScannerTest.java rename to plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScannerTest.java index 3ab03f3e989..bfbe6c6aee0 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/RegexpScannerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesRegexpScannerTest.java @@ -41,9 +41,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -public class RegexpScannerTest { +public class IgnoreIssuesRegexpScannerTest { - private RegexpScanner regexpScanner; + private IgnoreIssuesRegexpScanner regexpScanner; private String javaFile; @Mock @@ -70,7 +70,7 @@ public class RegexpScannerTest { when(patternsInitializer.getBlockPatterns()).thenReturn(Arrays.asList(blockPattern1, blockPattern2)); when(patternsInitializer.getPatternMatcher()).thenReturn(patternMatcher); - regexpScanner = new RegexpScanner(patternsInitializer); + regexpScanner = new IgnoreIssuesRegexpScanner(patternsInitializer); verify(patternsInitializer, times(1)).getAllFilePatterns(); verify(patternsInitializer, times(1)).getBlockPatterns(); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScannerTest.java similarity index 96% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java rename to plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScannerTest.java index 98ec8ec805c..5fc3a27c648 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/SourceScannerTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/scanner/IgnoreIssuesSourceScannerTest.java @@ -50,12 +50,12 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -public class SourceScannerTest { +public class IgnoreIssuesSourceScannerTest { - private SourceScanner scanner; + private IgnoreIssuesSourceScanner scanner; @Mock - private RegexpScanner regexpScanner; + private IgnoreIssuesRegexpScanner regexpScanner; @Mock private InclusionPatternInitializer inclusionPatternInitializer; @Mock @@ -85,7 +85,7 @@ public class SourceScannerTest { Mockito.doReturn("java").when(project).getLanguageKey(); when(fs.sourceCharset()).thenReturn(UTF_8); - scanner = new SourceScanner(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs); + scanner = new IgnoreIssuesSourceScanner(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs); } @Test -- 2.39.5