use of hudson.plugins.cobertura.CoberturaBuildAction in project phabricator-jenkins-plugin by uber.
the class CoberturaCoverageProvider method computeCoverage.
private void computeCoverage() {
AbstractBuild build = getBuild();
if (build == null) {
mHasComputedCoverage = true;
return;
}
// Check if there is a cobertura build action
CoberturaBuildAction coberturaAction = build.getAction(CoberturaBuildAction.class);
if (coberturaAction != null) {
mCoverageResult = coberturaAction.getResult();
if (mCoverageResult != null) {
computeLineCoverage();
}
mHasComputedCoverage = true;
return;
}
// Fallback to scanning for the reports
copyCoverageToJenkinsMaster(build);
File[] reports = getCoberturaReports(build);
CoverageResult result = null;
if (reports != null) {
for (File report : reports) {
try {
result = CoberturaCoverageParser.parse(report, result);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load " + report, e);
}
}
}
if (result != null) {
result.setOwner(build);
computeLineCoverage();
cleanupCoverageFilesOnJenkinsMaster();
}
if (result != null) {
result.setOwner(build);
}
mCoverageResult = result;
mHasComputedCoverage = true;
}
use of hudson.plugins.cobertura.CoberturaBuildAction in project phabricator-jenkins-plugin by uber.
the class PhabricatorNotifier method getCoverageProvider.
/**
* Get the coverage provider for the build
*
* @param build The current build
* @param listener The build listener
* @return The current coverage, if any
*/
private CoverageProvider getCoverageProvider(Run<?, ?> build, FilePath workspace, TaskListener listener, Set<String> includeFiles) {
Result buildResult;
if (build.getResult() == null) {
buildResult = Result.SUCCESS;
} else {
buildResult = build.getResult();
}
if (!buildResult.isBetterOrEqualTo(Result.UNSTABLE)) {
return null;
}
copyCoverageToJenkinsMaster(build, workspace, listener);
CoverageProvider coverageProvider = null;
Logger logger = new Logger(listener.getLogger());
// Only one coverage plugin provider is supported per build
if (Jenkins.getInstance().getPlugin("cobertura") != null) {
CoberturaBuildAction coberturaBuildAction = build.getAction(CoberturaBuildAction.class);
if (coberturaBuildAction != null) {
// Choose only a single coverage provider
logger.info(UBERALLS_TAG, "Using coverage metrics from Cobertura Jenkins Plugin");
coverageProvider = new CoberturaPluginCoverageProvider(getCoverageReports(build), includeFiles, coberturaBuildAction);
}
}
if (coverageProvider == null && Jenkins.getInstance().getPlugin("jacoco") != null) {
JacocoBuildAction jacocoBuildAction = build.getAction(JacocoBuildAction.class);
if (jacocoBuildAction != null) {
logger.info(UBERALLS_TAG, "Using coverage metrics from Jacoco Jenkins Plugin");
coverageProvider = new JacocoPluginCoverageProvider(getCoverageReports(build), includeFiles, jacocoBuildAction);
}
}
if (coverageProvider == null) {
logger.info(UBERALLS_TAG, "Trying to obtain coverage metrics by parsing coverage xml files");
coverageProvider = new XmlCoverageProvider(getCoverageReports(build), includeFiles);
}
coverageProvider.computeCoverageIfNeeded();
cleanupCoverageFilesOnJenkinsMaster(build);
if (coverageProvider.hasCoverage()) {
return coverageProvider;
} else {
logger.info(UBERALLS_TAG, "No coverage results found");
return null;
}
}
Aggregations