From 8b40dfa3df3f6e51b0c3eeaf2167abbd1933b3ee Mon Sep 17 00:00:00 2001 From: Simon Priadka Date: Mon, 11 Dec 2017 12:54:21 +0100 Subject: [PATCH] enable custom pitest versions to be used in ScmTask --- .../gradle/pitest/PitestPlugin.groovy | 26 +++++++++++++++---- .../gradle/pitest/PluginConstants.groovy | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy index 1450b1cf..946c1e85 100755 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PitestPlugin.groovy @@ -22,7 +22,6 @@ import info.solidsoft.gradle.pitest.extension.ScmPitestPluginExtension import info.solidsoft.gradle.pitest.task.AbstractPitestTask import info.solidsoft.gradle.pitest.task.PitestTask import info.solidsoft.gradle.pitest.task.ScmPitestTask -import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.FileCollection @@ -37,7 +36,6 @@ import org.gradle.api.plugins.JavaBasePlugin class PitestPlugin implements Plugin { public final static String DEFAULT_PITEST_VERSION = '1.2.2' public final static String PITEST_TASK_GROUP = "Report" - public final static String PITEST_TASK_NAME = "pitest" private final static List DYNAMIC_LIBRARY_EXTENSIONS = ['so', 'dll', 'dylib'] private final static List FILE_EXTENSIONS_TO_FILTER_FROM_CLASSPATH = ['pom'] + DYNAMIC_LIBRARY_EXTENSIONS @@ -60,6 +58,7 @@ class PitestPlugin implements Plugin { this.project = project applyRequiredJavaPlugin() createPitestConfiguration() + createScmPitestConfiguration() pitestExtension = project.extensions.create(PluginConstants.PITEST_EXTENSION_NAME, PitestPluginExtension, project) scmPitestExtension = project.extensions.create(PluginConstants.SCM_PITEST_EXTENSION_NAME, ScmPitestPluginExtension, project) project.plugins.withType(JavaBasePlugin) { @@ -71,7 +70,8 @@ class PitestPlugin implements Plugin { project.afterEvaluate { pitestTask.dependsOn(calculateTasksToDependOn()) scmPitestTask.dependsOn(calculateTasksToDependOn()) - addPitestCommandLineToConfiguration() + addPitestCommandLineToPitestConfiguration() + addPitestCommandLineToScmPitestConfiguration() } } @@ -88,6 +88,13 @@ class PitestPlugin implements Plugin { } } + private void createScmPitestConfiguration() { + project.rootProject.buildscript.configurations.maybeCreate(PluginConstants.SCM_PITEST_CONFIGURATION_NAME).with { + visible = false + description = "The Pitest libraries to be used for this project." + } + } + private void configureScmTaskFromExtension(ScmPitestTask task, ScmPitestPluginExtension extension) { configurePitestTaskFromExtension(task, extension) task.conventionMapping.with { @@ -101,6 +108,7 @@ class PitestPlugin implements Plugin { endVersionType = { extension.endVersionType } includes = {extension.includes} managerClasspath = { extension.managerClasspath } + launchClasspath = { project.rootProject.buildscript.configurations[PluginConstants.SCM_PITEST_CONFIGURATION_NAME] } } } @@ -198,8 +206,16 @@ class PitestPlugin implements Plugin { } @CompileStatic - private void addPitestCommandLineToConfiguration() { + private void addPitestCommandLineToPitestConfiguration() { log.info("Using PIT: $pitestExtension.pitestVersion") - project.rootProject.buildscript.dependencies.add(PluginConstants.PITEST_CONFIGURATION_NAME, "org.pitest:pitest-command-line:$pitestExtension.pitestVersion") + project.rootProject.buildscript.dependencies.add(PluginConstants.PITEST_CONFIGURATION_NAME, + "org.pitest:pitest-command-line:$pitestExtension.pitestVersion") + } + + @CompileStatic + private void addPitestCommandLineToScmPitestConfiguration() { + log.info("Using PIT: $scmPitestExtension.pitestVersion") + project.rootProject.buildscript.dependencies.add(PluginConstants.SCM_PITEST_CONFIGURATION_NAME, + "org.pitest:pitest-command-line:$scmPitestExtension.pitestVersion") } } diff --git a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PluginConstants.groovy b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PluginConstants.groovy index feb83c31..1af54d6b 100755 --- a/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PluginConstants.groovy +++ b/plugin/src/main/groovy/info/solidsoft/gradle/pitest/PluginConstants.groovy @@ -6,4 +6,5 @@ interface PluginConstants { String PITEST_EXTENSION_NAME = "pitest" String SCM_PITEST_EXTENSION_NAME = "scmPitest" String PITEST_CONFIGURATION_NAME = "pitest" + String SCM_PITEST_CONFIGURATION_NAME = "scmPitest" }