Skip to content

Some fixes and a performance enhancement #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
59 changes: 41 additions & 18 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Object>() {
public Object call() throws Exception {
return testSourceSet.output.classesDir;
}
})
conventionMapping.map("classpath", new Callable<Object>() {
public Object call() throws Exception {
return testSourceSet.runtimeClasspath;
}
})
}

project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ScoveragePlugin implements Plugin<Project> {
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) {
Expand Down
23 changes: 17 additions & 6 deletions src/test/groovy/org/scoverage/PluginAcceptanceTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ dependencies {

checkScoverage {
minimumLineRate = 1.0
}

tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = project.hasProperty('useAnt') ? project.property('useAnt').toBoolean() : true
}