From d7a48e72291c0469759fd0566128ab376c9991b4 Mon Sep 17 00:00:00 2001 From: Kirill Shmakov Date: Fri, 11 Oct 2019 14:33:43 +0300 Subject: [PATCH] Add Native Debug plugin advertising --- .../KotlinMPPGradleProjectResolver.kt | 11 +++++- .../idea/configuration/kotlinResolverUtil.kt | 37 +++++++++++++++++++ .../configuration/kotlinResolverUtil.kt.183 | 8 ++++ .../configuration/kotlinResolverUtil.kt.191 | 8 ++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt create mode 100644 idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.183 create mode 100644 idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.191 diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt index a5dc3832402..75defe78554 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinMPPGradleProjectResolver.kt @@ -79,9 +79,16 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() { } override fun populateModuleContentRoots(gradleModule: IdeaModule, ideModule: DataNode) { - if (resolverCtx.getExtraProject(gradleModule, KotlinMPPGradleModel::class.java) == null) { + val mppModel = resolverCtx.getExtraProject(gradleModule, KotlinMPPGradleModel::class.java) + if (mppModel == null) { return super.populateModuleContentRoots(gradleModule, ideModule) + } else { + if (!nativeDebugAdvertised && mppModel.kotlinNativeHome.isNotEmpty()) { + nativeDebugAdvertised = true + suggestNativeDebug(resolverCtx.projectPath) + } } + populateContentRoots(gradleModule, ideModule, resolverCtx) } @@ -216,6 +223,8 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() { Key.create /* module ids*/>>("gradleMPPArtifactsMap") val proxyObjectCloningCache = WeakHashMap() + private var nativeDebugAdvertised = false + fun initializeModuleData( gradleModule: IdeaModule, mainModuleNode: DataNode, diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt new file mode 100644 index 00000000000..706a8a20519 --- /dev/null +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2019 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.configuration + +import com.intellij.ide.plugins.PluginManager +import com.intellij.notification.Notification +import com.intellij.notification.NotificationAction +import com.intellij.notification.NotificationType +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.extensions.PluginId +import com.intellij.openapi.project.ProjectManager +import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser +import com.intellij.util.PlatformUtils + +const val NATIVE_DEBUG_ID = "com.intellij.nativeDebug" + +fun suggestNativeDebug(projectPath: String) { + if (!PlatformUtils.isIdeaUltimate() || + PluginManager.isPluginInstalled(PluginId.getId(NATIVE_DEBUG_ID))) { + return + } + + val project = ProjectManager.getInstance().openProjects.firstOrNull { it.basePath == projectPath } ?: return + + PluginsAdvertiser.NOTIFICATION_GROUP.createNotification( + PluginsAdvertiser.DISPLAY_ID, + "Native Debug plugin allows debug from Idea", + NotificationType.INFORMATION, null + ).addAction(object : NotificationAction("Install") { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + PluginsAdvertiser.installAndEnablePlugins(setOf(NATIVE_DEBUG_ID)) { notification.expire() } + } + }).notify(project) +} \ No newline at end of file diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.183 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.183 new file mode 100644 index 00000000000..acf58a54edb --- /dev/null +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.183 @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2019 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.configuration + +fun suggestNativeDebug(projectPath: String) {} \ No newline at end of file diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.191 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.191 new file mode 100644 index 00000000000..acf58a54edb --- /dev/null +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/kotlinResolverUtil.kt.191 @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2019 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.configuration + +fun suggestNativeDebug(projectPath: String) {} \ No newline at end of file