Skip to content

Commit 530752b

Browse files
author
Arseniy Volynets
committed
Merge branch 'vol0n/clion_plugin' into fix_bugs_after_refactoring
2 parents 9457770 + d2b2b7e commit 530752b

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.utbot.cpp.clion.plugin.settings
33
import com.intellij.openapi.components.Service
44
import com.intellij.openapi.components.service
55
import com.intellij.openapi.project.Project
6-
import com.intellij.openapi.project.guessProjectDir
76
import com.jetbrains.cidr.cpp.execution.CMakeAppRunConfiguration
87
import org.utbot.cpp.clion.plugin.listeners.UTBotSettingsChangedListener
98
import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
@@ -19,14 +18,10 @@ class UTBotAllProjectSettings(val project: Project) {
1918
val storedSettings: UTBotProjectStoredSettings.State
2019
get() = project.service<UTBotProjectStoredSettings>().state
2120

21+
// todo: maybe remove this property and access directly
2222
var projectPath: String
2323
get() {
24-
// if true then there is nothing persisted in xml files and plugin was launched for the first time
25-
if (storedSettings.projectPath == null)
26-
// so we should guess the project path
27-
storedSettings.projectPath = project.guessProjectDir()?.path
2824
return storedSettings.projectPath
29-
?: error("Could not guess project path! Should be specified in settings")
3025
}
3126
set(value) {
3227
storedSettings.projectPath = value
@@ -67,12 +62,13 @@ class UTBotAllProjectSettings(val project: Project) {
6762
fun predictPaths() {
6863
fun getSourceFoldersFromSources(sources: Collection<File>) = sources.map { it.parent }.toMutableSet()
6964

70-
storedSettings.remotePath = projectPath
71-
storedSettings.buildDirRelativePath = "build-utbot"
65+
storedSettings.remotePath = UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
66+
storedSettings.buildDirRelativePath = UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_BUILD_DIR
7267
storedSettings.targetPath = UTBotTarget.autoTarget.path
7368

7469
try {
75-
storedSettings.testDirPath = Paths.get(projectPath, "tests").toString()
70+
storedSettings.testDirPath =
71+
Paths.get(projectPath, UTBotProjectStoredSettings.DEFAULT_RELATIVE_PATH_TO_TEST_DIR).toString()
7672
} catch (e: IllegalStateException) {
7773
notifyWarning("Guessing settings failed: could not guess project path! Please specify it in settings!")
7874
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
99
import com.intellij.openapi.ui.DialogPanel
1010
import com.intellij.ui.dsl.builder.BottomGap
1111
import com.intellij.ui.dsl.builder.COLUMNS_LARGE
12+
import com.intellij.ui.dsl.builder.LabelPosition
1213
import com.intellij.ui.dsl.builder.Panel
1314
import com.intellij.ui.dsl.builder.Row
1415
import com.intellij.ui.dsl.builder.bindIntText
@@ -95,17 +96,18 @@ class UTBotConfigurable(private val myProject: Project) : BoundConfigurable(
9596
UTBot.message("settings.project.testsDir.browse.title")
9697
).rowComment(UTBot.message("paths.testsDirectory.description"))
9798

98-
row(UTBot.message("settings.project.sourcePaths")) {
99+
row {
99100
val pane = UTBotProjectViewPaneForSettings(myProject)
100101
cell(pane.createComponent()).onApply {
101102
pane.apply()
102103
}.onReset {
103104
pane.reset()
104105
}.onIsModified {
105106
pane.isModified()
106-
}
107+
}.label(UTBot.message("settings.project.sourcePaths"), LabelPosition.TOP)
107108
}.bottomGap(BottomGap.SMALL).rowComment(UTBot.message("paths.sourceDirectories.description"))
108109

110+
109111
row {
110112
label("Try to get paths from CMake model: ")
111113
button("Detect Paths") {

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import com.intellij.openapi.components.Service
55
import com.intellij.openapi.components.State
66
import com.intellij.openapi.components.Storage
77
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.project.guessProjectDir
89
import org.utbot.cpp.clion.plugin.ui.targetsToolWindow.UTBotTarget
10+
import java.nio.file.Paths
911

1012
/**
1113
* Settings that are specific to each project
@@ -20,11 +22,11 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
2022

2123
// serialized by the ide
2224
data class State(
23-
var projectPath: String? = null,
24-
var buildDirRelativePath: String = "build-utbot",
25+
var projectPath: String = "",
26+
var buildDirRelativePath: String = DEFAULT_RELATIVE_PATH_TO_BUILD_DIR,
2527
var testDirPath: String = "",
2628
var targetPath: String = UTBotTarget.autoTarget.path,
27-
var remotePath: String = "",
29+
var remotePath: String = REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO,
2830
var sourceDirs: Set<String> = setOf(),
2931
var cmakeOptions: String = DEFAULT_CMAKE_OPTIONS.joinToString(" "),
3032
var generateForStaticFunctions: Boolean = true,
@@ -55,7 +57,21 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
5557
myState = state
5658
}
5759

60+
// called when during component initialization if there is no persisted state.
61+
// See java docs for PersistingStateComponent
62+
override fun noStateLoaded() {
63+
myState.projectPath =
64+
project.guessProjectDir()?.path ?: error("Could not guess project path! Should be specified in settings")
65+
myState.testDirPath = Paths.get(myState.projectPath).resolve(DEFAULT_RELATIVE_PATH_TO_TEST_DIR).toString()
66+
myState.remotePath = REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
67+
}
68+
69+
5870
companion object {
5971
val DEFAULT_CMAKE_OPTIONS = listOf("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-DCMAKE_EXPORT_LINK_COMMANDS=ON")
72+
// local means no conversion of paths is needed. This is the case for when server runs locally on Linux
73+
const val REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO = ""
74+
const val DEFAULT_RELATIVE_PATH_TO_TEST_DIR = "utbot-tests"
75+
const val DEFAULT_RELATIVE_PATH_TO_BUILD_DIR = "utbot-build"
6076
}
6177
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/ui/wizard/steps/ConnectionStep.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import org.utbot.cpp.clion.plugin.utils.validateInput
3434
import javax.swing.JComponent
3535
import javax.swing.event.DocumentEvent
3636
import kotlin.properties.Delegates
37+
import org.utbot.cpp.clion.plugin.settings.UTBotProjectStoredSettings
38+
import org.utbot.cpp.clion.plugin.utils.isWindows
3739

3840
enum class ConnectionStatus {
3941
Connected,
@@ -61,7 +63,8 @@ class ConnectionStep(
6163
if (newValue) {
6264
portTextField.text = UTBotAllProjectSettings.DEFAULT_PORT.toString()
6365
hostTextField.text = UTBotAllProjectSettings.DEFAULT_HOST
64-
remotePathTextField.text = project.settings.projectPath.toWslFormat()
66+
remotePathTextField.text = if (isWindows) project.settings.projectPath.toWslFormat()
67+
else UTBotProjectStoredSettings.REMOTE_PATH_VALUE_FOR_LOCAL_SCENARIO
6568
}
6669
}
6770
}
@@ -167,9 +170,10 @@ class ConnectionStep(
167170
addHtml("media/remote_path.html")
168171
panel {
169172
row {
170-
textField().bindText(settingsModel.projectSettings::remotePath).columns(COLUMNS_LARGE).applyToComponent {
171-
remotePathTextField = this
172-
}.enabledIf(object : ComponentPredicate() {
173+
textField().bindText(settingsModel.projectSettings::remotePath).columns(COLUMNS_LARGE)
174+
.applyToComponent {
175+
remotePathTextField = this
176+
}.enabledIf(object : ComponentPredicate() {
173177
override fun invoke() = !useConnectionDefaults.value
174178
override fun addListener(listener: (Boolean) -> Unit) {
175179
useConnectionDefaults.addOnChangeListener { newValue -> listener(!newValue) }

clion-plugin/src/main/resources/messages/UTBot.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ projectConfigure.reconfigure=Reset cache and configure project
66
wizard.show=Quickstart wizard
77
settings.project.projectPath=Path to project:
88
settings.project.projectPath.title=Choose project directory
9-
settings.project.projectPath.info=Path to project:
10-
settings.project.sourcePaths=Source paths:
9+
settings.project.projectPath.info=Path to project (local). Generally it is guessed automatically. But in rare cases should be set manually
10+
settings.project.sourcePaths=Source paths
1111
settings.project.buildDir=Build directory:
1212
settings.project.target=target path:
1313
settings.project.testsDir=Tests directory:
@@ -34,12 +34,12 @@ requests.buildDir.description.progress=Creating build directory...
3434
uri.wiki=https://github.com/UnitTestBot/UTBotCpp/wiki
3535
deployment.utbotHost.description=UTBot Server host address. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#deployment>Learn more</a>
3636
deployment.utbotPort.description=UTBot Server port. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#utbot-port>Learn more</a>
37-
deployment.remotePath.description=Remote path configuration specifies the path to the project on a remote host. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#remote-path>Learn more</a>
37+
deployment.remotePath.description=Remote path configuration specifies the path to the project on a remote host. Empty value specifies local scenario (for Linux). <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#remote-path>Learn more</a>
3838
paths.buildDirectory.description=Relative path to build directory with compile_commands.json and/or coverage.json. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#build-directory>Learn more</a>
3939
paths.target.description=Path to target which is passed to UTBot
4040
paths.cmakeOptions.description=Options passed to CMake command. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#cmake-options>Learn more</a>
4141
paths.testsDirectory.description=Relative path to directory in which tests will be generated. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#tests-directory>Learn more</a>
42-
paths.sourceDirectories.description=Paths to directories, that are marked as source directories. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#source-directories>Learn more</a>
42+
paths.sourceDirectories.description=Mark/unmark directory as source by double-clicking or using actions from context menu. You can also unmark or mark directories in UTBot project view pane. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#source-directories>Learn more</a>
4343
testsGeneration.verboseFormatting.description=If set to true, tests will be formatted in more detailed form. <a href=https://github.com/UnitTestBot/UTBotCpp/wiki/vscode-extension-settings#verbose-formatting>Learn more</a>
4444
testsGeneration.verboseFormatting.title=Use verbose mode
4545
testsGeneration.generateForStaticFunctions.title=Generate for static functions

0 commit comments

Comments
 (0)