-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support deterministic Cobertuna Reports #121
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import edu.hm.hafner.util.FilteredLog; | ||
import edu.hm.hafner.util.PathUtil; | ||
import edu.hm.hafner.util.SecureXmlParserFactory; | ||
import edu.hm.hafner.util.TreeString; | ||
Check warning on line 29 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
|
||
/** | ||
* Parses Cobertura reports into a hierarchical Java Object Model. | ||
|
@@ -140,17 +141,20 @@ | |
|
||
private FileNode createFileNode(final StartElement element, final PackageNode packageNode) { | ||
var fileName = getValueOf(element, FILE_NAME); | ||
var path = getTreeStringBuilder().intern(PATH_UTIL.getRelativePath(fileName)); | ||
|
||
return packageNode.findOrCreateFileNode(getFileName(fileName), path); | ||
var relativePath = PATH_UTIL.getRelativePath(fileName); | ||
var actualPath = relativePath.startsWith("/_/") ? | ||
Check warning on line 145 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Code CoveragePartially covered line
Check warning on line 145 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
Check warning on line 145 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Java Compilercheckstyle:check
Check warning on line 145 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / CheckStyleOperatorWrapCheck
Raw output
|
||
relativePath.replace("/_/", "./") : | ||
Check warning on line 146 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Code CoverageNot covered line
Check warning on line 146 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Java Compilercheckstyle:check
Check warning on line 146 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / CheckStyleOperatorWrapCheck
Raw output
|
||
relativePath; | ||
var finalPath = getTreeStringBuilder().intern(actualPath); | ||
return packageNode.findOrCreateFileNode(getFileName(fileName), finalPath); | ||
} | ||
|
||
private String getFileName(final String relativePath) { | ||
var path = Paths.get(PATH_UTIL.getAbsolutePath(relativePath)).getFileName(); | ||
if (path == null) { | ||
return relativePath; | ||
} | ||
return path.toString(); | ||
var fileName = Paths.get(PATH_UTIL.getAbsolutePath(relativePath)).getFileName(); | ||
var actualFileName = (fileName != null && fileName.toString().startsWith("/_/")) ? | ||
Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Code CoveragePartially covered line
Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Java Compilercheckstyle:check
Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / CheckStyleOperatorWrapCheck
Raw output
Check warning on line 154 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / PMDUnnecessaryLocalBeforeReturn
Raw output
|
||
fileName.toString().replace("/_/", "./") : | ||
Check warning on line 155 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Code CoverageNot covered line
Check warning on line 155 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Java Compilercheckstyle:check
Check warning on line 155 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / CheckStyleOperatorWrapCheck
Raw output
|
||
(fileName != null ? fileName.toString() : relativePath); | ||
Check warning on line 156 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / Code CoveragePartially covered line
Check warning on line 156 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java ci.jenkins.io / PMDUselessParentheses
Raw output
|
||
return actualFileName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract the file name logic into a method and reuse it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.CognitiveComplexity"}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract
"/_/"
as a constant with a meaningful name (deterministic...).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't you use
String#replaceFirst
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I've replaced the manual prefix check with String#replaceFirst to simplify the logic