com.bmuschko.gradle.clover.AggregateDatabasesTask.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-clover-plugin Show documentation
Show all versions of gradle-clover-plugin Show documentation
Gradle plugin for generating a code coverage report using Clover.
package com.bmuschko.gradle.clover
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.TaskAction
class AggregateDatabasesTask extends DefaultTask {
/**
* Classpath containing Clover Ant tasks.
*/
@InputFiles
FileCollection cloverClasspath
/**
* The location to write the Clover coverage database resulting from the merge.
*/
@Input
String initString
List testTasks = new ArrayList()
void aggregate(Task testTask) {
dependsOn testTask
testTasks << testTask
}
@TaskAction
void aggregateDatabases() {
File aggregationFile = new File(project.buildDir, getInitString())
List cloverDbFiles = getTestTaskCloverDbFiles(aggregationFile)
if(existsAtLeastOneCloverDbFile(cloverDbFiles)) {
ant.taskdef(resource: 'cloverlib.xml', classpath: getCloverClasspath().asPath)
ant.'clover-merge'(initString: aggregationFile.canonicalPath) {
cloverDbFiles.each { cloverDbFile ->
if(cloverDbFile.exists()) {
ant.cloverDb(initString: cloverDbFile.canonicalPath)
}
}
}
}
}
/**
* Test task Clover database files.
*
* @param aggregationFile Aggregation file
* @return Clover database files
*/
private List getTestTaskCloverDbFiles(File aggregationFile) {
testTasks.collect { new File("${aggregationFile.canonicalPath}-${it.name}") }
}
/**
* Checks if at least one Clover database file exists.
*
* @param cloverDbFiles Clover database files
* @return Flag
*/
private boolean existsAtLeastOneCloverDbFile(List cloverDbFiles) {
cloverDbFiles.findAll { cloverDbFile -> cloverDbFile.exists() }.size() > 0
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy