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 diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 05364a9..578bdd4 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -10,6 +10,9 @@ 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 + +import java.util.concurrent.Callable /** * Defines a new SourceSet for the code to be instrumented. @@ -55,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) { @@ -116,20 +138,21 @@ class ScoverageExtension { if (extension.highlighting) { parameters.add('-Yrangepos') } - scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } - // exclude the scala libraries that are added to enable scala version detection - classpath += pluginDependencies - } - - t.tasks[ScoveragePlugin.TEST_NAME].configure { - def existingClasspath = classpath - classpath = t.files(t.sourceSets[ScoveragePlugin.CONFIGURATION_NAME].output.classesDir) + - pluginDependencies + - existingClasspath + if (scalaCompileOptions.useAnt) { + scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } + } else { + doFirst { + GFileUtils.deleteDirectory(destinationDir) + } + scalaCompileOptions.additionalParameters = parameters + } + // the compile task creates a store of measured statements + outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml')) } 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, 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) { 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