Skip to content

fix settings #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.utbot.cpp.clion.plugin

import com.intellij.ide.util.RunOnceUtil
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import org.utbot.cpp.clion.plugin.client.Client
import org.utbot.cpp.clion.plugin.client.ClientManager
import org.utbot.cpp.clion.plugin.settings.pluginSettings
import org.utbot.cpp.clion.plugin.settings.settings
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
Expand All @@ -27,10 +26,11 @@ class UTBotStartupActivity : StartupActivity {


private fun showWizardOnFirstOpen(project: Project) {
if (pluginSettings.isFirstLaunch && !Client.IS_TEST_MODE) {
pluginSettings.isFirstLaunch = false
if (!ApplicationManager.getApplication().isUnitTestMode) {
invokeOnEdt {
UTBotWizard(project).showAndGet()
RunOnceUtil.runOnceForProject(project, "Show UTBot quick-start wizard to configure project") {
UTBotWizard(project).showAndGet()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class Client(
}

companion object {
var IS_TEST_MODE = false
const val HEARTBEAT_INTERVAL: Long = 500L
const val SERVER_TIMEOUT: Long = 300000L
const val DELAY_TIME: Long = 500L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ val Project.settings: UTBotAllProjectSettings
get() = this.service()

val projectIndependentSettings: UTBotProjectIndependentSettings.State
get() = service<UTBotProjectIndependentSettings>().state

val pluginSettings: UTBotPluginSpecificSettings
get() = service()
get() = service<UTBotProjectIndependentSettings>().state
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded
import org.utbot.cpp.clion.plugin.utils.isWindows
import org.utbot.cpp.clion.plugin.utils.notifyWarning
import org.utbot.cpp.clion.plugin.utils.path
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
Expand All @@ -18,29 +19,23 @@ class UTBotAllProjectSettings(val project: Project) {
val storedSettings: UTBotProjectStoredSettings.State
get() = project.service<UTBotProjectStoredSettings>().state

// todo: maybe remove this property and access directly
var projectPath: String
get() {
return storedSettings.projectPath
}
set(value) {
storedSettings.projectPath = value
}

val buildDirPath: Path
get() = Paths.get(projectPath).resolve(storedSettings.buildDirRelativePath)
get() = Paths.get(project.path).resolve(storedSettings.buildDirRelativePath)

val testsDirPath: Path
get() = Paths.get(project.path).resolve(storedSettings.testsDirRelativePath)

val convertedSourcePaths: List<String>
get() = storedSettings.sourceDirs.map { it.convertToRemotePathIfNeeded(project) }

val convertedTestDirPath: String
get() = storedSettings.testDirPath.convertToRemotePathIfNeeded(project)
get() = testsDirPath.toString().convertToRemotePathIfNeeded(project)

val convertedTargetPath: String
get() = if (storedSettings.targetPath == UTBotTarget.autoTarget.path) storedSettings.targetPath
else storedSettings.targetPath.convertToRemotePathIfNeeded(project)

val convertedProjectPath: String get() = projectPath.convertToRemotePathIfNeeded(project)
val convertedProjectPath: String get() = project.path.convertToRemotePathIfNeeded(project)

/**
* If this property returns true, plugin must convert path sent and returned from server.
Expand All @@ -52,7 +47,7 @@ class UTBotAllProjectSettings(val project: Project) {
get() {
val isLocalHost =
projectIndependentSettings.serverName == "localhost" || projectIndependentSettings.serverName == "127.0.0.01"
return !(storedSettings.remotePath == projectPath && isLocalHost) || isWindows
return !(storedSettings.remotePath == UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO && isLocalHost) || isWindows
}

fun fireUTBotSettingsChanged() {
Expand All @@ -66,13 +61,6 @@ class UTBotAllProjectSettings(val project: Project) {
storedSettings.buildDirRelativePath = UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_BUILD_DIR
storedSettings.targetPath = UTBotTarget.autoTarget.path

try {
storedSettings.testDirPath =
Paths.get(projectPath, UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_TEST_DIR).toString()
} catch (e: IllegalStateException) {
notifyWarning("Guessing settings failed: could not guess project path! Please specify it in settings!")
}

val cmakeRunConfiguration = CMakeAppRunConfiguration.getSelectedConfigurationAndTarget(project)?.first
val buildConfigurationSources = cmakeRunConfiguration?.cMakeTarget?.buildConfigurations?.map { it.sources }
//TODO: why do we use firstOrNull here?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

package org.utbot.cpp.clion.plugin.settings

import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.options.BoundConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.components.JBTextField
import com.intellij.ui.dsl.builder.BottomGap
import com.intellij.ui.dsl.builder.COLUMNS_LARGE
import com.intellij.ui.dsl.builder.LabelPosition
Expand All @@ -24,19 +26,23 @@ import org.utbot.cpp.clion.plugin.UTBot
import org.utbot.cpp.clion.plugin.listeners.UTBotSettingsChangedListener
import org.utbot.cpp.clion.plugin.ui.ObservableValue
import org.utbot.cpp.clion.plugin.ui.sourceFoldersView.UTBotProjectViewPaneForSettings
import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
import org.utbot.cpp.clion.plugin.utils.commandLineEditor
import org.utbot.cpp.clion.plugin.utils.isWindows
import org.utbot.cpp.clion.plugin.utils.path
import org.utbot.cpp.clion.plugin.utils.toWslFormat
import java.awt.Dimension
import java.nio.file.Paths

class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
"Project Settings to Generate Tests"
) {
private val logger = Logger.getInstance("ProjectConfigurable")
private val panel by lazy { createMainPanel() }

private val settings: UTBotProjectStoredSettings.State
get() = myProject.settings.storedSettings
private val settings: UTBotProjectStoredSettings = myProject.service()
private lateinit var portTextfield: JBTextField
private lateinit var serverNameTextField: JBTextField

private val isLocalOrWsl = ObservableValue(settings.isLocalOrWslScenario)

Expand All @@ -62,16 +68,17 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
private fun createMainPanel(): DialogPanel {
logger.trace("createPanel was called")
return panel {
group("Connection Settings") { this.createConnectionSettings() }
group("Paths") { this.createPathsSettings() }
group("CMake") { this.createCMakeSettings() }
group("Generator Settings") { this.createGeneratorSettings() }
group("Connection Settings") { createConnectionSettings() }
group("Paths") { createPathsSettings() }
group("CMake") { createCMakeSettings() }
group("Generator Settings") { createGeneratorSettings() }
}
}

private fun Panel.createConnectionSettings() {
row(UTBot.message("settings.project.port")) {
intTextField().bindIntText(projectIndependentSettings::port).applyToComponent {
portTextfield = this
maximumSize = TEXT_FIELD_MAX_SIZE
}
}.rowComment(UTBot.message("deployment.utbotPort.description"))
Expand All @@ -94,6 +101,7 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(

row(UTBot.message("settings.project.serverName")) {
textField().bindText(projectIndependentSettings::serverName).applyToComponent {
serverNameTextField = this
isLocalOrWsl.addOnChangeListener { newValue ->
if (newValue)
this.text = "localhost"
Expand All @@ -106,38 +114,31 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
.applyToComponent {
isLocalOrWsl.addOnChangeListener { newValue ->
if (newValue)
this.text = if (isWindows) myProject.settings.projectPath.toWslFormat() else ""
this.text = if (isWindows) myProject.path.toWslFormat() else ""
}
}.enabledIf(enabledIfNotLocalOrWslScenario)
}.rowComment(UTBot.message("deployment.remotePath.description"))
}

private fun Panel.createPathsSettings() {
row(UTBot.message("settings.project.projectPath")) {
textFieldWithBrowseButton(
UTBot.message("settings.project.projectPath.title"),
myProject,
FileChooserDescriptorFactory.createSingleFileDescriptor()
).bindText(
getter = { myProject.settings.projectPath },
setter = { value -> myProject.settings.projectPath = value })
.columns(COLUMNS_LARGE)
}.rowComment(UTBot.message("settings.project.projectPath.info"))
createPathChooser(
settings::buildDirRelativePath,
UTBot.message("settings.project.buildDir"),
UTBot.message("settings.project.buildDir.browse.title")
).rowComment(UTBot.message("paths.buildDirectory.description"))
createPathChooser(
settings::targetPath,
UTBot.message("settings.project.target"),
UTBot.message("settings.project.target.browse.title")
).rowComment(UTBot.message("paths.target.description"))
createPathChooser(
settings::testDirPath,
UTBot.message("settings.project.testsDir"),
UTBot.message("settings.project.testsDir.browse.title")
).rowComment(UTBot.message("paths.testsDirectory.description"))

row(UTBot.message("settings.project.target")) {
textField().bindText(
getter = {
settings.uiTargetPath
},
setter = {}
).columns(COLUMNS_LARGE).enabled(false)
}.rowComment(UTBot.message("paths.target.description"))

row(UTBot.message("settings.project.testsDir")) {
textField().bindText(settings::testDirRelativePath).columns(COLUMNS_LARGE)
}.rowComment(UTBot.message("paths.testsDir.description"))

row {
val pane = UTBotProjectViewPaneForSettings(myProject)
Expand Down Expand Up @@ -221,7 +222,7 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
spinner(
UTBotProjectStoredSettings.TIMEOUT_PER_TEST_MIN_VALUE..
UTBotProjectStoredSettings.TIMEOUT_PER_TEST_MAX_VALUE
).bindIntValue(settings::timeoutPerFunction).applyToComponent {
).bindIntValue(settings::timeoutPerTest).applyToComponent {
maximumSize = TEXT_FIELD_MAX_SIZE
}
}.rowComment(UTBot.message("advanced.timeoutPerTest.description"))
Expand All @@ -232,8 +233,12 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
}

override fun apply() {
val wereConnectionSettingsModified =
portTextfield.text != projectIndependentSettings.port.toString() || serverNameTextField.text != projectIndependentSettings.serverName
panel.apply()
myProject.settings.fireUTBotSettingsChanged()
if (wereConnectionSettingsModified)
projectIndependentSettings.fireConnectionSettingsChanged()
}

override fun reset() {
Expand Down

This file was deleted.

Loading