summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-12 17:56:00 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-12 17:56:23 +0100
commitb218afa5a514c2a3a7fcb856cde88d884fc129c8 (patch)
tree0ce15e51e62abf163b4aef938e11eb7e13273530 /plugins
parent102fe9aa9858c9371140ce66b30d48be21a24696 (diff)
downloadsonarqube-b218afa5a514c2a3a7fcb856cde88d884fc129c8.tar.gz
sonarqube-b218afa5a514c2a3a7fcb856cde88d884fc129c8.zip
SONAR-1896 SONAR-3739 improve the API of scan file system
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java4
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java51
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ProjectFileSystemLogger.java58
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java98
4 files changed, 0 insertions, 211 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 44dea680560..0a136a4fcef 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -29,10 +29,8 @@ import org.sonar.api.checks.NoSonarFilter;
import org.sonar.api.notifications.NotificationDispatcherMetadata;
import org.sonar.api.resources.Java;
import org.sonar.core.timemachine.Periods;
-import org.sonar.plugins.core.batch.ExcludedResourceFilter;
import org.sonar.plugins.core.batch.IndexProjectPostJob;
import org.sonar.plugins.core.batch.MavenInitializer;
-import org.sonar.plugins.core.batch.ProjectFileSystemLogger;
import org.sonar.plugins.core.charts.DistributionAreaChart;
import org.sonar.plugins.core.charts.DistributionBarChart;
import org.sonar.plugins.core.charts.XradarChart;
@@ -413,7 +411,6 @@ public final class CorePlugin extends SonarPlugin {
return ImmutableList.of(
DefaultResourceTypes.class,
UserManagedMetrics.class,
- ProjectFileSystemLogger.class,
Periods.class,
// maven
@@ -495,7 +492,6 @@ public final class CorePlugin extends SonarPlugin {
OverallCoverageDecorator.class,
OverallBranchCoverageDecorator.class,
ApplyProjectRolesDecorator.class,
- ExcludedResourceFilter.class,
CommentDensityDecorator.class,
NoSonarFilter.class,
DirectoriesDecorator.class,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java
deleted file mode 100644
index 46516ff4d8a..00000000000
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ExcludedResourceFilter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.core.batch;
-
-import org.sonar.api.batch.ResourceFilter;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-
-/**
- * @since 1.12
- */
-public class ExcludedResourceFilter implements ResourceFilter {
- private final Project project;
-
- public ExcludedResourceFilter(Project project) {
- this.project = project;
- }
-
- public boolean isIgnored(Resource resource) {
- String[] patterns = ResourceUtils.isUnitTestClass(resource) ? project.getTestExclusionPatterns() : project.getExclusionPatterns();
- if (patterns == null) {
- return false;
- }
-
- for (String pattern : patterns) {
- if (resource.matchFilePattern(pattern)) {
- return true;
- }
- }
-
- return false;
- }
-}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ProjectFileSystemLogger.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ProjectFileSystemLogger.java
deleted file mode 100644
index 3364e99b8f6..00000000000
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/batch/ProjectFileSystemLogger.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.core.batch;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Initializer;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectFileSystem;
-
-import java.util.Arrays;
-import java.util.List;
-
-public class ProjectFileSystemLogger extends Initializer {
- private static final Logger LOG = LoggerFactory.getLogger(ProjectFileSystemLogger.class);
-
- @Override
- public void execute(Project project) {
- logExclusionPatterns("Excluded sources: {}", project.getExclusionPatterns());
- logExclusionPatterns("Excluded tests: {}", project.getTestExclusionPatterns());
-
- ProjectFileSystem projectFileSystem = project.getFileSystem();
- logDirectories("Source directories:", projectFileSystem.getSourceDirs());
- logDirectories("Test directories:", projectFileSystem.getTestDirs());
- }
-
- private void logExclusionPatterns(String message, String[] exclusionPatterns) {
- if (exclusionPatterns != null && exclusionPatterns.length > 0) {
- LOG.info(message, Arrays.toString(exclusionPatterns));
- }
- }
-
- private void logDirectories(String name, List<java.io.File> dirs) {
- if (!dirs.isEmpty()) {
- LOG.info(name);
- for (java.io.File dir : dirs) {
- LOG.info(" {}", dir);
- }
- }
- }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java
deleted file mode 100644
index 1b9612ae750..00000000000
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/batch/ExcludedResourceFilterTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.plugins.core.batch;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ExcludedResourceFilterTest {
-
- @Test
- public void doNotFailIfNoPatterns() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- Project project = new Project("foo").setConfiguration(conf);
- ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
- assertThat(filter.isIgnored(mock(Resource.class)), is(false));
- }
-
- @Test
- public void noPatternsMatch() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
- Project project = new Project("foo").setConfiguration(conf);
- ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
- assertThat(filter.isIgnored(mock(Resource.class)), is(false));
- }
-
- @Test
- public void ignoreResourceIfMatchesPattern() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
- Project project = new Project("foo").setConfiguration(conf);
- ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
-
- Resource resource = mock(Resource.class);
- when(resource.matchFilePattern("**/bar/*")).thenReturn(true);
-
- assertThat(filter.isIgnored(resource), is(true));
- }
-
- @Test
- public void ignoreTestIfMatchesPattern() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
- Project project = new Project("foo").setConfiguration(conf);
- ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
-
- Resource resource = mock(Resource.class);
- when(resource.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
- when(resource.matchFilePattern("**/bar/*")).thenReturn(true);
-
- assertThat(filter.isIgnored(resource), is(true));
- }
-
- /**
- * See SONAR-1115 Source exclusion patterns do not apply to unit tests.
- */
- @Test
- public void doNotExcludeUnitTestFiles() {
- PropertiesConfiguration conf = new PropertiesConfiguration();
- conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, new String[]{"**/foo/*.java", "**/bar/*"});
- Project project = new Project("foo").setConfiguration(conf);
- ExcludedResourceFilter filter = new ExcludedResourceFilter(project);
-
- Resource unitTest = mock(Resource.class);
- when(unitTest.getQualifier()).thenReturn(Qualifiers.UNIT_TEST_FILE);
-
- // match exclusion pattern
- when(unitTest.matchFilePattern("**/bar/*")).thenReturn(true);
-
- assertThat(filter.isIgnored(unitTest), is(false));
- }
-}