2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.findbugs;
22 import org.apache.commons.configuration.Configuration;
23 import org.sonar.api.batch.Initializer;
24 import org.sonar.api.batch.SupportedEnvironment;
25 import org.sonar.api.batch.maven.MavenPlugin;
26 import org.sonar.api.batch.maven.MavenUtils;
27 import org.sonar.api.resources.Java;
28 import org.sonar.api.resources.Project;
31 * Configures Sonar FindBugs Plugin according to configuration of findbugs-maven-plugin.
32 * Supports only "excludeFilterFile".
36 @SupportedEnvironment("maven")
37 public class FindbugsMavenInitializer extends Initializer {
39 private static final String FINDBUGS_GROUP_ID = MavenUtils.GROUP_ID_CODEHAUS_MOJO;
40 private static final String FINDBUGS_ARTIFACT_ID = "findbugs-maven-plugin";
43 public boolean shouldExecuteOnProject(Project project) {
44 return Java.KEY.equals(project.getLanguageKey())
45 && !project.getFileSystem().mainFiles(Java.KEY).isEmpty();
49 public void execute(Project project) {
50 Configuration conf = project.getConfiguration();
51 if (!conf.containsKey(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY)) {
52 conf.setProperty(FindbugsConstants.EXCLUDES_FILTERS_PROPERTY, getExcludesFiltersFromPluginConfiguration(project));
56 private static String getExcludesFiltersFromPluginConfiguration(Project project) {
57 MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), FINDBUGS_GROUP_ID, FINDBUGS_ARTIFACT_ID);
58 return mavenPlugin != null ? mavenPlugin.getParameter("excludeFilterFile") : null;