Skip to content

Commit

Permalink
basic support for aggregating scoverage across subprojects
Browse files Browse the repository at this point in the history
  • Loading branch information
maiflai committed Feb 8, 2015
1 parent 60f63a0 commit 24f1a98
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 19 deletions.
22 changes: 22 additions & 0 deletions src/main/groovy/org/scoverage/AggregateReportApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.scoverage;

import scoverage.Coverage;
import scoverage.report.CoberturaXmlWriter;
import scoverage.report.CoverageAggregator;
import scoverage.report.ScoverageHtmlWriter;

import java.io.File;

public class AggregateReportApp {

public static void main(String... args) {
File rootDir = new File(args[0]);
File reportDir = new File(args[1]);
Boolean clean = Boolean.parseBoolean(args[2]);
reportDir.mkdirs();
Coverage coverage = CoverageAggregator.aggregate(rootDir, clean).get();
new ScoverageHtmlWriter(rootDir, reportDir).write(coverage);
new CoberturaXmlWriter(rootDir, reportDir).write(coverage);
}

}
24 changes: 24 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageAggregate.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.scoverage

import org.gradle.api.tasks.JavaExec

class ScoverageAggregate extends JavaExec {

boolean clean = false
File reportDir

@Override
void exec() {
setClasspath(ScoveragePlugin.extensionIn(project).pluginClasspath)
setMain('org.scoverage.AggregateReportApp')
def reportPath = reportDirOrDefault()
setArgs([project.projectDir, reportPath.absolutePath, clean])
super.exec()
def reportEntryPoint = new File(reportPath, 'index.html').absolutePath
project.logger.lifecycle("Wrote aggregated scoverage report to ${reportEntryPoint}")
}

def reportDirOrDefault() {
return reportDir ? reportDir : new File(project.buildDir, 'scoverage-aggregate')
}
}
24 changes: 6 additions & 18 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ScoverageExtension {
/** regex for each excluded file */
List<String> excludedFiles = []

FileCollection pluginClasspath

ScoverageExtension(Project project) {

project.plugins.apply(JavaPlugin.class);
Expand Down Expand Up @@ -93,8 +95,9 @@ class ScoverageExtension {
})
}

project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
project.tasks.create(ScoveragePlugin.REPORT_NAME, ScoverageReport.class) {
dependsOn(project.tasks[ScoveragePlugin.TEST_NAME])
onlyIf { ScoveragePlugin.extensionIn(project).dataDir.list() }
}

project.tasks.create(ScoveragePlugin.CHECK_NAME, OverallCheckTask.class) {
Expand All @@ -104,6 +107,8 @@ class ScoverageExtension {
sources = project.projectDir
dataDir = new File(project.buildDir, 'scoverage')
reportDir = new File(project.buildDir, 'reports' + File.separatorChar + 'scoverage')
def classLocation = ScoverageExtension.class.getProtectionDomain().getCodeSource().getLocation()
pluginClasspath = project.files(classLocation.file) + project.configurations.scoverage
}

private Action<Project> configureRuntimeOptions = new Action<Project>() {
Expand All @@ -113,7 +118,6 @@ class ScoverageExtension {

def extension = ScoveragePlugin.extensionIn(t)
extension.dataDir.mkdirs()
extension.reportDir.mkdirs()

Configuration configuration = t.configurations[ScoveragePlugin.CONFIGURATION_NAME]
File pluginFile
Expand All @@ -122,7 +126,6 @@ class ScoverageExtension {
} catch(NoSuchElementException e) {
throw new GradleException("Could not find a plugin jar in configuration '${ScoveragePlugin.CONFIGURATION_NAME}'")
}
FileCollection pluginDependencies = configuration.filter { it != pluginFile }

t.tasks[ScoveragePlugin.COMPILE_NAME].configure {
List<String> parameters = ['-Xplugin:' + pluginFile.absolutePath]
Expand Down Expand Up @@ -151,21 +154,6 @@ class ScoverageExtension {
// the compile task creates a store of measured statements
outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml'))
}

t.tasks[ScoveragePlugin.REPORT_NAME].configure {
def classLocation = ScoverageExtension.class.getProtectionDomain().getCodeSource().getLocation()
classpath = project.files(classLocation.file) + configuration
main = 'org.scoverage.ScoverageReport'
args = [
extension.sources,
extension.dataDir.absolutePath,
extension.reportDir.absolutePath
]
inputs.dir(extension.dataDir)
outputs.dir(extension.reportDir)
}

}
}

}
16 changes: 16 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageReport.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.scoverage

import org.gradle.api.tasks.JavaExec

class ScoverageReport extends JavaExec {

@Override
void exec() {
def extension = ScoveragePlugin.extensionIn(project)
extension.reportDir.mkdirs()
setClasspath(extension.pluginClasspath)
setMain('org.scoverage.SingleReportApp')
setArgs([extension.sources.absolutePath, extension.dataDir.absolutePath, extension.reportDir.absolutePath])
super.exec()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* late binding of scoverage core libraries (without a dependency on groovy)
*/
public class ScoverageReport {
public class SingleReportApp {

public static void main(String... args) {
File sourceDir = new File(args[0]);
Expand Down

0 comments on commit 24f1a98

Please sign in to comment.