summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-02-19 10:39:17 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2016-02-22 10:57:26 +0100
commitaccc8fc25dbdddb7fc6fbc5fa171ce29929d01d9 (patch)
tree0b4daa853beea7ec734f8b52df0cf126f4e7efe8 /sonar-plugin-api/src
parentcef567021858b0e7239ac80d4512172ef7b70dbd (diff)
downloadsonarqube-accc8fc25dbdddb7fc6fbc5fa171ce29929d01d9.tar.gz
sonarqube-accc8fc25dbdddb7fc6fbc5fa171ce29929d01d9.zip
SONAR-5772 New executable_lines_data metric
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java30
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java24
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java22
4 files changed, 50 insertions, 28 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index 66734f4026f..228dab0a51c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -96,7 +96,7 @@ public interface SensorContext {
/**
* Builder to define coverage in a file.
- * Don't forget to call {@link NewDuplication#save()}.
+ * Don't forget to call {@link NewCoverage#save()}.
*/
NewCoverage newCoverage();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
index ceef90f9788..cdab75f44c4 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/CoverageType.java
@@ -20,9 +20,31 @@
package org.sonar.api.batch.sensor.coverage;
import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.sonar.api.measures.Metric;
-import static org.sonar.api.measures.CoreMetrics.*;
+import static org.sonar.api.measures.CoreMetrics.CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.CONDITIONS_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.COVERAGE_LINE_HITS_DATA;
+import static org.sonar.api.measures.CoreMetrics.COVERED_CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.IT_CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.IT_CONDITIONS_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.IT_COVERAGE_LINE_HITS_DATA;
+import static org.sonar.api.measures.CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.IT_LINES_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.IT_UNCOVERED_CONDITIONS;
+import static org.sonar.api.measures.CoreMetrics.IT_UNCOVERED_LINES;
+import static org.sonar.api.measures.CoreMetrics.LINES_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_CONDITIONS_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_LINES_TO_COVER;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_UNCOVERED_CONDITIONS;
+import static org.sonar.api.measures.CoreMetrics.OVERALL_UNCOVERED_LINES;
+import static org.sonar.api.measures.CoreMetrics.UNCOVERED_CONDITIONS;
+import static org.sonar.api.measures.CoreMetrics.UNCOVERED_LINES;
/**
* Different coverage categories.
@@ -43,6 +65,7 @@ public enum CoverageType {
private final Metric uncoveredConditions;
private final Metric coveredConditionsByLine;
private final Metric conditionsByLine;
+ private final Set<Metric> all;
private CoverageType(Metric linesToCover, Metric uncoveredLines, Metric lineHitsData, Metric conditionsToCover, Metric uncoveredConditions, Metric coveredConditionsByLine,
Metric conditionsByLine) {
@@ -53,6 +76,11 @@ public enum CoverageType {
this.uncoveredConditions = uncoveredConditions;
this.coveredConditionsByLine = coveredConditionsByLine;
this.conditionsByLine = conditionsByLine;
+ this.all = ImmutableSet.of(linesToCover, uncoveredLines, lineHitsData, conditionsToCover, uncoveredConditions, coveredConditionsByLine, conditionsByLine);
+ }
+
+ public Set<Metric> allMetrics() {
+ return all;
}
public Metric linesToCover() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
index 7f4ca3ec676..96e5f9737ba 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/internal/DefaultCoverage.java
@@ -21,6 +21,9 @@ package org.sonar.api.batch.sensor.coverage.internal;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
+import java.util.Collections;
+import java.util.SortedMap;
+import javax.annotation.Nullable;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.sensor.coverage.CoverageType;
@@ -28,11 +31,6 @@ import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.internal.DefaultStorable;
import org.sonar.api.batch.sensor.internal.SensorStorage;
-import javax.annotation.Nullable;
-
-import java.util.Collections;
-import java.util.SortedMap;
-
public class DefaultCoverage extends DefaultStorable implements NewCoverage {
private DefaultInputFile inputFile;
@@ -64,7 +62,6 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
@Override
public NewCoverage ofType(CoverageType type) {
- validateFile();
Preconditions.checkNotNull(type, "type can't be null");
this.type = type;
return this;
@@ -93,20 +90,6 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
Preconditions.checkState(line > 0, "Line number must be strictly positive: " + line);
}
- private void validateLines() {
- for (int l : hitsByLine.keySet()) {
- validateLine(l);
- }
-
- for (int l : conditionsByLine.keySet()) {
- validateLine(l);
- }
-
- for (int l : coveredConditionsByLine.keySet()) {
- validateLine(l);
- }
- }
-
private void validateFile() {
Preconditions.checkNotNull(inputFile, "Call onFile() first");
}
@@ -157,7 +140,6 @@ public class DefaultCoverage extends DefaultStorable implements NewCoverage {
public void doSave() {
validateFile();
Preconditions.checkNotNull(type, "Call ofType() first");
- validateLines();
storage.store(this);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
index da186c87254..796c66d1a15 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.measures;
-import com.google.common.annotations.Beta;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.lang.reflect.Field;
@@ -2123,7 +2122,6 @@ public final class CoreMetrics {
/**
* @since 2.14
*/
- @Beta
public static final String NCLOC_DATA_KEY = "ncloc_data";
/**
@@ -2133,7 +2131,6 @@ public final class CoreMetrics {
* @see org.sonar.api.measures.FileLinesContext
* @since 2.14
*/
- @Beta
public static final Metric<String> NCLOC_DATA = new Metric.Builder(NCLOC_DATA_KEY, "ncloc_data", Metric.ValueType.DATA)
.setHidden(true)
.setDomain(DOMAIN_SIZE)
@@ -2142,7 +2139,6 @@ public final class CoreMetrics {
/**
* @since 2.14
*/
- @Beta
public static final String COMMENT_LINES_DATA_KEY = "comment_lines_data";
/**
@@ -2152,12 +2148,28 @@ public final class CoreMetrics {
* @see org.sonar.api.measures.FileLinesContext
* @since 2.14
*/
- @Beta
public static final Metric<String> COMMENT_LINES_DATA = new Metric.Builder(COMMENT_LINES_DATA_KEY, "comment_lines_data", Metric.ValueType.DATA)
.setHidden(true)
.setDomain(DOMAIN_DOCUMENTATION)
.create();
+ /**
+ * @since 5.5
+ */
+ public static final String EXECUTABLE_LINES_DATA_KEY = "executable_lines_data";
+
+ /**
+ * Information about executable lines of code in file.
+ * Key-value pairs, where key - is a number of line, and value - is an indicator of whether line contains executable code (1) or not (0).
+ *
+ * @see org.sonar.api.measures.FileLinesContext
+ * @since 5.5
+ */
+ public static final Metric<String> EXECUTABLE_LINES_DATA = new Metric.Builder(EXECUTABLE_LINES_DATA_KEY, "executable_lines_data", Metric.ValueType.DATA)
+ .setHidden(true)
+ .setDomain(DOMAIN_TESTS)
+ .create();
+
// --------------------------------------------------------------------------------------------------------------------
//
// OTHERS