Use PluginManagerCore instead of PluginManager
Relates to #KT-35918
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.notification.Notification
|
||||
import com.intellij.notification.NotificationAction
|
||||
import com.intellij.notification.NotificationType
|
||||
@@ -19,7 +19,8 @@ const val NATIVE_DEBUG_ID = "com.intellij.nativeDebug"
|
||||
|
||||
fun suggestNativeDebug(projectPath: String) {
|
||||
if (!PlatformUtils.isIdeaUltimate() ||
|
||||
PluginManager.isPluginInstalled(PluginId.getId(NATIVE_DEBUG_ID))) {
|
||||
PluginManagerCore.isPluginInstalled(PluginId.getId(NATIVE_DEBUG_ID))
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -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 provides debugger for Kotlin/Native",
|
||||
NotificationType.INFORMATION, null
|
||||
).addAction(object : NotificationAction("Install") {
|
||||
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
|
||||
PluginsAdvertiser.installAndEnablePlugins(setOf(NATIVE_DEBUG_ID)) { notification.expire() }
|
||||
}
|
||||
}).notify(project)
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.intellij.execution.Location
|
||||
import com.intellij.execution.actions.ConfigurationFromContext
|
||||
import com.intellij.execution.junit.JUnitConfigurationProducer
|
||||
import com.intellij.execution.testframework.AbstractPatternBasedConfigurationProducer
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.extensions.PluginId.getId
|
||||
import com.intellij.openapi.util.component1
|
||||
import com.intellij.openapi.util.component2
|
||||
@@ -20,7 +20,7 @@ private val isJUnitEnabled by lazy { isPluginEnabled("JUnit") }
|
||||
private val isTestNgEnabled by lazy { isPluginEnabled("TestNG-J") }
|
||||
|
||||
private fun isPluginEnabled(id: String): Boolean {
|
||||
return PluginManager.isPluginInstalled(getId(id)) && !PluginManager.isDisabled(id)
|
||||
return PluginManagerCore.isPluginInstalled(getId(id)) && !PluginManagerCore.isDisabled(id)
|
||||
}
|
||||
|
||||
internal fun ConfigurationFromContext.isJpsJunitConfiguration(): Boolean {
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.vcs
|
||||
|
||||
import com.intellij.BundleBase.replaceMnemonicAmpersand
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
@@ -32,7 +32,7 @@ import javax.swing.JPanel
|
||||
private val BUNCH_PLUGIN_ID = PluginId.getId("org.jetbrains.bunch.tool.idea.plugin")
|
||||
|
||||
private var Project.bunchFileCheckEnabled: Boolean
|
||||
by NotNullableUserDataProperty(Key.create("IS_BUNCH_FILE_CHECK_ENABLED_KOTLIN"), !PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID))
|
||||
by NotNullableUserDataProperty(Key.create("IS_BUNCH_FILE_CHECK_ENABLED_KOTLIN"), !PluginManagerCore.isPluginInstalled(BUNCH_PLUGIN_ID))
|
||||
|
||||
class BunchFileCheckInHandlerFactory : CheckinHandlerFactory() {
|
||||
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler {
|
||||
@@ -43,7 +43,7 @@ class BunchFileCheckInHandlerFactory : CheckinHandlerFactory() {
|
||||
private val project get() = checkInProjectPanel.project
|
||||
|
||||
override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent? {
|
||||
if (PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID)) return null
|
||||
if (PluginManagerCore.isPluginInstalled(BUNCH_PLUGIN_ID)) return null
|
||||
BunchFileUtils.bunchFile(project) ?: return null
|
||||
|
||||
val bunchFilesCheckBox = NonFocusableCheckBox(replaceMnemonicAmpersand("Check &bunch files"))
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.vcs
|
||||
|
||||
import com.intellij.BundleBase.replaceMnemonicAmpersand
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.Messages.NO
|
||||
import com.intellij.openapi.ui.Messages.YES
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.vcs.CheckinProjectPanel
|
||||
import com.intellij.openapi.vcs.changes.CommitContext
|
||||
import com.intellij.openapi.vcs.changes.CommitExecutor
|
||||
import com.intellij.openapi.vcs.checkin.CheckinHandler
|
||||
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory
|
||||
import com.intellij.openapi.vcs.ui.RefreshableOnComponent
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.ui.NonFocusableCheckBox
|
||||
import com.intellij.util.PairConsumer
|
||||
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||
import java.awt.GridLayout
|
||||
import java.io.File
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
|
||||
private val BUNCH_PLUGIN_ID = PluginId.getId("org.jetbrains.bunch.tool.idea.plugin")
|
||||
|
||||
private var Project.bunchFileCheckEnabled: Boolean
|
||||
by NotNullableUserDataProperty(Key.create("IS_BUNCH_FILE_CHECK_ENABLED_KOTLIN"), !PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID))
|
||||
|
||||
class BunchFileCheckInHandlerFactory : CheckinHandlerFactory() {
|
||||
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler {
|
||||
return BunchCheckInHandler(panel)
|
||||
}
|
||||
|
||||
class BunchCheckInHandler(private val checkInProjectPanel: CheckinProjectPanel) : CheckinHandler() {
|
||||
private val project get() = checkInProjectPanel.project
|
||||
|
||||
override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent? {
|
||||
if (PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID)) return null
|
||||
BunchFileUtils.bunchFile(project) ?: return null
|
||||
|
||||
val bunchFilesCheckBox = NonFocusableCheckBox(replaceMnemonicAmpersand("Check &bunch files"))
|
||||
return object : RefreshableOnComponent {
|
||||
override fun getComponent(): JComponent {
|
||||
val panel = JPanel(GridLayout(1, 0))
|
||||
panel.add(bunchFilesCheckBox)
|
||||
return panel
|
||||
}
|
||||
|
||||
override fun refresh() {}
|
||||
override fun saveState() {
|
||||
project.bunchFileCheckEnabled = bunchFilesCheckBox.isSelected
|
||||
}
|
||||
|
||||
override fun restoreState() {
|
||||
bunchFilesCheckBox.isSelected = project.bunchFileCheckEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeCheckin(
|
||||
executor: CommitExecutor?,
|
||||
additionalDataConsumer: PairConsumer<Any, Any>?
|
||||
): ReturnResult {
|
||||
if (!project.bunchFileCheckEnabled) return ReturnResult.COMMIT
|
||||
|
||||
val extensions = BunchFileUtils.bunchExtension(project)?.toSet() ?: return ReturnResult.COMMIT
|
||||
|
||||
val forgottenFiles = HashSet<File>()
|
||||
val commitFiles = checkInProjectPanel.files.filter { it.isFile }.toSet()
|
||||
for (file in commitFiles) {
|
||||
if (file.extension in extensions) continue
|
||||
|
||||
val parent = file.parent ?: continue
|
||||
val name = file.name
|
||||
for (extension in extensions) {
|
||||
val bunchFile = File(parent, "$name.$extension")
|
||||
if (bunchFile !in commitFiles && bunchFile.exists()) {
|
||||
forgottenFiles.add(bunchFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forgottenFiles.isEmpty()) return ReturnResult.COMMIT
|
||||
|
||||
val projectBaseFile = File(project.basePath)
|
||||
var filePaths = forgottenFiles.map { it.relativeTo(projectBaseFile).path }.sorted()
|
||||
if (filePaths.size > 15) {
|
||||
filePaths = filePaths.take(15) + "..."
|
||||
}
|
||||
|
||||
when (Messages.showYesNoCancelDialog(
|
||||
project,
|
||||
"Several bunch files haven't been updated:\n\n${filePaths.joinToString("\n")}\n\nDo you want to review them before commit?",
|
||||
"Forgotten Bunch Files", "Review", "Commit", CommonBundle.getCancelButtonText(), Messages.getWarningIcon()
|
||||
)) {
|
||||
YES -> {
|
||||
return ReturnResult.CLOSE_WINDOW
|
||||
}
|
||||
NO -> return ReturnResult.COMMIT
|
||||
}
|
||||
|
||||
return ReturnResult.CANCEL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object BunchFileUtils {
|
||||
fun bunchFile(project: Project): VirtualFile? {
|
||||
val baseDir = project.baseDir ?: return null
|
||||
return baseDir.findChild(".bunch")
|
||||
}
|
||||
|
||||
fun bunchExtension(project: Project): List<String>? {
|
||||
val bunchFile: VirtualFile = bunchFile(project) ?: return null
|
||||
val file = File(bunchFile.path)
|
||||
if (!file.exists()) return null
|
||||
|
||||
val lines = file.readLines().map { it.trim() }.filter { !it.isEmpty() }
|
||||
if (lines.size <= 1) return null
|
||||
|
||||
return lines.drop(1).map { it.split('_').first() }
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.tools.projectWizard.wizard.service
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.BuildSystemAvailabilityWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
@@ -19,5 +19,5 @@ class IdeaBuildSystemAvailabilityWizardService : BuildSystemAvailabilityWizardSe
|
||||
}
|
||||
|
||||
private fun isPluginEnabled(id: String) =
|
||||
PluginManager.getPlugin(PluginId.getId(id))?.isEnabled == true
|
||||
PluginManagerCore.getPlugin(PluginId.getId(id))?.isEnabled == true
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.tools.projectWizard.wizard.service
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.service.BuildSystemAvailabilityWizardService
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.BuildSystemType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem.isGradle
|
||||
|
||||
class IdeaBuildSystemAvailabilityWizardService : BuildSystemAvailabilityWizardService, IdeaWizardService {
|
||||
override fun isAvailable(buildSystemType: BuildSystemType): Boolean = when {
|
||||
buildSystemType.isGradle -> isPluginEnabled("org.jetbrains.plugins.gradle")
|
||||
buildSystemType == BuildSystemType.Maven -> isPluginEnabled("org.jetbrains.idea.maven")
|
||||
else -> true
|
||||
}
|
||||
|
||||
private fun isPluginEnabled(id: String) =
|
||||
PluginManager.getPlugin(PluginId.getId(id))?.isEnabled == true
|
||||
}
|
||||
@@ -176,7 +176,7 @@ class KotlinPluginUpdater : Disposable {
|
||||
}
|
||||
|
||||
private fun initPluginDescriptor(newVersion: String): IdeaPluginDescriptor {
|
||||
val originalPlugin = PluginManager.getPlugin(KotlinPluginUtil.KOTLIN_PLUGIN_ID)!!
|
||||
val originalPlugin = PluginManagerCore.getPlugin(KotlinPluginUtil.KOTLIN_PLUGIN_ID)!!
|
||||
return PluginNode(KotlinPluginUtil.KOTLIN_PLUGIN_ID).apply {
|
||||
version = newVersion
|
||||
name = originalPlugin.name
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.actions.internal.refactoringTesting
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
@@ -24,7 +24,7 @@ internal fun gitReset(project: Project, projectRoot: VirtualFile) {
|
||||
fun Class<*>.loadMethodOrThrow(name: String, vararg arguments: Class<*>) =
|
||||
getMethodOrNull(name, *arguments) ?: error("${this.name}::$name not loaded")
|
||||
|
||||
val loader = PluginManager.getPlugin(PluginId.getId("Git4Idea"))?.pluginClassLoader ?: error("Git plugin is not found")
|
||||
val loader = PluginManagerCore.getPlugin(PluginId.getId("Git4Idea"))?.pluginClassLoader ?: error("Git plugin is not found")
|
||||
|
||||
val gitCls = loader.loadClassOrThrow("git4idea.commands.Git")
|
||||
val gitLineHandlerCls = loader.loadClassOrThrow("git4idea.commands.GitLineHandler")
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.actions.internal.refactoringTesting
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.gradle.getMethodOrNull
|
||||
|
||||
internal fun <T> lazyPub(initializer: () -> T) = lazy(LazyThreadSafetyMode.PUBLICATION, initializer)
|
||||
|
||||
internal fun gitReset(project: Project, projectRoot: VirtualFile) {
|
||||
|
||||
fun ClassLoader.loadClassOrThrow(name: String) =
|
||||
loadClass(name) ?: error("$name not loaded")
|
||||
|
||||
fun Class<*>.loadMethodOrThrow(name: String, vararg arguments: Class<*>) =
|
||||
getMethodOrNull(name, *arguments) ?: error("${this.name}::$name not loaded")
|
||||
|
||||
val loader = PluginManager.getPlugin(PluginId.getId("Git4Idea"))?.pluginClassLoader ?: error("Git plugin is not found")
|
||||
|
||||
val gitCls = loader.loadClassOrThrow("git4idea.commands.Git")
|
||||
val gitLineHandlerCls = loader.loadClassOrThrow("git4idea.commands.GitLineHandler")
|
||||
val gitCommandCls = loader.loadClassOrThrow("git4idea.commands.GitCommand")
|
||||
val gitCommandResultCls = loader.loadClassOrThrow("git4idea.commands.GitCommandResult")
|
||||
val gitLineHandlerCtor = gitLineHandlerCls.getConstructor(Project::class.java, VirtualFile::class.java, gitCommandCls) ?: error(
|
||||
"git4idea.commands.GitLineHandler::ctor not loaded"
|
||||
)
|
||||
val runCommand = gitCls.loadMethodOrThrow("runCommand", gitLineHandlerCls)
|
||||
val getExitCode = gitCommandResultCls.loadMethodOrThrow("getExitCode")
|
||||
val gitLineHandlerAddParameters = gitLineHandlerCls.loadMethodOrThrow("addParameters", List::class.java)
|
||||
|
||||
val gitCommandReset = gitCommandCls.getField("RESET")?.get(null) ?: error("git4idea.commands.GitCommand.RESET not loaded")
|
||||
|
||||
val resetLineHandler = gitLineHandlerCtor.newInstance(project, projectRoot, gitCommandReset)
|
||||
gitLineHandlerAddParameters.invoke(resetLineHandler, listOf("--hard", "HEAD"))
|
||||
|
||||
val gitService = ServiceManager.getService(gitCls)
|
||||
val runCommandResult = runCommand.invoke(gitService, resetLineHandler)
|
||||
|
||||
val gitResetResultCode = getExitCode.invoke(runCommandResult) as Int
|
||||
if (gitResetResultCode == 0) {
|
||||
VfsUtil.markDirtyAndRefresh(false, true, false, projectRoot)
|
||||
//GitRepositoryManager.getInstance(project).updateRepository(d.getGitRoot())
|
||||
} else {
|
||||
error("Git reset failed")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun edtExecute(crossinline body: () -> Unit) {
|
||||
ApplicationManager.getApplication().invokeAndWait {
|
||||
body()
|
||||
}
|
||||
}
|
||||
|
||||
inline fun readAction(crossinline body: () -> Unit) {
|
||||
ApplicationManager.getApplication().runReadAction {
|
||||
body()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user