-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a flag to mark the issues that are part of modified code.
- Loading branch information
Showing
8 changed files
with
217 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/edu/hm/hafner/analysis/IssuesInModifiedCodeMarker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package edu.hm.hafner.analysis; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
|
||
import edu.hm.hafner.util.PathUtil; | ||
|
||
/** | ||
* Computes old, new, and fixed issues based on the reports of two consecutive static analysis runs for the same | ||
* software artifact. | ||
* | ||
* @author Ullrich Hafner | ||
*/ | ||
@SuppressWarnings("PMD.DataClass") | ||
public class IssuesInModifiedCodeMarker { | ||
private static final PathUtil PATH_UTIL = new PathUtil(); | ||
|
||
/** | ||
* Finds and marks all issues that are part the changes in a source control diff. | ||
* | ||
* @param report | ||
* the report with the issues to scan | ||
* @param modifiedLinesInFilesMapping | ||
* a mapping modified lines within files | ||
*/ | ||
public void markIssuesInModifiedCode(final Report report, final Map<String, Set<Integer>> modifiedLinesInFilesMapping) { | ||
for (Entry<String, Set<Integer>> include : modifiedLinesInFilesMapping.entrySet()) { | ||
report.filter(issue -> affectsChangedLineInFile(issue, include.getKey(), include.getValue())) | ||
.stream() | ||
.forEach(Issue::markAsPartOfModifiedCode); | ||
} | ||
} | ||
|
||
private boolean affectsChangedLineInFile(final Issue issue, final String fileName, final Set<Integer> lines) { | ||
var normalizedPath = PATH_UTIL.getRelativePath(fileName); | ||
|
||
if (!issue.getFileName().endsWith(normalizedPath)) { // check only the suffix | ||
return false; | ||
} | ||
return lines.stream().anyMatch(issue::affectsLine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.