Skip to content

Commit cce88d7

Browse files
authored
Merge pull request #113 from eyalroth/bug/112/specific-module-without-normal-compile
Fix #112 - specific module in multi module project without normal compilation
2 parents 1270643 + 86fe8d2 commit cce88d7

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed

src/functionalTest/java/org.scoverage/ScalaMultiModuleTest.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,38 @@ public void reportScoverageOnlyRoot() {
3636
@Test
3737
public void reportScoverageOnlyA() {
3838

39-
AssertableBuildResult result = dryRun("clean", ":a:" + ScoveragePlugin.getREPORT_NAME());
39+
AssertableBuildResult result = run("clean", ":a:" + ScoveragePlugin.getREPORT_NAME());
4040

4141
result.assertTaskDoesntExist(ScoveragePlugin.getREPORT_NAME());
42-
result.assertTaskExists("a:" + ScoveragePlugin.getREPORT_NAME());
4342
result.assertTaskDoesntExist("b:" + ScoveragePlugin.getREPORT_NAME());
4443
result.assertTaskDoesntExist("common:" + ScoveragePlugin.getREPORT_NAME());
44+
45+
result.assertTaskSucceeded("a:" + ScoveragePlugin.getCOMPILE_NAME());
46+
result.assertTaskSucceeded("a:" + ScoveragePlugin.getREPORT_NAME());
47+
48+
assertAReportFilesExist();
49+
}
50+
51+
@Test
52+
public void reportScoverageOnlyAWithoutNormalCompilation() {
53+
54+
AssertableBuildResult result = run("clean", ":a:" + ScoveragePlugin.getREPORT_NAME(),
55+
"-x", "compileScala");
56+
57+
result.assertTaskSkipped("compileScala");
58+
result.assertTaskSkipped("a:compileScala");
59+
result.assertTaskSkipped("common:compileScala");
60+
result.assertTaskSucceeded("common:" + ScoveragePlugin.getCOMPILE_NAME());
61+
result.assertTaskSucceeded("a:" + ScoveragePlugin.getCOMPILE_NAME());
62+
result.assertTaskSucceeded("a:" + ScoveragePlugin.getREPORT_NAME());
63+
64+
assertAReportFilesExist();
65+
66+
Assert.assertTrue(resolve(buildDir(resolve(projectDir(), "a")), "classes/scala/main/org/hello/a/WorldA.class").exists());
67+
Assert.assertFalse(resolve(buildDir(resolve(projectDir(), "a")), "classes/scala/scoverage/org/hello/a/WorldA.class").exists());
68+
69+
Assert.assertTrue(resolve(buildDir(resolve(projectDir(), "common")), "classes/scala/main/org/hello/common/WorldCommon.class").exists());
70+
Assert.assertFalse(resolve(buildDir(resolve(projectDir(), "common")), "classes/scala/scoverage/org/hello/common/WorldCommon.class").exists());
4571
}
4672

4773
@Test

src/main/groovy/org/scoverage/ScoveragePlugin.groovy

+39-37
Original file line numberDiff line numberDiff line change
@@ -247,51 +247,53 @@ class ScoveragePlugin implements Plugin<PluginAware> {
247247
}
248248
}
249249
}
250+
}
250251

251-
compileTask.configure {
252-
if (!graph.hasTask(originalCompileTask)) {
253-
destinationDir = originalCompileTask.destinationDir
254-
} else {
255-
doFirst {
256-
destinationDir.deleteDir()
257-
}
252+
compileTask.configure {
253+
if (!graph.hasTask(originalCompileTask)) {
254+
project.logger.info("Making scoverage compilation the primary compilation task (instead of compileScala)")
255+
destinationDir = originalCompileTask.destinationDir
256+
} else {
257+
doFirst {
258+
destinationDir.deleteDir()
259+
}
258260

259-
// delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
260-
doLast {
261-
def originalCompileTaskName = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
262-
.getCompileTaskName("scala")
263-
def originalDestinationDir = project.tasks[originalCompileTaskName].destinationDir
264-
265-
def findFiles = { File dir, Closure<Boolean> condition = null ->
266-
def files = []
267-
268-
if (dir.exists()) {
269-
dir.eachFileRecurse(FILES) { f ->
270-
if (condition == null || condition(f)) {
271-
def relativePath = dir.relativePath(f)
272-
files << relativePath
273-
}
261+
// delete non-instrumented classes by comparing normally compiled classes to those compiled with scoverage
262+
doLast {
263+
project.logger.info("Deleting classes compiled by scoverage but non-instrumented (identical to normal compilation)")
264+
def originalCompileTaskName = project.sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
265+
.getCompileTaskName("scala")
266+
def originalDestinationDir = project.tasks[originalCompileTaskName].destinationDir
267+
268+
def findFiles = { File dir, Closure<Boolean> condition = null ->
269+
def files = []
270+
271+
if (dir.exists()) {
272+
dir.eachFileRecurse(FILES) { f ->
273+
if (condition == null || condition(f)) {
274+
def relativePath = dir.relativePath(f)
275+
files << relativePath
274276
}
275277
}
276-
277-
files
278278
}
279279

280-
def isSameFile = { String relativePath ->
281-
def fileA = new File(originalDestinationDir, relativePath)
282-
def fileB = new File(destinationDir, relativePath)
283-
FileUtils.contentEquals(fileA, fileB)
284-
}
280+
files
281+
}
285282

286-
def originalClasses = findFiles(originalDestinationDir)
287-
def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
288-
def relativePath = destinationDir.relativePath(f)
289-
originalClasses.contains(relativePath) && isSameFile(relativePath)
290-
})
283+
def isSameFile = { String relativePath ->
284+
def fileA = new File(originalDestinationDir, relativePath)
285+
def fileB = new File(destinationDir, relativePath)
286+
FileUtils.contentEquals(fileA, fileB)
287+
}
291288

292-
identicalInstrumentedClasses.each { f ->
293-
Files.deleteIfExists(destinationDir.toPath().resolve(f))
294-
}
289+
def originalClasses = findFiles(originalDestinationDir)
290+
def identicalInstrumentedClasses = findFiles(destinationDir, { f ->
291+
def relativePath = destinationDir.relativePath(f)
292+
originalClasses.contains(relativePath) && isSameFile(relativePath)
293+
})
294+
295+
identicalInstrumentedClasses.each { f ->
296+
Files.deleteIfExists(destinationDir.toPath().resolve(f))
295297
}
296298
}
297299
}

0 commit comments

Comments
 (0)