use of com.uber.jenkins.phabricator.coverage.JacocoPluginCoverageProvider 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