Skip to content

Commit 10a38dd

Browse files
committed
Improved aggregation task
Aggregate task now use settings to configure which outputs should be aggregated (HTML, XML, debug XML and cobertura). Tests for aggregation added using dummy test project ('water').
1 parent aa31181 commit 10a38dd

File tree

13 files changed

+198
-40
lines changed

13 files changed

+198
-40
lines changed

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ There is now experimental support for aggregating coverage statistics across sub
6666
The project hosting the aggregation task **must** be configured as the sub-projects are;
6767
i.e. with the scoverage plugin applied and the scoverage dependencies configured.
6868

69+
You also have to declare this task:
70+
6971
```groovy
7072
task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
7173
```
7274

73-
This will produce a report into _build_ / scoverage-aggregate
75+
This will produce a report into `build/scoverage-aggregate` directory.
76+
77+
Aggregation uses same flags as reporting for enabling/disabling different output types.
7478

7579
CheckScoverage
7680
--------------

Diff for: src/main/groovy/org/scoverage/AggregateReportApp.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ public static void main(String... args) {
1313
File rootDir = new File(args[0]);
1414
File reportDir = new File(args[1]);
1515
Boolean clean = Boolean.parseBoolean(args[2]);
16-
reportDir.mkdirs();
16+
17+
Boolean coverageOutputCobertura = java.lang.Boolean.valueOf(args[3]);
18+
Boolean coverageOutputXML = java.lang.Boolean.valueOf(args[4]);
19+
Boolean coverageOutputHTML = java.lang.Boolean.valueOf(args[5]);
20+
Boolean coverageDebug = java.lang.Boolean.valueOf(args[6]);
21+
1722
Coverage coverage = CoverageAggregator.aggregate(rootDir, clean).get();
18-
new ScoverageHtmlWriter(rootDir, reportDir).write(coverage);
19-
new CoberturaXmlWriter(rootDir, reportDir).write(coverage);
23+
24+
ScoverageWriter.write(
25+
rootDir,
26+
reportDir,
27+
coverage,
28+
coverageOutputCobertura,
29+
coverageOutputXML,
30+
coverageOutputHTML,
31+
coverageDebug
32+
);
2033
}
2134

2235
}

Diff for: src/main/groovy/org/scoverage/ScoverageAggregate.groovy

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ class ScoverageAggregate extends JavaExec {
99

1010
@Override
1111
void exec() {
12+
def extension = ScoveragePlugin.extensionIn(project)
1213
setClasspath(ScoveragePlugin.extensionIn(project).pluginClasspath)
1314
setMain('org.scoverage.AggregateReportApp')
1415
def reportPath = reportDirOrDefault()
15-
setArgs([project.projectDir, reportPath.absolutePath, clean])
16+
setArgs([
17+
project.projectDir,
18+
reportPath.absolutePath,
19+
clean,
20+
// TODO - consider separate options for `report` and `aggregate` tasks
21+
extension.coverageOutputCobertura,
22+
extension.coverageOutputXML,
23+
extension.coverageOutputHTML,
24+
extension.coverageDebug
25+
])
1626
super.exec()
17-
def reportEntryPoint = new File(reportPath, 'index.html').absolutePath
18-
project.logger.lifecycle("Wrote aggregated scoverage report to ${reportEntryPoint}")
1927
}
2028

2129
def reportDirOrDefault() {
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.scoverage
2+
3+
import org.gradle.tooling.BuildLauncher
4+
import org.gradle.tooling.GradleConnector
5+
import org.hamcrest.core.Is
6+
import org.junit.Assert
7+
8+
/**
9+
* Some utils for easy acceptance testing.
10+
*/
11+
class AcceptanceTestUtils {
12+
13+
14+
protected BuildLauncher setupBuild(File projectRoot, boolean useAnt) {
15+
return GradleConnector.
16+
newConnector().
17+
forProjectDirectory(projectRoot).
18+
connect().
19+
newBuild().
20+
withArguments("-PuseAnt=$useAnt")
21+
}
22+
23+
protected void checkFile(String description, File file, boolean shouldExist) throws Exception {
24+
Assert.assertThat(description + ' should be created at ' + file.absolutePath, file.exists(), Is.is(shouldExist))
25+
}
26+
27+
protected File reportDir(File baseDir) {
28+
return new File(baseDir, 'build/reports/scoverage')
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.scoverage
2+
3+
import org.junit.Test
4+
5+
class AggregationAcceptanceTest extends AcceptanceTestUtils {
6+
7+
private static File aggregateReportDir(File baseDir) {
8+
return new File(baseDir, 'build/scoverage-aggregate')
9+
}
10+
11+
private testWater(boolean useAnt) throws Exception {
12+
File projectDir = new File('src/test/water')
13+
14+
def build = setupBuild(projectDir, useAnt)
15+
build.forTasks('clean', 'reportScoverage', 'aggregateScoverage').run()
16+
17+
def indexHtml = new File(aggregateReportDir(projectDir), 'index.html')
18+
checkFile('an aggregated index HTML file', indexHtml, true)
19+
20+
def cobertura = new File(aggregateReportDir(projectDir), 'cobertura.xml')
21+
checkFile('an aggregated cobertura XML file', cobertura, true)
22+
23+
def scoverageXml = new File(aggregateReportDir(projectDir), 'scoverage.xml')
24+
checkFile('an aggregated scoverage XML file', scoverageXml, true)
25+
26+
def krillsHtml = new File(aggregateReportDir(projectDir), 'krills.html')
27+
checkFile('a HTML file for \'krills\' sub-project', krillsHtml, true)
28+
29+
def whalesHtml = new File(aggregateReportDir(projectDir), 'whales.html')
30+
checkFile('a HTML file for \'whales\' sub-project', whalesHtml, true)
31+
}
32+
33+
@Test
34+
public void testMultiProjectAggregationWithAnt() throws Exception {
35+
testWater(true)
36+
}
37+
38+
@Test
39+
public void testMultiProjectAggregationWithZinc() throws Exception {
40+
testWater(false)
41+
}
42+
}

Diff for: src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.scoverage
2+
3+
import org.junit.Test
4+
5+
class SimpleReportAcceptanceTest extends AcceptanceTestUtils {
6+
7+
private testHappyDay(boolean useAnt) throws Exception {
8+
File projectRoot = new File('src/test/happy day')
9+
def build = setupBuild(projectRoot, useAnt)
10+
11+
build.forTasks('clean', 'checkScoverage').run()
12+
13+
def html = new File(reportDir(projectRoot), 'index.html')
14+
checkFile('an index HTML file', html, true)
15+
def cobertura = new File(reportDir(projectRoot), 'cobertura.xml')
16+
checkFile('a cobertura XML file', cobertura, true)
17+
def scoverageXml = new File(reportDir(projectRoot), 'scoverage.xml')
18+
checkFile('a scoverage XML file', scoverageXml, true)
19+
}
20+
21+
@Test
22+
public void testAntProjectWithCompleteCoverage() throws Exception {
23+
testHappyDay(true)
24+
}
25+
26+
@Test
27+
public void testZincProjectWithCompleteCoverage() throws Exception {
28+
testHappyDay(false)
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package whales
2+
3+
class BlueWhale {
4+
def swim(): String = "I'm swimming!"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package whales
2+
3+
import org.junit.Test
4+
import org.junit.Assert
5+
6+
class BlueWhaleTest {
7+
8+
@Test def bob(): Unit = {
9+
Assert.assertEquals("Whale cannot swim :(", new BlueWhale().swim(), "I'm swimming!")
10+
}
11+
}

Diff for: src/test/water/build.gradle

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
description = 'a multi-project setup for gradle-scoverage'
2+
3+
buildscript {
4+
repositories {
5+
// need to get up to the working directory of gradle-plugins build
6+
flatDir dir: "${project.projectDir}/../../../build/libs"
7+
}
8+
dependencies {
9+
classpath name: 'gradle-scoverage', version: '+'
10+
}
11+
}
12+
13+
task aggregateScoverage(type: org.scoverage.ScoverageAggregate)
14+
15+
allprojects {
16+
repositories {
17+
mavenCentral()
18+
}
19+
20+
apply plugin: 'scoverage'
21+
22+
dependencies {
23+
scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.0.4',
24+
'org.scoverage:scalac-scoverage-runtime_2.11:1.0.4'
25+
compile 'org.scala-lang:scala-library:2.11.5'
26+
27+
testCompile 'junit:junit:4.11'
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package krills
2+
3+
class NorthernKrill {
4+
def swim(): String = "I can only float :("
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package krills
2+
3+
import org.junit.Test
4+
import org.junit.Assert
5+
6+
class NorthernKrillTest {
7+
8+
@Test def bob(): Unit = {
9+
Assert.assertEquals("Krill can swim", new NorthernKrill().swim(), "I can only float :(")
10+
}
11+
}

Diff for: src/test/water/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include 'bluewhale', 'krill'

0 commit comments

Comments
 (0)