Skip to content

Commit

Permalink
fix: add required junit-platform-launcher dependency if it's missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mjedynak committed Feb 18, 2024
1 parent 128fbe8 commit 4e6c737
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ intellij {

// --- properties ---
ext.pitVersion = '1.15.2'
ext.pitJunit5PluginVersion = '1.2.1'
sourceCompatibility = 1.11
// --- properties ---

Expand All @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
}
}

0 comments on commit 4e6c737

Please sign in to comment.