aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-08-26 12:25:31 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-08-31 09:49:14 +0200
commitfd90efb85f075b9f048a9ebbc6f2438d6c153dd5 (patch)
treec3fe640c3c0e4031ae816da3a516978e7e4ec610 /sonar-plugin-api/src
parent27ad46fd2b4f9bcd3becdf0c68b38200e6f6b5b8 (diff)
downloadsonarqube-fd90efb85f075b9f048a9ebbc6f2438d6c153dd5.tar.gz
sonarqube-fd90efb85f075b9f048a9ebbc6f2438d6c153dd5.zip
SONAR-6730 Add issues in Measure API
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/Issue.java52
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java157
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java12
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java24
5 files changed, 251 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/Issue.java
new file mode 100644
index 00000000000..e4233c2a6a5
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/Issue.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.ce.measure;
+
+import javax.annotation.CheckForNull;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.Duration;
+
+public interface Issue {
+
+ String key();
+
+ RuleKey ruleKey();
+
+ /**
+ * Available list of status can be found in {@link org.sonar.api.issue.Issue#STATUSES}
+ */
+ String status();
+
+ /**
+ * Available list of resolutions can be found in {@link org.sonar.api.issue.Issue#RESOLUTIONS}
+ */
+ @CheckForNull
+ String resolution();
+
+ /**
+ * See constants in {@link org.sonar.api.rule.Severity}.
+ */
+ String severity();
+
+ @CheckForNull
+ Duration debt();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java
index 0d1e2c866f5..32d5d90e469 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/ce/measure/MeasureComputer.java
@@ -20,6 +20,7 @@
package org.sonar.api.ce.measure;
+import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
@@ -142,6 +143,11 @@ public interface MeasureComputer {
*/
void addMeasure(String metric, String value);
+ /**
+ * Return list of issues of current component.
+ */
+ List<? extends Issue> getIssues();
+
}
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java
new file mode 100644
index 00000000000..0f47f4ff133
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/IssueImpl.java
@@ -0,0 +1,157 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.test.ce.measure;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.api.ce.measure.Issue;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rule.Severity;
+import org.sonar.api.utils.Duration;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class IssueImpl implements Issue {
+
+ private String key;
+ private String status;
+ private String resolution;
+ private String severity;
+ private RuleKey ruleKey;
+ private Duration debt;
+
+ private IssueImpl(Builder builder) {
+ this.key = builder.key;
+ this.status = builder.status;
+ this.resolution = builder.resolution;
+ this.severity = builder.severity;
+ this.ruleKey = builder.ruleKey;
+ this.debt = builder.debt;
+ }
+
+ @Override
+ public String key() {
+ return key;
+ }
+
+ @Override
+ public RuleKey ruleKey() {
+ return ruleKey;
+ }
+
+ @Override
+ public String status() {
+ return status;
+ }
+
+ @Override
+ @CheckForNull
+ public String resolution() {
+ return resolution;
+ }
+
+ @Override
+ public String severity() {
+ return severity;
+ }
+
+ @Override
+ @CheckForNull
+ public Duration debt() {
+ return debt;
+ }
+
+ public static class Builder {
+ private String key;
+ private String status;
+ private String resolution;
+ private String severity;
+ private RuleKey ruleKey;
+ private Duration debt;
+
+ public Builder setKey(String key) {
+ this.key = validateKey(key);
+ return this;
+ }
+
+ public Builder setResolution(@Nullable String resolution) {
+ this.resolution = validateResolution(resolution);
+ return this;
+ }
+
+ public Builder setSeverity(String severity) {
+ this.severity = validateSeverity(severity);
+ return this;
+ }
+
+ public Builder setStatus(String status) {
+ this.status = validateStatus(status);
+ return this;
+ }
+
+ public Builder setRuleKey(RuleKey ruleKey) {
+ this.ruleKey = validateRuleKey(ruleKey);
+ return this;
+ }
+
+ public Builder setDebt(@Nullable Duration debt) {
+ this.debt = debt;
+ return this;
+ }
+
+ private static String validateKey(String key){
+ checkNotNull(key, "key cannot be null");
+ return key;
+ }
+
+ private static RuleKey validateRuleKey(RuleKey ruleKey){
+ checkNotNull(ruleKey, "ruleKey cannot be null");
+ return ruleKey;
+ }
+
+ private static String validateResolution(@Nullable String resolution){
+ checkArgument(resolution == null || org.sonar.api.issue.Issue.RESOLUTIONS.contains(resolution), String.format("resolution '%s' is invalid", resolution));
+ return resolution;
+ }
+
+ private static String validateSeverity(String severity){
+ checkNotNull(severity, "severity cannot be null");
+ checkArgument(Severity.ALL.contains(severity), String.format("severity '%s' is invalid", severity));
+ return severity;
+ }
+
+ private static String validateStatus(String status){
+ checkNotNull(status, "status cannot be null");
+ checkArgument(org.sonar.api.issue.Issue.STATUSES.contains(status), String.format("status '%s' is invalid", status));
+ return status;
+ }
+
+ public Issue build(){
+ validateKey(key);
+ validateResolution(resolution);
+ validateSeverity(severity);
+ validateStatus(status);
+ validateRuleKey(ruleKey);
+ return new IssueImpl(this);
+ }
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java
index f8182f5483f..a49b2d6611e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/MeasureComputerImplementationContext.java
@@ -22,6 +22,7 @@ package org.sonar.api.test.ce.measure;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -29,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.ce.measure.Component;
+import org.sonar.api.ce.measure.Issue;
import org.sonar.api.ce.measure.Measure;
import org.sonar.api.ce.measure.MeasureComputer;
import org.sonar.api.ce.measure.Settings;
@@ -43,6 +45,7 @@ public class MeasureComputerImplementationContext implements MeasureComputer.Imp
private Map<String, Measure> componentMeasureByMetricKey = new HashMap<>();
private Multimap<String, Measure> childrenComponentMeasureByMetricKey = ArrayListMultimap.create();
+ private List<Issue> issues = new ArrayList<>();
public MeasureComputerImplementationContext(Component component, Settings settings, MeasureComputer measureComputer) {
this.measureComputer = measureComputer;
@@ -137,6 +140,15 @@ public class MeasureComputerImplementationContext implements MeasureComputer.Imp
}
}
+ @Override
+ public List<Issue> getIssues() {
+ return issues;
+ }
+
+ public void setIssues(List<Issue> issues){
+ this.issues = issues;
+ }
+
private void validateInputMetric(String metric) {
Set<String> allowedMetrics = new HashSet<>();
allowedMetrics.addAll(measureComputer.getInputMetrics());
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java
new file mode 100644
index 00000000000..aaa0831b888
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/ce/measure/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.api.test.ce.measure;
+
+import javax.annotation.ParametersAreNonnullByDefault;