Search in sources :

Example 1 with XmlCoverageProvider

use of com.uber.jenkins.phabricator.coverage.XmlCoverageProvider 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;
    }
}
Also used : CoberturaPluginCoverageProvider(com.uber.jenkins.phabricator.coverage.CoberturaPluginCoverageProvider) JacocoPluginCoverageProvider(com.uber.jenkins.phabricator.coverage.JacocoPluginCoverageProvider) CoverageProvider(com.uber.jenkins.phabricator.coverage.CoverageProvider) CoberturaPluginCoverageProvider(com.uber.jenkins.phabricator.coverage.CoberturaPluginCoverageProvider) XmlCoverageProvider(com.uber.jenkins.phabricator.coverage.XmlCoverageProvider) XmlCoverageProvider(com.uber.jenkins.phabricator.coverage.XmlCoverageProvider) JacocoPluginCoverageProvider(com.uber.jenkins.phabricator.coverage.JacocoPluginCoverageProvider) JacocoBuildAction(hudson.plugins.jacoco.JacocoBuildAction) CoberturaBuildAction(hudson.plugins.cobertura.CoberturaBuildAction) Logger(com.uber.jenkins.phabricator.utils.Logger) Result(hudson.model.Result)

Aggregations

CoberturaPluginCoverageProvider (com.uber.jenkins.phabricator.coverage.CoberturaPluginCoverageProvider)1 CoverageProvider (com.uber.jenkins.phabricator.coverage.CoverageProvider)1 JacocoPluginCoverageProvider (com.uber.jenkins.phabricator.coverage.JacocoPluginCoverageProvider)1 XmlCoverageProvider (com.uber.jenkins.phabricator.coverage.XmlCoverageProvider)1 Logger (com.uber.jenkins.phabricator.utils.Logger)1 Result (hudson.model.Result)1 CoberturaBuildAction (hudson.plugins.cobertura.CoberturaBuildAction)1 JacocoBuildAction (hudson.plugins.jacoco.JacocoBuildAction)1