From 8dc99d8df125014d5f8ad4fda34379ab24dbe918 Mon Sep 17 00:00:00 2001 From: Vladislav Rassokhin Date: Mon, 24 Jul 2023 16:05:21 +0200 Subject: [PATCH] [jps caches] Replace "JetBrains Internal Authentication" with "Space" plugin (IJI-1252) GitOrigin-RevId: 2f77b3037b862a996c0febf43410e94eba00f790 --- .../client/CompilerCacheServerAuthService.kt | 7 +-- .../cache/client/JpsServerAuthExtension.kt | 62 ++++++++++++++++--- .../messages/JavaCompilerBundle.properties | 10 +-- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/cache/client/CompilerCacheServerAuthService.kt b/java/compiler/impl/src/com/intellij/compiler/cache/client/CompilerCacheServerAuthService.kt index 5a4d553791bd..d8510ee04d7d 100644 --- a/java/compiler/impl/src/com/intellij/compiler/cache/client/CompilerCacheServerAuthService.kt +++ b/java/compiler/impl/src/com/intellij/compiler/cache/client/CompilerCacheServerAuthService.kt @@ -2,11 +2,8 @@ package com.intellij.compiler.cache.client import com.intellij.compiler.cache.client.JpsServerAuthExtension.Companion.getInstance -import com.intellij.compiler.cache.ui.CompilerCacheNotifications -import com.intellij.notification.NotificationType import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.compiler.JavaCompilerBundle import com.intellij.openapi.components.Service import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.thisLogger @@ -23,10 +20,8 @@ class CompilerCacheServerAuthService(private val project: Project, private val s fun getRequestHeaders(force: Boolean): Map { val authExtension = getInstance() if (authExtension == null) { - val message = JavaCompilerBundle.message("notification.content.internal.authentication.plugin.required.for.correct.work") ApplicationManager.getApplication().invokeLater { - CompilerCacheNotifications.ATTENTION.createNotification(JavaCompilerBundle.message("notification.title.jps.caches.downloader"), - message, NotificationType.WARNING).notify(project) + JpsServerAuthExtension.notifyMissingRequiredPlugin(project) } return emptyMap() } diff --git a/java/compiler/impl/src/com/intellij/compiler/cache/client/JpsServerAuthExtension.kt b/java/compiler/impl/src/com/intellij/compiler/cache/client/JpsServerAuthExtension.kt index 98b7028d26ff..26a2274ddca4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/cache/client/JpsServerAuthExtension.kt +++ b/java/compiler/impl/src/com/intellij/compiler/cache/client/JpsServerAuthExtension.kt @@ -2,14 +2,21 @@ package com.intellij.compiler.cache.client import com.intellij.compiler.cache.ui.CompilerCacheNotifications -import com.intellij.notification.NotificationListener +import com.intellij.ide.plugins.IdeaPluginDescriptorImpl +import com.intellij.ide.plugins.PluginEnabler +import com.intellij.ide.plugins.PluginManagerCore +import com.intellij.notification.Notification +import com.intellij.notification.NotificationAction import com.intellij.notification.NotificationType import com.intellij.openapi.Disposable +import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.application.EDT import com.intellij.openapi.compiler.JavaCompilerBundle import com.intellij.openapi.diagnostic.thisLogger import com.intellij.openapi.extensions.ExtensionPointName +import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.project.Project +import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.installAndEnable import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Key import kotlinx.coroutines.Dispatchers @@ -45,6 +52,27 @@ interface JpsServerAuthExtension { fun getInstance(): JpsServerAuthExtension? = EP_NAME.extensionList.firstOrNull() + private val SPACE_PLUGIN_ID = PluginId.getId("com.jetbrains.space") + + private val INSTALL_PLUGIN_ACTION by lazy { + object : NotificationAction(JavaCompilerBundle.messagePointer("notification.action.install.space.plugin")) { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + installAndEnable(e.project, setOf(SPACE_PLUGIN_ID)) { + notification.expire() + } + } + } + } + + private val ENABLE_PLUGIN_ACTION by lazy { + object : NotificationAction(JavaCompilerBundle.messagePointer("notification.action.enable.space.plugin")) { + override fun actionPerformed(e: AnActionEvent, notification: Notification) { + PluginEnabler.getInstance().enableById(setOf(SPACE_PLUGIN_ID)) + notification.expire() + } + } + } + suspend fun checkAuthenticated(parentDisposable: Disposable, project: Project, onAuthCompleted: Runnable) { val disposable = Disposer.newDisposable() Disposer.register(parentDisposable, disposable) @@ -54,24 +82,38 @@ interface JpsServerAuthExtension { if (userData == null) { project.putUserData(NOTIFICATION_SHOWN_KEY, true) withContext(Dispatchers.EDT) { - CompilerCacheNotifications.ATTENTION - .createNotification(JavaCompilerBundle.message("notification.title.jps.caches.downloader"), - JavaCompilerBundle.message( - "notification.content.internal.authentication.plugin.required.for.correct.work"), - NotificationType.WARNING) - .setListener(NotificationListener.URL_OPENING_LISTENER) - .notify(project) + notifyMissingRequiredPlugin(project) } } - thisLogger().warn("JetBrains Internal Authentication plugin is required for the correct work. Please enable it.") + thisLogger().warn("Space plugin is required for the correct work. Please enable it.") return } withContext(Dispatchers.IO) { - authExtension.checkAuthenticated("Jps Caches Downloader", disposable, Runnable { + authExtension.checkAuthenticated(JavaCompilerBundle.message("notification.title.jps.caches.downloader"), disposable, Runnable { Disposer.dispose(disposable) onAuthCompleted.run() }) } } + + internal fun notifyMissingRequiredPlugin(project: Project) { + val plugin = PluginManagerCore.getPlugin(SPACE_PLUGIN_ID) + val action = when { + plugin == null -> INSTALL_PLUGIN_ACTION + plugin is IdeaPluginDescriptorImpl && plugin.isDeleted -> null + !plugin.isEnabled -> ENABLE_PLUGIN_ACTION + else -> return + } + CompilerCacheNotifications.ATTENTION + .createNotification(JavaCompilerBundle.message("notification.title.jps.caches.downloader"), + JavaCompilerBundle.message("notification.content.space.plugin.required.for.correct.work"), + NotificationType.WARNING) + .apply { + if (action != null) { + addAction(action) + } + } + .notify(project) + } } } \ No newline at end of file diff --git a/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties b/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties index 52d74b0756f4..2723abc8528c 100644 --- a/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties +++ b/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties @@ -336,11 +336,13 @@ notification.group.compiler=Build finished compiler.cache.description=Compiler Cache compiler.cache.option.force.update=Force update caches compiler.cache.option.disable.update=Disable cache download -compiler.cache.option.cleanup.asynchronously=Cleanup aynchronously +compiler.cache.option.cleanup.asynchronously=Cleanup asynchronously compiler.cache.option.max.download.time=Maximum duration of caches download: -compiler.cache.option.max.download.time.units= mins -notification.title.jps.caches.downloader=Jps caches downloader -notification.content.internal.authentication.plugin.required.for.correct.work=JetBrains Internal Authentication is required for the correct work of JPS Caches +compiler.cache.option.max.download.time.units= minutes +notification.title.jps.caches.downloader=JPS caches downloader +notification.content.space.plugin.required.for.correct.work=Space plugin is required for the correct work of JPS Caches +notification.action.install.space.plugin=Install Space plugin +notification.action.enable.space.plugin=Enable Space plugin notification.title.git.crlf.config=Wrong Git line-endings configuration notification.content.git.crlf.config=To have working compiler caches you need to execute {0} command and force checkout the project class.can.be.record.suppress.conversion.if.annotated.description=Specify class names or package wildcards like com.example.* \ No newline at end of file