You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NewCoverage.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.api.batch.sensor.coverage;
  21. import org.sonar.api.batch.fs.InputFile;
  22. /**
  23. * This class is used to report code coverage on files.
  24. *
  25. * Example:
  26. *
  27. * <pre>
  28. * sensorContext.newCoverage().onFile(file)
  29. .lineHits(1, 2)
  30. .lineHits(2, 5)
  31. .lineHits(3, 0)
  32. . ...
  33. .conditions(3, 4, 2)
  34. .conditions(12, 2, 2)
  35. . ...
  36. .save();
  37. *
  38. * </pre>
  39. *
  40. * Since 6.2 you can save several reports for the same file and reports will be merged using the following "additive" strategy:
  41. * <ul>
  42. * <li>Line hits are cumulated</li>
  43. * <li>We keep the max for condition coverage. Examples: 2/4 + 2/4 = 2/4, 2/4 + 3/4 = 3/4</li>
  44. * </ul>
  45. *
  46. * @since 5.2
  47. */
  48. public interface NewCoverage {
  49. /**
  50. * The covered file.
  51. */
  52. NewCoverage onFile(InputFile inputFile);
  53. /**
  54. * Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines.
  55. * @param line Line number (starts at 1).
  56. * @param hits Number of time the line was hit.
  57. */
  58. NewCoverage lineHits(int line, int hits);
  59. /**
  60. * Call this method as many time as needed to report coverage of conditions.
  61. * @param line Line number (starts at 1).
  62. * @param conditions Number of conditions on this line (should be greater than 1).
  63. * @param coveredConditions Number of covered conditions.
  64. */
  65. NewCoverage conditions(int line, int conditions, int coveredConditions);
  66. /**
  67. * Call this method to save the coverage report for the given file. Data will be merged with existing coverage information.
  68. */
  69. void save();
  70. }