PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/bamboo/plugin/dotnet/ncover/ViewNCoverBuildResults.java

https://bitbucket.org/atlassian/bamboo-dotnet-plugin/
Java | 94 lines | 52 code | 13 blank | 29 comment | 6 complexity | 85bb172dcc3bff55ca9bbca921f17369 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /**
  2. *
  3. */
  4. package com.atlassian.bamboo.plugin.dotnet.ncover;
  5. import com.atlassian.bamboo.build.ViewBuildResults;
  6. import com.atlassian.bamboo.resultsummary.BuildResultsSummary;
  7. import com.atlassian.bamboo.util.NumberUtils;
  8. import com.google.common.collect.Lists;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.apache.log4j.Logger;
  11. import java.io.BufferedReader;
  12. import java.io.IOException;
  13. import java.io.StringReader;
  14. import java.util.Collection;
  15. import java.util.StringTokenizer;
  16. /**
  17. * NCover-specifc {@link ViewBuildResults} subclass that handles populating
  18. * the <code>coverageChanges</code> collection when servicing requests to
  19. * display the NCover Build results tab.
  20. *
  21. * @author Ross Rowe
  22. *
  23. */
  24. public class ViewNCoverBuildResults extends ViewBuildResults {
  25. private static final long serialVersionUID = 1L;
  26. private Collection<NCoverCoverageInformation> coverageChanges = Lists.newArrayList();
  27. private static final Logger log = Logger
  28. .getLogger(ViewNCoverBuildResults.class);
  29. /**
  30. * Performs the super.execute(), and populates the
  31. * <code>coverageChanges</code> variable.
  32. *
  33. * @return
  34. * @throws Exception
  35. * if an error occurs processing the action
  36. */
  37. @Override
  38. public String execute() throws Exception {
  39. String superResult = super.doExecute();
  40. if (ERROR.equals(superResult)) {
  41. return ERROR;
  42. }
  43. populateCoverageChanges(getBuildResultsSummary());
  44. return superResult;
  45. }
  46. /**
  47. * Reads the NCover Coverage Changes from the {@link BuildResultsSummary}'s
  48. * customBuildData, and adds corresponding
  49. * {@link NCoverCoverageInformation} instances into the
  50. * <code>coverageChanges</code> variable.
  51. *
  52. * @param buildResultsSummary
  53. */
  54. private void populateCoverageChanges(BuildResultsSummary buildResultsSummary)
  55. {
  56. String csv = buildResultsSummary.getCustomBuildData().get(NCoverBuildProcessor.NCOVER_COVERAGE_CHANGES);
  57. if (csv != null && !StringUtils.isEmpty(csv)) {
  58. BufferedReader reader = new BufferedReader(new StringReader(csv));
  59. String line = null;
  60. try {
  61. while ((line = reader.readLine()) != null) {
  62. StringTokenizer tokenizer = new StringTokenizer(line, ",");
  63. String className = tokenizer.nextToken();
  64. Double lineRate = NumberUtils.stringToDouble(tokenizer.nextToken());
  65. Double delta = NumberUtils.stringToDouble(tokenizer.nextToken());
  66. //lineRate = NumberUtils.round(lineRate * 100, 2);
  67. //delta = NumberUtils.round(delta * 100, 2);
  68. coverageChanges.add(new NCoverCoverageInformation(
  69. className, lineRate, delta));
  70. }
  71. } catch (NumberFormatException e) {
  72. log.error(e);
  73. } catch (IOException e) {
  74. log.error(e);
  75. }
  76. }
  77. }
  78. public Collection getCoverageChanges() {
  79. return coverageChanges;
  80. }
  81. }