Skip to content

Commit

Permalink
[Gradle|Daemon|JVM] patch: create notification to migrate project to …
Browse files Browse the repository at this point in the history
…Daemon Jvm criteria

closes #2882

Issues: IDEA-358562

GitOrigin-RevId: eb7201530f268ad9e89c4643f8d9062eaadb58bb
  • Loading branch information
HackerMadCat authored and intellij-monorepo-bot committed Jan 8, 2025
1 parent a2be41b commit c866044
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<externalProjectDataService implementation="org.jetbrains.kotlin.idea.gradleJava.configuration.kpm.KotlinFragmentDataService"/>

<externalSystemTaskNotificationListener implementation="org.jetbrains.kotlin.idea.gradleJava.scripting.importing.KotlinDslSyncListener"/>
<externalSystemTaskNotificationListener implementation="org.jetbrains.kotlin.idea.gradleJava.toolchain.GradleDaemonToolchainMigrateNotificationListener"/>
<externalSystemTaskNotificationListener implementation="org.jetbrains.kotlin.idea.gradleJava.toolchain.GradleDaemonJvmCriteriaMigrationNotificationListener"/>

<editorNotificationProvider implementation="org.jetbrains.kotlin.idea.gradleJava.scripting.GradleScriptNotificationProvider"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.gradleJava.toolchain

import com.intellij.ide.BrowserUtil
import com.intellij.ide.util.propComponentProperty
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project
import org.jetbrains.plugins.gradle.service.project.GradleNotification
import org.jetbrains.plugins.gradle.service.project.GradleNotificationIdsHolder
import org.jetbrains.plugins.gradle.util.GradleBundle


object GradleDaemonJvmCriteriaMigrationNotification {

private const val DISABLE_DAEMON_TOOLCHAIN_MIGRATION = "GradleDaemonJvmCriteriaMigrationNotification.isNotificationDisabled"

fun show(project: Project, externalProjectPath: String) {
var isNotificationDisabled: Boolean by propComponentProperty(project, DISABLE_DAEMON_TOOLCHAIN_MIGRATION, false)

if (isNotificationDisabled) return

GradleNotification.gradleNotificationGroup.createNotification(
title = GradleBundle.message("gradle.notifications.daemon.toolchain.migration.title", project.name),
content = GradleBundle.message("gradle.notifications.daemon.toolchain.migration.description"),
type = NotificationType.INFORMATION
)
.setDisplayId(GradleNotificationIdsHolder.daemonToolchainMigration)
.addAction(NotificationAction.createSimple(GradleBundle.message("gradle.notifications.daemon.toolchain.migration.info.action.text")) {
BrowserUtil.browse(GradleBundle.message("gradle.notifications.daemon.toolchain.migration.info.url"))
})
.addAction(NotificationAction.createSimpleExpiring(GradleBundle.message("gradle.notifications.daemon.toolchain.migration.accept.action.text")) {
isNotificationDisabled = true
GradleDaemonJvmCriteriaMigrationHelper.migrateToDaemonJvmCriteria(project, externalProjectPath)
})
.addAction(NotificationAction.createSimpleExpiring(GradleBundle.message("gradle.notifications.daemon.toolchain.migration.cancel.action.text")) {
isNotificationDisabled = true
})
.notify(project)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import com.intellij.openapi.util.registry.Registry
import org.jetbrains.plugins.gradle.service.execution.GradleDaemonJvmHelper
import org.jetbrains.plugins.gradle.settings.GradleSettings
import org.jetbrains.plugins.gradle.util.GradleConstants
import java.nio.file.Path

class GradleDaemonToolchainMigrateNotificationListener: ExternalSystemTaskNotificationListener {
class GradleDaemonJvmCriteriaMigrationNotificationListener: ExternalSystemTaskNotificationListener {

override fun onSuccess(projectPath: String, id: ExternalSystemTaskId) {
if (!Registry.`is`("gradle.daemon.jvm.criteria.suggest.migration")) return
if (GradleConstants.SYSTEM_ID.id != id.projectSystemId.id || id.type != ExternalSystemTaskType.RESOLVE_PROJECT) return

if (id.projectSystemId != GradleConstants.SYSTEM_ID) return
if (id.type != ExternalSystemTaskType.RESOLVE_PROJECT) return
val project = id.findProject() ?: return
val projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(projectPath) ?: return

if (!GradleDaemonJvmHelper.isDaemonJvmCriteriaSupported(projectSettings.resolveGradleVersion())) return
if (GradleDaemonJvmHelper.isProjectUsingDaemonJvmCriteria(projectSettings)) return

GradleDaemonToolchainMigrateNotification.show(project, projectPath)
val settings = GradleSettings.getInstance(project)
val projectSettings = settings.getLinkedProjectSettings(projectPath) ?: return
val gradleVersion = projectSettings.resolveGradleVersion()
if (GradleDaemonJvmHelper.isDaemonJvmCriteriaSupported(gradleVersion)) {
if (!GradleDaemonJvmHelper.isProjectUsingDaemonJvmCriteria(Path.of(projectPath), gradleVersion)) {
GradleDaemonJvmCriteriaMigrationNotification.show(project, projectPath)
}
}
}
}

This file was deleted.

0 comments on commit c866044

Please sign in to comment.