
org.sonar.plugins.clover.AbstractCloverMavenCollector Maven / Gradle / Ivy
/*
* Sonar, entreprise quality control tool.
* Copyright (C) 2007-2008 Hortis-GRC SA
* mailto:be_agile HAT hortis DOT ch
*
* 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.clover;
import org.apache.commons.configuration.Configuration;
import org.apache.maven.plugin.logging.Log;
import org.sonar.plugins.api.maven.*;
import org.sonar.plugins.api.maven.model.MavenPlugin;
import org.sonar.plugins.api.maven.model.MavenPom;
import org.sonar.plugins.surefire.SurefireMavenCollector;
import java.io.File;
public abstract class AbstractCloverMavenCollector extends AbstractJavaMavenCollector implements CollectsCodeCoverage {
protected Class extends MavenPluginHandler> mavenPluginHandlerClass;
private Configuration configuration;
protected CloverMavenPlugin cloverMavenPlugin;
protected AbstractCloverMavenCollector(JavaMeasuresRecorder measuresRecorder, Log log, Configuration configuration) {
super(measuresRecorder, log);
this.configuration = configuration;
}
public boolean shouldStopOnFailure() {
return true;
}
protected boolean shouldCollectIfNoSources() {
return false;
}
public boolean shouldCollectOn(MavenPom pom) {
MavenPlugin plugin = pom.getBuildPlugin(getGroupId(), getArtifactId());
return super.shouldCollectOn(pom) && shouldExecutePlugin(plugin);
}
@Override
protected boolean shouldCollectIfLightMode() {
return false;
}
public Class extends MavenPluginHandler> dependsOnMavenPlugin(MavenPom pom) {
return getMavenPluginHandlerClass();
}
protected abstract Class extends MavenPluginHandler> getMavenPluginHandlerClass();
public boolean shouldExecutePlugin(MavenPlugin plugin){
CloverMavenPlugin cloverMavenPlugin = new CloverMavenPlugin(plugin, getPluginVersion(), getPropKeyLicense(), getLog(), configuration);
return cloverMavenPlugin.shouldBeExecuted();
}
public void collect(MavenPom pom) {
File reportFile = MavenCollectorUtils.findFileFromBuildDirectory(pom, "site/clover/clover.xml");
XmlCollector xmlCollector = new XmlCollector(getMeasuresRecorder());
xmlCollector.collect(reportFile);
}
public void configure(CollectsUnitTests unitTestsCollector) {
if (unitTestsCollector instanceof SurefireMavenCollector) {
((SurefireMavenCollector)unitTestsCollector).overrideReportsDirectory("/clover/surefire-reports");
}
}
protected abstract String getGroupId();
protected abstract String getArtifactId();
protected abstract int getPluginVersion();
protected abstract String getPropKeyLicense();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy