PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/atlassian/bamboo-dotnet-plugin/
Java | 69 lines | 47 code | 9 blank | 13 comment | 2 complexity | a5952e696de4d0514c9f7ff0212b5ebf MD5 | raw file
Possible License(s): BSD-3-Clause
  1. package com.atlassian.bamboo.plugin.dotnet.ncover;
  2. import com.atlassian.bamboo.chains.ChainResultsSummary;
  3. import com.atlassian.bamboo.index.CustomPostBuildIndexWriter;
  4. import com.atlassian.bamboo.index.PostChainIndexWriter;
  5. import com.atlassian.bamboo.resultsummary.BuildResultsSummary;
  6. import com.atlassian.bamboo.resultsummary.ResultsSummary;
  7. import org.apache.log4j.Logger;
  8. import org.apache.lucene.document.Document;
  9. import org.apache.lucene.document.DoubleField;
  10. import org.apache.lucene.document.Field;
  11. import org.jetbrains.annotations.NotNull;
  12. import java.text.NumberFormat;
  13. import java.text.ParseException;
  14. /**
  15. * Handles persisting results obtained from parsing the NCover XML report file.
  16. *
  17. * @author Ross Rowe
  18. */
  19. public class NCoverPostBuildIndexWriter implements CustomPostBuildIndexWriter, PostChainIndexWriter
  20. {
  21. private static final Logger log = Logger.getLogger(NCoverPostBuildIndexWriter.class);
  22. /**
  23. * Updates the <code>Document</code> with the results that have been stored
  24. * in the <code>BuildResultsSummary</code> parameter.
  25. *
  26. * @param document
  27. * @param resultsSummary
  28. * the build results summary
  29. */
  30. @Override
  31. public void updateIndexDocument(@NotNull Document document, @NotNull BuildResultsSummary resultsSummary)
  32. {
  33. updateIndex(document, resultsSummary);
  34. }
  35. @Override
  36. public void updateIndexDocument(@NotNull final Document document, @NotNull final ChainResultsSummary resultsSummary)
  37. {
  38. updateIndex(document, resultsSummary);
  39. }
  40. private void updateIndex(final Document document, final ResultsSummary resultsSummary)
  41. {
  42. String coverStr = resultsSummary.getCustomBuildData().get(NCoverBuildProcessor.NCOVER_LINE_RATE);
  43. if (coverStr == null)
  44. {
  45. return;
  46. }
  47. NumberFormat numberFormat = NumberFormat.getInstance();
  48. try
  49. {
  50. Number number = numberFormat.parse(coverStr);
  51. double coverDbl = number.doubleValue();
  52. Field field = new DoubleField(NCoverBuildProcessor.NCOVER_LINE_RATE, coverDbl, Field.Store.YES);
  53. document.add(field);
  54. }
  55. catch (ParseException e)
  56. {
  57. log.error(e);
  58. }
  59. }
  60. }