/src/main/java/com/atlassian/bamboo/plugin/dotnet/ncover/ViewNCoverBuildResults.java
Java | 94 lines | 52 code | 13 blank | 29 comment | 6 complexity | 85bb172dcc3bff55ca9bbca921f17369 MD5 | raw file
Possible License(s): BSD-3-Clause
- /**
- *
- */
- package com.atlassian.bamboo.plugin.dotnet.ncover;
- import com.atlassian.bamboo.build.ViewBuildResults;
- import com.atlassian.bamboo.resultsummary.BuildResultsSummary;
- import com.atlassian.bamboo.util.NumberUtils;
- import com.google.common.collect.Lists;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.log4j.Logger;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.StringReader;
- import java.util.Collection;
- import java.util.StringTokenizer;
- /**
- * NCover-specifc {@link ViewBuildResults} subclass that handles populating
- * the <code>coverageChanges</code> collection when servicing requests to
- * display the NCover Build results tab.
- *
- * @author Ross Rowe
- *
- */
- public class ViewNCoverBuildResults extends ViewBuildResults {
- private static final long serialVersionUID = 1L;
- private Collection<NCoverCoverageInformation> coverageChanges = Lists.newArrayList();
- private static final Logger log = Logger
- .getLogger(ViewNCoverBuildResults.class);
- /**
- * Performs the super.execute(), and populates the
- * <code>coverageChanges</code> variable.
- *
- * @return
- * @throws Exception
- * if an error occurs processing the action
- */
- @Override
- public String execute() throws Exception {
- String superResult = super.doExecute();
- if (ERROR.equals(superResult)) {
- return ERROR;
- }
- populateCoverageChanges(getBuildResultsSummary());
- return superResult;
- }
- /**
- * Reads the NCover Coverage Changes from the {@link BuildResultsSummary}'s
- * customBuildData, and adds corresponding
- * {@link NCoverCoverageInformation} instances into the
- * <code>coverageChanges</code> variable.
- *
- * @param buildResultsSummary
- */
- private void populateCoverageChanges(BuildResultsSummary buildResultsSummary)
- {
- String csv = buildResultsSummary.getCustomBuildData().get(NCoverBuildProcessor.NCOVER_COVERAGE_CHANGES);
- if (csv != null && !StringUtils.isEmpty(csv)) {
- BufferedReader reader = new BufferedReader(new StringReader(csv));
- String line = null;
- try {
- while ((line = reader.readLine()) != null) {
- StringTokenizer tokenizer = new StringTokenizer(line, ",");
- String className = tokenizer.nextToken();
- Double lineRate = NumberUtils.stringToDouble(tokenizer.nextToken());
- Double delta = NumberUtils.stringToDouble(tokenizer.nextToken());
- //lineRate = NumberUtils.round(lineRate * 100, 2);
- //delta = NumberUtils.round(delta * 100, 2);
- coverageChanges.add(new NCoverCoverageInformation(
- className, lineRate, delta));
- }
- } catch (NumberFormatException e) {
- log.error(e);
- } catch (IOException e) {
- log.error(e);
- }
- }
- }
- public Collection getCoverageChanges() {
- return coverageChanges;
- }
- }