build.gradle.kts: report error to build tool window
Move errors found in KotlinDslScriptModels from Messages Toolwindow to Build Toolwindow
This commit is contained in:
@@ -40,6 +40,6 @@ text.see.manual.installation.instructions=See manual installation instructions <
|
|||||||
text.the.associated.gradle.project.isn.t.imported=The associated Gradle Project isn't imported.
|
text.the.associated.gradle.project.isn.t.imported=The associated Gradle Project isn't imported.
|
||||||
text.was.modified={0} was modified
|
text.was.modified={0} was modified
|
||||||
title.configure.kotlin.gradle.plugin=Configure Kotlin-Gradle Plugin
|
title.configure.kotlin.gradle.plugin=Configure Kotlin-Gradle Plugin
|
||||||
title.kotlin.build.script=Kotlin Build Script
|
title.kotlin.build.script=Gradle Kotlin DSL Scripts errors
|
||||||
title.update.language.version=Update Language Version
|
title.update.language.version=Update Language Version
|
||||||
tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed=The external Gradle project needs to be imported to get this script analyzed. <br/>You can import the related Gradle project or click "{0}" to get code insight without importing.
|
tool.tip.text.the.external.gradle.project.needs.to.be.imported.to.get.this.script.analyzed=The external Gradle project needs to be imported to get this script analyzed. <br/>You can import the related Gradle project or click "{0}" to get code insight without importing.
|
||||||
+8
-70
@@ -5,19 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.scripting.gradle.importing
|
package org.jetbrains.kotlin.idea.scripting.gradle.importing
|
||||||
|
|
||||||
import com.intellij.build.SyncViewManager
|
|
||||||
import com.intellij.openapi.components.service
|
import com.intellij.openapi.components.service
|
||||||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemEventDispatcher
|
|
||||||
import com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager
|
|
||||||
import com.intellij.openapi.externalSystem.service.notification.NotificationCategory
|
|
||||||
import com.intellij.openapi.externalSystem.service.notification.NotificationData
|
|
||||||
import com.intellij.openapi.externalSystem.service.notification.NotificationSource
|
|
||||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.pom.Navigatable
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinIdeaGradleBundle
|
|
||||||
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||||
import org.jetbrains.kotlin.idea.core.script.configuration.cache.CachedConfigurationInputs
|
import org.jetbrains.kotlin.idea.core.script.configuration.cache.CachedConfigurationInputs
|
||||||
import org.jetbrains.kotlin.idea.core.script.configuration.cache.ScriptConfigurationSnapshot
|
import org.jetbrains.kotlin.idea.core.script.configuration.cache.ScriptConfigurationSnapshot
|
||||||
@@ -29,7 +19,6 @@ import org.jetbrains.kotlin.scripting.resolve.ScriptCompilationConfigurationWrap
|
|||||||
import org.jetbrains.kotlin.scripting.resolve.VirtualFileScriptSource
|
import org.jetbrains.kotlin.scripting.resolve.VirtualFileScriptSource
|
||||||
import org.jetbrains.kotlin.scripting.resolve.adjustByDefinition
|
import org.jetbrains.kotlin.scripting.resolve.adjustByDefinition
|
||||||
import org.jetbrains.plugins.gradle.service.project.ProjectResolverContext
|
import org.jetbrains.plugins.gradle.service.project.ProjectResolverContext
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
import kotlin.script.experimental.jvm.JvmDependency
|
import kotlin.script.experimental.jvm.JvmDependency
|
||||||
@@ -46,19 +35,17 @@ fun saveScriptModels(
|
|||||||
|
|
||||||
val scriptConfigurations = mutableListOf<Pair<VirtualFile, ScriptConfigurationSnapshot>>()
|
val scriptConfigurations = mutableListOf<Pair<VirtualFile, ScriptConfigurationSnapshot>>()
|
||||||
|
|
||||||
val syncViewManager = project.service<SyncViewManager>()
|
val errorReporter = KotlinGradleDslErrorReporter(project, task)
|
||||||
val buildEventDispatcher =
|
|
||||||
ExternalSystemEventDispatcher(task, syncViewManager)
|
|
||||||
|
|
||||||
val javaHome = settings.javaHome?.let { File(it) }
|
val javaHome = settings.javaHome?.let { File(it) }
|
||||||
models.forEach { buildScript ->
|
models.forEach { model ->
|
||||||
val scriptFile = File(buildScript.file)
|
val scriptFile = File(model.file)
|
||||||
val virtualFile = VfsUtil.findFile(scriptFile.toPath(), true)!!
|
val virtualFile = VfsUtil.findFile(scriptFile.toPath(), true)!!
|
||||||
|
|
||||||
val inputs = getGradleScriptInputsStamp(
|
val inputs = getGradleScriptInputsStamp(
|
||||||
project,
|
project,
|
||||||
virtualFile,
|
virtualFile,
|
||||||
givenTimeStamp = buildScript.inputsTimeStamp
|
givenTimeStamp = model.inputsTimeStamp
|
||||||
)
|
)
|
||||||
|
|
||||||
val definition = virtualFile.findScriptDefinition(project) ?: return@forEach
|
val definition = virtualFile.findScriptDefinition(project) ?: return@forEach
|
||||||
@@ -68,13 +55,13 @@ fun saveScriptModels(
|
|||||||
if (javaHome != null) {
|
if (javaHome != null) {
|
||||||
jvm.jdkHome(javaHome)
|
jvm.jdkHome(javaHome)
|
||||||
}
|
}
|
||||||
defaultImports(buildScript.imports)
|
defaultImports(model.imports)
|
||||||
dependencies(JvmDependency(buildScript.classPath.map {
|
dependencies(JvmDependency(model.classPath.map {
|
||||||
File(
|
File(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
ide.dependenciesSources(JvmDependency(buildScript.sourcePath.map {
|
ide.dependenciesSources(JvmDependency(model.sourcePath.map {
|
||||||
File(
|
File(
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
@@ -96,9 +83,7 @@ fun saveScriptModels(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
buildScript.messages.forEach {
|
errorReporter.reportError(scriptFile, model)
|
||||||
addBuildScriptDiagnosticMessage(it, virtualFile, project)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGradleProjectRootsAfterImport(
|
saveGradleProjectRootsAfterImport(
|
||||||
@@ -107,51 +92,4 @@ fun saveScriptModels(
|
|||||||
|
|
||||||
project.service<ScriptConfigurationManager>().saveCompilationConfigurationAfterImport(scriptConfigurations)
|
project.service<ScriptConfigurationManager>().saveCompilationConfigurationAfterImport(scriptConfigurations)
|
||||||
project.service<GradleScriptInputsWatcher>().clearState()
|
project.service<GradleScriptInputsWatcher>().clearState()
|
||||||
}
|
|
||||||
|
|
||||||
private fun addBuildScriptDiagnosticMessage(
|
|
||||||
message: KotlinDslScriptModel.Message,
|
|
||||||
virtualFile: VirtualFile,
|
|
||||||
project: Project
|
|
||||||
) {
|
|
||||||
val notification = NotificationData(
|
|
||||||
KotlinIdeaGradleBundle.message("title.kotlin.build.script"),
|
|
||||||
message.text,
|
|
||||||
when (message.severity) {
|
|
||||||
KotlinDslScriptModel.Severity.WARNING -> NotificationCategory.WARNING
|
|
||||||
KotlinDslScriptModel.Severity.ERROR -> NotificationCategory.ERROR
|
|
||||||
},
|
|
||||||
NotificationSource.PROJECT_SYNC
|
|
||||||
)
|
|
||||||
|
|
||||||
notification.navigatable =
|
|
||||||
LazyNavigatable(
|
|
||||||
virtualFile,
|
|
||||||
project,
|
|
||||||
message.position
|
|
||||||
)
|
|
||||||
|
|
||||||
ExternalSystemNotificationManager.getInstance(project).showNotification(
|
|
||||||
GradleConstants.SYSTEM_ID,
|
|
||||||
notification
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
class LazyNavigatable internal constructor(
|
|
||||||
private val virtualFile: VirtualFile,
|
|
||||||
private val project: Project,
|
|
||||||
val position: KotlinDslScriptModel.Position?
|
|
||||||
) : Navigatable {
|
|
||||||
private val openFileDescriptor: Navigatable by lazy {
|
|
||||||
if (position != null) OpenFileDescriptor(project, virtualFile, position.line, position.column)
|
|
||||||
else OpenFileDescriptor(project, virtualFile, -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun navigate(requestFocus: Boolean) {
|
|
||||||
if (openFileDescriptor.canNavigate()) openFileDescriptor.navigate(requestFocus)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun canNavigate(): Boolean = virtualFile.exists()
|
|
||||||
|
|
||||||
override fun canNavigateToSource(): Boolean = canNavigate()
|
|
||||||
}
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.scripting.gradle.importing
|
||||||
|
|
||||||
|
import com.intellij.build.FilePosition
|
||||||
|
import com.intellij.build.SyncViewManager
|
||||||
|
import com.intellij.build.events.MessageEvent
|
||||||
|
import com.intellij.build.events.impl.FileMessageEventImpl
|
||||||
|
import com.intellij.build.events.impl.MessageEventImpl
|
||||||
|
import com.intellij.openapi.components.service
|
||||||
|
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
|
||||||
|
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemEventDispatcher
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
private const val gradle_build_script_errors_group = "Kotlin Build Script Errors"
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
|
class KotlinGradleDslErrorReporter(
|
||||||
|
project: Project,
|
||||||
|
private val task: ExternalSystemTaskId
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val syncViewManager = project.service<SyncViewManager>()
|
||||||
|
private val buildEventDispatcher = ExternalSystemEventDispatcher(task, syncViewManager)
|
||||||
|
|
||||||
|
fun reportError(
|
||||||
|
scriptFile: File,
|
||||||
|
model: KotlinDslScriptModel
|
||||||
|
) {
|
||||||
|
model.messages.forEach {
|
||||||
|
val severity = when (it.severity) {
|
||||||
|
KotlinDslScriptModel.Severity.WARNING -> MessageEvent.Kind.WARNING
|
||||||
|
KotlinDslScriptModel.Severity.ERROR -> MessageEvent.Kind.ERROR
|
||||||
|
}
|
||||||
|
val position = it.position
|
||||||
|
if (position == null) {
|
||||||
|
buildEventDispatcher.onEvent(
|
||||||
|
task,
|
||||||
|
MessageEventImpl(
|
||||||
|
task,
|
||||||
|
severity,
|
||||||
|
gradle_build_script_errors_group,
|
||||||
|
it.text,
|
||||||
|
it.details
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
buildEventDispatcher.onEvent(
|
||||||
|
task,
|
||||||
|
FileMessageEventImpl(
|
||||||
|
task,
|
||||||
|
severity,
|
||||||
|
gradle_build_script_errors_group,
|
||||||
|
it.text, it.details,
|
||||||
|
// 0-based line numbers
|
||||||
|
FilePosition(scriptFile, position.line - 1, position.column)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("UNUSED_PARAMETER", "unused")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.scripting.gradle.importing
|
||||||
|
|
||||||
|
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class KotlinGradleDslErrorReporter(
|
||||||
|
private val project: Project,
|
||||||
|
private val task: ExternalSystemTaskId
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun reportError(
|
||||||
|
scriptFile: File,
|
||||||
|
model: KotlinDslScriptModel
|
||||||
|
) {
|
||||||
|
// KotlinDslModels aren't imported in 191
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user