public NonClosedTracking<RAW, BASE> trackNonClosed(Input<RAW> rawInput, Input<BASE> baseInput) {
NonClosedTracking<RAW, BASE> tracking = NonClosedTracking.of(rawInput, baseInput);
- // 1. match issues with same rule, same line and same line hash, but not necessarily with same message
+ // 1. match by rule, line, line hash and message
+ match(tracking, LineAndLineHashAndMessage::new);
+
+ // 2. match issues with same rule, same line and same line hash, but not necessarily with same message
match(tracking, LineAndLineHashKey::new);
- // 2. detect code moves by comparing blocks of codes
+ // 3. detect code moves by comparing blocks of codes
detectCodeMoves(rawInput, baseInput, tracking);
- // 3. match issues with same rule, same message and same line hash
+ // 4. match issues with same rule, same message and same line hash
match(tracking, LineHashAndMessageKey::new);
- // 4. match issues with same rule, same line and same message
+ // 5. match issues with same rule, same line and same message
match(tracking, LineAndMessageKey::new);
- // 5. match issues with same rule and same line hash but different line and different message.
+ // 6. match issues with same rule and same line hash but different line and different message.
// See SONAR-2812
match(tracking, LineHashKey::new);
public static final RuleKey RULE_UNUSED_PRIVATE_METHOD = RuleKey.of("java", "UnusedPrivateMethod");
public static final RuleKey RULE_NOT_DESIGNED_FOR_EXTENSION = RuleKey.of("java", "NotDesignedForExtension");
public static final RuleKey RULE_USE_DIAMOND = RuleKey.of("java", "UseDiamond");
+ public static final RuleKey RULE_MISSING_PACKAGE_INFO = RuleKey.of("java", "MissingPackageInfo");
@Rule
public ExpectedException thrown = ExpectedException.none();
assertThat(tracking.baseFor(raw1)).isEqualTo(base1);
}
+ @Test
+ public void match_issues_with_same_rule_key_on_project_level() {
+ FakeInput baseInput = new FakeInput();
+ Issue base1 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, "[com.test:abc] Missing package-info.java in package.");
+ Issue base2 = baseInput.createIssue(RULE_MISSING_PACKAGE_INFO, "[com.test:abc/def] Missing package-info.java in package.");
+
+ FakeInput rawInput = new FakeInput();
+ Issue raw1 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, "[com.test:abc/def] Missing package-info.java in package.");
+ Issue raw2 = rawInput.createIssue(RULE_MISSING_PACKAGE_INFO, "[com.test:abc] Missing package-info.java in package.");
+
+ Tracking<Issue, Issue> tracking = tracker.trackNonClosed(rawInput, baseInput);
+ assertThat(tracking.getUnmatchedBases()).hasSize(0);
+ assertThat(tracking.baseFor(raw1)).isEqualTo(base2);
+ assertThat(tracking.baseFor(raw2)).isEqualTo(base1);
+ }
+
private static class Issue implements Trackable {
private final RuleKey ruleKey;
private final Integer line;