Skip to content

Commit 180553a

Browse files
UI. Gradle project. Test sources root can be located anywhere #549 (#577)
1 parent 71611c3 commit 180553a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
569569
try {
570570
val contentEntry = modifiableModel.contentEntries
571571
.filterNot { it.file == null }
572-
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, true) }
572+
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, false) }
573573
?: return false
574574

575575
contentEntry.addSourceRootIfAbsent(

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/components/TestFolderComboWithBrowseButton.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ import javax.swing.JList
1616
import org.utbot.common.PathUtil
1717
import org.utbot.intellij.plugin.models.GenerateTestsModel
1818
import org.utbot.intellij.plugin.ui.utils.addDedicatedTestRoot
19+
import org.utbot.intellij.plugin.ui.utils.isGradle
1920
import org.utbot.intellij.plugin.ui.utils.suitableTestSourceRoots
2021

2122
class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) : ComboboxWithBrowseButton() {
2223

2324
private val SET_TEST_FOLDER = "set test folder"
2425

2526
init {
27+
if (model.project.isGradle()) {
28+
setButtonEnabled(false)
29+
button.toolTipText = "Please define custom test source root via Gradle"
30+
}
2631
childComponent.isEditable = false
2732
childComponent.renderer = object : ColoredListCellRenderer<Any?>() {
2833
override fun customizeCellRenderer(

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/ModuleUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.intellij.plugin.ui.utils
22

3+
import com.android.tools.idea.gradle.project.GradleProjectInfo
34
import org.utbot.common.PathUtil.toPath
45
import org.utbot.common.WorkaroundReason
56
import org.utbot.common.workaround
@@ -144,14 +145,14 @@ private fun Module.suitableTestSourceFolders(codegenLanguage: CodegenLanguage):
144145
// Heuristics: User is more likely to choose the shorter path
145146
.sortedBy { it.url.length }
146147
}
148+
fun Project.isGradle() = GradleProjectInfo.getInstance(this).isBuildWithGradle
147149

148150
private const val dedicatedTestSourceRootName = "utbot_tests"
149151
fun Module.addDedicatedTestRoot(testSourceRoots: MutableList<VirtualFile>): VirtualFile? {
152+
// Don't suggest new test source roots for Gradle project where 'unexpected' test roots won't work
153+
if (project.isGradle()) return null
150154
// Dedicated test root already exists
151-
// OR it looks like standard structure of Gradle project where 'unexpected' test roots won't work
152-
if (testSourceRoots.any { file ->
153-
file.name == dedicatedTestSourceRootName || file.path.endsWith("src/test/java")
154-
}) return null
155+
if (testSourceRoots.any { file -> file.name == dedicatedTestSourceRootName }) return null
155156

156157
val moduleInstance = ModuleRootManager.getInstance(this)
157158
val testFolder = moduleInstance.contentEntries.flatMap { it.sourceFolders.toList() }

0 commit comments

Comments
 (0)