[jps caches] Replace "JetBrains Internal Authentication" with "Space" plugin (IJI-1252)

GitOrigin-RevId: 2f77b3037b862a996c0febf43410e94eba00f790
This commit is contained in:
Vladislav Rassokhin
2023-07-24 16:05:21 +02:00
committed by intellij-monorepo-bot
parent cf3dd94f78
commit 8dc99d8df1
3 changed files with 59 additions and 20 deletions

View File

@@ -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<String, String> {
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()
}

View File

@@ -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)
}
}
}

View File

@@ -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=<a href="https://plugins.jetbrains.com/plugin/14567-jetbrains-internal-authentication">JetBrains Internal Authentication</a> 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 <code>{0}</code> command and force checkout the project
class.can.be.record.suppress.conversion.if.annotated.description=Specify class names or package wildcards like <code>com.example.*</code>