Search in sources :

Example 1 with CoverageResult

use of hudson.plugins.cobertura.targets.CoverageResult 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 CoverageResult

use of hudson.plugins.cobertura.targets.CoverageResult in project phabricator-jenkins-plugin by uber.

the class CoberturaCoverageProviderTest method getMockResult.

private CoverageResult getMockResult() {
    Ratio ratio = Ratio.create(75.0f, 100.0f);
    CoverageResult result = mock(CoverageResult.class);
    when(result.getCoverage(CoverageMetric.LINE)).thenReturn(ratio);
    return result;
}
Also used : Ratio(hudson.plugins.cobertura.Ratio) CoverageResult(hudson.plugins.cobertura.targets.CoverageResult)

Example 3 with CoverageResult

use of hudson.plugins.cobertura.targets.CoverageResult in project phabricator-jenkins-plugin by uber.

the class CoberturaPluginCoverageProviderTest method getMockResult.

private CoverageResult getMockResult() {
    Ratio ratio = Ratio.create(75.0f, 100.0f);
    CoverageResult result = mock(CoverageResult.class);
    when(result.getCoverage(CoverageMetric.LINE)).thenReturn(ratio);
    return result;
}
Also used : Ratio(hudson.plugins.cobertura.Ratio) CoverageResult(hudson.plugins.cobertura.targets.CoverageResult)

Example 4 with CoverageResult

use of hudson.plugins.cobertura.targets.CoverageResult in project phabricator-jenkins-plugin by uber.

the class CoberturaCoverageProviderTest method testConvertCobertura.

@WithoutJenkins
@Test
public void testConvertCobertura() {
    CoverageResult result = getMockResult();
    CodeCoverageMetrics metrics = CoberturaCoverageProvider.convertCobertura(result);
    assertEquals(75.0f, metrics.getLineCoveragePercent(), 0.0f);
    assertEquals(0.0f, metrics.getPackageCoveragePercent(), 0.0f);
}
Also used : CoverageResult(hudson.plugins.cobertura.targets.CoverageResult) Test(org.junit.Test) WithoutJenkins(org.jvnet.hudson.test.WithoutJenkins)

Example 5 with CoverageResult

use of hudson.plugins.cobertura.targets.CoverageResult in project phabricator-jenkins-plugin by uber.

the class CoberturaPluginCoverageProvider method computeMetrics.

@Override
protected void computeMetrics() {
    CoverageResult coverageResult = buildAction.getResult();
    metrics = convertCobertura(coverageResult);
}
Also used : CoverageResult(hudson.plugins.cobertura.targets.CoverageResult)

Aggregations

CoverageResult (hudson.plugins.cobertura.targets.CoverageResult)6 Ratio (hudson.plugins.cobertura.Ratio)2 Test (org.junit.Test)2 AbstractBuild (hudson.model.AbstractBuild)1 CoberturaBuildAction (hudson.plugins.cobertura.CoberturaBuildAction)1 File (java.io.File)1 IOException (java.io.IOException)1 WithoutJenkins (org.jvnet.hudson.test.WithoutJenkins)1