Skip to content

Commit

Permalink
Merge pull request #285 from uhafner/files
Browse files Browse the repository at this point in the history
Add methods to expose files and issues from reports
  • Loading branch information
uhafner authored Dec 6, 2023
2 parents 8bfd62c + 531c2fa commit eef2070
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 81 deletions.
37 changes: 35 additions & 2 deletions src/main/java/edu/hm/hafner/grading/AggregatedScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.coverage.FileNode;
import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.grading.AnalysisScore.AnalysisScoreBuilder;
Expand All @@ -28,7 +30,7 @@
* @author Eva-Maria Zeintl
* @author Ullrich Hafner
*/
@SuppressWarnings("PMD.GodClass")
@SuppressWarnings({"PMD.GodClass", "PMD.CyclomaticComplexity"})
public final class AggregatedScore implements Serializable {
@Serial
private static final long serialVersionUID = 3L;
Expand Down Expand Up @@ -297,6 +299,37 @@ public List<CoverageScore> getCodeCoverageScores() {
return scores;
}

/**
* Returns all issues that have been reported by the static analysis tools.
*
* @return the issues
*/
public List<Issue> getIssues() {
return getAnalysisScores().stream()
.map(AnalysisScore::getReport)
.flatMap(Report::stream)
.toList();
}

/**
* Returns the covered files for the specified metric.
*
* @param metric
* the metric to get the covered files for
*
* @return the covered files
*/
public List<FileNode> getCoveredFiles(final Metric metric) {
return getCodeCoverageScores().stream()
.map(CoverageScore::getSubScores)
.flatMap(Collection::stream)
.filter(score -> score.getMetric() == metric)
.map(CoverageScore::getReport)
.map(Node::getAllFileNodes)
.flatMap(Collection::stream)
.toList();
}

public List<AnalysisScore> getAnalysisScores() {
return List.copyOf(analysisScores);
}
Expand Down Expand Up @@ -457,7 +490,7 @@ public void gradeTests(final TestReportFactory factory) {

/**
* Returns statistical metrics for the results aggregated in this score. The key of the returned map is a string
* that identifies the metric, the value is the integer based result.
* that identifies the metric, the value is the integer-based result.
*
* @return the metrics
*/
Expand Down
Loading

0 comments on commit eef2070

Please sign in to comment.