public static EVMViewBean getCurrentPVACEV(Job<?, ?> project) { final Run<?, ?> tb = project.getLastSuccessfulBuild(); Run<?, ?> b = project.getLastBuild(); while (b != null) { ProjectSummaryAction a = PMUtils.findActionByUrlEndsWith(b, ProjectSummaryAction.class, PMConstants.BASE); if (a != null) return a.getCurrentPVACEV(); if (b == tb) // if even the last successful build didn't produce the test // result, // that means we just don't have any tests configured. return null; b = b.getPreviousBuild(); } return null; }
@Override public Run<?, ?> getBuild(Job<?, ?> project) { return project.getLastSuccessfulBuild(); }
/** * Summarize the last coverage results of all jobs. If a job doesn't include any coverage, add * zero. * * @param jobs a final Collection of Job objects * @return JacocoCoverageResultSummary the result summary */ public static JacocoCoverageResultSummary getResultSummary(final Collection<Job<?, ?>> jobs) { JacocoCoverageResultSummary summary = new JacocoCoverageResultSummary(); for (Job<?, ?> job : jobs) { float classCoverage = 0.0f; float lineCoverage = 0.0f; float methodCoverage = 0.0f; float branchCoverage = 0.0f; float instructionCoverage = 0.0f; float complexityScore = 0.0f; Run<?, ?> run = job.getLastSuccessfulBuild(); if (run != null) { JacocoBuildAction jacocoAction = job.getLastSuccessfulBuild().getAction(JacocoBuildAction.class); if (null != jacocoAction) { if (null != jacocoAction.getClassCoverage()) { classCoverage = jacocoAction.getClassCoverage().getPercentageFloat(); BigDecimal bigClassCoverage = new BigDecimal(classCoverage); bigClassCoverage = bigClassCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); classCoverage = bigClassCoverage.floatValue(); } if (null != jacocoAction.getLineCoverage()) { lineCoverage = jacocoAction.getLineCoverage().getPercentageFloat(); BigDecimal bigLineCoverage = new BigDecimal(lineCoverage); bigLineCoverage = bigLineCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); lineCoverage = bigLineCoverage.floatValue(); } if (null != jacocoAction.getMethodCoverage()) { methodCoverage = jacocoAction.getMethodCoverage().getPercentageFloat(); BigDecimal bigMethodCoverage = new BigDecimal(methodCoverage); bigMethodCoverage = bigMethodCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); methodCoverage = bigMethodCoverage.floatValue(); } if (null != jacocoAction.getBranchCoverage()) { branchCoverage = jacocoAction.getBranchCoverage().getPercentageFloat(); BigDecimal bigBranchCoverage = new BigDecimal(branchCoverage); bigBranchCoverage = bigBranchCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); branchCoverage = bigBranchCoverage.floatValue(); } if (null != jacocoAction.getInstructionCoverage()) { instructionCoverage = jacocoAction.getInstructionCoverage().getPercentageFloat(); BigDecimal bigInstructionCoverage = new BigDecimal(instructionCoverage); bigInstructionCoverage = bigInstructionCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); instructionCoverage = bigInstructionCoverage.floatValue(); } if (null != jacocoAction.getComplexityScore()) { complexityScore = jacocoAction.getComplexityScore().getPercentageFloat(); BigDecimal bigComplexityCoverage = new BigDecimal(complexityScore); bigComplexityCoverage = bigComplexityCoverage.setScale(1, BigDecimal.ROUND_HALF_EVEN); complexityScore = bigComplexityCoverage.floatValue(); } } } summary.addCoverageResult( new JacocoCoverageResultSummary( job, lineCoverage, methodCoverage, classCoverage, branchCoverage, instructionCoverage, complexityScore)); } return summary; }