|
|
| Line 1: | |||
| + | This report has to be used in conjunction with a report template such as the [[HTML Template]]. | ||
| + | ---- | ||
| + | ''Meta-Data Script:'' | ||
| + | <pre> | ||
| + | import com.urbancode.anthill3.domain.reporting.*; | ||
| + | ReportMetaData rmd = new ReportMetaData(); | ||
| + | rmd.addColumn("Status"); | ||
| + | rmd.addColumn("Project"); | ||
| + | rmd.addColumn("Branch"); | ||
| + | rmd.addColumn("Tests"); | ||
| + | rmd.addColumn("Tests Passing"); | ||
| + | rmd.addColumn("Line Coverage"); | ||
| + | rmd.addColumn("Branch Coverage"); | ||
| + | rmd.addColumn("Latest Stamp"); | ||
| + | rmd.addColumn("Date"); | ||
| + | return rmd; | ||
| + | </pre> | ||
| + | ---- | ||
| + | ''Report Script:'' | ||
| + | <pre>import com.urbancode.anthill3.dashboard.BuildLifeWorkflowCaseSummary; | ||
| + | import com.urbancode.anthill3.dashboard.DashboardFactory; | ||
| + | import com.urbancode.anthill3.domain.buildlife.BuildLife; | ||
| + | import com.urbancode.anthill3.domain.buildlife.BuildLifeFactory; | ||
| + | import com.urbancode.anthill3.domain.coverage.CoverageReport; | ||
| + | import com.urbancode.anthill3.domain.persistent.PersistenceException; | ||
| + | import com.urbancode.anthill3.domain.project.Project; | ||
| + | import com.urbancode.anthill3.domain.project.ProjectFactory; | ||
| + | import com.urbancode.anthill3.domain.reporting.ReportMetaData; | ||
| + | import com.urbancode.anthill3.domain.reporting.ReportOutput; | ||
| + | import com.urbancode.anthill3.domain.reporting.ReportRow; | ||
| + | import com.urbancode.anthill3.domain.test.TestReportFactory; | ||
| + | import com.urbancode.anthill3.domain.workflow.Workflow; | ||
| + | import com.urbancode.anthill3.domain.workflow.WorkflowStatusEnum; | ||
| + | import com.urbancode.anthill3.web.project.ProjectTasks; | ||
| + | import com.urbancode.anthill3.domain.test.TestReport; | ||
| + | import com.urbancode.anthill3.runtime.scripting.helpers.CoverageHelper; | ||
| + | import java.util.List; | ||
| + | String serverUrl = reportUrl.substring(0, reportUrl.indexOf("/", 10)); | ||
| + | String buildLifeUrl = serverUrl + ProjectTasks.methodUrl("viewBuildLife"); | ||
| + | Project[] projectArray = ProjectFactory.getInstance().restoreAllActive(); | ||
| + | List workflowList = new java.util.ArrayList(); | ||
| + | for (int i = 0; i < projectArray.length; i++) { | ||
| + | Workflow[] originatingArray = projectArray[i].getOriginatingWorkflowArray(); | ||
| + | for (int j = 0; j < originatingArray.length; j++) { | ||
| + | workflowList.add(originatingArray[j]); | ||
| + | } | ||
| + | } | ||
| + | ReportOutput output = new ReportOutput(metaData); | ||
| + | Workflow[] workflows = new Workflow[ workflowList.size() ]; | ||
| + | workflowList.toArray(workflows); | ||
| + | for (int i = 0; i < workflows.length; i++) { | ||
| + | BuildLifeWorkflowCaseSummary[] mostRecentSummaryArray = | ||
| + | DashboardFactory.getInstance().getBuildLifeWorkflowSummariesByWorkflow(workflows[i].getId(), null, new Integer(1)); | ||
| + | if (mostRecentSummaryArray.length > 0) { | ||
| + | BuildLifeWorkflowCaseSummary summary = mostRecentSummaryArray[0]; | ||
| + | |||
| + | ReportRow row = new ReportRow(output, "1"); | ||
| + | |||
| + | ///////// PROJECT ///////////////// | ||
| + | String projectName = summary.getProjectName(); | ||
| + | Long projectId = summary.getProjectId(); | ||
| + | String projectUrl = "/tasks/project/ProjectTasks/viewDashboard?projectId=" + projectId; | ||
| + | // HTML OUTPUT | ||
| + | // row.setColumnValue("Project", "<b><a href=\"" + projectUrl + "\">" + projectName + "</a></b>"); | ||
| + | // CSV OUTPUT | ||
| + | row.setColumnValue("Project", projectName); | ||
| + | ///////// BRANCH ///////////////// | ||
| + | row.setColumnValue("Branch", summary.getWorkflowName()); | ||
| + | |||
| + | ///////// DATE /////////////////// | ||
| + | row.setColumnValue("Date", summary.getEndDate() == null ? "Running" : String.valueOf(summary.getEndDate())); | ||
| + | ///////// STATUS ///////////////// | ||
| + | WorkflowStatusEnum workflowStatus = summary.getStatus(); | ||
| + | String workflowStatusColor = workflowStatus.getColor(); | ||
| + | String workflowStatusName = workflowStatus.getName(); | ||
| + | if ("Complete".equals(workflowStatusName)) { | ||
| + | workflowStatusName = "Success"; | ||
| + | } | ||
| + | // HTML OUTPUT | ||
| + | //row.setColumnValue("Status", "<font color=\"" + workflowStatusColor + "\">" + workflowStatusName + "</font>"); | ||
| + | // CSV OUTPUT | ||
| + | row.setColumnValue("Status", workflowStatusName); | ||
| + | ///////// STAMP ///////////////// | ||
| + | String stamp = summary.getLatestStamp(); | ||
| + | Long buildLifeId = summary.getBuildLifeId(); | ||
| + | buildLifeUrl = "/tasks/project/ProjectTasks/viewBuildLife?buildLifeId=" + buildLifeId; | ||
| + | // HTML OUTPUT | ||
| + | //row.setColumnValue("Latest Stamp", "<a href=\"" + buildLifeUrl + "\">" + stamp + "</a>"); | ||
| + | // CSV OUTPUT | ||
| + | row.setColumnValue("Latest Stamp", stamp); | ||
| + | ///////// TESTS /////////////// | ||
| + | BuildLife buildLife = BuildLifeFactory.getInstance().restore(summary.getBuildLifeId()); | ||
| + | TestReport[] tests = TestReportFactory.getInstance().restoreAllForBuildLife(buildLife); | ||
| + | |||
| + | int numberOfTests = 0; | ||
| + | int numberOfSuccesses = 0; | ||
| + | for (int j = 0; j < tests.length; j++) { | ||
| + | numberOfTests += tests[j].getNumberOfTests(); | ||
| + | numberOfSuccesses += tests[j].getNumberOfSuccesses(); | ||
| + | } | ||
| + | row.setColumnValue("Tests", "" + numberOfTests); | ||
| + | |||
| + | ///////// TESTS PASSING ///////// | ||
| + | long testsPassingFinal = 0; | ||
| + | if (numberOfTests > 0) { | ||
| + | testsPassingFinal = Math.round(((double)numberOfSuccesses / (double)numberOfTests) * 100.0); | ||
| + | } | ||
| + | row.setColumnValue("Tests Passing", "" + testsPassingFinal + "%"); | ||
| + | ///////// LINE COVERAGE ////////////// | ||
| + | ///////// BRANCH COVERAGE //////////// | ||
| + | CoverageReport[] coverageReport = CoverageHelper.getForBuildLife(buildLife); | ||
| + | long lineCoverageFinal = 0; | ||
| + | long branchCoverageFinal = 0; | ||
| + | if (coverageReport != null && coverageReport.length > 0) { | ||
| + | double lineCoverageTotal = 0.0; | ||
| + | int lineCoverageCount = 0; | ||
| + | double branchCoverageTotal = 0.0; | ||
| + | int branchCoverageCount = 0; | ||
| + | for( int k = 0; k < coverageReport.length; ++k) { | ||
| + | if (coverageReport[k].getLinePercentage() != null) { | ||
| + | lineCoverageTotal += coverageReport[k].getLinePercentage().doubleValue(); | ||
| + | lineCoverageCount++; | ||
| + | } | ||
| + | if (coverageReport[k].getBranchPercentage() != null) { | ||
| + | branchCoverageTotal += coverageReport[k].getBranchPercentage().doubleValue(); | ||
| + | branchCoverageCount++; | ||
| + | } | ||
| + | } | ||
| + | if (lineCoverageCount > 0) { | ||
| + | lineCoverageFinal = Math.round( 100.0 * (lineCoverageTotal / (double)lineCoverageCount));; | ||
| + | } | ||
| + | if (branchCoverageCount > 0) { | ||
| + | branchCoverageFinal = Math.round( 100.0 * (branchCoverageTotal / (double)branchCoverageCount)); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | row.setColumnValue("Line Coverage", "" + lineCoverageFinal + "%" ); | ||
| + | row.setColumnValue("Branch Coverage", "" + branchCoverageFinal + "%" ); | ||
| + | |||
| + | output.addRow(row); | ||
| + | } | ||
| + | } | ||
| + | return output; | ||
| + | </pre> | ||
| + | ---- | ||
| + | '''Related Content''' | ||
| + | [[AnthillPro Template Reports]]<br/> | ||
| + | [[Report Templates]] | ||