001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * Sonar is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 3 of the License, or (at your option) any later version.
010     *
011     * Sonar is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with Sonar; if not, write to the Free Software
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019     */
020    package org.sonar.plugins.cobertura;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.sonar.api.CoreProperties;
024    import org.sonar.api.batch.maven.MavenPlugin;
025    import org.sonar.api.batch.maven.MavenPluginHandler;
026    import org.sonar.api.batch.maven.MavenSurefireUtils;
027    import org.sonar.api.resources.Project;
028    import org.sonar.plugins.cobertura.api.CoberturaUtils;
029    
030    public class CoberturaMavenPluginHandler implements MavenPluginHandler {
031    
032      public String getGroupId() {
033        return CoberturaUtils.COBERTURA_GROUP_ID;
034      }
035    
036      public String getArtifactId() {
037        return CoberturaUtils.COBERTURA_ARTIFACT_ID;
038      }
039    
040      public String getVersion() {
041        return "2.5.1";
042      }
043    
044      public boolean isFixedVersion() {
045        return false;
046      }
047    
048      public String[] getGoals() {
049        return new String[] { "cobertura" };
050      }
051    
052      public void configure(Project project, MavenPlugin coberturaPlugin) {
053        configureCobertura(project, coberturaPlugin);
054        MavenSurefireUtils.configure(project);
055      }
056    
057      private void configureCobertura(Project project, MavenPlugin coberturaPlugin) {
058        coberturaPlugin.setParameter("formats/format", "xml");
059        for (String pattern : project.getExclusionPatterns()) {
060          if (pattern.endsWith(".java")) {
061            pattern = StringUtils.substringBeforeLast(pattern, ".") + ".class";
062    
063          } else if (StringUtils.substringAfterLast(pattern, "/").indexOf(".") < 0) {
064            pattern = pattern + ".class";
065          }
066          coberturaPlugin.addParameter("instrumentation/excludes/exclude", pattern);
067        }
068        coberturaPlugin.setParameter("maxmem", project.getConfiguration().getString(CoreProperties.COBERTURA_MAXMEM_PROPERTY,
069            CoreProperties.COBERTURA_MAXMEM_DEFAULT_VALUE));
070      }
071    }