Skip to content

Commit

Permalink
Merge pull request #233 from amosproj/Bugfix/224-all-kinds-of-fixes
Browse files Browse the repository at this point in the history
Bugfix/224 all kinds of fixes
  • Loading branch information
lheimbs authored Feb 5, 2024
2 parents 9b00502 + 6a6e788 commit 8a28224
Show file tree
Hide file tree
Showing 40 changed files with 709 additions and 928 deletions.
15 changes: 10 additions & 5 deletions pitmutationmate-override-plugin/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ tasks.test {
useJUnitPlatform()
}

val beanUtilsVersion = "1.8.3"
val nebulaTestVersion = "10.3.0"
val spockVersion = "2.2-groovy-3.0"
val junitPlatformVersion = "1.9.2"

dependencies {
implementation("commons-beanutils:commons-beanutils-core:1.8.3")
implementation("commons-beanutils:commons-beanutils-core:$beanUtilsVersion")

testImplementation("com.netflix.nebula:nebula-test:10.3.0")
testImplementation("org.spockframework:spock-core:2.2-groovy-3.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.2")
testImplementation("com.netflix.nebula:nebula-test:$nebulaTestVersion")
testImplementation("org.spockframework:spock-core:$spockVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
}

group = "io.github.amos-pitmutationmate.pitmutationmate.override"
version = "1.2"
version = "1.3"

gradlePlugin {
website = "https://github.com/amosproj/amos2023ws02-pitest-ide-plugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 Lennart Heimbs
// SPDX-FileCopyrightText: 2023-2024
//
// SPDX-License-Identifier: MIT

Expand All @@ -8,6 +8,8 @@ import org.gradle.api.file.Directory

/**
* Configuration values for the PIT plugin.
*
* All value assignments are examples and only used to infer the type of the attribute.
*/
class PITConfigurationValues {

Expand All @@ -19,5 +21,8 @@ class PITConfigurationValues {
Set<String> targetTests = ['test3', 'test4']
Set<String> outputFormats = ['XML', 'HTML']
Directory reportDir = new File('build/reports/pitest') as Directory // groovylint-disable-line
Integer mutationThreshold = 0
Integer coverageThreshold = 0
Integer testStrengthThreshold = 0

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.amosproj.pitmutationmate.override.reader.SystemPropertyOverride
import io.github.amosproj.pitmutationmate.override.strategy.DependencyInclusionStrategy
import io.github.amosproj.pitmutationmate.override.strategy.OverrideStrategy
import io.github.amosproj.pitmutationmate.override.strategy.PitestPropertyOverrideStrategy
import io.github.amosproj.pitmutationmate.override.tasks.PitmutationmateStatusCheckTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger
Expand All @@ -25,6 +26,9 @@ class PITSettingOverridePlugin implements Plugin<Project> {
private final static String PORT_PROPERTY_NAME = 'port'

void apply(Project project) {

project.tasks.register(PitmutationmateStatusCheckTask.TASK_NAME, PitmutationmateStatusCheckTask)

OverrideReader overrideReader = new SystemPropertyOverrideReader()
Map<String, String> overrideProperties = overrideReader.parseProperties()
log.debug("Found override properties: $overrideProperties")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: 2023-2024
//
// SPDX-License-Identifier: MIT

package io.github.amosproj.pitmutationmate.override.tasks

import groovy.json.JsonOutput
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
* Task to check the status of plugins needed for PITmutationmate intellij plugin.
*/
class PitmutationmateStatusCheckTask extends DefaultTask {

public final static String TASK_NAME = "pitmutationmateStatusCheck"
private final static String PITEST_PLUGIN_NAME = "info.solidsoft.pitest"
private final static String ANDROID_PITEST_PLUGIN_NAME = "pl.droidsonroids.pitest"
private final static String ANDROID_PLUGIN_NAME = "com.android.application"
private boolean isPitestPluginApplied = false
private boolean isAndroidPitestPluginApplied = false
private boolean isAndroidPluginApplied = false
private String[] androidBuildTypes = []

/**
* Check the status of the plugins.
*/
private void checkPluginStatusInternal() {
isPitestPluginApplied = project.plugins.hasPlugin(PITEST_PLUGIN_NAME)
isAndroidPitestPluginApplied = project.plugins.hasPlugin(ANDROID_PITEST_PLUGIN_NAME)
isAndroidPluginApplied = project.plugins.hasPlugin(ANDROID_PLUGIN_NAME)

def projectIterator = project.subprojects.iterator()
def subproject
while (projectIterator.hasNext()) {
subproject = projectIterator.next()
if (subproject.plugins.hasPlugin(PITEST_PLUGIN_NAME)) {
isPitestPluginApplied = true
}
if (subproject.plugins.hasPlugin(ANDROID_PITEST_PLUGIN_NAME)) {
isAndroidPitestPluginApplied = true
}
if (subproject.plugins.hasPlugin(ANDROID_PLUGIN_NAME)) {
isAndroidPluginApplied = true
}
}
}

/**
* Check the build types of the android plugin.
*/
private void checkAndroidBuildTypeInternal() {
def extension = project.extensions.findByName("android")
def projectIterator = project.subprojects.iterator()
def subproject
while (extension == null && projectIterator.hasNext()) {
subproject = projectIterator.next()
extension = subproject.extensions.findByName("android")
}

if (extension != null) {
def buildTypes = extension.getProperty('buildTypes')
if (buildTypes != null) {
androidBuildTypes = buildTypes.collect { it.name }
}
}
}

/**
* Print the status of the plugins.
*/
private void printStatus() {
String json = JsonOutput.toJson([
pitestPluginApplied : isPitestPluginApplied,
androidPitestPluginApplied: isAndroidPitestPluginApplied,
androidPluginApplied : isAndroidPluginApplied,
androidBuildTypes : androidBuildTypes
])
String prettyJson = JsonOutput.prettyPrint(json)
println prettyJson
}

/**
* Check the status of the plugins.
*/
@TaskAction
void checkStatus() {
checkPluginStatusInternal()
checkAndroidBuildTypeInternal()
printStatus()
}

}
25 changes: 18 additions & 7 deletions pitmutationmate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,39 @@ plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.9.0"
id("org.jetbrains.intellij") version "1.17.0"
id("info.solidsoft.pitest") version "1.15.0"
kotlin("plugin.serialization") version "1.9.22"
}

tasks.test {
useJUnitPlatform()
}

val gradleToolingApiVersion = "7.4.2"
val pitestCommandLineVersion = "1.7.0"
val junitVersion = "5.8.1"
val mockitoVersion = "5.8.0"
val slf4jVersion = "2.0.11"
val kotlinSerializationVersion = "1.6.0"

dependencies {
implementation("org.pitest:pitest-command-line:1.7.0")
implementation("org.junit.jupiter:junit-jupiter:5.8.1")
implementation("org.junit.jupiter:junit-jupiter:5.8.1")
implementation("org.pitest:pitest-command-line:$pitestCommandLineVersion")
implementation("org.gradle:gradle-tooling-api:$gradleToolingApiVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")

runtimeOnly("org.slf4j:slf4j-api:$slf4jVersion")

testImplementation("org.mockito:mockito-core:5.8.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
testImplementation("org.mockito:mockito-core:$mockitoVersion")
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}

group = "com.amos.pitmutationmate"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://repo.gradle.org/gradle/libs-releases/")
}

// Configure Gradle IntelliJ Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

package com.amos.pitmutationmate.pitmutationmate.actions

import com.amos.pitmutationmate.pitmutationmate.services.PluginCheckerService
import com.amos.pitmutationmate.pitmutationmate.services.TestEnvCheckerService
import com.amos.pitmutationmate.pitmutationmate.utils.Utils
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.components.service
Expand All @@ -20,7 +20,7 @@ import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.psi.KtClass
import java.io.File

class ContextMenuAction : RunConfigurationAction() {
class ContextMenuAction : AnAction() {
private val logger = Logger.getInstance(ContextMenuAction::class.java)

private fun updateAndExecuteForFile(psiFileArray: Array<PsiFile>, project: Project) {
Expand All @@ -31,19 +31,25 @@ class ContextMenuAction : RunConfigurationAction() {
val psiClasses = (psiFile as PsiClassOwner).classes
for (psiClass in psiClasses) {
if (!testEnvChecker.isPsiTestClass(psiClass)) {
val fqn = psiClass.qualifiedName
if (fqn != null) {
classFQNs = if (classFQNs != "") {
"$classFQNs,$fqn"
} else {
fqn
}
}
classFQNs = buildClassFQN(psiClass, classFQNs)
}
}
}
logger.info("ContextMenuAction: selected classes are $classFQNs.")
updateAndExecuteRunConfig(classFQNs, project)
RunConfigurationActionRunner.updateAndExecuteRunConfig(classFQNs, project)
}

private fun buildClassFQN(psiClass: PsiClass, classFQNs: String): String {
var newClassFQNs = classFQNs
val fqn = psiClass.qualifiedName
if (fqn != null) {
newClassFQNs = if (classFQNs != "") {
"$classFQNs,$fqn"
} else {
fqn
}
}
return newClassFQNs
}

private fun actionEditorPopup(e: AnActionEvent) {
Expand All @@ -62,7 +68,7 @@ class ContextMenuAction : RunConfigurationAction() {
}

logger.info("ContextMenuAction: selected class is $classFQN.")
updateAndExecuteRunConfig(classFQN, e.project!!)
RunConfigurationActionRunner.updateAndExecuteRunConfig(classFQN, e.project!!)
}
}

Expand All @@ -71,8 +77,7 @@ class ContextMenuAction : RunConfigurationAction() {
val path = psiDirectory.virtualFile.path
val directory = File(path)

directory.walk()
.filter { it.isFile && (it.extension == "java" || it.extension == "kt") }
directory.walk().filter { it.isFile && (it.extension == "java" || it.extension == "kt") }
.forEach { Utils.getPsiFileFromPath(e.project!!, it.toString())?.let { it1 -> psiFileArray += it1 } }

updateAndExecuteForFile(psiFileArray, e.project!!)
Expand All @@ -93,22 +98,17 @@ class ContextMenuAction : RunConfigurationAction() {
}

is KtClass -> {
updateAndExecuteRunConfig(psiElement.fqName.toString(), e.project!!)
RunConfigurationActionRunner.updateAndExecuteRunConfig(psiElement.fqName.toString(), e.project!!)
}

is PsiClass -> {
updateAndExecuteRunConfig(psiElement.qualifiedName, e.project!!)
RunConfigurationActionRunner.updateAndExecuteRunConfig(psiElement.qualifiedName, e.project!!)
}
}
}
}

override fun update(e: AnActionEvent) {
val pluginError = e.project?.service<PluginCheckerService>()?.getErrorMessage()
if (pluginError != null) {
e.presentation.isEnabled = false
return
}
e.presentation.isEnabled = shouldEnablePitRun(e)
}

Expand All @@ -132,9 +132,11 @@ class ContextMenuAction : RunConfigurationAction() {
if (e.place == "ProjectViewPopup" && psiElement is PsiDirectory) {
val directory = File(psiElement.virtualFile.path)
var returnValue = false
directory.walk()
.filter { it.isFile && (it.extension == "kt" || it.extension == "java") }
.forEach { if (!testEnvChecker.isTestFile(it)) { returnValue = true } }
directory.walk().filter { it.isFile && (it.extension == "kt" || it.extension == "java") }.forEach {
if (!testEnvChecker.isTestFile(it)) {
returnValue = true
}
}
return returnValue
}
return validFile && !testEnvChecker.isTestFile(File(psiFile!!.virtualFile.path))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,46 @@ package com.amos.pitmutationmate.pitmutationmate.actions
import com.amos.pitmutationmate.pitmutationmate.icons.Icons
import com.amos.pitmutationmate.pitmutationmate.services.TestEnvCheckerService
import com.intellij.execution.lineMarker.RunLineMarkerContributor
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.KtClass
import javax.swing.Icon

class GutterMarker : RunLineMarkerContributor() {
private val gutterIcon: Icon = Icons.RunButton

override fun getInfo(psielement: PsiElement): Info? {
val gutterIcon: Icon = Icons.RunButton
val project = psielement.project

if (psielement.parent is PsiClass && psielement.text.equals("class")) {
if (project.service<TestEnvCheckerService>().isPsiTestClass(psielement.parent as PsiClass)) {
return null
}
val toolTipProvider: (PsiElement) -> String = { _ -> "Run PIT MutationMate on '${(psielement.parent as PsiClass).name}'" }
val fqn = (psielement.parent as PsiClass).qualifiedName
val action: Array<GutterAction?> = arrayOf(fqn?.let { GutterAction(it) })
return Info(gutterIcon, action, toolTipProvider)

return Info(gutterIcon, toolTipProvider, getAction(project, fqn))
}
if (psielement.parent is KtClass && psielement.text.equals("class")) {
if (project.service<TestEnvCheckerService>().isKtTestClass(psielement.parent as KtClass)) {
return null
}
val toolTipProvider: (PsiElement) -> String = { _ -> "Run PIT MutationMate on '${(psielement.parent as KtClass).name}'" }
val fqn = (psielement.parent as KtClass).fqName.toString()
val action: Array<GutterAction?> = arrayOf(GutterAction(fqn))
return Info(gutterIcon, action, toolTipProvider)
return Info(gutterIcon, toolTipProvider, getAction(project, fqn))
}
return null
}

private fun getAction(project: Project, fqdn: String?): AnAction {
return object : AnAction("Run PIT MutationMate", "Initializes a PiTest run on the selected class", gutterIcon) {
override fun actionPerformed(e: AnActionEvent) {
RunConfigurationActionRunner.updateAndExecuteRunConfig(fqdn, project)
}
}
}
}
Loading

0 comments on commit 8a28224

Please sign in to comment.