1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
* SonarQube :: Plugin API
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program 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.
*
* This program 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.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;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
/**
* @since 1.10
* @deprecated since 5.2. Ignored by design because of Compute Engine.
*/
@Deprecated
public class RuleMeasure extends Measure {
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 != null ? rule.ruleKey() : null, rulePriority, ruleCategory);
}
/**
* This constructor is for internal use only. Please use static methods createForXXX().
*/
public RuleMeasure(Metric metric, @Nullable RuleKey ruleKey, @Nullable RulePriority rulePriority, @Nullable Integer ruleCategory) {
super(metric);
this.ruleKey = ruleKey;
this.rulePriority = rulePriority;
}
@CheckForNull
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.create(ruleKey.repository(), ruleKey.rule());
}
/**
* @deprecated since 4.4 use {@link #setRuleKey(org.sonar.api.rule.RuleKey)}
*/
@Deprecated
public RuleMeasure setRule(Rule rule) {
this.ruleKey = rule.ruleKey();
return this;
}
/**
* @deprecated since 2.14 use {@link #getSeverity()} instead. See SONAR-1829.
*/
@Deprecated
@CheckForNull
public RulePriority getRulePriority() {
return rulePriority;
}
/**
* @since 2.14
*/
@CheckForNull
public RulePriority getSeverity() {
return rulePriority;
}
/**
* @deprecated since 2.14 use {@link #setSeverity(org.sonar.api.rules.RulePriority)} instead. See SONAR-1829.
*/
@Deprecated
public RuleMeasure setRulePriority(RulePriority rulePriority) {
this.rulePriority = rulePriority;
return this;
}
/**
* @since 2.14
*/
public RuleMeasure setSeverity(RulePriority severity) {
this.rulePriority = severity;
return this;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj.getClass().equals(RuleMeasure.class))) {
// for the moment.
return false;
}
if (this == obj) {
return true;
}
RuleMeasure other = (RuleMeasure) obj;
return new EqualsBuilder()
.append(getMetric(), other.getMetric())
.append(personId, other.personId)
.append(ruleKey, other.ruleKey)
.isEquals();
}
@Override
public RuleMeasure setValue(@Nullable Double v) {
return (RuleMeasure) super.setValue(v);
}
@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(getMetric())
.append(personId)
.append(ruleKey)
.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("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);
}
/**
* @deprecated since 2.5. See SONAR-2007.
*/
@Deprecated
public static RuleMeasure createForCategory(Metric metric, Integer category, @Nullable Double value) {
return new RuleMeasure(metric, (RuleKey) null, null, category).setValue(value);
}
}
|