Skip to content

Commit

Permalink
Merge pull request #939 from emouty/add_type_and_category_to_cpd_issues
Browse files Browse the repository at this point in the history
Add category and type to code duplication issues
  • Loading branch information
uhafner authored Sep 4, 2023
2 parents a137c72 + f90c316 commit 85dac07
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public Report parse(final ReaderFactory readerFactory) throws ParsingCanceledExc
throw new ParsingException("Input stream is not a valid duplications file.");
}

issueBuilder.setMessage("Found duplicated code.");
issueBuilder.setMessage("Found duplicated code.")
.setCategory("Code Duplication");
return convertDuplicationsToIssues(duplications, issueBuilder);
}
catch (IOException | SAXException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected Report convertDuplicationsToIssues(final List<Duplication> duplication
.setLineStart(file.getLine())
.setLineEnd(file.getLine() + duplication.getLines() - 1)
.setFileName(file.getPath())
.setType("CPD")
.setAdditionalProperties(group);
Issue issue = issueBuilder.build();
group.add(issue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ protected Report convertDuplicationsToIssues(final List<Duplicate> duplications,
.setLineStart(lineRange.getStart())
.setLineEnd(lineRange.getEnd())
.setFileName(fragment.getFileName())
.setType("DupFinder")
.setAdditionalProperties(group);
Issue issue = issueBuilder.buildAndClean();
Issue issue = issueBuilder.build();
group.add(issue);
report.add(issue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ protected Report convertDuplicationsToIssues(final List<Set> duplications, final
.setLineStart(file.getStartLineNumber())
.setLineEnd(file.getEndLineNumber())
.setFileName(file.getSourceFile())
.setAdditionalProperties(group);
Issue issue = issueBuilder.buildAndClean();
.setAdditionalProperties(group)
.setType("Simian");
Issue issue = issueBuilder.build();
group.add(issue);
report.add(issue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
.hasLineStart(274).hasLineEnd(274 + 95 - 1)
.hasFileName(FILE_NAME_REPORTER)
.hasSeverity(Severity.WARNING_HIGH)
.hasMessage("Found duplicated code.");
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("CPD");
softly.assertThat(publisherSecond)
.hasLineStart(202).hasLineEnd(202 + 95 - 1)
.hasFileName(FILE_NAME_PUBLISHER)
.hasSeverity(Severity.WARNING_HIGH)
.hasMessage("Found duplicated code.");
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("CPD");

Serializable additionalProperties = publisherSecond.getAdditionalProperties();
softly.assertThat(additionalProperties).isEqualTo(reporterSecond.getAdditionalProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ private void assertThatReporterAndPublisherDuplicationsAreCorrectlyLinked(
assertThat(publisher)
.hasLineStart(PUBLISHER_LINE).hasLineEnd(PUBLISHER_LINE + 11)
.hasFileName(PUBLISHER)
.hasSeverity(Severity.WARNING_LOW);
.hasSeverity(Severity.WARNING_LOW)
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("DupFinder");
assertThat(reporter)
.hasLineStart(REPORTER_LINE).hasLineEnd(REPORTER_LINE + 11)
.hasFileName(REPORTER)
.hasSeverity(Severity.WARNING_LOW);
.hasSeverity(Severity.WARNING_LOW)
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("DupFinder");

assertThat(Objects.requireNonNull(publisher.getAdditionalProperties()))
.isEqualTo(Objects.requireNonNull(reporter.getAdditionalProperties()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ protected void assertThatIssuesArePresent(final Report report,
softly.assertThat(firstIssue)
.hasLineStart(93).hasLineEnd(98)
.hasFileName(MAVEN_BUILD)
.hasSeverity(Severity.WARNING_LOW);
.hasSeverity(Severity.WARNING_LOW)
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("Simian");
softly.assertThat(firstIssue.getDescription()).isEmpty();

Issue secondIssue = report.get(1);
softly.assertThat(secondIssue)
.hasLineStart(76).hasLineEnd(81)
.hasFileName(MAVEN_BUILD)
.hasSeverity(Severity.WARNING_LOW);
.hasSeverity(Severity.WARNING_LOW)
.hasMessage("Found duplicated code.")
.hasCategory("Code Duplication")
.hasType("Simian");
softly.assertThat(secondIssue.getDescription()).isEmpty();
}

Expand Down

0 comments on commit 85dac07

Please sign in to comment.