Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.coverage.Metric;
import edu.hm.hafner.coverage.ModuleNode;
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.TreeStringBuilder;
import edu.umd.cs.findbugs.annotations.NonNull;

import org.kohsuke.stapler.AncestorInPath;
Expand Down Expand Up @@ -63,7 +62,7 @@
*
* @author Ullrich Hafner
*/
@SuppressWarnings({"checkstyle:ClassFanOutComplexity", "PMD.GodClass"})
@SuppressWarnings({"PMD.GodClass", "checkstyle:ClassFanOutComplexity", "checkstyle:ClassDataAbstractionCoupling"})
public class CoverageRecorder extends Recorder {
static final String CHECKS_DEFAULT_NAME = "Code Coverage";

Expand Down Expand Up @@ -379,7 +378,7 @@ void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener t
"No tools defined that will record the coverage files");
}
else {
perform(run, workspace, taskListener, resultHandler, log);
perform(run, workspace, taskListener, resultHandler, log, logHandler);
}

}
Expand All @@ -389,23 +388,21 @@ void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener t
}

private void perform(final Run<?, ?> run, final FilePath workspace, final TaskListener taskListener,
final StageResultHandler resultHandler, final FilteredLog log) throws InterruptedException {
final StageResultHandler resultHandler, final FilteredLog log, final LogHandler logHandler) throws InterruptedException {
List<Node> results = recordCoverageResults(run, workspace, taskListener, resultHandler, log);

if (!results.isEmpty()) {
CoverageReporter reporter = new CoverageReporter();
var rootNode = Node.merge(results);
// TODO: move code to coverage model
var sources = rootNode.getAll(Metric.MODULE)
.stream()
.filter(ModuleNode.class::isInstance)
.map(ModuleNode.class::cast)
.map(ModuleNode::getSourceFolders)
.flatMap(Collection::stream)
.collect(Collectors.toSet());

var sources = rootNode.getSourceFolders();
sources.addAll(getSourceDirectoriesPaths());

resolveAbsolutePaths(rootNode, workspace, sources, log);
logHandler.log(log);

var action = reporter.publishAction(getActualId(), getName(), getIcon(), rootNode, run,
workspace, taskListener, getQualityGates(), getScm(), sources,
workspace, taskListener, getQualityGates(), getScm(),
getSourceCodeEncoding(), getSourceCodeRetention(), resultHandler);
if (!skipPublishingChecks) {
var checksPublisher = new CoverageChecksPublisher(action, rootNode, getChecksName(), getChecksAnnotationScope());
Expand All @@ -414,6 +411,21 @@ workspace, taskListener, getQualityGates(), getScm(), sources,
}
}

private void resolveAbsolutePaths(final Node rootNode, final FilePath workspace, final Set<String> sources,
final FilteredLog log) throws InterruptedException {
log.logInfo("Resolving source code files...");
var pathMapping = new PathResolver().resolvePaths(rootNode.getFiles(), sources, workspace, log);

if (!pathMapping.isEmpty()) {
log.logInfo("Making paths of " + pathMapping.size() + " source code files relative to workspace root...");
var builder = new TreeStringBuilder();
rootNode.getAllFileNodes().stream()
.filter(file -> pathMapping.containsKey(file.getRelativePath()))
.forEach(file -> file.setRelativePath(builder.intern(pathMapping.get(file.getRelativePath()))));
builder.dedup();
}
}

private String getIcon() {
var icons = tools.stream().map(CoverageTool::getParser).map(Parser::getIcon).collect(Collectors.toSet());
if (icons.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.apache.commons.lang3.math.Fraction;

Expand All @@ -15,7 +14,6 @@
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.Value;
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.TreeStringBuilder;
import edu.umd.cs.findbugs.annotations.CheckForNull;

import hudson.FilePath;
Expand All @@ -42,9 +40,8 @@
public class CoverageReporter {
@SuppressWarnings("checkstyle:ParameterNumber")
CoverageBuildAction publishAction(final String id, final String optionalName, final String icon, final Node rootNode,
final Run<?, ?> build,
final FilePath workspace, final TaskListener listener, final List<CoverageQualityGate> qualityGates,
final String scm, final Set<String> sourceDirectories, final String sourceCodeEncoding,
final Run<?, ?> build, final FilePath workspace, final TaskListener listener,
final List<CoverageQualityGate> qualityGates, final String scm, final String sourceCodeEncoding,
final SourceCodeRetention sourceCodeRetention, final StageResultHandler resultHandler)
throws InterruptedException {
FilteredLog log = new FilteredLog("Errors while reporting code coverage results:");
Expand Down Expand Up @@ -98,8 +95,6 @@ CoverageBuildAction publishAction(final String id, final String optionalName, fi
filesToStore = rootNode.getAllFileNodes();
}

resolveAbsolutePaths(rootNode, workspace, sourceDirectories, log, filesToStore);

action = new CoverageBuildAction(build, id, optionalName, icon, rootNode, qualityGateResult, log,
referenceAction.getOwner().getExternalizableId(), coverageDelta,
modifiedLinesCoverageRoot.aggregateValues(), modifiedLinesCoverageDelta,
Expand All @@ -112,8 +107,6 @@ CoverageBuildAction publishAction(final String id, final String optionalName, fi

filesToStore = rootNode.getAllFileNodes();

resolveAbsolutePaths(rootNode, workspace, sourceDirectories, log, filesToStore);

action = new CoverageBuildAction(build, id, optionalName, icon, rootNode, qualityGateStatus, log);
}

Expand All @@ -131,22 +124,6 @@ CoverageBuildAction publishAction(final String id, final String optionalName, fi
return action;
}

private void resolveAbsolutePaths(final Node rootNode, final FilePath workspace, final Set<String> sourceDirectories,
final FilteredLog log, final List<FileNode> filesToStore) throws InterruptedException {
log.logInfo("Resolving source code files...");
var relativePaths = filesToStore.stream().map(FileNode::getRelativePath).collect(Collectors.toSet());
var pathMapping = new PathResolver().resolvePaths(relativePaths, sourceDirectories, workspace, log);

if (!pathMapping.isEmpty()) {
log.logInfo("Making paths of " + pathMapping.size() + " source code files relative to workspace root...");
var builder = new TreeStringBuilder();
rootNode.getAllFileNodes().stream()
.filter(file -> pathMapping.containsKey(file.getRelativePath()))
.forEach(file -> file.setRelativePath(builder.intern(pathMapping.get(file.getRelativePath()))));
builder.dedup();
}
}

private void createDeltaReports(final Node rootNode, final FilteredLog log, final Node referenceRoot,
final CodeDeltaCalculator codeDeltaCalculator, final Delta delta) {
FileChangesProcessor fileChangesProcessor = new FileChangesProcessor();
Expand Down