GradleBuildRoot: std scripts under project roots should be treated as new
This commit is contained in:
+3
-4
@@ -30,10 +30,9 @@ class MissingGradleScriptConfigurationNotificationProvider(private val project:
|
||||
if (!isGradleKotlinScript(file)) return null
|
||||
if (file.fileType != KotlinFileType.INSTANCE) return null
|
||||
|
||||
val scriptUnderRoot = GradleBuildRootsManager.getInstance(project).findScriptBuildRoot(file)
|
||||
val root = scriptUnderRoot?.root
|
||||
val scriptUnderRoot = GradleBuildRootsManager.getInstance(project).findScriptBuildRoot(file) ?: return null
|
||||
return when {
|
||||
root is GradleBuildRoot.Unlinked -> EditorNotificationPanel().apply {
|
||||
scriptUnderRoot.isUnrelatedScript -> EditorNotificationPanel().apply {
|
||||
text(KotlinIdeaGradleBundle.message("text.the.associated.gradle.project.isn.t.imported"))
|
||||
|
||||
val linkProjectText = KotlinIdeaGradleBundle.message("action.label.text.load.script.configuration")
|
||||
@@ -59,7 +58,7 @@ class MissingGradleScriptConfigurationNotificationProvider(private val project:
|
||||
linkProjectText
|
||||
)
|
||||
}
|
||||
root is GradleBuildRoot.New && !root.importing -> EditorNotificationPanel().apply {
|
||||
scriptUnderRoot.isNewScript -> EditorNotificationPanel().apply {
|
||||
text(getMissingConfigurationNotificationText())
|
||||
createActionLabel(getMissingConfigurationActionText()) {
|
||||
runPartialGradleImport(project)
|
||||
|
||||
+13
-2
@@ -57,12 +57,23 @@ abstract class GradleBuildRootsLocator {
|
||||
class ScriptUnderRoot(
|
||||
val root: GradleBuildRoot?,
|
||||
val script: GradleScriptInfo? = null
|
||||
)
|
||||
) {
|
||||
val isUnrelatedScript: Boolean
|
||||
get() = root is GradleBuildRoot.Unlinked
|
||||
|
||||
val isNewScript: Boolean
|
||||
get() = root is GradleBuildRoot.Linked &&
|
||||
!isImported &&
|
||||
!root.importing
|
||||
|
||||
private val isImported: Boolean
|
||||
get() = script != null
|
||||
}
|
||||
|
||||
fun findScriptBuildRoot(gradleKtsFile: VirtualFile): ScriptUnderRoot? =
|
||||
findScriptBuildRoot(gradleKtsFile.path)
|
||||
|
||||
protected fun findScriptBuildRoot(filePath: String, searchNearestLegacy: Boolean = true): ScriptUnderRoot? {
|
||||
fun findScriptBuildRoot(filePath: String, searchNearestLegacy: Boolean = true): ScriptUnderRoot? {
|
||||
if (!filePath.endsWith(".gradle.kts")) return null
|
||||
|
||||
val scriptInfo = getScriptInfo(filePath)
|
||||
|
||||
+19
-2
@@ -6,11 +6,28 @@
|
||||
package org.jetbrains.kotlin.idea.scripting.gradle.roots
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class GradleBuildRootsLocatorTest : AbstractGradleBuildRootsLocatorTest() {
|
||||
@Test
|
||||
fun testUnlinkedBuildGradleKtsNearProjectRoot() {
|
||||
fun testNewBuildGradleKtsNearProjectRoot() {
|
||||
// the build.gradle.kts under the project root will be definitive import at next import
|
||||
// so, we should not treat it as unlinked
|
||||
newImportedGradleProject("imported", relativeScripts = listOf())
|
||||
assert(findScriptBuildRoot("imported/build.gradle.kts")?.root is GradleBuildRoot.Unlinked)
|
||||
val scriptUnderRoot = findScriptBuildRoot("imported/build.gradle.kts")
|
||||
assertNotNull(scriptUnderRoot)
|
||||
assertTrue(scriptUnderRoot.isNewScript)
|
||||
assertFalse(scriptUnderRoot.isUnrelatedScript)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuildGradleKtsNearProjectRoot() {
|
||||
newImportedGradleProject("imported", relativeScripts = listOf("build.gradle.kts"))
|
||||
val scriptUnderRoot = findScriptBuildRoot("imported/build.gradle.kts")
|
||||
assertNotNull(scriptUnderRoot)
|
||||
assertFalse(scriptUnderRoot.isNewScript)
|
||||
assertFalse(scriptUnderRoot.isUnrelatedScript)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user