Skip to content

Commit

Permalink
Fix Issue #112: When Clover is disabled eliminate recompilation of so…
Browse files Browse the repository at this point in the history
…urces during test task execution

This change eliminated the injected task actions for Test task type
when `enabled` flag is set to false. Previously we simply relied to
the OpenClover closer-setup Ant task enabled flag to disable instrumentation
but we also caused the recompilation of the classes when the enabled==false.
With this change there is no action and classes are compiled only once.
  • Loading branch information
Alex-Vol-SV committed May 7, 2018
1 parent b65bcba commit 53ab8f6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/groovy/com/bmuschko/gradle/clover/CloverPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,12 @@ class CloverPlugin implements Plugin<Project> {
configureActionsForTask(test, project, cloverPluginConvention, resolver, aggregateDatabasesTask)
}
}
// If we are generating instrumented JAR files make sure the Jar
// tasks run after the Test tasks so that the instrumented classes
// get packaged in the archives.
if (project.hasProperty('cloverInstrumentedJar')) {
project.tasks.withType(Jar) { Jar jar ->
jar.mustRunAfter test
}
}
}
}

@CompileStatic
private boolean testTaskEnabled(Test test, CloverPluginConvention cloverPluginConvention) {
!((cloverPluginConvention.includeTasks && !(test.name in cloverPluginConvention.includeTasks)) || test.name in cloverPluginConvention.excludeTasks)
cloverPluginConvention.enabled && !((cloverPluginConvention.includeTasks && !(test.name in cloverPluginConvention.includeTasks)) || test.name in cloverPluginConvention.excludeTasks)
}

@CompileStatic
Expand All @@ -126,6 +118,12 @@ class CloverPlugin implements Plugin<Project> {
test.doLast createCreateSnapshotAction(cloverPluginConvention, project, test)
if (project.hasProperty('cloverInstrumentedJar')) {
log.info "Skipping RestoreOriginalClassesAction for {} to generate instrumented JAR", test
// If we are generating instrumented JAR files make sure the Jar
// tasks run after the Test tasks so that the instrumented classes
// get packaged in the archives.
project.tasks.withType(Jar) { Jar jar ->
jar.mustRunAfter test
}
} else {
test.doLast createRestoreOriginalClassesAction(resolver, test)
}
Expand Down

0 comments on commit 53ab8f6

Please sign in to comment.