*/
package org.sonar.server.qualitygate.changeevent;
+import java.util.EnumSet;
import java.util.Set;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ServerSide;
void onIssueChanges(QGChangeEvent qualityGateEvent, Set<ChangedIssue> changedIssues);
interface ChangedIssue {
+
String getKey();
Status getStatus();
RuleType getType();
+
+ String getSeverity();
+
+ default boolean isNotClosed() {
+ return !Status.CLOSED_STATUSES.contains(getStatus());
+ }
}
enum Status {
REOPENED,
RESOLVED_FP,
RESOLVED_WF,
- RESOLVED_FIXED
+ RESOLVED_FIXED;
+
+ protected static final Set<Status> CLOSED_STATUSES = EnumSet.of(CONFIRMED, RESOLVED_FIXED, RESOLVED_FP, RESOLVED_WF);
}
}
private final String key;
private final QGChangeEventListener.Status status;
private final RuleType type;
+ private final String severity;
- private ChangedIssueImpl(DefaultIssue issue) {
+ ChangedIssueImpl(DefaultIssue issue) {
this.key = issue.key();
this.status = statusOf(issue);
this.type = issue.type();
+ this.severity = issue.severity();
}
static QGChangeEventListener.Status statusOf(DefaultIssue issue) {
return type;
}
+ @Override
+ public String getSeverity() {
+ return severity;
+ }
+
@Override
public String toString() {
return "ChangedIssueImpl{" +
"key='" + key + '\'' +
", status=" + status +
", type=" + type +
+ ", severity=" + severity +
'}';
}
}
verifyNoMoreInteractions(listener1, listener2, listener3);
}
+ @Test
+ public void isNotClosed_returns_true_if_issue_in_one_of_opened_states() {
+ DefaultIssue defaultIssue = new DefaultIssue();
+ defaultIssue.setStatus(Issue.STATUS_REOPENED);
+ defaultIssue.setKey("abc");
+ defaultIssue.setType(RuleType.BUG);
+ defaultIssue.setSeverity("BLOCKER");
+
+ ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+ assertThat(changedIssue.isNotClosed()).isTrue();
+ }
+
+ @Test
+ public void isNotClosed_returns_false_if_issue_in_one_of_closed_states() {
+ DefaultIssue defaultIssue = new DefaultIssue();
+ defaultIssue.setStatus(Issue.STATUS_CONFIRMED);
+ defaultIssue.setKey("abc");
+ defaultIssue.setType(RuleType.BUG);
+ defaultIssue.setSeverity("BLOCKER");
+
+ ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+ assertThat(changedIssue.isNotClosed()).isFalse();
+ }
+
@Test
public void test_status_mapping() {
assertThat(ChangedIssueImpl.statusOf(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isEqualTo(QGChangeEventListener.Status.OPEN);
.toArray(Tuple[]::new);
assertThat(changedIssues)
.hasSize(issues.length)
- .extracting(ChangedIssue::getKey, t -> t.getStatus(), ChangedIssue::getType)
+ .extracting(ChangedIssue::getKey, ChangedIssue::getStatus, ChangedIssue::getType)
.containsOnly(expected);
}
metric.new_duplicated_lines.extra_short_name=Duplicated Lines
metric.new_duplicated_lines.description=Duplicated Lines on New Code
metric.new_duplicated_lines_density.description=Duplicated lines on new code balanced by statements
-metric.new_duplicated_lines_density.name=Duplicated Lines on New Code (%)
+metric.new_duplicated_lines_density.name=Duplicated Lines on New Code
metric.new_duplicated_lines_density.short_name=Duplications
metric.new_duplicated_lines_density.extra_short_name=Density
metric.new_info_violations.description=New Info issues
/**
* @since 6.1
*/
- public static final Metric<Integer> NEW_DUPLICATED_LINES_DENSITY = new Metric.Builder(NEW_DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines on New Code (%)",
+ public static final Metric<Integer> NEW_DUPLICATED_LINES_DENSITY = new Metric.Builder(NEW_DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines on New Code",
Metric.ValueType.PERCENT)
.setDescription("Duplicated lines on new code balanced by statements")
.setDirection(Metric.DIRECTION_WORST)