]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7057 Delete deprecated org.sonar.api.checks.NoSonarFilter 628/head
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 12 Nov 2015 13:45:00 +0000 (14:45 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Nov 2015 12:37:25 +0000 (13:37 +0100)
sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java
sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/checks/NoSonarFilterTest.java [deleted file]

index 3f5bf958a8b0b21180e6ef0f4cf95bb7f5a65cad..6938bc79eb826ba749008404b6fcb22dc69825d8 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.internal.FileMetadata;
 import org.sonar.api.batch.rule.CheckFactory;
-import org.sonar.api.checks.NoSonarFilter;
 import org.sonar.api.resources.Project;
 import org.sonar.api.scan.filesystem.FileExclusions;
 import org.sonar.batch.DefaultProjectTree;
@@ -161,7 +160,6 @@ public class ModuleScanContainer extends ComponentContainer {
       IssueExclusionsLoader.class,
       EnforceIssuesFilter.class,
       IgnoreIssuesFilter.class,
-      NoSonarFilter.class,
 
       // Perspectives
       BatchPerspectives.class,
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 (file)
index b8e4401..0000000
+++ /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 (file)
index 64581c1..0000000
+++ /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();
-
-  }
-}