From 4e6c737274a742f5d62cdca2ef21529d73156a48 Mon Sep 17 00:00:00 2001 From: mjedynak Date: Sun, 18 Feb 2024 17:13:09 +0100 Subject: [PATCH] fix: add required junit-platform-launcher dependency if it's missing --- build.gradle | 3 ++- .../plugins/pit/ClassPathPopulator.groovy | 22 ++++++++++++------- .../plugins/pit/ClassPathPopulatorTest.groovy | 11 ++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 594fd44..f83ff57 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ intellij { // --- properties --- ext.pitVersion = '1.15.2' +ext.pitJunit5PluginVersion = '1.2.1' sourceCompatibility = 1.11 // --- properties --- @@ -27,8 +28,8 @@ dependencies { implementation("org.pitest:pitest-command-line:$pitVersion") { transitive = false } implementation("org.pitest:pitest-entry:$pitVersion") { transitive = false } implementation("org.pitest:pitest:$pitVersion") { transitive = false } + implementation "org.pitest:pitest-junit5-plugin:$pitJunit5PluginVersion" implementation 'org.apache.commons:commons-text:1.10.0' - implementation 'org.pitest:pitest-junit5-plugin:1.2.1' compileOnly 'org.codehaus.groovy:groovy-all:2.5.14' testCompileOnly 'org.codehaus.groovy:groovy-all:2.5.14' testImplementation('org.spockframework:spock-core:0.7-groovy-2.0') { diff --git a/src/main/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulator.groovy b/src/main/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulator.groovy index e49e1ff..f38af9c 100644 --- a/src/main/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulator.groovy +++ b/src/main/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulator.groovy @@ -2,28 +2,34 @@ package pl.mjedynak.idea.plugins.pit import com.intellij.openapi.application.PathManager import com.intellij.util.PathsList +import groovy.transform.CompileStatic +@CompileStatic class ClassPathPopulator { static final String PITEST_VERSION = '1.15.2' - static final String PITEST_JAR = 'pitest-' + PITEST_VERSION + JAR_EXTENSION - static final String PITEST_COMMAND_LINE_JAR = 'pitest-command-line-' + PITEST_VERSION + JAR_EXTENSION - static final String PITEST_ENTRY_JAR = 'pitest-entry-' + PITEST_VERSION + JAR_EXTENSION + static final String PITEST_JUNIT5_PLUGIN_VERSION = '1.2.1' static final String SEPARATOR = System.getProperty('file.separator') static final String PLUGIN_NAME = 'pit-idea-plugin' static final String LIB_DIR = 'lib' - static final String JAR_EXTENSION = '.jar' void populateClassPathWithPitJar(PathsList classPath) { String pluginsPath = PathManager.pluginsPath String path = pluginsPath + SEPARATOR + PLUGIN_NAME + SEPARATOR + LIB_DIR + SEPARATOR classPath.with { - addFirst(path + PITEST_JAR) - addFirst(path + PITEST_COMMAND_LINE_JAR) - addFirst(path + PITEST_ENTRY_JAR) + addFirst(path + "pitest-${PITEST_VERSION}.jar") + addFirst(path + "pitest-command-line-${PITEST_VERSION}.jar") + addFirst(path + "pitest-entry-${PITEST_VERSION}.jar") addFirst(path + 'commons-lang3-3.12.0.jar') addFirst(path + 'commons-text-1.10.0.jar') - addFirst(path + 'pitest-junit5-plugin-1.2.0.jar') + addFirst(path + "pitest-junit5-plugin-${PITEST_JUNIT5_PLUGIN_VERSION}.jar") + if (noPlatformLauncherDependency(classPath)) { + addFirst(path + 'junit-platform-launcher-1.9.2.jar') + } } } + + private static boolean noPlatformLauncherDependency(PathsList classPath) { + return !classPath.pathList.find { it.contains("junit-platform-launcher") } + } } diff --git a/src/test/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulatorTest.groovy b/src/test/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulatorTest.groovy index 6a2c1ea..1af98d5 100644 --- a/src/test/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulatorTest.groovy +++ b/src/test/groovy/pl/mjedynak/idea/plugins/pit/ClassPathPopulatorTest.groovy @@ -3,6 +3,7 @@ package pl.mjedynak.idea.plugins.pit import spock.lang.Specification import static pl.mjedynak.idea.plugins.pit.ClassPathPopulator.PITEST_VERSION +import static pl.mjedynak.idea.plugins.pit.ClassPathPopulator.PITEST_JUNIT5_PLUGIN_VERSION class ClassPathPopulatorTest extends Specification { @@ -15,4 +16,14 @@ class ClassPathPopulatorTest extends Specification { then: version == PITEST_VERSION } + + def "should have the same PIT Junit5 Plugin version as specified in build.gradle"() { + when: + File gradleBuildFile = new File('build.gradle') + String lineWithVersion = gradleBuildFile.filterLine { String line -> line.startsWith('ext.pitJunit5PluginVersion') } + String version = lineWithVersion[lineWithVersion.indexOf("'") + 1 .. lineWithVersion.lastIndexOf("'") - 1] + + then: + version == PITEST_JUNIT5_PLUGIN_VERSION + } }