001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch.sensor.coverage;
021
022import org.sonar.api.batch.fs.InputFile;
023
024/**
025 * This class is used to report code coverage on files.
026 * 
027 * Example:
028 * 
029 * <pre>
030 *   sensorContext.newCoverage().onFile(file)
031       .lineHits(1, 2)
032       .lineHits(2, 5)
033       .lineHits(3, 0)
034       . ...
035       .conditions(3, 4, 2)
036       .conditions(12, 2, 2)
037       . ...
038       .save();
039 *     
040 * </pre>
041 * 
042 * Since 6.2 you can save several reports for the same file and reports will be merged using the following "additive" strategy:
043 * <ul>
044 *   <li>Line hits are cumulated</li>
045 *   <li>We keep the max for condition coverage. Examples: 2/4 + 2/4 = 2/4, 2/4 + 3/4 = 3/4</li>
046 * </ul>
047 * 
048 * @since 5.2
049 */
050public interface NewCoverage {
051
052  /**
053   * The covered file.
054   */
055  NewCoverage onFile(InputFile inputFile);
056
057  /**
058   * @deprecated since 6.2 SonarQube merge all coverage reports and don't keep track of different test category
059   */
060  @Deprecated
061  NewCoverage ofType(CoverageType type);
062
063  /**
064   * Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines.
065   * @param line Line number (starts at 1).
066   * @param hits Number of time the line was hit.
067   */
068  NewCoverage lineHits(int line, int hits);
069
070  /**
071   * Call this method as many time as needed to report coverage of conditions.
072   * @param line Line number (starts at 1).
073   * @param conditions Number of conditions on this line (should be greater than 1).
074   * @param coveredConditions Number of covered conditions.
075   */
076  NewCoverage conditions(int line, int conditions, int coveredConditions);
077
078  /**
079   * Call this method to save the coverage report for the given file. Data will be merged with existing coverage information.
080   */
081  void save();
082}