Search in sources :

Example 1 with CoberturaBuildAction

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;
}
Also used : AbstractBuild(hudson.model.AbstractBuild) CoberturaBuildAction(hudson.plugins.cobertura.CoberturaBuildAction) IOException(java.io.IOException) File(java.io.File) CoverageResult(hudson.plugins.cobertura.targets.CoverageResult)

Example 2 with CoberturaBuildAction

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;
    }
}
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

CoberturaBuildAction (hudson.plugins.cobertura.CoberturaBuildAction)2 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 AbstractBuild (hudson.model.AbstractBuild)1 Result (hudson.model.Result)1 CoverageResult (hudson.plugins.cobertura.targets.CoverageResult)1 JacocoBuildAction (hudson.plugins.jacoco.JacocoBuildAction)1 File (java.io.File)1 IOException (java.io.IOException)1