Skip to content
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

UI. Gradle project. Test sources root can be located anywhere #549 #577

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
Expand Up @@ -569,7 +569,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
try {
val contentEntry = modifiableModel.contentEntries
.filterNot { it.file == null }
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, true) }
.firstOrNull { VfsUtil.isAncestor(it.file!!, testSourceRoot, false) }
?: return false

contentEntry.addSourceRootIfAbsent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ import javax.swing.JList
import org.utbot.common.PathUtil
import org.utbot.intellij.plugin.models.GenerateTestsModel
import org.utbot.intellij.plugin.ui.utils.addDedicatedTestRoot
import org.utbot.intellij.plugin.ui.utils.isGradle
import org.utbot.intellij.plugin.ui.utils.suitableTestSourceRoots

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

private val SET_TEST_FOLDER = "set test folder"

init {
if (model.project.isGradle()) {
setButtonEnabled(false)
button.toolTipText = "Please define custom test source root via Gradle"
}
childComponent.isEditable = false
childComponent.renderer = object : ColoredListCellRenderer<Any?>() {
override fun customizeCellRenderer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utbot.intellij.plugin.ui.utils

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

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

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