diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-25 11:17:09 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-04-25 11:21:03 +0200 |
commit | 7b301db8c7e3000ff2a04fce5534e45e7d973a1f (patch) | |
tree | 6f1092d7cbe3b8ebe38899777200fe3cf715a9b4 /sonar-plugin-api/src | |
parent | 5a80556a153a2e771920094228ac2e97dd5e7530 (diff) | |
download | sonarqube-7b301db8c7e3000ff2a04fce5534e45e7d973a1f.tar.gz sonarqube-7b301db8c7e3000ff2a04fce5534e45e7d973a1f.zip |
Revert "SONAR-3437, SONAR-5189 Store measures in a persistit cache"
This reverts commit 46395126b184c343df5471a147cdb48133f59f6f.
Diffstat (limited to 'sonar-plugin-api/src')
11 files changed, 114 insertions, 174 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 4eb61021ca5..866785feeef 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,8 +30,6 @@ 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; @@ -120,10 +118,8 @@ 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 5aa343120b6..e2448adb5da 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,7 +28,6 @@ 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; @@ -38,7 +37,7 @@ import java.util.Date; * * @since 1.10 */ -public class Measure implements Serializable { +public class Measure { 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; @@ -48,6 +47,8 @@ public class Measure implements Serializable { */ public static final int DEFAULT_PRECISION = 1; + // for internal use + private Long id; protected String metricKey; protected Metric metric; protected Double value; @@ -412,6 +413,24 @@ public class Measure implements Serializable { } /** + * @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 + */ + public Measure setId(Long id) { + this.id = id; + return this; + } + + /** * @return the first variation value * @since 2.5 */ @@ -627,7 +646,7 @@ public class Measure implements Serializable { return metric.isOptimizedBestValue() == Boolean.TRUE && metric.getBestValue() != null && (value == null || NumberUtils.compare(metric.getBestValue(), value) == 0) - && allNull(alertStatus, description, tendency, url, data) + && allNull(id, alertStatus, description, tendency, url, data) && isZeroVariation(variation1, variation2, variation3, variation4, variation5); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java index c7731a1120a..e6c0c4912e1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilter.java @@ -19,12 +19,13 @@ */ package org.sonar.api.measures; +import java.util.Collection; /** * @since 1.10 */ public interface MeasuresFilter<M> { - M filter(Iterable<Measure> measures); + M filter(Collection<Measure> measures); } 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 7a89e5f2030..4ed4a8ffb1b 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,7 +19,6 @@ */ 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; @@ -38,15 +37,8 @@ public final class MeasuresFilters { public static MeasuresFilter<Collection<Measure>> all() { return new MeasuresFilter<Collection<Measure>>() { - @Override - public Collection<Measure> filter(Iterable<Measure> measures) { - Collection<Measure> all = new ArrayList<Measure>(); - for (Measure measure : measures) { - if (measure != null) { - all.add(measure); - } - } - return all; + public Collection<Measure> filter(Collection<Measure> measures) { + return measures; } }; } @@ -57,8 +49,8 @@ public final class MeasuresFilters { public static MeasuresFilter<Measure> metric(final String metricKey) { return new MetricFilter<Measure>(metricKey) { - @Override - public Measure filter(Iterable<Measure> measures) { + + public Measure filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -78,8 +70,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(Iterable<Measure> measures) { + public Measure filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -109,8 +100,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(Iterable<Measure> measures) { + public Measure filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -138,7 +128,7 @@ public final class MeasuresFilters { */ public static MeasuresFilter<Measure> measure(final Measure measure) { return new MeasuresFilter<Measure>() { - public Measure filter(Iterable<Measure> measures) { + public Measure filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -153,7 +143,7 @@ public final class MeasuresFilters { } public static MeasuresFilter<RuleMeasure> rule(final Metric metric, final Rule rule) { - return new RuleFilter(metric, rule.ruleKey()); + return new RuleFilter(metric, rule); } public static MeasuresFilter<Collection<RuleMeasure>> rules(final Metric metric) { @@ -161,11 +151,10 @@ public final class MeasuresFilters { private boolean apply(Measure measure) { return measure instanceof RuleMeasure && metric.equals(measure.getMetric()) - && measure.getPersonId() == null && ((RuleMeasure) measure).ruleKey() != null; + && measure.getPersonId() == null && ((RuleMeasure) measure).getRule() != null; } - @Override - public Collection<RuleMeasure> filter(Iterable<Measure> measures) { + public Collection<RuleMeasure> filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -213,8 +202,7 @@ public final class MeasuresFilters { abstract boolean doApply(RuleMeasure ruleMeasure); - @Override - public M filter(Iterable<Measure> measures) { + public M filter(Collection<Measure> measures) { if (measures == null) { return null; } @@ -228,17 +216,17 @@ public final class MeasuresFilters { } private static class RuleFilter extends AbstractRuleMeasureFilter<RuleMeasure> { - private RuleKey ruleKey; + private Rule rule; - protected RuleFilter(Metric metric, RuleKey ruleKey) { + protected RuleFilter(Metric metric, Rule rule) { super(metric); - this.ruleKey = ruleKey; + this.rule = rule; } @Override boolean doApply(RuleMeasure measure) { - return measure.ruleKey() != null - && ruleKey.equals(measure.ruleKey()); + return measure.getRule() != null + && rule.equals(measure.getRule()); } } } 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 bc809c88884..dc7d507153b 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,16 +27,7 @@ import org.sonar.api.ServerExtension; import org.sonar.api.batch.InstantiationStrategy; import javax.annotation.Nullable; -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; +import javax.persistence.*; /** * This class represents the definition of a metric in Sonar. @@ -46,7 +37,7 @@ import java.io.Serializable; @Table(name = "metrics") @Entity(name = "Metric") @InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class Metric implements ServerExtension, BatchExtension, Serializable { +public class Metric implements ServerExtension, BatchExtension { /** * A metric bigger value means a degradation @@ -89,7 +80,7 @@ public class Metric implements ServerExtension, BatchExtension, Serializable { private Integer id; @Transient - private transient Formula formula; + private Formula formula; @Column(name = "name", updatable = false, nullable = false, length = 64) private String key; @@ -215,7 +206,7 @@ public class Metric implements ServerExtension, BatchExtension, Serializable { */ @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 b2feae04744..b0e1199a5c1 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,7 +22,6 @@ 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; @@ -33,54 +32,24 @@ import javax.annotation.Nullable; */ public class RuleMeasure extends Measure { - /** - * @deprecated since 4.4 - */ - @Deprecated - private transient Rule rule; - private RuleKey ruleKey; + private Rule rule; 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); - this.rule = rule; - } - - public RuleMeasure(Metric metric, @Nullable RuleKey ruleKey, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) { super(metric); - this.ruleKey = ruleKey; + this.rule = rule; 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; } - /** - * @deprecated since 4.4 use {@link #setRuleKey()} - */ - @Deprecated public RuleMeasure setRule(Rule rule) { this.rule = rule; - this.ruleKey = rule.ruleKey(); return this; } @@ -146,10 +115,10 @@ public class RuleMeasure extends Measure { } RuleMeasure other = (RuleMeasure) obj; return new EqualsBuilder() - .append(getMetric(), other.getMetric()) - .append(personId, other.personId) - .append(ruleKey, other.ruleKey) - .isEquals(); + .append(getMetric(), other.getMetric()) + .append(personId, other.personId) + .append(rule, other.rule) + .isEquals(); } @Override @@ -160,42 +129,35 @@ public class RuleMeasure extends Measure { @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(getMetric()) - .append(personId) - .append(ruleKey) - .toHashCode(); + .append(getMetric()) + .append(personId) + .append(rule) + .toHashCode(); } @Override public String toString() { return new ToStringBuilder(this) - .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(); + .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(); } - /** - * @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, (RuleKey) null, priority, null).setValue(value); + return new RuleMeasure(metric, null, priority, null).setValue(value); } /** @@ -203,6 +165,6 @@ public class RuleMeasure extends Measure { */ @Deprecated public static RuleMeasure createForCategory(Metric metric, Integer category, @Nullable Double value) { - return new RuleMeasure(metric, (RuleKey) null, null, category).setValue(value); + return new RuleMeasure(metric, 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 402a5ec9f9d..39453f963ff 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,19 +34,7 @@ import org.sonar.check.Cardinality; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -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 javax.persistence.*; import java.util.ArrayList; import java.util.Date; @@ -291,15 +279,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; } @@ -480,6 +468,7 @@ public class Rule { return this; } + /** * For internal use only. * @@ -510,34 +499,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 b649a4e466a..fadad455575 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,7 +22,6 @@ package org.sonar.api.technicaldebt.batch; import javax.annotation.CheckForNull; -import java.io.Serializable; import java.util.Date; import java.util.List; @@ -31,7 +30,7 @@ import java.util.List; * @deprecated since 4.3 */ @Deprecated -public interface Characteristic extends Serializable { +public interface Characteristic { 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 71204e9ffb8..606d2a3fb18 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,7 +24,6 @@ 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; /** @@ -32,7 +31,7 @@ import java.util.Date; * @deprecated since 4.3 */ @Deprecated -public interface Requirement extends Serializable { +public interface Requirement { 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 ea075ed2a99..f9f569f199b 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,7 +25,6 @@ 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; @@ -38,8 +37,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)); } @@ -47,13 +46,10 @@ 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)); - Iterator<Measure> filteredMeasures = MeasuresFilters.all().filter(measures).iterator(); - filteredMeasures.next(); - filteredMeasures.next(); - assertThat(filteredMeasures.hasNext(), is(false)); + assertThat(MeasuresFilters.all().filter(measures).size(), is(2)); } @Test @@ -62,13 +58,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)); } @@ -79,13 +75,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)); } @@ -94,10 +90,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 3f9f67ce236..091d8c781cd 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.ruleKey(), m.ruleKey()) && + ObjectUtils.equals(rule, m.getRule()) && NumberUtils.compare(value, m.getValue()) == 0; } } |