Skip to content

Commit

Permalink
Merge branch 'main' into Feature/208-Historical-data-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
QW3RAT authored Jan 31, 2024
2 parents 97dac1d + 3b789e3 commit aef7829
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfigurationTy
import com.intellij.execution.ExecutorRegistry
import com.intellij.execution.ProgramRunnerUtil
import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.project.Project

Expand All @@ -18,13 +17,18 @@ abstract class RunConfigurationAction : AnAction() {

val runManager = RunManager.getInstance(project)

val runConfig: RunnerAndConfigurationSettings = runManager.createConfiguration("Temp Pitest Config", RunConfigurationType::class.java)
var runConfig = runManager.findConfigurationByName("Default")
if (runConfig == null) {
runConfig = runManager.createConfiguration("Default", RunConfigurationType::class.java)
(runConfig.configuration as RunConfiguration).isDefault = true
}
runConfig.configuration.let {
val rc = it as RunConfiguration
if (classFQN != null) {
rc.classFQN = classFQN
}
}
runManager.addConfiguration(runConfig)

ProgramRunnerUtil.executeConfiguration(runConfig, executor!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,46 @@ class RunConfiguration(
return super.getOptions() as RunConfigurationOptions
}

var isDefault: Boolean
get() = options.isDefault
set(isDefault) {
options.isDefault = isDefault
}

var taskName: String?
get() = options.taskName
set(taskName) {
options.taskName = taskName
logger.debug("MutationMateRunConfiguration: taskName was updated to '$taskName'.")
}

var gradleExecutable: String?
get() = options.gradleExecutable
set(gradleExecutable) {
options.gradleExecutable = gradleExecutable
logger.debug("MutationMateRunConfiguration: gradleExecutable was updated to '$gradleExecutable'.")
}

var buildType: String?
get() = options.buildType
set(buildType) {
options.buildType = buildType
}

var verbose: Boolean
get() = options.verbose
set(verbose) {
options.verbose = verbose
}

var classFQN: String?
get() = options.classFQN
set(classFQN) {
options.classFQN = classFQN
logger.debug("MutationMateRunConfiguration: classFQN was updated to '$classFQN'.")
}

override fun getConfigurationEditor(): SettingsEditor<out RunConfiguration> {
return com.amos.pitmutationmate.pitmutationmate.configuration.SettingsEditor()
val settingsEditor = com.amos.pitmutationmate.pitmutationmate.configuration.SettingsEditor()
settingsEditor.checkDefault(this)
return settingsEditor
}

override fun getState(
Expand All @@ -77,11 +94,11 @@ class RunConfiguration(
if (project.isMavenized) {
logger.debug("MutationMateRunConfiguration: executing maven task.")
val mavenTaskExecutor = MavenTaskExecutor()
return mavenTaskExecutor.executeTask(project, gradleExecutable, taskName, classFQN)
return mavenTaskExecutor.executeTask(project, options)
}
logger.debug("MutationMateRunConfiguration: executing gradle task.")
val gradleTaskExecutor = GradleTaskExecutor()
return gradleTaskExecutor.executeTask(project, gradleExecutable, taskName, classFQN)
return gradleTaskExecutor.executeTask(project, options)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,45 @@ import com.intellij.execution.configurations.RunConfigurationOptions
import com.intellij.openapi.components.StoredProperty

class RunConfigurationOptions : RunConfigurationOptions() {
private var taskNameOption: StoredProperty<String?> = string("").provideDelegate(this, "gradle.task")
private var isDefaultOption: StoredProperty<Boolean> = property(false).provideDelegate(this, "isDefault")
var isDefault: Boolean
get() = isDefaultOption.getValue(this)
set(value) {
isDefaultOption.setValue(this, value)
}

private var taskNameOption: StoredProperty<String?> = string("").provideDelegate(this, "taskName")
var taskName: String?
get() = taskNameOption.getValue(this)
set(value) {
taskNameOption.setValue(this, value)
}

private var classFQNOption: StoredProperty<String?> = string("").provideDelegate(this, "gradle.task")
private var classFQNOption: StoredProperty<String?> = string("").provideDelegate(this, "classFQN")
var classFQN: String?
get() = classFQNOption.getValue(this)
set(value) {
classFQNOption.setValue(this, value)
}

private val gradleExecutableOption: StoredProperty<String?> = string("").provideDelegate(this, "gradle.executable")
private val gradleExecutableOption: StoredProperty<String?> = string("").provideDelegate(this, "gradleExecutable")
var gradleExecutable: String?
get() = gradleExecutableOption.getValue(this)
set(value) {
gradleExecutableOption.setValue(this, value)
}

private val buildTypeOption: StoredProperty<String?> = string("").provideDelegate(this, "buildType")
var buildType: String?
get() = buildTypeOption.getValue(this)
set(value) {
buildTypeOption.setValue(this, value)
}

private val verboseOption: StoredProperty<Boolean> = property(false).provideDelegate(this, "verbose")
var verbose: Boolean
get() = verboseOption.getValue(this)
set(value) {
verboseOption.setValue(this, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UIUtil
import java.awt.Font
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
Expand All @@ -20,7 +21,8 @@ class SettingsEditor : SettingsEditor<RunConfiguration>() {
private val gradleTaskField: TextFieldWithHistory = TextFieldWithHistory()
private val gradleExecutableField: TextFieldWithBrowseButton = TextFieldWithBrowseButton()
private val targetClasses: JBTextField = JBTextField()
private val label = JLabel("Target classes should be given as a comma-separated list (no spaces!)\nof the fully qualified names of the desired classes to test.")
private val buildTypesField: JBTextField = JBTextField()
private val verboseCheckbox = JCheckBox("Enable Pitest verbose mode")

init {
gradleTaskField.text = "pitest"
Expand All @@ -31,34 +33,52 @@ class SettingsEditor : SettingsEditor<RunConfiguration>() {
FileChooserDescriptorFactory.createSingleFileDescriptor()
)
targetClasses.emptyText.setText("com.myproj.package1.classA,com.myproj.package1.classB,com.myproj.package2.classC,...")
val userFont = UIUtil.getLabelFont()
val customFont = Font(userFont.name, userFont.style, 12)
label.font = customFont
buildTypesField.emptyText.setText("<none>")
myPanel = FormBuilder.createFormBuilder()
.addLabeledComponent("Gradle task", gradleTaskField)
.addLabeledComponent("Gradle script", gradleExecutableField)
.addLabeledComponent("Android build type", buildTypesField)
.addLabeledComponent("", getBuildTypesMessage())
.addLabeledComponent("Pitest Verbose mode", verboseCheckbox)
.addLabeledComponent("Target classes", targetClasses)
.addLabeledComponent("", getScopeTipMessage())
.panel
}

private fun getScopeTipMessage(): JLabel {
val multilineText = "<html>The scope should be given as a comma-separated list (no spaces!) of the fully qualified names<br>of the desired classes to test.</html>"
val multilineText = "<html>The scope should be given as a comma-separated list (no spaces!)<br/>of the fully qualified names of the desired classes to test.</html>"
val scopeTipMessage = JLabel(multilineText)
scopeTipMessage.font = Font(UIUtil.getLabelFont().name, UIUtil.getLabelFont().style, 12)
return scopeTipMessage
}

private fun getBuildTypesMessage(): JLabel {
val multilineText = "<html>The Android build type of which you want to use for the pitest results from.<br/>If kept empty, <c>debug</c> is tried first and last no build sub-path is used.</html>"
val scopeTipMessage = JLabel(multilineText)
scopeTipMessage.font = Font(UIUtil.getLabelFont().name, UIUtil.getLabelFont().style, 12)
return scopeTipMessage
}

fun checkDefault(runConfiguration: RunConfiguration) {
if (runConfiguration.isDefault) {
targetClasses.isEditable = false
}
}

override fun resetEditorFrom(runConfiguration: RunConfiguration) {
targetClasses.text = runConfiguration.classFQN
gradleTaskField.text = runConfiguration.taskName
runConfiguration.gradleExecutable.also { gradleExecutableField.text = it ?: "" }
buildTypesField.text = runConfiguration.buildType
verboseCheckbox.isSelected = runConfiguration.verbose
}

override fun applyEditorTo(runConfiguration: RunConfiguration) {
runConfiguration.classFQN = targetClasses.text
runConfiguration.taskName = gradleTaskField.text
runConfiguration.gradleExecutable = gradleExecutableField.text
runConfiguration.buildType = buildTypesField.text
runConfiguration.verbose = verboseCheckbox.isSelected
}

override fun createEditor(): JComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.amos.pitmutationmate.pitmutationmate.execution

import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfigurationOptions
import com.amos.pitmutationmate.pitmutationmate.services.ReportPathGeneratorService
import com.amos.pitmutationmate.pitmutationmate.services.UdpMessagingServer
import com.intellij.execution.configurations.GeneralCommandLine
Expand All @@ -19,28 +20,26 @@ abstract class BasePitestExecutor {

fun executeTask(
project: Project,
executable: String?,
overrideTaskName: String?,
classFQN: String?
options: RunConfigurationOptions
): ProcessHandler {
val messagingServer = project.service<UdpMessagingServer>()
messagingServer.startServer(classFQN) // Start the UDP server
messagingServer.startServer(options.classFQN) // Start the UDP server

val reportDir = project.service<ReportPathGeneratorService>().getReportPath()
val reportPathGenerator = project.service<ReportPathGeneratorService>()
reportPathGenerator.setBuildType(options.buildType)
val reportDir = reportPathGenerator.getReportPath()

val commandLine = buildCommandLine(executable, overrideTaskName, project.basePath!!, classFQN, reportDir, messagingServer.port)
val commandLine = buildCommandLine(options, project.basePath!!, reportDir, messagingServer.port)
log.debug("BasePitestExecutor: executeTask: commandLine: $commandLine")
val processHandler = createProcessHandler(commandLine)
processHandler.addProcessListener(ExecutionDoneProcessListener(project, classFQN))
processHandler.addProcessListener(ExecutionDoneProcessListener(project, options.classFQN))
ProcessTerminatedListener.attach(processHandler)
return processHandler
}

abstract fun buildCommandLine(
executable: String?,
overrideTaskName: String?,
options: RunConfigurationOptions,
projectDir: String,
classFQN: String?,
reportDir: Path,
port: Int
): GeneralCommandLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.amos.pitmutationmate.pitmutationmate.execution

import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfigurationOptions
import com.intellij.execution.configurations.GeneralCommandLine
import java.io.File
import java.nio.file.Path
Expand All @@ -20,19 +21,17 @@ class GradleTaskExecutor : BasePitestExecutor() {
private var systemInfoProvider: SystemInfoProvider = SystemInfo()

override fun buildCommandLine(
executable: String?,
overrideTaskName: String?,
options: RunConfigurationOptions,
projectDir: String,
classFQN: String?,
reportDir: Path,
port: Int
): GeneralCommandLine {
val commandLine = GeneralCommandLine()
var gradleExecutable: String? = executable
var gradleExecutable: String? = options.gradleExecutable
var taskName: String? = PITEST_TASK_NAME

if (!overrideTaskName.isNullOrEmpty()) {
taskName = overrideTaskName
if (!options.taskName.isNullOrEmpty()) {
taskName = options.taskName
}

if (systemInfoProvider.isWindows()) {
Expand All @@ -49,20 +48,20 @@ class GradleTaskExecutor : BasePitestExecutor() {
commandLine.addParameters(UNIX_FIRST_PARAMETER, gradleExecutable, taskName)
}

commandLine.addParameters(getPitestOverrideParameters(classFQN, port, reportDir))
commandLine.addParameters(getPitestOverrideParameters(options.classFQN, port, reportDir, options.verbose))

commandLine.workDirectory = File(projectDir)
return commandLine
}

private fun getPitestOverrideParameters(classFQN: String?, port: Int, reportDir: Path): List<String> {
private fun getPitestOverrideParameters(classFQN: String?, port: Int, reportDir: Path, verbose: Boolean): List<String> {
val parameters = mutableListOf<String>()
if (!classFQN.isNullOrEmpty()) {
parameters.add("-Dpitmutationmate.override.targetClasses=$classFQN")
}
parameters.add("-Dpitmutationmate.override.outputFormats=XML,report-coverage")
parameters.add("-Dpitmutationmate.override.addCoverageListenerDependency=io.github.amosproj:coverage-reporter:1.1")
parameters.add("-Dpitmutationmate.override.verbose=true")
parameters.add("-Dpitmutationmate.override.verbose=$verbose")
parameters.add("-Dpitmutationmate.override.port=$port")
parameters.add("-Dpitmutationmate.override.reportDir=${reportDir.toAbsolutePath()}")
return parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.amos.pitmutationmate.pitmutationmate.execution

import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfigurationOptions
import com.intellij.execution.configurations.GeneralCommandLine
import java.io.File
import java.nio.file.Path
Expand All @@ -12,26 +13,24 @@ class MavenTaskExecutor : BasePitestExecutor() {
private var mavenExecutable: String = "mvn"

override fun buildCommandLine(
executable: String?,
overrideTaskName: String?,
options: RunConfigurationOptions,
projectDir: String,
classFQN: String?,
reportDir: Path,
port: Int
): GeneralCommandLine {
val commandLine = GeneralCommandLine()

if (!executable.isNullOrEmpty()) {
this.mavenExecutable = executable
if (!options.gradleExecutable.isNullOrEmpty()) {
this.mavenExecutable = options.gradleExecutable!!
}

if (!overrideTaskName.isNullOrEmpty()) {
this.taskName = overrideTaskName
if (!options.taskName.isNullOrEmpty()) {
this.taskName = options.taskName!!
}

commandLine.exePath = mavenExecutable
commandLine.addParameters(this.taskName)
commandLine.addParameters(getPitestOverrideParameters(classFQN))
commandLine.addParameters(getPitestOverrideParameters(options.classFQN))

commandLine.workDirectory = File(projectDir)
return commandLine
Expand Down
Loading

0 comments on commit aef7829

Please sign in to comment.