From d054196d51e4a69208cdfb9ca3f3584d6febde18 Mon Sep 17 00:00:00 2001 From: Stu Date: Sat, 10 Jan 2015 10:14:42 +0000 Subject: [PATCH 1/8] capture the measured statements file as an output of the compilation step --- src/main/groovy/org/scoverage/ScoverageExtension.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 05364a9..42f4f97 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -119,6 +119,8 @@ class ScoverageExtension { scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } // exclude the scala libraries that are added to enable scala version detection classpath += pluginDependencies + // the compile task creates a store of measured statements + outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml')) } t.tasks[ScoveragePlugin.TEST_NAME].configure { From ea989cfa5110d2b94605a15077c370855ddd1f5c Mon Sep 17 00:00:00 2001 From: Stu Date: Sat, 10 Jan 2015 23:01:34 +0000 Subject: [PATCH 2/8] zinc scalac does not support escaped parameters --- .../org/scoverage/ScoverageExtension.groovy | 6 ++++- .../org/scoverage/PluginAcceptanceTest.groovy | 23 ++++++++++++++----- src/test/{happyday => happy day}/build.gradle | 4 ++++ .../src/main/scala/hello/World.scala | 0 .../src/test/scala/hello/WorldTest.scala | 0 5 files changed, 26 insertions(+), 7 deletions(-) rename src/test/{happyday => happy day}/build.gradle (82%) rename src/test/{happyday => happy day}/src/main/scala/hello/World.scala (100%) rename src/test/{happyday => happy day}/src/test/scala/hello/WorldTest.scala (100%) diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 42f4f97..7aec8af 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -116,7 +116,11 @@ class ScoverageExtension { if (extension.highlighting) { parameters.add('-Yrangepos') } - scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } + if (scalaCompileOptions.useAnt) { + scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } + } else { + scalaCompileOptions.additionalParameters = parameters + } // exclude the scala libraries that are added to enable scala version detection classpath += pluginDependencies // the compile task creates a store of measured statements diff --git a/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy b/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy index 7ad5ff0..21cade1 100644 --- a/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy +++ b/src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy @@ -8,15 +8,26 @@ import static org.hamcrest.core.Is.is class PluginAcceptanceTest { - @Test - public void testProjectWithCompleteCoverage() throws Exception { + static def checkHappyDay(boolean useAnt) { + def projectRoot = "src/test/happy day" def build = GradleConnector. - newConnector(). - forProjectDirectory(new File("src/test/happyday")). - connect().newBuild() + newConnector(). + forProjectDirectory(new File(projectRoot)). + connect().newBuild(). + withArguments("-PuseAnt=$useAnt") build.forTasks('clean', 'checkScoverage').run() - def html = new File('src/test/happyday/build/reports/scoverage/index.html') + def html = new File("$projectRoot/build/reports/scoverage/index.html") assertThat('an HTML file should be created at ' + html.absolutePath, html.exists(), is(true)) } + + @Test + public void testAntProjectWithCompleteCoverage() throws Exception { + checkHappyDay(true) + } + + @Test + public void testZincProjectWithCompleteCoverage() throws Exception { + checkHappyDay(false) + } } diff --git a/src/test/happyday/build.gradle b/src/test/happy day/build.gradle similarity index 82% rename from src/test/happyday/build.gradle rename to src/test/happy day/build.gradle index 5f69f1c..b00ef3b 100644 --- a/src/test/happyday/build.gradle +++ b/src/test/happy day/build.gradle @@ -25,4 +25,8 @@ dependencies { checkScoverage { minimumLineRate = 1.0 +} + +tasks.withType(ScalaCompile) { + scalaCompileOptions.useAnt = project.hasProperty('useAnt') ? project.property('useAnt').toBoolean() : true } \ No newline at end of file diff --git a/src/test/happyday/src/main/scala/hello/World.scala b/src/test/happy day/src/main/scala/hello/World.scala similarity index 100% rename from src/test/happyday/src/main/scala/hello/World.scala rename to src/test/happy day/src/main/scala/hello/World.scala diff --git a/src/test/happyday/src/test/scala/hello/WorldTest.scala b/src/test/happy day/src/test/scala/hello/WorldTest.scala similarity index 100% rename from src/test/happyday/src/test/scala/hello/WorldTest.scala rename to src/test/happy day/src/test/scala/hello/WorldTest.scala From c2f643a7563a7f7c46077ebb01803120a043b4a0 Mon Sep 17 00:00:00 2001 From: Stu Date: Thu, 5 Feb 2015 21:08:13 +0000 Subject: [PATCH 3/8] zinc scalac does not currently support forcing a clean build --- src/main/groovy/org/scoverage/ScoverageExtension.groovy | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 7aec8af..3cfe63a 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -10,6 +10,7 @@ import org.gradle.api.plugins.scala.ScalaPlugin import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.testing.Test +import org.gradle.util.GFileUtils /** * Defines a new SourceSet for the code to be instrumented. @@ -119,6 +120,9 @@ class ScoverageExtension { if (scalaCompileOptions.useAnt) { scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } } else { + doFirst { + GFileUtils.deleteDirectory(destinationDir) + } scalaCompileOptions.additionalParameters = parameters } // exclude the scala libraries that are added to enable scala version detection From 7dfcf9423aa7451210b31042a3dd2f5fbda9cd83 Mon Sep 17 00:00:00 2001 From: Stu Date: Thu, 5 Feb 2015 23:00:55 +0000 Subject: [PATCH 4/8] remove the double-compilation of main scala files --- .../org/scoverage/ScoverageExtension.groovy | 44 ++++++++++++------- .../org/scoverage/ScoveragePlugin.groovy | 1 + 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 3cfe63a..5862b98 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -12,6 +12,8 @@ import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.testing.Test import org.gradle.util.GFileUtils +import java.util.concurrent.Callable + /** * Defines a new SourceSet for the code to be instrumented. * Defines a new Test Task which executes normal tests with the instrumented classes. @@ -56,18 +58,37 @@ class ScoverageExtension { description = 'Scoverage dependencies' } - project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) { - def mainSourceSet = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) + def mainSourceSet = project.sourceSets.create('scoverage') { + def original = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) + + java.source(original.java) + scala.source(original.scala) + + compileClasspath += original.compileClasspath + project.configurations.scoverage + runtimeClasspath = it.output + project.configurations.runtime + } + + def testSourceSet = project.sourceSets.create('testScoverage') { + def original = project.sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME) - java.source(mainSourceSet.java) - scala.source(mainSourceSet.scala) + java.source(original.java) + scala.source(original.scala) - compileClasspath += mainSourceSet.compileClasspath - runtimeClasspath += mainSourceSet.runtimeClasspath + compileClasspath = mainSourceSet.output + project.configurations.testCompile + runtimeClasspath = it.output + mainSourceSet.output + project.configurations.scoverage + project.configurations.testRuntime } project.tasks.create(ScoveragePlugin.TEST_NAME, Test.class) { - dependsOn(project.tasks[ScoveragePlugin.COMPILE_NAME]) + conventionMapping.map("testClassesDir", new Callable() { + public Object call() throws Exception { + return testSourceSet.output.classesDir; + } + }) + conventionMapping.map("classpath", new Callable() { + public Object call() throws Exception { + return testSourceSet.runtimeClasspath; + } + }) } project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) { @@ -125,19 +146,10 @@ class ScoverageExtension { } scalaCompileOptions.additionalParameters = parameters } - // exclude the scala libraries that are added to enable scala version detection - classpath += pluginDependencies // the compile task creates a store of measured statements outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml')) } - t.tasks[ScoveragePlugin.TEST_NAME].configure { - def existingClasspath = classpath - classpath = t.files(t.sourceSets[ScoveragePlugin.CONFIGURATION_NAME].output.classesDir) + - pluginDependencies + - existingClasspath - } - t.tasks[ScoveragePlugin.REPORT_NAME].configure { classpath = project.buildscript.configurations.classpath + configuration main = 'org.scoverage.ScoverageReport' diff --git a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy index 4f43b0e..31b955e 100644 --- a/src/main/groovy/org/scoverage/ScoveragePlugin.groovy +++ b/src/main/groovy/org/scoverage/ScoveragePlugin.groovy @@ -10,6 +10,7 @@ class ScoveragePlugin implements Plugin { static String REPORT_NAME = 'reportScoverage' static String CHECK_NAME = 'checkScoverage' static String COMPILE_NAME = 'compileScoverageScala' + static String COMPILE_TEST_NAME = 'compileTestScoverageScala' @Override void apply(Project t) { From 14b953b188e447af55dfe353f470c4e8d244bf27 Mon Sep 17 00:00:00 2001 From: Stu Date: Thu, 5 Feb 2015 23:20:13 +0000 Subject: [PATCH 5/8] detect the location of the reporting class rather than rely on the buildscript classpath --- src/main/groovy/org/scoverage/ScoverageExtension.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 5862b98..578bdd4 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -151,7 +151,8 @@ class ScoverageExtension { } t.tasks[ScoveragePlugin.REPORT_NAME].configure { - classpath = project.buildscript.configurations.classpath + configuration + def classLocation = ScoverageExtension.class.getProtectionDomain().getCodeSource().getLocation() + classpath = project.files(classLocation.file) + configuration main = 'org.scoverage.ScoverageReport' args = [ extension.sources, From 6aa3b3c5f7382490e249c5be099a704f300e7068 Mon Sep 17 00:00:00 2001 From: Stu Date: Thu, 5 Feb 2015 20:56:23 +0000 Subject: [PATCH 6/8] inject version at build time --- build.gradle | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/build.gradle b/build.gradle index 677b2d5..720efae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,3 @@ -def isDirty = { -> - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'status', '--porcelain' - standardOutput = stdout - } - return stdout.toString().trim() -} -def getVersionName = { -> - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'describe', '--tags' - standardOutput = stdout - } - def gitVersionName = stdout.toString().trim() - return isDirty() ? gitVersionName + '-SNAPSHOT' : gitVersionName -} -version = getVersionName() - repositories { mavenCentral() } From 7c9bf203e1151997fc7e53a63800bc46ffda015e Mon Sep 17 00:00:00 2001 From: Stu Date: Thu, 5 Feb 2015 23:43:13 +0000 Subject: [PATCH 7/8] remove auto-publish --- .travis.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 119a88d..87912d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,3 @@ -env: - global: - secure: IErJADm+yokOba01GxnJzLcB+yZJXXA6ISFkznsjh4UowStgNB6+mIvj9Hw8Sfnk7poU5H7tFrkfEDnusKavw71k0Hv4DIIoPcLRnRP0grngL0DsvYIaY4CQFJfKNkR/syv/y6b/cObMmgvdNlqKmJxCAA0sGSJBg2SuJa/usIM= language: groovy script: - - "gradle build test" -after_script: -- if [[ $TRAVIS_TEST_RESULT == 0 && "$TRAVIS_BRANCH" == "master" ]]; then gradle uploadArchives; - fi + - "gradle build test" \ No newline at end of file From a8bd9f5a68071b6037959a5102b9efb8e8002740 Mon Sep 17 00:00:00 2001 From: Stu Date: Fri, 6 Feb 2015 08:06:27 +0000 Subject: [PATCH 8/8] build requires a version else tests cannot detect the jar to be tested --- build.gradle | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build.gradle b/build.gradle index 720efae..677b2d5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,22 @@ +def isDirty = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'status', '--porcelain' + standardOutput = stdout + } + return stdout.toString().trim() +} +def getVersionName = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--tags' + standardOutput = stdout + } + def gitVersionName = stdout.toString().trim() + return isDirty() ? gitVersionName + '-SNAPSHOT' : gitVersionName +} +version = getVersionName() + repositories { mavenCentral() }