diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-12 14:45:00 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-20 13:37:25 +0100 |
commit | 1787a07549561cb576eeeeb31e2208b753d20cb3 (patch) | |
tree | b22466e2b32047ccb5cf686687639b0f2939fe55 /sonar-plugin-api/src | |
parent | 2cd1a9722bf414d3ab9eb73a40bd138821a362e2 (diff) | |
download | sonarqube-1787a07549561cb576eeeeb31e2208b753d20cb3.tar.gz sonarqube-1787a07549561cb576eeeeb31e2208b753d20cb3.zip |
SONAR-7057 Delete deprecated org.sonar.api.checks.NoSonarFilter
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java | 73 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java | 91 |
2 files changed, 0 insertions, 164 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java deleted file mode 100644 index b8e4401d7f5..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.checks; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.sonar.api.scan.issue.filter.IssueFilter; -import com.google.common.collect.Maps; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.api.resources.Resource; - -import java.util.Map; -import java.util.Set; - -/** - * @since 2.1 - * @deprecated in 3.6. Replaced by {@link org.sonar.api.issue.NoSonarFilter} - */ -@Deprecated -public class NoSonarFilter implements IssueFilter { - - private final Map<String, Set<Integer>> noSonarLinesByKey = Maps.newHashMap(); - private SonarIndex sonarIndex; - - public NoSonarFilter(SonarIndex sonarIndex) { - this.sonarIndex = sonarIndex; - } - - public void addResource(Resource model, Set<Integer> noSonarLines) { - if (model != null && noSonarLines != null) { - // Reload resource to handle backward compatibility of resource keys - Resource resource = sonarIndex.getResource(model); - if (resource != null) { - noSonarLinesByKey.put(resource.getEffectiveKey(), noSonarLines); - } - } - } - - @Override - public boolean accept(FilterableIssue issue, IssueFilterChain chain) { - boolean accepted = true; - if (issue.line() != null) { - Set<Integer> noSonarLines = noSonarLinesByKey.get(issue.componentKey()); - accepted = noSonarLines == null || !noSonarLines.contains(issue.line()); - if (!accepted && StringUtils.containsIgnoreCase(issue.ruleKey().rule(), "nosonar")) { - accepted = true; - } - } - if (accepted) { - accepted = chain.accept(issue); - } - return accepted; - } -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java deleted file mode 100644 index 64581c1e859..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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.api.checks; - -import org.sonar.api.scan.issue.filter.FilterableIssue; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.batch.SonarIndex; -import org.sonar.api.scan.issue.filter.IssueFilterChain; -import org.sonar.api.resources.File; -import org.sonar.api.rule.RuleKey; - -import java.util.HashSet; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class NoSonarFilterTest { - - private SonarIndex sonarIndex = mock(SonarIndex.class); - NoSonarFilter filter = new NoSonarFilter(sonarIndex); - private File javaFile; - IssueFilterChain chain = mock(IssueFilterChain.class); - - @Before - public void prepare() { - when(chain.accept(isA(FilterableIssue.class))).thenReturn(true); - javaFile = File.create("org/foo/Bar.java"); - javaFile.setEffectiveKey("struts:org/foo/Bar.java"); - when(sonarIndex.getResource(javaFile)).thenReturn(javaFile); - } - - @Test - public void ignoreLinesCommentedWithNoSonar() { - Set<Integer> noSonarLines = new HashSet<>(); - noSonarLines.add(31); - noSonarLines.add(55); - filter.addResource(javaFile, noSonarLines); - - FilterableIssue issue = mock(FilterableIssue.class); - when(issue.componentKey()).thenReturn("struts:org/foo/Bar.java"); - when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "Foo")); - - // violation on class - assertThat(filter.accept(issue, chain)).isTrue(); - - // violation on lines - when(issue.line()).thenReturn(30); - assertThat(filter.accept(issue, chain)).isTrue(); - when(issue.line()).thenReturn(31); - assertThat(filter.accept(issue, chain)).isFalse(); - } - - @Test - public void should_accept_violations_from_no_sonar_rules() { - // The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !! - - Set<Integer> noSonarLines = new HashSet<>(); - noSonarLines.add(31); - filter.addResource(javaFile, noSonarLines); - - FilterableIssue issue = mock(FilterableIssue.class); - when(issue.componentKey()).thenReturn("struts:org.apache.Action"); - when(issue.ruleKey()).thenReturn(RuleKey.of("squid", "NoSonarCheck")); - - when(issue.line()).thenReturn(31); - assertThat(filter.accept(issue, chain)).isTrue(); - - } -} |