diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-04 10:16:50 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-04 10:17:18 +0100 |
commit | 88554cc3c9747e266247f7d27ab3c22c93c6fa0d (patch) | |
tree | 7cd18655d9787b222825b022682201933ff6faed /sonar-batch/src/main/java/org/sonar/batch/bootstrap | |
parent | 8c4d787e20a63ece8620eac0a7686cb16dc536a7 (diff) | |
download | sonarqube-88554cc3c9747e266247f7d27ab3c22c93c6fa0d.tar.gz sonarqube-88554cc3c9747e266247f7d27ab3c22c93c6fa0d.zip |
SONAR-2967 extract the new component ProjectFilter from ProjectTree
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar/batch/bootstrap')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java | 1 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java | 73 |
2 files changed, 74 insertions, 0 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java index 822d6ca7a8d..0dbe5c95b97 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchModule.java @@ -49,6 +49,7 @@ public class BatchModule extends Module { @Override protected void configure() { addCoreSingleton(ProjectTree.class); + addCoreSingleton(ProjectFilter.class); addCoreSingleton(ProjectConfigurator.class); addCoreSingleton(DefaultResourceCreationLock.class); addCoreSingleton(DefaultIndex.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java new file mode 100644 index 00000000000..5ecf6606dc0 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ProjectFilter.java @@ -0,0 +1,73 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.batch.bootstrap; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.config.Settings; +import org.sonar.api.resources.Project; + +/** + * Filter projects to analyze by using the properties sonar.skippedModules and sonar.includedModules + * + * @since 2.12 + */ +public class ProjectFilter { + + private Settings settings; + + public ProjectFilter(Settings settings) { + this.settings = settings; + } + + public boolean isExcluded(Project project) { + Project p = project; + while (p != null) { + if (isExcluded(getArtifactId(p))) { + return true; + } + p = p.getParent(); + } + return false; + } + + private boolean isExcluded(String artifactId) { + String[] includedArtifactIds = settings.getStringArray("sonar.includedModules"); + + if (includedArtifactIds.length > 0) { + return !ArrayUtils.contains(includedArtifactIds, artifactId); + } + String[] excludedArtifactIds = settings.getStringArray("sonar.skippedModules"); + return ArrayUtils.contains(excludedArtifactIds, artifactId); + } + + // TODO see http://jira.codehaus.org/browse/SONAR-2324 + static String getArtifactId(Project project) { + String key = project.getKey(); + if (StringUtils.isNotBlank(project.getBranch())) { + // remove branch part + key = StringUtils.removeEnd(project.getKey(), ":" + project.getBranch()); + } + if (key.contains(":")) { + return StringUtils.substringAfter(key, ":"); + } + return key; + } +} |