Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created new plugin PitestAggregatorPlugin for aggregation proce…
…ss for multi-project resolves: gh-80
- Loading branch information
1 parent
ddb995f
commit f706426
Showing
11 changed files
with
424 additions
and
4 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
44 changes: 44 additions & 0 deletions
44
src/funcTest/resources/testProjects/multiproject/build-report.gradle
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,44 @@ | ||
buildscript { | ||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
dependencies { | ||
//Local/current version of the plugin should be put on a classpath earlier to override that plugin version | ||
// classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.3-SNAPSHOT' | ||
} | ||
} | ||
|
||
apply plugin: "info.solidsoft.pitest.aggregator" | ||
|
||
subprojects { | ||
apply plugin: 'java' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'junit:junit:4.12' | ||
} | ||
|
||
version = '1.0' | ||
group = 'pitest.sample.multimodule' | ||
} | ||
|
||
[":shared", ":for-report"].each { subprojectName -> | ||
configure(project(subprojectName)) { | ||
apply plugin: "info.solidsoft.pitest" | ||
|
||
dependencies { | ||
implementation 'org.slf4j:slf4j-api:1.7.25' | ||
implementation 'org.slf4j:slf4j-nop:1.7.25' | ||
} | ||
|
||
pitest { | ||
outputFormats = ["HTML","XML"] | ||
timestampedReports = false | ||
exportLineCoverage = true | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../multiproject/for-report/src/main/java/pitest/sample/multimodule/forreport/ForReport.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,31 @@ | ||
package pitest.sample.multimodule.forreport; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ForReport { | ||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private String name; | ||
|
||
public ForReport(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String notUsed() { | ||
return "notUsed"; | ||
} | ||
|
||
public String readProperty() { | ||
logger.info("to fail on broken dependency"); | ||
return "important"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...multiproject/for-report/src/test/java/pitest/sample/multimodule/shared/ForReportTest.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,20 @@ | ||
package pitest.sample.multimodule.forreport; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ForReportTest { | ||
@Test | ||
public void testName() { | ||
ForReport shared = new ForReport("testname1"); | ||
assertEquals("testname1", shared.getName()); | ||
shared.setName("testname2"); | ||
assertEquals("testname2", shared.getName()); | ||
} | ||
|
||
@Test | ||
public void testCallLogger() { | ||
new ForReport("P").readProperty(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/funcTest/resources/testProjects/multiproject/settings-report.gradle
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,3 @@ | ||
include "shared", "for-report" | ||
|
||
rootProject.buildFileName = "build-report.gradle" |
181 changes: 181 additions & 0 deletions
181
src/main/groovy/info/solidsoft/gradle/pitest/AggregateReportTask.groovy
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,181 @@ | ||
package info.solidsoft.gradle.pitest | ||
|
||
import groovy.transform.CompileStatic | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.reporting.ReportingExtension | ||
import org.gradle.api.tasks.Classpath | ||
import org.gradle.api.tasks.InputFiles | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.PathSensitive | ||
import org.gradle.api.tasks.PathSensitivity | ||
import org.gradle.api.tasks.SkipWhenEmpty | ||
import org.gradle.api.tasks.TaskAction | ||
import org.pitest.aggregate.ReportAggregator | ||
import org.pitest.mutationtest.config.DirectoryResultOutputStrategy | ||
import org.pitest.mutationtest.config.UndatedReportDirCreationStrategy | ||
|
||
import java.util.stream.Collectors | ||
|
||
/** | ||
* Task to aggregate pitest report | ||
*/ | ||
@CompileStatic | ||
class AggregateReportTask extends DefaultTask { | ||
|
||
private static final String MUTATION_FILE_NAME = "mutations.xml"; | ||
private static final String LINE_COVERAGE_FILE_NAME = "linecoverage.xml"; | ||
|
||
@OutputDirectory | ||
final DirectoryProperty reportDir | ||
|
||
@OutputFile | ||
final RegularFileProperty reportFile | ||
|
||
@SkipWhenEmpty | ||
@InputFiles | ||
@PathSensitive(PathSensitivity.RELATIVE) | ||
final ConfigurableFileCollection sourceDirs | ||
|
||
@SkipWhenEmpty | ||
@InputFiles | ||
@Classpath | ||
final ConfigurableFileCollection additionalClasspath | ||
|
||
@SkipWhenEmpty | ||
@InputFiles | ||
@PathSensitive(PathSensitivity.RELATIVE) | ||
final ConfigurableFileCollection mutationFiles | ||
|
||
@SkipWhenEmpty | ||
@InputFiles | ||
@PathSensitive(PathSensitivity.RELATIVE) | ||
final ConfigurableFileCollection lineCoverageFiles | ||
|
||
AggregateReportTask() { | ||
reportDir = project.objects.directoryProperty() | ||
reportDir.set(new File(getReportBaseDirectory(), PitestPlugin.PITEST_REPORT_DIRECTORY_NAME)) | ||
|
||
reportFile = project.objects.fileProperty() | ||
reportFile.set(reportDir.file("index.html")) | ||
|
||
Set<PitestTask> pitestTasks = getAllPitestTasks() | ||
|
||
sourceDirs = project.objects.fileCollection() | ||
sourceDirs.from = collectSourceDirs(pitestTasks) | ||
|
||
additionalClasspath = project.objects.fileCollection() | ||
additionalClasspath.from = collectClasspathDirs(pitestTasks) | ||
|
||
Set<Project> projectsWithPitest = getProjectsWithPitestPlugin() | ||
|
||
mutationFiles = project.objects.fileCollection() | ||
mutationFiles.from = collectMutationFiles(projectsWithPitest) | ||
|
||
lineCoverageFiles = project.objects.fileCollection() | ||
lineCoverageFiles.from = collectLineCoverageFiles(projectsWithPitest) | ||
} | ||
|
||
@TaskAction | ||
void aggregate() { | ||
logger.info("Aggregating pitest reports") | ||
|
||
ReportAggregator.Builder builder = ReportAggregator.builder() | ||
|
||
lineCoverageFiles.each { file -> builder.addLineCoverageFile(file) } | ||
mutationFiles.each { file -> builder.addMutationResultsFile(file) } | ||
sourceDirs.each { file -> builder.addSourceCodeDirectory(file) } | ||
additionalClasspath.each { file -> builder.addCompiledCodeDirectory(file) } | ||
|
||
ReportAggregator aggregator = builder.resultOutputStrategy(new DirectoryResultOutputStrategy( | ||
reportDir.asFile.get().absolutePath, | ||
new UndatedReportDirCreationStrategy())) | ||
.build() | ||
aggregator.aggregateReport() | ||
|
||
logger.info("Aggregated report ${reportFile.asFile.get().absolutePath}") | ||
} | ||
|
||
private static Set<Provider<File>> collectMutationFiles(Set<Project> pitestProjects) { | ||
return pitestProjects.stream() | ||
.map { prj -> prj.extensions.getByType(PitestPluginExtension) } | ||
.map { extension -> extension.reportDir.file(MUTATION_FILE_NAME) } | ||
.collect(Collectors.toSet()) | ||
} | ||
|
||
private static Set<Provider<File>> collectLineCoverageFiles(Set<Project> pitestProjects) { | ||
return pitestProjects.stream() | ||
.map { prj -> prj.extensions.getByType(PitestPluginExtension) } | ||
.map { extension -> extension.reportDir.file(LINE_COVERAGE_FILE_NAME) } | ||
.collect(Collectors.toSet()) | ||
} | ||
|
||
DirectoryProperty getReportDir() { | ||
return reportDir | ||
} | ||
|
||
ConfigurableFileCollection getAdditionalClasspath() { | ||
return additionalClasspath | ||
} | ||
|
||
ConfigurableFileCollection getMutationFiles() { | ||
return mutationFiles | ||
} | ||
|
||
ConfigurableFileCollection getLineCoverageFiles() { | ||
return lineCoverageFiles | ||
} | ||
|
||
ConfigurableFileCollection getSourceDirs() { | ||
return sourceDirs | ||
} | ||
|
||
private File getReportBaseDirectory() { | ||
// if Java plugin configured on root project | ||
if (project.extensions.findByType(ReportingExtension)) { | ||
return project.extensions.getByType(ReportingExtension).baseDir | ||
} | ||
return new File(project.buildDir, "reports") | ||
} | ||
|
||
private Set<Project> getProjectsWithPitestPlugin() { | ||
Set<Project> projects = [] as Set | ||
if (isRootPitestConfigured()) { | ||
projects.add(project) | ||
} | ||
projects.addAll(getSubprojectsWithPitest()) | ||
return projects | ||
} | ||
|
||
private boolean isRootPitestConfigured() { | ||
return project.plugins.hasPlugin(PitestPlugin.PLUGIN_ID) && project.extensions.findByType(PitestPluginExtension) | ||
} | ||
|
||
private Set<Project> getSubprojectsWithPitest() { | ||
return project.subprojects.findAll { prj -> prj.plugins.hasPlugin(PitestPlugin.PLUGIN_ID) } | ||
} | ||
|
||
private Set<PitestTask> getAllPitestTasks() { | ||
return project.getTasksByName(PitestPlugin.PITEST_TASK_NAME, true) as Set<PitestTask> | ||
} | ||
|
||
private Set<Provider<Set<File>>> collectSourceDirs(Set<PitestTask> pitestTasks) { | ||
return pitestTasks.stream() | ||
.map { task -> task.sourceDirs } | ||
.map { cfc -> project.provider { cfc.files.findAll { f -> f.isDirectory() } } } | ||
.collect(Collectors.toSet()) | ||
} | ||
|
||
private Set<Provider<Set<File>>> collectClasspathDirs(Set<PitestTask> pitestTasks) { | ||
return pitestTasks.stream() | ||
.map { task -> task.additionalClasspath } | ||
.map { cfc -> project.provider { cfc.files.findAll { f -> f.isDirectory() } } } | ||
.collect(Collectors.toSet()) | ||
} | ||
|
||
} |
Oops, something went wrong.