aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-04-23 14:41:32 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-04-30 17:27:21 +0200
commit171cd79c0b5152461434951ed5d6e5e58849a7b7 (patch)
tree4b6443640045992fd3eb06de6cba382ab0621628 /sonar-plugin-api/src
parentca2bf42757a1e6471dab4c3fe8f4d98bfd2267d4 (diff)
downloadsonarqube-171cd79c0b5152461434951ed5d6e5e58849a7b7.tar.gz
sonarqube-171cd79c0b5152461434951ed5d6e5e58849a7b7.zip
SONAR-3437, SONAR-5189 Store measures in a persistit cache
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java22
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java31
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java17
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java83
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java55
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java3
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasuresFiltersTest.java46
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/IsRuleMeasure.java2
10 files changed, 165 insertions, 101 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
index 866785feeef..4eb61021ca5 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
@@ -30,6 +30,8 @@ import org.sonar.api.rules.Violation;
import org.sonar.api.violations.ViolationQuery;
import org.sonar.graph.DirectedGraphAccessor;
+import javax.annotation.CheckForNull;
+
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -118,8 +120,10 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe
@Deprecated
public abstract Resource addResource(Resource resource);
+ @CheckForNull
public abstract Measure getMeasure(Resource resource, Metric metric);
+ @CheckForNull
public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
index e2448adb5da..3d38e52aea8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
@@ -28,6 +28,7 @@ import org.sonar.api.technicaldebt.batch.Requirement;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
@@ -37,7 +38,7 @@ import java.util.Date;
*
* @since 1.10
*/
-public class Measure {
+public class Measure implements Serializable {
private static final String INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5 = "Index should be in range from 1 to 5";
protected static final int MAX_TEXT_SIZE = 96;
@@ -47,8 +48,6 @@ public class Measure {
*/
public static final int DEFAULT_PRECISION = 1;
- // for internal use
- private Long id;
protected String metricKey;
protected Metric metric;
protected Double value;
@@ -413,20 +412,11 @@ public class Measure {
}
/**
- * @return the measure id - Internal use only
- */
- public Long getId() {
- return id;
- }
-
- /**
- * Sets the measure id - Internal use only
- *
- * @param id the id
- * @return the measure object instance
+ * Called by views when cloning measures
+ * @deprecated since 4.4 not used
*/
+ @Deprecated
public Measure setId(Long id) {
- this.id = id;
return this;
}
@@ -646,7 +636,7 @@ public class Measure {
return metric.isOptimizedBestValue() == Boolean.TRUE
&& metric.getBestValue() != null
&& (value == null || NumberUtils.compare(metric.getBestValue(), value) == 0)
- && allNull(id, alertStatus, description, tendency, url, data)
+ && allNull(alertStatus, description, tendency, url, data)
&& isZeroVariation(variation1, variation2, variation3, variation4, variation5);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java
index 4ed4a8ffb1b..f11a225e668 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.measures;
+import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.technicaldebt.batch.Characteristic;
import org.sonar.api.technicaldebt.batch.Requirement;
@@ -37,8 +38,15 @@ public final class MeasuresFilters {
public static MeasuresFilter<Collection<Measure>> all() {
return new MeasuresFilter<Collection<Measure>>() {
+ @Override
public Collection<Measure> filter(Collection<Measure> measures) {
- return measures;
+ Collection<Measure> all = new ArrayList<Measure>();
+ for (Measure measure : measures) {
+ if (measure != null) {
+ all.add(measure);
+ }
+ }
+ return all;
}
};
}
@@ -49,7 +57,7 @@ public final class MeasuresFilters {
public static MeasuresFilter<Measure> metric(final String metricKey) {
return new MetricFilter<Measure>(metricKey) {
-
+ @Override
public Measure filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -70,6 +78,7 @@ public final class MeasuresFilters {
public static MeasuresFilter<Measure> characteristic(final Metric metric, final Characteristic characteristic) {
return new MetricFilter<Measure>(metric) {
+ @Override
public Measure filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -100,6 +109,7 @@ public final class MeasuresFilters {
public static MeasuresFilter<Measure> requirement(final Metric metric, final Requirement requirement) {
return new MetricFilter<Measure>(metric) {
+ @Override
public Measure filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -128,6 +138,7 @@ public final class MeasuresFilters {
*/
public static MeasuresFilter<Measure> measure(final Measure measure) {
return new MeasuresFilter<Measure>() {
+ @Override
public Measure filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -143,7 +154,7 @@ public final class MeasuresFilters {
}
public static MeasuresFilter<RuleMeasure> rule(final Metric metric, final Rule rule) {
- return new RuleFilter(metric, rule);
+ return new RuleFilter(metric, rule.ruleKey());
}
public static MeasuresFilter<Collection<RuleMeasure>> rules(final Metric metric) {
@@ -151,9 +162,10 @@ public final class MeasuresFilters {
private boolean apply(Measure measure) {
return measure instanceof RuleMeasure && metric.equals(measure.getMetric())
- && measure.getPersonId() == null && ((RuleMeasure) measure).getRule() != null;
+ && measure.getPersonId() == null && ((RuleMeasure) measure).ruleKey() != null;
}
+ @Override
public Collection<RuleMeasure> filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -202,6 +214,7 @@ public final class MeasuresFilters {
abstract boolean doApply(RuleMeasure ruleMeasure);
+ @Override
public M filter(Collection<Measure> measures) {
if (measures == null) {
return null;
@@ -216,17 +229,17 @@ public final class MeasuresFilters {
}
private static class RuleFilter extends AbstractRuleMeasureFilter<RuleMeasure> {
- private Rule rule;
+ private RuleKey ruleKey;
- protected RuleFilter(Metric metric, Rule rule) {
+ protected RuleFilter(Metric metric, RuleKey ruleKey) {
super(metric);
- this.rule = rule;
+ this.ruleKey = ruleKey;
}
@Override
boolean doApply(RuleMeasure measure) {
- return measure.getRule() != null
- && rule.equals(measure.getRule());
+ return measure.ruleKey() != null
+ && ruleKey.equals(measure.ruleKey());
}
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
index dc7d507153b..bc809c88884 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
@@ -27,7 +27,16 @@ import org.sonar.api.ServerExtension;
import org.sonar.api.batch.InstantiationStrategy;
import javax.annotation.Nullable;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+import java.io.Serializable;
/**
* This class represents the definition of a metric in Sonar.
@@ -37,7 +46,7 @@ import javax.persistence.*;
@Table(name = "metrics")
@Entity(name = "Metric")
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public class Metric implements ServerExtension, BatchExtension {
+public class Metric implements ServerExtension, BatchExtension, Serializable {
/**
* A metric bigger value means a degradation
@@ -80,7 +89,7 @@ public class Metric implements ServerExtension, BatchExtension {
private Integer id;
@Transient
- private Formula formula;
+ private transient Formula formula;
@Column(name = "name", updatable = false, nullable = false, length = 64)
private String key;
@@ -206,7 +215,7 @@ public class Metric implements ServerExtension, BatchExtension {
*/
@Deprecated
public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, @Nullable String domain,
- boolean userManaged) {
+ boolean userManaged) {
this.key = key;
this.description = description;
this.type = type;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
index b0e1199a5c1..b0932018c03 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/RuleMeasure.java
@@ -22,6 +22,7 @@ package org.sonar.api.measures;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
@@ -32,24 +33,47 @@ import javax.annotation.Nullable;
*/
public class RuleMeasure extends Measure {
- private Rule rule;
+ private RuleKey ruleKey;
private RulePriority rulePriority;
/**
* This constructor is for internal use only. Please use static methods createForXXX().
+ * @deprecated since 4.4 use {@link #RuleMeasure(Metric, RuleKey, RulePriority, Integer)}
*/
+ @Deprecated
public RuleMeasure(Metric metric, @Nullable Rule rule, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
+ this(metric, rule.ruleKey(), rulePriority, ruleCategory);
+ }
+
+ public RuleMeasure(Metric metric, @Nullable RuleKey ruleKey, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
super(metric);
- this.rule = rule;
+ this.ruleKey = ruleKey;
this.rulePriority = rulePriority;
}
+ public RuleKey ruleKey() {
+ return ruleKey;
+ }
+
+ public RuleMeasure setRuleKey(RuleKey ruleKey) {
+ this.ruleKey = ruleKey;
+ return this;
+ }
+
+ /**
+ * @deprecated since 4.4 use {@link #ruleKey()}
+ */
+ @Deprecated
public Rule getRule() {
- return rule;
+ return Rule.create(ruleKey.repository(), ruleKey.rule());
}
+ /**
+ * @deprecated since 4.4 use {@link #setRuleKey()}
+ */
+ @Deprecated
public RuleMeasure setRule(Rule rule) {
- this.rule = rule;
+ this.ruleKey = rule.ruleKey();
return this;
}
@@ -115,10 +139,10 @@ public class RuleMeasure extends Measure {
}
RuleMeasure other = (RuleMeasure) obj;
return new EqualsBuilder()
- .append(getMetric(), other.getMetric())
- .append(personId, other.personId)
- .append(rule, other.rule)
- .isEquals();
+ .append(getMetric(), other.getMetric())
+ .append(personId, other.personId)
+ .append(ruleKey, other.ruleKey)
+ .isEquals();
}
@Override
@@ -129,35 +153,42 @@ public class RuleMeasure extends Measure {
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(getMetric())
- .append(personId)
- .append(rule)
- .toHashCode();
+ .append(getMetric())
+ .append(personId)
+ .append(ruleKey)
+ .toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", getId())
- .append("metric", metric)
- .append("personId", personId)
- .append("rule", rule)
- .append("value", value)
- .append("data", data)
- .append("description", description)
- .append("alertStatus", alertStatus)
- .append("alertText", alertText)
- .append("tendency", tendency)
- .append("severity", rulePriority)
- .toString();
+ .append("metric", metric)
+ .append("personId", personId)
+ .append("ruleKey", ruleKey)
+ .append("value", value)
+ .append("data", data)
+ .append("description", description)
+ .append("alertStatus", alertStatus)
+ .append("alertText", alertText)
+ .append("tendency", tendency)
+ .append("severity", rulePriority)
+ .toString();
}
+ /**
+ * @deprecated since 4.4 use {@link #createForRule(Metric, RuleKey, Double)}
+ */
+ @Deprecated
public static RuleMeasure createForRule(Metric metric, Rule rule, @Nullable Double value) {
return new RuleMeasure(metric, rule, null, null).setValue(value);
}
+ public static RuleMeasure createForRule(Metric metric, RuleKey ruleKey, @Nullable Double value) {
+ return new RuleMeasure(metric, ruleKey, null, null).setValue(value);
+ }
+
public static RuleMeasure createForPriority(Metric metric, RulePriority priority, @Nullable Double value) {
- return new RuleMeasure(metric, null, priority, null).setValue(value);
+ return new RuleMeasure(metric, (RuleKey) null, priority, null).setValue(value);
}
/**
@@ -165,6 +196,6 @@ public class RuleMeasure extends Measure {
*/
@Deprecated
public static RuleMeasure createForCategory(Metric metric, Integer category, @Nullable Double value) {
- return new RuleMeasure(metric, null, null, category).setValue(value);
+ return new RuleMeasure(metric, (RuleKey) null, null, category).setValue(value);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index 39453f963ff..402a5ec9f9d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -34,7 +34,19 @@ import org.sonar.check.Cardinality;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import java.util.ArrayList;
import java.util.Date;
@@ -279,15 +291,15 @@ public class Rule {
public RuleParam createParameter() {
RuleParam parameter = new RuleParam()
- .setRule(this);
+ .setRule(this);
params.add(parameter);
return parameter;
}
public RuleParam createParameter(String key) {
RuleParam parameter = new RuleParam()
- .setKey(key)
- .setRule(this);
+ .setKey(key)
+ .setRule(this);
params.add(parameter);
return parameter;
}
@@ -468,7 +480,6 @@ public class Rule {
return this;
}
-
/**
* For internal use only.
*
@@ -499,34 +510,34 @@ public class Rule {
}
Rule other = (Rule) obj;
return new EqualsBuilder()
- .append(pluginName, other.getRepositoryKey())
- .append(key, other.getKey())
- .isEquals();
+ .append(pluginName, other.getRepositoryKey())
+ .append(key, other.getKey())
+ .isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
- .append(pluginName)
- .append(key)
- .toHashCode();
+ .append(pluginName)
+ .append(key)
+ .toHashCode();
}
@Override
public String toString() {
// Note that ReflectionToStringBuilder will not work here - see SONAR-3077
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
- .append("id", id)
- .append("name", name)
- .append("key", key)
- .append("configKey", configKey)
- .append("plugin", pluginName)
- .append("severity", priority)
- .append("cardinality", cardinality)
- .append("status", status)
- .append("language", language)
- .append("parent", parent)
- .toString();
+ .append("id", id)
+ .append("name", name)
+ .append("key", key)
+ .append("configKey", configKey)
+ .append("plugin", pluginName)
+ .append("severity", priority)
+ .append("cardinality", cardinality)
+ .append("status", status)
+ .append("language", language)
+ .append("parent", parent)
+ .toString();
}
@CheckForNull
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
index fadad455575..b649a4e466a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java
@@ -22,6 +22,7 @@ package org.sonar.api.technicaldebt.batch;
import javax.annotation.CheckForNull;
+import java.io.Serializable;
import java.util.Date;
import java.util.List;
@@ -30,7 +31,7 @@ import java.util.List;
* @deprecated since 4.3
*/
@Deprecated
-public interface Characteristic {
+public interface Characteristic extends Serializable {
Integer id();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
index 606d2a3fb18..71204e9ffb8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
@@ -24,6 +24,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.WorkUnit;
import org.sonar.api.utils.internal.WorkDuration;
+import java.io.Serializable;
import java.util.Date;
/**
@@ -31,7 +32,7 @@ import java.util.Date;
* @deprecated since 4.3
*/
@Deprecated
-public interface Requirement {
+public interface Requirement extends Serializable {
Integer id();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasuresFiltersTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasuresFiltersTest.java
index f9f569f199b..ea075ed2a99 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasuresFiltersTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasuresFiltersTest.java
@@ -25,6 +25,7 @@ import org.sonar.api.rules.RulePriority;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import static org.hamcrest.core.Is.is;
@@ -37,8 +38,8 @@ public class MeasuresFiltersTest {
MeasuresFilter<Measure> filter = MeasuresFilters.metric(CoreMetrics.VIOLATIONS);
Collection<Measure> measures = Arrays.asList(
- RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 50.0),
- new Measure(CoreMetrics.VIOLATIONS, 500.0));
+ RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 50.0),
+ new Measure(CoreMetrics.VIOLATIONS, 500.0));
assertThat(filter.filter(measures).getValue(), is(500.0));
}
@@ -46,10 +47,13 @@ public class MeasuresFiltersTest {
@Test
public void all() {
Collection<Measure> measures = Arrays.asList(
- RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 50.0),
- new Measure(CoreMetrics.VIOLATIONS, 500.0));
+ RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 50.0),
+ new Measure(CoreMetrics.VIOLATIONS, 500.0));
- assertThat(MeasuresFilters.all().filter(measures).size(), is(2));
+ Iterator<Measure> filteredMeasures = MeasuresFilters.all().filter(measures).iterator();
+ filteredMeasures.next();
+ filteredMeasures.next();
+ assertThat(filteredMeasures.hasNext(), is(false));
}
@Test
@@ -58,13 +62,13 @@ public class MeasuresFiltersTest {
Rule rule2 = new Rule("pmd", "key2");
MeasuresFilter<RuleMeasure> filter = MeasuresFilters.rule(CoreMetrics.VIOLATIONS, rule1);
List<Measure> measures = Arrays.asList(
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0),
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0),
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS_DENSITY, rule2, 3.3),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS_DENSITY, rule2, 3.3),
- RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0),
- RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0),
- new Measure(CoreMetrics.VIOLATIONS, 500.0));
+ RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0),
+ RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0),
+ new Measure(CoreMetrics.VIOLATIONS, 500.0));
assertThat(filter.filter(measures).getValue(), is(50.0));
}
@@ -75,13 +79,13 @@ public class MeasuresFiltersTest {
Rule rule2 = new Rule("pmd", "key2");
MeasuresFilter<Collection<RuleMeasure>> filter = MeasuresFilters.rules(CoreMetrics.VIOLATIONS);
List<Measure> measures = Arrays.asList(
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0),
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0),
- RuleMeasure.createForRule(CoreMetrics.VIOLATIONS_DENSITY, rule2, 3.3),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule1, 50.0),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule2, 10.0),
+ RuleMeasure.createForRule(CoreMetrics.VIOLATIONS_DENSITY, rule2, 3.3),
- RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0),
- RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0),
- new Measure(CoreMetrics.VIOLATIONS, 500.0));
+ RuleMeasure.createForPriority(CoreMetrics.VIOLATIONS, RulePriority.CRITICAL, 400.0),
+ RuleMeasure.createForPriority(CoreMetrics.COVERAGE, RulePriority.CRITICAL, 400.0),
+ new Measure(CoreMetrics.VIOLATIONS, 500.0));
assertThat(filter.filter(measures).size(), is(2));
}
@@ -90,10 +94,10 @@ public class MeasuresFiltersTest {
public void measure() {
MeasuresFilter<Measure> filter = MeasuresFilters.measure(new Measure(CoreMetrics.VIOLATIONS));
List<Measure> measures = Arrays.asList(
- new Measure(CoreMetrics.COMMENT_LINES, 50.0),
- new Measure(CoreMetrics.VIOLATIONS, 10.0),
- RuleMeasure.createForCategory(CoreMetrics.VIOLATIONS, 2, 12.0),
- new Measure(CoreMetrics.COVERAGE, 15.0));
+ new Measure(CoreMetrics.COMMENT_LINES, 50.0),
+ new Measure(CoreMetrics.VIOLATIONS, 10.0),
+ RuleMeasure.createForCategory(CoreMetrics.VIOLATIONS, 2, 12.0),
+ new Measure(CoreMetrics.COVERAGE, 15.0));
assertThat(filter.filter(measures).getValue(), is(10.0));
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsRuleMeasure.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsRuleMeasure.java
index 091d8c781cd..3f9f67ce236 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/test/IsRuleMeasure.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/IsRuleMeasure.java
@@ -46,7 +46,7 @@ public class IsRuleMeasure extends ArgumentMatcher<Measure> {
}
RuleMeasure m = (RuleMeasure) o;
return ObjectUtils.equals(metric, m.getMetric()) &&
- ObjectUtils.equals(rule, m.getRule()) &&
+ ObjectUtils.equals(rule.ruleKey(), m.ruleKey()) &&
NumberUtils.compare(value, m.getValue()) == 0;
}
}