Skip to content

Commit 12470a1

Browse files
vol0nEgorkaKulikov
andauthored
fix settings (#367)
* Fix: settings are not persisted, swap run icons - when in Configurable we used: project.settings.storedSettings it would return some instance of state. And because state can change, writes to that instance were not saved and so settings were not persisted - Fixed a bug with test run icons, "Run all tests" was swapped with "Run test" * Do not use projectPath, use project.path * fix: verbose mode enabling/disabling doesn't work * show wizard on project open * fix test dir setting * remove custome target, persist selected target * Little suggested changes * Some improvements to targets * fix: connectionSettingsChangedNotFired after settings changed Co-authored-by: Egor Kulikov <[email protected]>
1 parent 19cc7b3 commit 12470a1

File tree

17 files changed

+214
-148
lines changed

17 files changed

+214
-148
lines changed

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/UTBotStartupActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package org.utbot.cpp.clion.plugin
22

33
import com.intellij.ide.util.RunOnceUtil
4+
import com.intellij.openapi.application.ApplicationManager
45
import com.intellij.openapi.components.service
56
import com.intellij.openapi.project.Project
67
import com.intellij.openapi.startup.StartupActivity
7-
import org.utbot.cpp.clion.plugin.client.Client
88
import org.utbot.cpp.clion.plugin.client.ClientManager
9-
import org.utbot.cpp.clion.plugin.settings.pluginSettings
109
import org.utbot.cpp.clion.plugin.settings.settings
1110
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard
1211
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
@@ -27,10 +26,11 @@ class UTBotStartupActivity : StartupActivity {
2726

2827

2928
private fun showWizardOnFirstOpen(project: Project) {
30-
if (pluginSettings.isFirstLaunch && !Client.IS_TEST_MODE) {
31-
pluginSettings.isFirstLaunch = false
29+
if (!ApplicationManager.getApplication().isUnitTestMode) {
3230
invokeOnEdt {
33-
UTBotWizard(project).showAndGet()
31+
RunOnceUtil.runOnceForProject(project, "Show UTBot quick-start wizard to configure project") {
32+
UTBotWizard(project).showAndGet()
33+
}
3434
}
3535
}
3636
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class Client(
201201
}
202202

203203
companion object {
204-
var IS_TEST_MODE = false
205204
const val HEARTBEAT_INTERVAL: Long = 500L
206205
const val SERVER_TIMEOUT: Long = 300000L
207206
const val DELAY_TIME: Long = 500L

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/SettingsProvider.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ val Project.settings: UTBotAllProjectSettings
77
get() = this.service()
88

99
val projectIndependentSettings: UTBotProjectIndependentSettings.State
10-
get() = service<UTBotProjectIndependentSettings>().state
11-
12-
val pluginSettings: UTBotPluginSpecificSettings
13-
get() = service()
10+
get() = service<UTBotProjectIndependentSettings>().state

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotAllProjectSettings.kt

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
99
import org.utbot.cpp.clion.plugin.utils.convertToRemotePathIfNeeded
1010
import org.utbot.cpp.clion.plugin.utils.isWindows
1111
import org.utbot.cpp.clion.plugin.utils.notifyWarning
12+
import org.utbot.cpp.clion.plugin.utils.path
1213
import java.io.File
1314
import java.nio.file.Path
1415
import java.nio.file.Paths
@@ -18,29 +19,23 @@ class UTBotAllProjectSettings(val project: Project) {
1819
val storedSettings: UTBotProjectStoredSettings.State
1920
get() = project.service<UTBotProjectStoredSettings>().state
2021

21-
// todo: maybe remove this property and access directly
22-
var projectPath: String
23-
get() {
24-
return storedSettings.projectPath
25-
}
26-
set(value) {
27-
storedSettings.projectPath = value
28-
}
29-
3022
val buildDirPath: Path
31-
get() = Paths.get(projectPath).resolve(storedSettings.buildDirRelativePath)
23+
get() = Paths.get(project.path).resolve(storedSettings.buildDirRelativePath)
24+
25+
val testsDirPath: Path
26+
get() = Paths.get(project.path).resolve(storedSettings.testsDirRelativePath)
3227

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

3631
val convertedTestDirPath: String
37-
get() = storedSettings.testDirPath.convertToRemotePathIfNeeded(project)
32+
get() = testsDirPath.toString().convertToRemotePathIfNeeded(project)
3833

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

43-
val convertedProjectPath: String get() = projectPath.convertToRemotePathIfNeeded(project)
38+
val convertedProjectPath: String get() = project.path.convertToRemotePathIfNeeded(project)
4439

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

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

69-
try {
70-
storedSettings.testDirPath =
71-
Paths.get(projectPath, UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_TEST_DIR).toString()
72-
} catch (e: IllegalStateException) {
73-
notifyWarning("Guessing settings failed: could not guess project path! Please specify it in settings!")
74-
}
75-
7664
val cmakeRunConfiguration = CMakeAppRunConfiguration.getSelectedConfigurationAndTarget(project)?.first
7765
val buildConfigurationSources = cmakeRunConfiguration?.cMakeTarget?.buildConfigurations?.map { it.sources }
7866
//TODO: why do we use firstOrNull here?

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotConfigurable.kt

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

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

5+
import com.intellij.openapi.components.service
56
import com.intellij.openapi.diagnostic.Logger
67
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
78
import com.intellij.openapi.options.BoundConfigurable
89
import com.intellij.openapi.project.Project
910
import com.intellij.openapi.ui.DialogPanel
11+
import com.intellij.ui.components.JBTextField
1012
import com.intellij.ui.dsl.builder.BottomGap
1113
import com.intellij.ui.dsl.builder.COLUMNS_LARGE
1214
import com.intellij.ui.dsl.builder.LabelPosition
@@ -24,19 +26,23 @@ import org.utbot.cpp.clion.plugin.UTBot
2426
import org.utbot.cpp.clion.plugin.listeners.UTBotSettingsChangedListener
2527
import org.utbot.cpp.clion.plugin.ui.ObservableValue
2628
import org.utbot.cpp.clion.plugin.ui.sourceFoldersView.UTBotProjectViewPaneForSettings
29+
import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
2730
import org.utbot.cpp.clion.plugin.utils.commandLineEditor
2831
import org.utbot.cpp.clion.plugin.utils.isWindows
32+
import org.utbot.cpp.clion.plugin.utils.path
2933
import org.utbot.cpp.clion.plugin.utils.toWslFormat
3034
import java.awt.Dimension
35+
import java.nio.file.Paths
3136

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

38-
private val settings: UTBotProjectStoredSettings.State
39-
get() = myProject.settings.storedSettings
43+
private val settings: UTBotProjectStoredSettings = myProject.service()
44+
private lateinit var portTextfield: JBTextField
45+
private lateinit var serverNameTextField: JBTextField
4046

4147
private val isLocalOrWsl = ObservableValue(settings.isLocalOrWslScenario)
4248

@@ -62,16 +68,17 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
6268
private fun createMainPanel(): DialogPanel {
6369
logger.trace("createPanel was called")
6470
return panel {
65-
group("Connection Settings") { this.createConnectionSettings() }
66-
group("Paths") { this.createPathsSettings() }
67-
group("CMake") { this.createCMakeSettings() }
68-
group("Generator Settings") { this.createGeneratorSettings() }
71+
group("Connection Settings") { createConnectionSettings() }
72+
group("Paths") { createPathsSettings() }
73+
group("CMake") { createCMakeSettings() }
74+
group("Generator Settings") { createGeneratorSettings() }
6975
}
7076
}
7177

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

95102
row(UTBot.message("settings.project.serverName")) {
96103
textField().bindText(projectIndependentSettings::serverName).applyToComponent {
104+
serverNameTextField = this
97105
isLocalOrWsl.addOnChangeListener { newValue ->
98106
if (newValue)
99107
this.text = "localhost"
@@ -106,38 +114,31 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
106114
.applyToComponent {
107115
isLocalOrWsl.addOnChangeListener { newValue ->
108116
if (newValue)
109-
this.text = if (isWindows) myProject.settings.projectPath.toWslFormat() else ""
117+
this.text = if (isWindows) myProject.path.toWslFormat() else ""
110118
}
111119
}.enabledIf(enabledIfNotLocalOrWslScenario)
112120
}.rowComment(UTBot.message("deployment.remotePath.description"))
113121
}
114122

115123
private fun Panel.createPathsSettings() {
116-
row(UTBot.message("settings.project.projectPath")) {
117-
textFieldWithBrowseButton(
118-
UTBot.message("settings.project.projectPath.title"),
119-
myProject,
120-
FileChooserDescriptorFactory.createSingleFileDescriptor()
121-
).bindText(
122-
getter = { myProject.settings.projectPath },
123-
setter = { value -> myProject.settings.projectPath = value })
124-
.columns(COLUMNS_LARGE)
125-
}.rowComment(UTBot.message("settings.project.projectPath.info"))
126124
createPathChooser(
127125
settings::buildDirRelativePath,
128126
UTBot.message("settings.project.buildDir"),
129127
UTBot.message("settings.project.buildDir.browse.title")
130128
).rowComment(UTBot.message("paths.buildDirectory.description"))
131-
createPathChooser(
132-
settings::targetPath,
133-
UTBot.message("settings.project.target"),
134-
UTBot.message("settings.project.target.browse.title")
135-
).rowComment(UTBot.message("paths.target.description"))
136-
createPathChooser(
137-
settings::testDirPath,
138-
UTBot.message("settings.project.testsDir"),
139-
UTBot.message("settings.project.testsDir.browse.title")
140-
).rowComment(UTBot.message("paths.testsDirectory.description"))
129+
130+
row(UTBot.message("settings.project.target")) {
131+
textField().bindText(
132+
getter = {
133+
settings.uiTargetPath
134+
},
135+
setter = {}
136+
).columns(COLUMNS_LARGE).enabled(false)
137+
}.rowComment(UTBot.message("paths.target.description"))
138+
139+
row(UTBot.message("settings.project.testsDir")) {
140+
textField().bindText(settings::testDirRelativePath).columns(COLUMNS_LARGE)
141+
}.rowComment(UTBot.message("paths.testsDir.description"))
141142

142143
row {
143144
val pane = UTBotProjectViewPaneForSettings(myProject)
@@ -221,7 +222,7 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
221222
spinner(
222223
UTBotProjectStoredSettings.TIMEOUT_PER_TEST_MIN_VALUE..
223224
UTBotProjectStoredSettings.TIMEOUT_PER_TEST_MAX_VALUE
224-
).bindIntValue(settings::timeoutPerFunction).applyToComponent {
225+
).bindIntValue(settings::timeoutPerTest).applyToComponent {
225226
maximumSize = TEXT_FIELD_MAX_SIZE
226227
}
227228
}.rowComment(UTBot.message("advanced.timeoutPerTest.description"))
@@ -232,8 +233,12 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
232233
}
233234

234235
override fun apply() {
236+
val wereConnectionSettingsModified =
237+
portTextfield.text != projectIndependentSettings.port.toString() || serverNameTextField.text != projectIndependentSettings.serverName
235238
panel.apply()
236239
myProject.settings.fireUTBotSettingsChanged()
240+
if (wereConnectionSettingsModified)
241+
projectIndependentSettings.fireConnectionSettingsChanged()
237242
}
238243

239244
override fun reset() {

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotPluginSpecificSettings.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)