@@ -2,8 +2,10 @@ package org.scoverage
22
33import org.gradle.api.Action
44import org.gradle.api.Project
5+ import org.gradle.api.artifacts.ResolvedConfiguration
56import org.gradle.api.plugins.JavaPlugin
67import org.gradle.api.plugins.scala.ScalaPlugin
8+ import org.gradle.api.tasks.JavaExec
79import org.gradle.api.tasks.SourceSet
810import org.gradle.api.tasks.testing.Test
911
@@ -14,6 +16,14 @@ import org.gradle.api.tasks.testing.Test
1416 */
1517class ScoverageExtension {
1618
19+ /* * a directory to write working files to */
20+ File dataDir
21+ /* * a directory to write final output to */
22+ File reportDir
23+ /* * sources to highlight */
24+ SourceSet sourceSet
25+
26+
1727 ScoverageExtension (Project project ) {
1828
1929 project. plugins. apply(JavaPlugin . class);
@@ -22,11 +32,11 @@ class ScoverageExtension {
2232
2333 project. configurations. create(ScoveragePlugin . CONFIGURATION_NAME ) {
2434 visible = false
25- transitive = false
35+ transitive = true
2636 description = ' Scoverage dependencies'
2737 }
2838
29- project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
39+ sourceSet = project. sourceSets. create(ScoveragePlugin . CONFIGURATION_NAME ) {
3040 def mainSourceSet = project. sourceSets. getByName(SourceSet . MAIN_SOURCE_SET_NAME )
3141
3242 java. source(mainSourceSet. java)
@@ -44,34 +54,63 @@ class ScoverageExtension {
4454 dependsOn(project. tasks[ScoveragePlugin . TEST_NAME ])
4555 }
4656
57+ project. tasks. create(ScoveragePlugin . REPORT_NAME , JavaExec . class) {
58+ dependsOn(project. tasks[ScoveragePlugin . TEST_NAME ])
59+ }
60+
61+ dataDir = new File (project. buildDir, ' scoverage' )
62+ reportDir = new File (project. buildDir, ' reports' + File . separatorChar + ' scoverage' )
63+
4764 }
4865
4966 private Action<Project > configureRuntimeOptions = new Action<Project > () {
5067
5168 @Override
5269 void execute (Project t ) {
70+
71+ def extension = ScoveragePlugin . extensionIn(t)
72+ extension. dataDir. mkdirs()
73+ extension. reportDir. mkdirs()
74+
75+ ResolvedConfiguration s = t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]. resolvedConfiguration
76+ String pluginPath = s. getFirstLevelModuleDependencies(). iterator(). next(). moduleArtifacts. iterator(). next(). file. absolutePath
77+
5378 t. tasks[ScoveragePlugin . COMPILE_NAME ]. configure {
54- List<String > plugin = [' -Xplugin:' + t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]. singleFile]
79+
80+
81+ List<String > plugin = [' -Xplugin:' + pluginPath]
5582 List<String > parameters = scalaCompileOptions. additionalParameters
5683 if (parameters != null ) {
5784 plugin. addAll(parameters)
5885 }
86+ plugin. add(" -P:scoverage:dataDir:${ extension.dataDir.absolutePath} " . toString())
87+ plugin. add(' -P:scoverage:excludedPackages:' )
5988 scalaCompileOptions. additionalParameters = plugin
6089 // exclude the scala libraries that are added to enable scala version detection
6190 classpath + = t. configurations[ScoveragePlugin . CONFIGURATION_NAME ]
6291 }
63- t. tasks[ScoveragePlugin . TEST_NAME ]. configure {
64- // TODO : fix this
65- systemProperty ' scoverage.dataDir' , " ${ t.buildDir} /reports/${ t.extensions[ScoveragePlugin.CONFIGURATION_NAME].dataDirName} "
66- systemProperty ' scoverage.basedir' , " ${ t.rootDir.absolutePath} " // for multi-module checking
6792
93+ t. tasks[ScoveragePlugin . TEST_NAME ]. configure {
6894 def existingClasspath = classpath
6995 classpath = t. files(t. sourceSets[ScoveragePlugin . CONFIGURATION_NAME ]. output. classesDir) +
70- project. configurations[ScoveragePlugin . CONFIGURATION_NAME ] +
71- existingClasspath
96+ project. configurations[ScoveragePlugin . CONFIGURATION_NAME ] +
97+ existingClasspath
98+ }
99+
100+ t. tasks[ScoveragePlugin . REPORT_NAME ]. configure {
101+ classpath = project. buildscript. configurations. classpath +
102+ project. configurations[ScoveragePlugin . CONFIGURATION_NAME ]
103+ main = ' org.scoverage.ScoverageReport'
104+ args = [
105+ extension. sourceSet. allSource. iterator(). next(). absolutePath,
106+ extension. dataDir. absolutePath,
107+ extension. reportDir. absolutePath
108+ ]
109+ inputs. dir(extension. dataDir)
110+ outputs. dir(extension. reportDir)
72111 }
112+
73113 }
74114 }
75115
76- String dataDirName = ' scoverage'
77116}
0 commit comments