Skip to content

Commit 9ad6178

Browse files
committed
Merge pull request #36 from maiflai/bob
Some fixes and a performance enhancement
2 parents ae016e7 + a8bd9f5 commit 9ad6178

File tree

7 files changed

+64
-31
lines changed

7 files changed

+64
-31
lines changed

Diff for: .travis.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
env:
2-
global:
3-
secure: IErJADm+yokOba01GxnJzLcB+yZJXXA6ISFkznsjh4UowStgNB6+mIvj9Hw8Sfnk7poU5H7tFrkfEDnusKavw71k0Hv4DIIoPcLRnRP0grngL0DsvYIaY4CQFJfKNkR/syv/y6b/cObMmgvdNlqKmJxCAA0sGSJBg2SuJa/usIM=
41
language: groovy
52
script:
6-
- "gradle build test"
7-
after_script:
8-
- if [[ $TRAVIS_TEST_RESULT == 0 && "$TRAVIS_BRANCH" == "master" ]]; then gradle uploadArchives;
9-
fi
3+
- "gradle build test"

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

+41-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import org.gradle.api.plugins.scala.ScalaPlugin
1010
import org.gradle.api.tasks.JavaExec
1111
import org.gradle.api.tasks.SourceSet
1212
import org.gradle.api.tasks.testing.Test
13+
import org.gradle.util.GFileUtils
14+
15+
import java.util.concurrent.Callable
1316

1417
/**
1518
* Defines a new SourceSet for the code to be instrumented.
@@ -55,18 +58,37 @@ class ScoverageExtension {
5558
description = 'Scoverage dependencies'
5659
}
5760

58-
project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) {
59-
def mainSourceSet = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
61+
def mainSourceSet = project.sourceSets.create('scoverage') {
62+
def original = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
63+
64+
java.source(original.java)
65+
scala.source(original.scala)
66+
67+
compileClasspath += original.compileClasspath + project.configurations.scoverage
68+
runtimeClasspath = it.output + project.configurations.runtime
69+
}
70+
71+
def testSourceSet = project.sourceSets.create('testScoverage') {
72+
def original = project.sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME)
6073

61-
java.source(mainSourceSet.java)
62-
scala.source(mainSourceSet.scala)
74+
java.source(original.java)
75+
scala.source(original.scala)
6376

64-
compileClasspath += mainSourceSet.compileClasspath
65-
runtimeClasspath += mainSourceSet.runtimeClasspath
77+
compileClasspath = mainSourceSet.output + project.configurations.testCompile
78+
runtimeClasspath = it.output + mainSourceSet.output + project.configurations.scoverage + project.configurations.testRuntime
6679
}
6780

6881
project.tasks.create(ScoveragePlugin.TEST_NAME, Test.class) {
69-
dependsOn(project.tasks[ScoveragePlugin.COMPILE_NAME])
82+
conventionMapping.map("testClassesDir", new Callable<Object>() {
83+
public Object call() throws Exception {
84+
return testSourceSet.output.classesDir;
85+
}
86+
})
87+
conventionMapping.map("classpath", new Callable<Object>() {
88+
public Object call() throws Exception {
89+
return testSourceSet.runtimeClasspath;
90+
}
91+
})
7092
}
7193

7294
project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
@@ -116,20 +138,21 @@ class ScoverageExtension {
116138
if (extension.highlighting) {
117139
parameters.add('-Yrangepos')
118140
}
119-
scalaCompileOptions.additionalParameters = parameters.collect { escape(it) }
120-
// exclude the scala libraries that are added to enable scala version detection
121-
classpath += pluginDependencies
122-
}
123-
124-
t.tasks[ScoveragePlugin.TEST_NAME].configure {
125-
def existingClasspath = classpath
126-
classpath = t.files(t.sourceSets[ScoveragePlugin.CONFIGURATION_NAME].output.classesDir) +
127-
pluginDependencies +
128-
existingClasspath
141+
if (scalaCompileOptions.useAnt) {
142+
scalaCompileOptions.additionalParameters = parameters.collect { escape(it) }
143+
} else {
144+
doFirst {
145+
GFileUtils.deleteDirectory(destinationDir)
146+
}
147+
scalaCompileOptions.additionalParameters = parameters
148+
}
149+
// the compile task creates a store of measured statements
150+
outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml'))
129151
}
130152

131153
t.tasks[ScoveragePlugin.REPORT_NAME].configure {
132-
classpath = project.buildscript.configurations.classpath + configuration
154+
def classLocation = ScoverageExtension.class.getProtectionDomain().getCodeSource().getLocation()
155+
classpath = project.files(classLocation.file) + configuration
133156
main = 'org.scoverage.ScoverageReport'
134157
args = [
135158
extension.sources,

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

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ScoveragePlugin implements Plugin<Project> {
1010
static String REPORT_NAME = 'reportScoverage'
1111
static String CHECK_NAME = 'checkScoverage'
1212
static String COMPILE_NAME = 'compileScoverageScala'
13+
static String COMPILE_TEST_NAME = 'compileTestScoverageScala'
1314

1415
@Override
1516
void apply(Project t) {

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@ import static org.hamcrest.core.Is.is
88

99
class PluginAcceptanceTest {
1010

11-
@Test
12-
public void testProjectWithCompleteCoverage() throws Exception {
11+
static def checkHappyDay(boolean useAnt) {
12+
def projectRoot = "src/test/happy day"
1313
def build = GradleConnector.
14-
newConnector().
15-
forProjectDirectory(new File("src/test/happyday")).
16-
connect().newBuild()
14+
newConnector().
15+
forProjectDirectory(new File(projectRoot)).
16+
connect().newBuild().
17+
withArguments("-PuseAnt=$useAnt")
1718
build.forTasks('clean', 'checkScoverage').run()
1819

19-
def html = new File('src/test/happyday/build/reports/scoverage/index.html')
20+
def html = new File("$projectRoot/build/reports/scoverage/index.html")
2021
assertThat('an HTML file should be created at ' + html.absolutePath, html.exists(), is(true))
2122
}
23+
24+
@Test
25+
public void testAntProjectWithCompleteCoverage() throws Exception {
26+
checkHappyDay(true)
27+
}
28+
29+
@Test
30+
public void testZincProjectWithCompleteCoverage() throws Exception {
31+
checkHappyDay(false)
32+
}
2233
}

Diff for: src/test/happyday/build.gradle renamed to src/test/happy day/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ dependencies {
2525

2626
checkScoverage {
2727
minimumLineRate = 1.0
28+
}
29+
30+
tasks.withType(ScalaCompile) {
31+
scalaCompileOptions.useAnt = project.hasProperty('useAnt') ? project.property('useAnt').toBoolean() : true
2832
}

0 commit comments

Comments
 (0)