KotlinDslModels: project can be null in ExternalSystemTaskNotificationListener.onStart
For example when project is created from sources
This commit is contained in:
+4
-2
@@ -42,7 +42,7 @@ fun processScriptModel(
|
|||||||
val project = task.findProject() ?: return
|
val project = task.findProject() ?: return
|
||||||
val models = model.toListOfScriptModels(project)
|
val models = model.toListOfScriptModels(project)
|
||||||
|
|
||||||
project.kotlinGradleDslSync[task]?.models?.addAll(models)
|
project.kotlinGradleDslSync.getOrPut(task) { KotlinDslGradleBuildSync(task) }.models.addAll(models)
|
||||||
|
|
||||||
if (models.containsErrors()) {
|
if (models.containsErrors()) {
|
||||||
throw IllegalStateException(KotlinIdeaGradleBundle.message("title.kotlin.build.script"))
|
throw IllegalStateException(KotlinIdeaGradleBundle.message("title.kotlin.build.script"))
|
||||||
@@ -102,7 +102,9 @@ private fun KotlinDslScriptsModel.toListOfScriptModels(project: Project): List<K
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinDslGradleBuildSync(val workingDir: String, val taskId: ExternalSystemTaskId) {
|
class KotlinDslGradleBuildSync(val taskId: ExternalSystemTaskId) {
|
||||||
|
lateinit var workingDir: String
|
||||||
|
val projectRoots = mutableSetOf<String>()
|
||||||
val models = mutableListOf<KotlinDslScriptModel>()
|
val models = mutableListOf<KotlinDslScriptModel>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -13,15 +13,18 @@ import org.jetbrains.kotlin.idea.framework.GRADLE_SYSTEM_ID
|
|||||||
import org.jetbrains.kotlin.idea.scripting.gradle.GradleScriptDefinitionsContributor
|
import org.jetbrains.kotlin.idea.scripting.gradle.GradleScriptDefinitionsContributor
|
||||||
|
|
||||||
class KotlinDslSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
class KotlinDslSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
||||||
|
private val workingDirs = hashMapOf<ExternalSystemTaskId, String>()
|
||||||
|
|
||||||
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
|
override fun onStart(id: ExternalSystemTaskId, workingDir: String?) {
|
||||||
if (!isGradleProjectImport(id)) return
|
if (!isGradleProjectImport(id)) return
|
||||||
if (workingDir == null) return
|
if (workingDir == null) return
|
||||||
|
|
||||||
gradleState.isSyncInProgress = true
|
gradleState.isSyncInProgress = true
|
||||||
|
workingDirs[id] = workingDir
|
||||||
|
|
||||||
val project = id.findProject() ?: return
|
val project = id.findProject() ?: return
|
||||||
|
|
||||||
project.kotlinGradleDslSync[id] = KotlinDslGradleBuildSync(workingDir, id)
|
project.kotlinGradleDslSync[id] = KotlinDslGradleBuildSync(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEnd(id: ExternalSystemTaskId) {
|
override fun onEnd(id: ExternalSystemTaskId) {
|
||||||
@@ -29,6 +32,7 @@ class KotlinDslSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
|||||||
|
|
||||||
gradleState.isSyncInProgress = false
|
gradleState.isSyncInProgress = false
|
||||||
|
|
||||||
|
val workingDir = workingDirs.remove(id) ?: return
|
||||||
val project = id.findProject() ?: return
|
val project = id.findProject() ?: return
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@@ -37,6 +41,7 @@ class KotlinDslSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
|||||||
val sync = project.kotlinGradleDslSync.remove(id)
|
val sync = project.kotlinGradleDslSync.remove(id)
|
||||||
if (sync != null) {
|
if (sync != null) {
|
||||||
// For Gradle 6.0 or higher
|
// For Gradle 6.0 or higher
|
||||||
|
sync.workingDir = workingDir
|
||||||
saveScriptModels(project, sync)
|
saveScriptModels(project, sync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,6 +51,8 @@ class KotlinDslSyncListener : ExternalSystemTaskNotificationListenerAdapter() {
|
|||||||
|
|
||||||
gradleState.isSyncInProgress = false
|
gradleState.isSyncInProgress = false
|
||||||
|
|
||||||
|
workingDirs.remove(id)
|
||||||
|
|
||||||
val project = id.findProject() ?: return
|
val project = id.findProject() ?: return
|
||||||
|
|
||||||
project.kotlinGradleDslSync.remove(id)
|
project.kotlinGradleDslSync.remove(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user