Skip to content

Commit 2c223c0

Browse files
committed
Merge pull request #7 from maiflai/master
fix links to source files
2 parents d1fc3ac + 38700ca commit 2c223c0

File tree

7 files changed

+76
-9
lines changed

7 files changed

+76
-9
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ task sourcesJar(type: Jar) {
4444
classifier = 'sources'
4545
}
4646

47+
test {
48+
dependsOn jar
49+
}
50+
4751
artifacts {
4852
archives jar
4953
archives groovydocJar

src/main/groovy/org/scoverage/OverallCheckTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class OverallCheckTask extends DefaultTask {
1515
void requireLineCoverage() {
1616
def extension = ScoveragePlugin.extensionIn(project)
1717

18-
if (cobertura == null) cobertura = new File(extension.dataDir, 'cobertura.xml')
18+
if (cobertura == null) cobertura = new File(extension.reportDir, 'cobertura.xml')
1919

2020
def xml = new XmlParser().parse(cobertura)
2121
def overallLineRate = xml.attribute('line-rate').toDouble()

src/main/groovy/org/scoverage/ScoverageExtension.groovy

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class ScoverageExtension {
2121
/** a directory to write final output to */
2222
File reportDir
2323
/** sources to highlight */
24-
SourceSet sourceSet
25-
24+
File sources
2625

2726
ScoverageExtension(Project project) {
2827

@@ -36,7 +35,7 @@ class ScoverageExtension {
3635
description = 'Scoverage dependencies'
3736
}
3837

39-
sourceSet = project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) {
38+
project.sourceSets.create(ScoveragePlugin.CONFIGURATION_NAME) {
4039
def mainSourceSet = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
4140

4241
java.source(mainSourceSet.java)
@@ -50,17 +49,16 @@ class ScoverageExtension {
5049
dependsOn(project.tasks[ScoveragePlugin.COMPILE_NAME])
5150
}
5251

53-
project.tasks.create(ScoveragePlugin.CHECK_NAME, OverallCheckTask.class) {
52+
project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
5453
dependsOn(project.tasks[ScoveragePlugin.TEST_NAME])
5554
}
5655

57-
project.tasks.create(ScoveragePlugin.REPORT_NAME, JavaExec.class) {
58-
dependsOn(project.tasks[ScoveragePlugin.TEST_NAME])
56+
project.tasks.create(ScoveragePlugin.CHECK_NAME, OverallCheckTask.class) {
57+
dependsOn(project.tasks[ScoveragePlugin.REPORT_NAME])
5958
}
6059

6160
dataDir = new File(project.buildDir, 'scoverage')
6261
reportDir = new File(project.buildDir, 'reports' + File.separatorChar + 'scoverage')
63-
6462
}
6563

6664
private Action<Project> configureRuntimeOptions = new Action<Project>() {
@@ -69,6 +67,7 @@ class ScoverageExtension {
6967
void execute(Project t) {
7068

7169
def extension = ScoveragePlugin.extensionIn(t)
70+
extension.sources = t.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).scala.srcDirs.iterator().next() as File
7271
extension.dataDir.mkdirs()
7372
extension.reportDir.mkdirs()
7473

@@ -102,7 +101,7 @@ class ScoverageExtension {
102101
project.configurations[ScoveragePlugin.CONFIGURATION_NAME]
103102
main = 'org.scoverage.ScoverageReport'
104103
args = [
105-
extension.sourceSet.allSource.iterator().next().absolutePath,
104+
extension.sources,
106105
extension.dataDir.absolutePath,
107106
extension.reportDir.absolutePath
108107
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.scoverage
2+
3+
import org.gradle.tooling.GradleConnector
4+
import org.junit.Test
5+
6+
import static org.junit.Assert.assertThat
7+
import static org.hamcrest.core.Is.is
8+
9+
class PluginAcceptanceTest {
10+
11+
@Test
12+
public void testProjectWithCompleteCoverage() throws Exception {
13+
def build = GradleConnector.
14+
newConnector().
15+
forProjectDirectory(new File("src/test/happyday")).
16+
connect().newBuild()
17+
build.forTasks('clean', 'checkScoverage').run()
18+
19+
def html = new File('src/test/happyday/build/reports/scoverage/index.html')
20+
assertThat('an HTML file should be created at ' + html.absolutePath, html.exists(), is(true))
21+
}
22+
}

src/test/happyday/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
description = 'a project that builds successfully with 100% coverage'
2+
3+
buildscript {
4+
repositories {
5+
// need to get up to the working directory of gradle-plugins build
6+
flatDir dir: "${project.projectDir}/../../../build/libs"
7+
}
8+
dependencies {
9+
classpath name: 'gradle-scoverage', version: '+'
10+
}
11+
}
12+
13+
apply plugin: 'scoverage'
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
dependencies {
20+
scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:0.99.5'
21+
compile 'org.scala-lang:scala-library:2.11.0'
22+
testCompile 'junit:junit:4.11'
23+
}
24+
25+
checkScoverage {
26+
minimumLineRate = 1.0
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package hello
2+
3+
object World {
4+
def say() = println("ahoy")
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package hello
2+
3+
import org.junit.Test
4+
5+
class WorldTest {
6+
@Test
7+
def bob() {
8+
World.say()
9+
}
10+
}

0 commit comments

Comments
 (0)