]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3644 Fix issues when matching line range exclusions with file level issues
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 9 Sep 2013 16:07:58 +0000 (18:07 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 9 Sep 2013 16:07:58 +0000 (18:07 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/pattern/Pattern.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/ignore/pattern/PatternsInitializer.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/ignore/pattern/PatternTest.java

index 40e5855ecfadea8746ae2bb2fb75118532f84571..e46c7c8d48ae9952f53174bab98e94e79da9b169 100644 (file)
@@ -115,11 +115,15 @@ public class Pattern {
     return allLines;
   }
 
-  public boolean match(Issue violation) {
-    boolean match = violation.componentKey() != null
-      && matchRule(violation.ruleKey());
-    if (checkLines && violation.line() != null) {
-      match = match && matchLine(violation.line());
+  public boolean match(Issue issue) {
+    boolean match = matchResource(issue.componentKey())
+      && matchRule(issue.ruleKey());
+    if (checkLines) {
+      if (issue.line() == null) {
+        match = false;
+      } else {
+        match = match && matchLine(issue.line());
+      }
     }
     return match;
   }
index e310a265c378de52ce59893785375491207ad404..d98b50a9efec9e1db77d870ba01ed771f9a9c9f3 100644 (file)
@@ -121,7 +121,7 @@ public class PatternsInitializer implements BatchExtension {
   }
 
   public void addPatternToExcludeLines(String resource, Set<LineRange> lineRanges) {
-    addPatternForComponent(resource, new Pattern(resource, "*", lineRanges));
+    addPatternForComponent(resource, new Pattern(resource, "*", lineRanges).setCheckLines(true));
   }
 
   public void configurePatternsForComponent(String componentKey, String path) {
index da10e8545a34f173510b15f074477e3c98c079f3..7dd80bb57182c4343d5834c930141642e63f8ee0 100644 (file)
 
 package org.sonar.plugins.core.issue.ignore.pattern;
 
+import org.junit.Ignore;
+
 import org.junit.Test;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
-
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -81,7 +82,7 @@ public class PatternTest {
     Pattern pattern = new Pattern("*", "*");
     pattern.addLine(12);
 
-    assertThat(pattern.match(create(rule, javaFile, null))).isTrue();
+    assertThat(pattern.match(create(rule, javaFile, null))).isFalse();
     assertThat(pattern.match(create(rule, javaFile, 12))).isTrue();
     assertThat(pattern.match(create((Rule) null, javaFile, 5))).isFalse();
     assertThat(pattern.match(create(rule, null, null))).isFalse();