From f90c316a6301722b304221c8123f532e0df73939 Mon Sep 17 00:00:00 2001 From: Erwan Moutymbo Date: Wed, 9 Aug 2023 12:08:28 +0200 Subject: [PATCH] Add category and type to code duplication issues --- .../hafner/analysis/parser/dry/AbstractDryParser.java | 3 ++- .../hm/hafner/analysis/parser/dry/cpd/CpdParser.java | 1 + .../analysis/parser/dry/dupfinder/DupFinderParser.java | 3 ++- .../analysis/parser/dry/simian/SimianParser.java | 5 +++-- .../hafner/analysis/parser/dry/cpd/CpdParserTest.java | 8 ++++++-- .../parser/dry/dupfinder/DupFinderParserTest.java | 10 ++++++++-- .../analysis/parser/dry/simian/SimianParserTest.java | 10 ++++++++-- 7 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java index bc5ca22d9..a21f27806 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/AbstractDryParser.java @@ -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) { diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java index bc0e9d031..f4444b0ba 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParser.java @@ -64,6 +64,7 @@ protected Report convertDuplicationsToIssues(final List duplication .setLineStart(file.getLine()) .setLineEnd(file.getLine() + duplication.getLines() - 1) .setFileName(file.getPath()) + .setType("CPD") .setAdditionalProperties(group); Issue issue = issueBuilder.build(); group.add(issue); diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java index e2e80e02f..233119c4a 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParser.java @@ -79,8 +79,9 @@ protected Report convertDuplicationsToIssues(final List 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); } diff --git a/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java b/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java index b047f9299..65b82f750 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParser.java @@ -63,8 +63,9 @@ protected Report convertDuplicationsToIssues(final List 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); } diff --git a/src/test/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParserTest.java index 4e939bdd3..c7da45d30 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/dry/cpd/CpdParserTest.java @@ -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()); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParserTest.java index 307ee40c9..dd28b977d 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/dry/dupfinder/DupFinderParserTest.java @@ -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())); diff --git a/src/test/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParserTest.java index d88098a57..3230e60c6 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/dry/simian/SimianParserTest.java @@ -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(); }