[pitest-maven] report-aggregate fails due to test dependencies
See original GitHub issueI run pitmp on my whole project to generate reports for each module. Then I run pitest-maven report-aggregate on a reporting module (dedicated module that has dependencies to all other modules). I get the following error:
[ERROR] Failed to execute goal org.pitest:pitest-maven:1.4.8:report-aggregate (merge-pitest-reports) on project reporting: An error has occurred in PIT Test Report report generation.: /home/---/.m2/repository/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar is not a directory -> [Help 1]
I tried to understand why this is happening so I ran maven in debug mode and debugged pitest-maven. Here is the code that seems wrong to me (in AbstractPitAggregationReportMojo
class):
private List<File> getCompiledDirs(final MavenProject project)
throws Exception {
final List<String> sourceRoots = new ArrayList<>();
for (final Object artifactObj : FCollection
.filter(project.getPluginArtifactMap().values(), new DependencyFilter(
new PluginServices(this.getClass().getClassLoader())))) {
final Artifact artifact = (Artifact) artifactObj;
sourceRoots.add(artifact.getFile().getAbsolutePath());
}
return convertToRootDirs(project.getTestClasspathElements(),
Arrays.asList(project.getBuild().getOutputDirectory(),
project.getBuild().getTestOutputDirectory()),
sourceRoots);
}
The call to project.getTestClasspathElements()
returns the list of test sources but also the list of dependencies. Then in ReportAggregator
, the method addCompiledCodeDirectory
calls validateDirectory
with this code:
private void validateDirectory(final File directory) {
if (directory == null) {
throw new IllegalArgumentException("directory is null");
}
// For this method, a non existing directory is valid.
// It probably needs some special treatment later, but it shouldn't prevent the aggregator to be built.
if (directory.exists() && !directory.isDirectory()) {
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not a directory");
}
}
It fails here due to dependencies that are jars and not folders.
I think the issue comes from use of getTestClasspathElements()
. If you want only directories, it should be getTestCompileSourceRoots()
instead.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Waiting for @hcoles to merge it
@dan323 as per my comment on the PR, happy to merge if someone can resolve the conflicts and confirm that it works.