2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
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.updatecenter.mavenplugin;
22 import org.apache.commons.lang.ArrayUtils;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
28 import java.util.ArrayList;
29 import java.util.List;
32 * @author Evgeny Mandrikov
33 * @goal check-dependencies
34 * @requiresDependencyResolution runtime
38 public class CheckDependenciesMojo extends AbstractSonarPluginMojo {
40 private static final String[] GWT_ARTIFACT_IDS = {"gwt-user", "gwt-dev", "sonar-gwt-api"};
41 private static final String[] LOG_GROUP_IDS = {"log4j", "commons-logging"};
43 public void execute() throws MojoExecutionException, MojoFailureException {
44 if (!isSkipDependenciesPackaging()) {
46 checkLogDependencies();
47 checkGwtDependencies();
51 private void checkApiDependency() throws MojoExecutionException {
52 Artifact sonarApi = getSonarPluginApiArtifact();
54 if (sonarApi == null) {
55 throw new MojoExecutionException(
56 SONAR_GROUPID + ":" + SONAR_PLUGIN_API_ARTIFACTID + " should be declared in dependencies"
61 private void checkLogDependencies() throws MojoExecutionException {
62 List<String> ids = new ArrayList<String>();
63 for (Artifact dep : getIncludedArtifacts()) {
64 if (ArrayUtils.contains(LOG_GROUP_IDS, dep.getGroupId())) {
65 ids.add(dep.getDependencyConflictId());
69 StringBuilder message = new StringBuilder();
70 message.append("Dependencies on the following log libraries should be excluded or declared with scope 'provided':")
72 .append(StringUtils.join(ids, ", "))
74 getLog().warn(message.toString());
78 private void checkGwtDependencies() {
79 List<String> ids = new ArrayList<String>();
80 for (Artifact dep : getDependencyArtifacts(Artifact.SCOPE_COMPILE)) {
81 if (ArrayUtils.contains(GWT_ARTIFACT_IDS, dep.getArtifactId())) {
82 ids.add(dep.getDependencyConflictId());
86 getLog().warn(getMessage("GWT dependencies should be defined with scope 'provided':", ids));