From 74800304af7d3bbc51452b50060a93c40c03ce97 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 11 Sep 2024 09:07:38 +0200 Subject: [PATCH 01/11] working when opening --- .../jdks/PluginUpdateCheckerService.java | 79 +++++++++++++++++++ .../src/main/resources/META-INF/plugin.xml | 7 ++ 2 files changed, 86 insertions(+) create mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java new file mode 100644 index 00000000..9373f66e --- /dev/null +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -0,0 +1,79 @@ +/* + * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.gradle.jdks; + +import com.intellij.externalDependencies.DependencyOnPlugin; +import com.intellij.externalDependencies.ExternalDependenciesManager; +import com.intellij.ide.plugins.IdeaPluginDescriptor; +import com.intellij.ide.plugins.PluginManagerConfigurable; +import com.intellij.ide.plugins.PluginManagerCore; +import com.intellij.notification.NotificationGroupManager; +import com.intellij.notification.NotificationType; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.extensions.PluginId; +import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectUtil; +import com.intellij.openapi.startup.ProjectActivity; +import com.intellij.util.text.VersionComparatorUtil; +import java.util.Optional; +import kotlin.Unit; +import kotlin.coroutines.Continuation; +import org.jetbrains.annotations.NotNull; + +public final class PluginUpdateCheckerService implements ProjectActivity { + + @Override + public Object execute(@NotNull Project project, @NotNull Continuation continuation) { + PluginId pluginId = PluginId.getId("palantir-gradle-jdks"); + IdeaPluginDescriptor pluginDescriptor = PluginManagerCore.getPlugin(pluginId); + if (pluginDescriptor == null) { + return continuation; + } + Optional maybeMinVersion = + ExternalDependenciesManager.getInstance(project).getDependencies(DependencyOnPlugin.class).stream() + .filter(dependencyOnPlugin -> + dependencyOnPlugin.getPluginId().equals(pluginId.getIdString())) + .map(DependencyOnPlugin::getMinVersion) + .filter(version -> Optional.ofNullable(version).isPresent()) + .max((d1, d2) -> VersionComparatorUtil.compare(d1, d2)); + boolean isPluginUpToDate = maybeMinVersion + .map(minVersion -> VersionComparatorUtil.compare(pluginDescriptor.getVersion(), minVersion) > 0) + .orElse(true); + + if (!isPluginUpToDate) { + NotificationGroupManager.getInstance() + .getNotificationGroup("Update Palantir plugins") + .createNotification( + "Update palantir gradle JDK intellij plugin", + String.format( + "Project requires a version of palantir-gradle-jdks higher than %s. " + + "Please update the Intellij plugin in the Settings window.", + maybeMinVersion.get()), + NotificationType.ERROR) + .notify(project); + ApplicationManager.getApplication().invokeLater(() -> { + ShowSettingsUtil.getInstance() + .showSettingsDialog( + ProjectUtil.currentOrDefaultProject(project), + PluginManagerConfigurable.class, + configurable -> configurable.showPluginConfigurable(project, pluginDescriptor)); + }); + } + return continuation; + } +} diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index c7b153c8..38fde04b 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -12,5 +12,12 @@ + + + + + From 45e0af3da0261403cc5d3c4c55f3a7790538b8a2 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 11 Sep 2024 14:24:21 +0200 Subject: [PATCH 02/11] checkplugin as service --- ...xternalSystemTaskNotificationListener.java | 8 ++++- .../jdks/PluginUpdateCheckerService.java | 30 +++++++++++-------- .../src/main/resources/META-INF/plugin.xml | 4 --- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksExternalSystemTaskNotificationListener.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksExternalSystemTaskNotificationListener.java index 3bbf5410..5a5a9547 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksExternalSystemTaskNotificationListener.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksExternalSystemTaskNotificationListener.java @@ -20,6 +20,7 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationEvent; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; +import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -30,7 +31,12 @@ public void onStart(@NotNull ExternalSystemTaskId id, String _workingDir) { if (id.getProjectSystemId().equals(GradleConstants.SYSTEM_ID) && (id.getType() == ExternalSystemTaskType.RESOLVE_PROJECT || id.getType() == ExternalSystemTaskType.EXECUTE_TASK)) { - id.findProject().getService(GradleJdksProjectService.class).maybeSetupGradleJdks(); + Project project = id.findProject(); + if (project == null) { + return; + } + project.getService(PluginUpdateCheckerService.class).checkPluginVersion(); + project.getService(GradleJdksProjectService.class).maybeSetupGradleJdks(); } } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index 9373f66e..7edefb5b 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -24,25 +24,31 @@ import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.components.Service; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; -import com.intellij.openapi.startup.ProjectActivity; import com.intellij.util.text.VersionComparatorUtil; import java.util.Optional; -import kotlin.Unit; -import kotlin.coroutines.Continuation; -import org.jetbrains.annotations.NotNull; -public final class PluginUpdateCheckerService implements ProjectActivity { +@Service(Service.Level.PROJECT) +public final class PluginUpdateCheckerService { - @Override - public Object execute(@NotNull Project project, @NotNull Continuation continuation) { + private final Logger logger = Logger.getInstance(PluginUpdateCheckerService.class); + private final Project project; + + public PluginUpdateCheckerService(Project project) { + this.project = project; + } + + public void checkPluginVersion() { PluginId pluginId = PluginId.getId("palantir-gradle-jdks"); IdeaPluginDescriptor pluginDescriptor = PluginManagerCore.getPlugin(pluginId); if (pluginDescriptor == null) { - return continuation; + logger.info("Plugin " + pluginId + " not found"); + return; } Optional maybeMinVersion = ExternalDependenciesManager.getInstance(project).getDependencies(DependencyOnPlugin.class).stream() @@ -50,7 +56,7 @@ public Object execute(@NotNull Project project, @NotNull Continuation Optional.ofNullable(version).isPresent()) - .max((d1, d2) -> VersionComparatorUtil.compare(d1, d2)); + .max(VersionComparatorUtil::compare); boolean isPluginUpToDate = maybeMinVersion .map(minVersion -> VersionComparatorUtil.compare(pluginDescriptor.getVersion(), minVersion) > 0) .orElse(true); @@ -66,14 +72,14 @@ public Object execute(@NotNull Project project, @NotNull Continuation { + Runnable runnable = () -> { ShowSettingsUtil.getInstance() .showSettingsDialog( ProjectUtil.currentOrDefaultProject(project), PluginManagerConfigurable.class, configurable -> configurable.showPluginConfigurable(project, pluginDescriptor)); - }); + }; + ApplicationManager.getApplication().invokeLater(runnable); } - return continuation; } } diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index 38fde04b..ebf3874a 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -16,8 +16,4 @@ displayType="BALLOON" key="notification.group.gradleJdkSetup.plugins"/> - - - - From f96bac64728a3c71c9d3c049c0284ff85894cb6d Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 11 Sep 2024 15:07:20 +0200 Subject: [PATCH 03/11] update gradle jdks --- .../palantir/gradle/jdks/PluginUpdateCheckerService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index 7edefb5b..68537079 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -31,6 +31,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.util.text.VersionComparatorUtil; +import java.util.List; import java.util.Optional; @Service(Service.Level.PROJECT) @@ -65,10 +66,9 @@ public void checkPluginVersion() { NotificationGroupManager.getInstance() .getNotificationGroup("Update Palantir plugins") .createNotification( - "Update palantir gradle JDK intellij plugin", + "Update palantir-gradle-jdks plugin", String.format( - "Project requires a version of palantir-gradle-jdks higher than %s. " - + "Please update the Intellij plugin in the Settings window.", + "Please update the plugin in the Settings window to a version higher than '%s'", maybeMinVersion.get()), NotificationType.ERROR) .notify(project); @@ -77,7 +77,8 @@ public void checkPluginVersion() { .showSettingsDialog( ProjectUtil.currentOrDefaultProject(project), PluginManagerConfigurable.class, - configurable -> configurable.showPluginConfigurable(project, pluginDescriptor)); + _configurable -> + PluginManagerConfigurable.showPluginConfigurable(project, List.of(pluginId))); }; ApplicationManager.getApplication().invokeLater(runnable); } From 715146e5fb67eaf8b07dffec0ad67279fd045272 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 11 Sep 2024 15:23:14 +0000 Subject: [PATCH 04/11] Add generated changelog entries --- changelog/@unreleased/pr-410.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-410.v2.yml diff --git a/changelog/@unreleased/pr-410.v2.yml b/changelog/@unreleased/pr-410.v2.yml new file mode 100644 index 00000000..954ee529 --- /dev/null +++ b/changelog/@unreleased/pr-410.v2.yml @@ -0,0 +1,6 @@ +type: improvement +improvement: + description: '[Intellij plugin] Prompt user to update plugin when installed version + is lower than minVersion' + links: + - https://github.com/palantir/gradle-jdks/pull/410 From 7fde2aec2e7e7396dffd83e4db39a89107010651 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 11 Sep 2024 17:23:51 +0200 Subject: [PATCH 05/11] showPlugin --- .../palantir/gradle/jdks/PluginUpdateCheckerService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index 68537079..fb3543b8 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -31,8 +31,8 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.util.text.VersionComparatorUtil; -import java.util.List; import java.util.Optional; +import java.util.Set; @Service(Service.Level.PROJECT) public final class PluginUpdateCheckerService { @@ -77,8 +77,8 @@ public void checkPluginVersion() { .showSettingsDialog( ProjectUtil.currentOrDefaultProject(project), PluginManagerConfigurable.class, - _configurable -> - PluginManagerConfigurable.showPluginConfigurable(project, List.of(pluginId))); + _configurable -> PluginManagerConfigurable.showPluginConfigurableAndEnable( + project, Set.of(pluginDescriptor))); }; ApplicationManager.getApplication().invokeLater(runnable); } From 6bc3b5ac0c30c10d9a6c2afc293f086b931a2b39 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 12 Sep 2024 12:58:19 +0200 Subject: [PATCH 06/11] fixes --- .../jdks/PluginUpdateCheckerService.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index fb3543b8..8b5edbb3 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -19,17 +19,15 @@ import com.intellij.externalDependencies.DependencyOnPlugin; import com.intellij.externalDependencies.ExternalDependenciesManager; import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.ide.plugins.PluginManagerConfigurable; import com.intellij.ide.plugins.PluginManagerCore; +import com.intellij.notification.Notification; import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; -import com.intellij.openapi.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectUtil; +import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser; import com.intellij.util.text.VersionComparatorUtil; import java.util.Optional; import java.util.Set; @@ -37,6 +35,7 @@ @Service(Service.Level.PROJECT) public final class PluginUpdateCheckerService { + private static final String PLUGIN_ID = "palantir-gradle-jdks" private final Logger logger = Logger.getInstance(PluginUpdateCheckerService.class); private final Project project; @@ -45,7 +44,7 @@ public PluginUpdateCheckerService(Project project) { } public void checkPluginVersion() { - PluginId pluginId = PluginId.getId("palantir-gradle-jdks"); + PluginId pluginId = PluginId.getId(PLUGIN_ID); IdeaPluginDescriptor pluginDescriptor = PluginManagerCore.getPlugin(pluginId); if (pluginDescriptor == null) { logger.info("Plugin " + pluginId + " not found"); @@ -63,24 +62,16 @@ public void checkPluginVersion() { .orElse(true); if (!isPluginUpToDate) { - NotificationGroupManager.getInstance() + Notification notification = NotificationGroupManager.getInstance() .getNotificationGroup("Update Palantir plugins") .createNotification( "Update palantir-gradle-jdks plugin", String.format( "Please update the plugin in the Settings window to a version higher than '%s'", maybeMinVersion.get()), - NotificationType.ERROR) - .notify(project); - Runnable runnable = () -> { - ShowSettingsUtil.getInstance() - .showSettingsDialog( - ProjectUtil.currentOrDefaultProject(project), - PluginManagerConfigurable.class, - _configurable -> PluginManagerConfigurable.showPluginConfigurableAndEnable( - project, Set.of(pluginDescriptor))); - }; - ApplicationManager.getApplication().invokeLater(runnable); + NotificationType.ERROR); + notification.notify(project); + PluginsAdvertiser.installAndEnablePlugins(Set.of(PLUGIN_ID), notification::expire); } } } From b0235364e3a4192303733b83ffbf9debbdd4508f Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 12 Sep 2024 13:41:29 +0200 Subject: [PATCH 07/11] compile --- .../com/palantir/gradle/jdks/PluginUpdateCheckerService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index 8b5edbb3..d74dd4ec 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -35,7 +35,7 @@ @Service(Service.Level.PROJECT) public final class PluginUpdateCheckerService { - private static final String PLUGIN_ID = "palantir-gradle-jdks" + private static final String PLUGIN_ID = "palantir-gradle-jdks"; private final Logger logger = Logger.getInstance(PluginUpdateCheckerService.class); private final Project project; From 4cc93f6fb87442d1ff847cac70a3ea1e52594e35 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 12 Sep 2024 14:34:15 +0200 Subject: [PATCH 08/11] change order --- .../jdks/PluginUpdateCheckerService.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index d74dd4ec..9ff9629e 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -60,18 +60,18 @@ public void checkPluginVersion() { boolean isPluginUpToDate = maybeMinVersion .map(minVersion -> VersionComparatorUtil.compare(pluginDescriptor.getVersion(), minVersion) > 0) .orElse(true); - - if (!isPluginUpToDate) { - Notification notification = NotificationGroupManager.getInstance() - .getNotificationGroup("Update Palantir plugins") - .createNotification( - "Update palantir-gradle-jdks plugin", - String.format( - "Please update the plugin in the Settings window to a version higher than '%s'", - maybeMinVersion.get()), - NotificationType.ERROR); - notification.notify(project); - PluginsAdvertiser.installAndEnablePlugins(Set.of(PLUGIN_ID), notification::expire); + if (isPluginUpToDate) { + return; } + Notification notification = NotificationGroupManager.getInstance() + .getNotificationGroup("Update Palantir plugins") + .createNotification( + "Update palantir-gradle-jdks plugin", + String.format( + "Please update the plugin in the Settings window to a version higher than '%s'", + maybeMinVersion.get()), + NotificationType.ERROR); + notification.notify(project); + PluginsAdvertiser.installAndEnablePlugins(Set.of(PLUGIN_ID), notification::expire); } } From 52864999658eb82e5805c14486f3945c566db006 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Fri, 13 Sep 2024 15:51:11 +0200 Subject: [PATCH 09/11] can update version --- gradle-jdks/build.gradle | 1 + .../jdks/PalantirGradleJdksIdeaPlugin.java | 2 +- .../jdks/IntellijPluginCheckerTest.java | 56 +++++++++++++++++++ idea-plugin/build.gradle | 1 + .../jdks/PluginUpdateCheckerService.java | 48 ++++++++++++++++ versions.lock | 3 +- versions.props | 1 + 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java diff --git a/gradle-jdks/build.gradle b/gradle-jdks/build.gradle index ec104262..f92c7ed3 100644 --- a/gradle-jdks/build.gradle +++ b/gradle-jdks/build.gradle @@ -35,6 +35,7 @@ dependencies { testImplementation gradleTestKit() testImplementation project(':gradle-jdks-settings') testImplementation project(':gradle-jdks-test-common') + testImplementation 'com.google.code.gson:gson' testImplementation 'com.netflix.nebula:nebula-test' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.assertj:assertj-core' diff --git a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/PalantirGradleJdksIdeaPlugin.java b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/PalantirGradleJdksIdeaPlugin.java index 838887cc..2d228d43 100644 --- a/gradle-jdks/src/main/java/com/palantir/gradle/jdks/PalantirGradleJdksIdeaPlugin.java +++ b/gradle-jdks/src/main/java/com/palantir/gradle/jdks/PalantirGradleJdksIdeaPlugin.java @@ -25,7 +25,7 @@ public class PalantirGradleJdksIdeaPlugin implements Plugin { private static final Logger logger = Logging.getLogger(ToolchainsPlugin.class); - private static final String MIN_IDEA_PLUGIN_VERSION = "0.44.0"; + protected static final String MIN_IDEA_PLUGIN_VERSION = "0.44.0"; @Override public final void apply(Project rootProject) { diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java new file mode 100644 index 00000000..43579100 --- /dev/null +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java @@ -0,0 +1,56 @@ +/* + * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.gradle.jdks; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.junit.jupiter.api.Test; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class IntellijPluginCheckerTest { + + @Test + public void minimum_version_intellij_plugin_exists() + throws IOException, ParserConfigurationException, SAXException { + URL url = new URL("https://plugins.jetbrains.com/plugins/list?pluginId=24776"); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + assertThat(conn.getResponseCode()) + .isEqualTo(HttpURLConnection.HTTP_OK) + .describedAs("Failed to query plugin version", conn.getResponseCode()); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(conn.getInputStream()); + document.getDocumentElement().normalize(); + NodeList versionList = document.getElementsByTagName("version"); + assertThat(versionList.getLength()).isGreaterThan(0); + String version = versionList.item(0).getTextContent(); + assertThat(version) + .isGreaterThanOrEqualTo(PalantirGradleJdksIdeaPlugin.MIN_IDEA_PLUGIN_VERSION) + .describedAs( + "If this test fails, then the minimum required Intellij plugin version is not yet published."); + } +} diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index 608a37c8..b8521102 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -18,6 +18,7 @@ dependencies { implementation project(':gradle-jdks-setup-common') implementation project(':gradle-jdks-enablement') + implementation 'com.github.ben-manes.caffeine:caffeine' testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index 9ff9629e..b6b8e690 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -23,14 +23,26 @@ import com.intellij.notification.Notification; import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; +import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.application.PermanentInstallationID; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser; +import com.intellij.openapi.util.JDOMUtil; +import com.intellij.openapi.util.SystemInfo; +import com.intellij.util.io.HttpRequests; +import com.intellij.util.io.HttpRequests.RequestProcessor; import com.intellij.util.text.VersionComparatorUtil; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.Set; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jetbrains.annotations.NotNull; @Service(Service.Level.PROJECT) public final class PluginUpdateCheckerService { @@ -63,6 +75,7 @@ public void checkPluginVersion() { if (isPluginUpToDate) { return; } + Notification notification = NotificationGroupManager.getInstance() .getNotificationGroup("Update Palantir plugins") .createNotification( @@ -74,4 +87,39 @@ public void checkPluginVersion() { notification.notify(project); PluginsAdvertiser.installAndEnablePlugins(Set.of(PLUGIN_ID), notification::expire); } + + private static boolean canUpdateVersion(PluginId pluginId, String minimumExpectedVersion) throws IOException { + String buildNumber = ApplicationInfo.getInstance().getApiVersion(); + String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, StandardCharsets.UTF_8); + String uid = PermanentInstallationID.get(); + String pluginIdStr = pluginId.getIdString(); + String url = String.format( + "https://plugins.jetbrains.com/plugins/list?pluginId=%s&build=%s&pluginVersion=%s&os=%s&uuid=%s", + buildNumber, buildNumber, pluginIdStr, os, uid); + + Element responseDoc = HttpRequests.request(url).connect(new RequestProcessor() { + @Override + public Element process(@NotNull HttpRequests.Request request) throws IOException { + try { + return JDOMUtil.load(request.getInputStream()); + } catch (JDOMException e) { + throw new RuntimeException(e); + } + } + }); + + // No plugin version compatible with current IDEA build; don't try updating + if (!responseDoc.getName().equals("plugin-repository") + || responseDoc.getChildren().isEmpty()) { + return false; + } + + Optional latestVersion = Optional.ofNullable(responseDoc.getChild("category")) + .map(element -> element.getChild("idea-plugin")) + .map(element -> element.getChild("version")) + .map(Element::getText); + return latestVersion + .map(version -> VersionComparatorUtil.compare(version, minimumExpectedVersion) >= 0) + .orElse(false); + } } diff --git a/versions.lock b/versions.lock index 7ae110f6..0528281d 100644 --- a/versions.lock +++ b/versions.lock @@ -5,7 +5,7 @@ com.fasterxml.jackson.core:jackson-core:2.15.3 (1 constraints: 8b123e21) com.fasterxml.jackson.core:jackson-databind:2.15.3 (1 constraints: 3d05413b) com.github.ben-manes.caffeine:caffeine:3.1.8 (2 constraints: d216c42c) com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 1d0fb186) -com.google.errorprone:error_prone_annotations:2.28.0 (3 constraints: ae1f4750) +com.google.errorprone:error_prone_annotations:2.28.0 (4 constraints: 092bf08b) com.google.guava:failureaccess:1.0.2 (2 constraints: f2152a13) com.google.guava:guava:33.3.0-jre (5 constraints: 2e54389c) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) @@ -59,6 +59,7 @@ org.slf4j:slf4j-api:1.7.36 (4 constraints: 4b4a7558) [Test dependencies] cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24) +com.google.code.gson:gson:2.11.0 (1 constraints: 3605323b) com.netflix.nebula:nebula-test:10.6.1 (1 constraints: 3a053a3b) junit:junit:4.13.2 (1 constraints: 1b0e1d4c) net.bytebuddy:byte-buddy:1.15.0 (2 constraints: c516c250) diff --git a/versions.props b/versions.props index 3e9f3a7a..61c3064d 100644 --- a/versions.props +++ b/versions.props @@ -13,6 +13,7 @@ org.apache.commons:commons-compress = 1.27.1 com.palantir.gradle.auto-parallelizable:* = 1.4.0 org.ow2.asm:asm = 9.7 com.palantir.gradle.failure-reports:* = 1.9.0 +com.google.code.gson:gson = 2.11.0 # dependency-upgrader:OFF com.palantir.baseline:* = 5.53.0 From 9913e151f864ce91bf1dd03901fe7d0bcf5fcd50 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Fri, 13 Sep 2024 15:54:37 +0200 Subject: [PATCH 10/11] add test that checks intellij min version existance --- gradle-jdks/build.gradle | 1 - idea-plugin/build.gradle | 3 +- .../gradle/jdks/GradleJdksProjectService.java | 2 + .../jdks/PluginUpdateCheckerService.java | 49 +------------------ versions.lock | 3 +- versions.props | 1 - 6 files changed, 5 insertions(+), 54 deletions(-) diff --git a/gradle-jdks/build.gradle b/gradle-jdks/build.gradle index f92c7ed3..ec104262 100644 --- a/gradle-jdks/build.gradle +++ b/gradle-jdks/build.gradle @@ -35,7 +35,6 @@ dependencies { testImplementation gradleTestKit() testImplementation project(':gradle-jdks-settings') testImplementation project(':gradle-jdks-test-common') - testImplementation 'com.google.code.gson:gson' testImplementation 'com.netflix.nebula:nebula-test' testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.assertj:assertj-core' diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index b8521102..81fd581e 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -17,8 +17,7 @@ patchPluginXml { dependencies { implementation project(':gradle-jdks-setup-common') implementation project(':gradle-jdks-enablement') - - implementation 'com.github.ben-manes.caffeine:caffeine' + testImplementation 'org.assertj:assertj-core' testImplementation 'org.junit.jupiter:junit-jupiter' } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksProjectService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksProjectService.java index cba27ccf..1cdb9914 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksProjectService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksProjectService.java @@ -36,6 +36,7 @@ import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.platform.ide.progress.TaskCancellation; import com.intellij.platform.ide.progress.TasksKt; import com.intellij.platform.util.progress.StepsKt; import com.intellij.ui.content.Content; @@ -111,6 +112,7 @@ public void maybeSetupGradleJdks() { TasksKt.withBackgroundProgress( project, "Gradle JDK Setup", + TaskCancellation.nonCancellable(), (_coroutineScope, continuation) -> { StepsKt.withProgressText( "`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java index b6b8e690..f661eccb 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/PluginUpdateCheckerService.java @@ -23,31 +23,20 @@ import com.intellij.notification.Notification; import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; -import com.intellij.openapi.application.ApplicationInfo; -import com.intellij.openapi.application.PermanentInstallationID; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.PluginsAdvertiser; -import com.intellij.openapi.util.JDOMUtil; -import com.intellij.openapi.util.SystemInfo; -import com.intellij.util.io.HttpRequests; -import com.intellij.util.io.HttpRequests.RequestProcessor; import com.intellij.util.text.VersionComparatorUtil; -import java.io.IOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.Set; -import org.jdom.Element; -import org.jdom.JDOMException; -import org.jetbrains.annotations.NotNull; @Service(Service.Level.PROJECT) public final class PluginUpdateCheckerService { private static final String PLUGIN_ID = "palantir-gradle-jdks"; + private final Logger logger = Logger.getInstance(PluginUpdateCheckerService.class); private final Project project; @@ -75,7 +64,6 @@ public void checkPluginVersion() { if (isPluginUpToDate) { return; } - Notification notification = NotificationGroupManager.getInstance() .getNotificationGroup("Update Palantir plugins") .createNotification( @@ -87,39 +75,4 @@ public void checkPluginVersion() { notification.notify(project); PluginsAdvertiser.installAndEnablePlugins(Set.of(PLUGIN_ID), notification::expire); } - - private static boolean canUpdateVersion(PluginId pluginId, String minimumExpectedVersion) throws IOException { - String buildNumber = ApplicationInfo.getInstance().getApiVersion(); - String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, StandardCharsets.UTF_8); - String uid = PermanentInstallationID.get(); - String pluginIdStr = pluginId.getIdString(); - String url = String.format( - "https://plugins.jetbrains.com/plugins/list?pluginId=%s&build=%s&pluginVersion=%s&os=%s&uuid=%s", - buildNumber, buildNumber, pluginIdStr, os, uid); - - Element responseDoc = HttpRequests.request(url).connect(new RequestProcessor() { - @Override - public Element process(@NotNull HttpRequests.Request request) throws IOException { - try { - return JDOMUtil.load(request.getInputStream()); - } catch (JDOMException e) { - throw new RuntimeException(e); - } - } - }); - - // No plugin version compatible with current IDEA build; don't try updating - if (!responseDoc.getName().equals("plugin-repository") - || responseDoc.getChildren().isEmpty()) { - return false; - } - - Optional latestVersion = Optional.ofNullable(responseDoc.getChild("category")) - .map(element -> element.getChild("idea-plugin")) - .map(element -> element.getChild("version")) - .map(Element::getText); - return latestVersion - .map(version -> VersionComparatorUtil.compare(version, minimumExpectedVersion) >= 0) - .orElse(false); - } } diff --git a/versions.lock b/versions.lock index 0528281d..7ae110f6 100644 --- a/versions.lock +++ b/versions.lock @@ -5,7 +5,7 @@ com.fasterxml.jackson.core:jackson-core:2.15.3 (1 constraints: 8b123e21) com.fasterxml.jackson.core:jackson-databind:2.15.3 (1 constraints: 3d05413b) com.github.ben-manes.caffeine:caffeine:3.1.8 (2 constraints: d216c42c) com.google.code.findbugs:jsr305:3.0.2 (2 constraints: 1d0fb186) -com.google.errorprone:error_prone_annotations:2.28.0 (4 constraints: 092bf08b) +com.google.errorprone:error_prone_annotations:2.28.0 (3 constraints: ae1f4750) com.google.guava:failureaccess:1.0.2 (2 constraints: f2152a13) com.google.guava:guava:33.3.0-jre (5 constraints: 2e54389c) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) @@ -59,7 +59,6 @@ org.slf4j:slf4j-api:1.7.36 (4 constraints: 4b4a7558) [Test dependencies] cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24) -com.google.code.gson:gson:2.11.0 (1 constraints: 3605323b) com.netflix.nebula:nebula-test:10.6.1 (1 constraints: 3a053a3b) junit:junit:4.13.2 (1 constraints: 1b0e1d4c) net.bytebuddy:byte-buddy:1.15.0 (2 constraints: c516c250) diff --git a/versions.props b/versions.props index 61c3064d..3e9f3a7a 100644 --- a/versions.props +++ b/versions.props @@ -13,7 +13,6 @@ org.apache.commons:commons-compress = 1.27.1 com.palantir.gradle.auto-parallelizable:* = 1.4.0 org.ow2.asm:asm = 9.7 com.palantir.gradle.failure-reports:* = 1.9.0 -com.google.code.gson:gson = 2.11.0 # dependency-upgrader:OFF com.palantir.baseline:* = 5.53.0 From 96085dea51fa1d24ac25717a9c3d5ae1d8d2c1b7 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Fri, 13 Sep 2024 16:09:31 +0200 Subject: [PATCH 11/11] use gradle version comparison --- .../gradle/jdks/IntellijPluginCheckerTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java index 43579100..39ffc784 100644 --- a/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java +++ b/gradle-jdks/src/test/java/com/palantir/gradle/jdks/IntellijPluginCheckerTest.java @@ -25,6 +25,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.junit.jupiter.api.Test; +import org.spockframework.util.VersionNumber; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; @@ -48,9 +49,15 @@ public void minimum_version_intellij_plugin_exists() NodeList versionList = document.getElementsByTagName("version"); assertThat(versionList.getLength()).isGreaterThan(0); String version = versionList.item(0).getTextContent(); - assertThat(version) - .isGreaterThanOrEqualTo(PalantirGradleJdksIdeaPlugin.MIN_IDEA_PLUGIN_VERSION) - .describedAs( - "If this test fails, then the minimum required Intellij plugin version is not yet published."); + assertThat(compareVersions(version, PalantirGradleJdksIdeaPlugin.MIN_IDEA_PLUGIN_VERSION)) + .as( + "If this test fails, then the minimum required Intellij plugin version is not " + + "yet published. version=%s, expected_min_version=%s", + version, PalantirGradleJdksIdeaPlugin.MIN_IDEA_PLUGIN_VERSION) + .isGreaterThan(0); + } + + private static int compareVersions(String version1, String version2) { + return VersionNumber.parse(version1).compareTo(VersionNumber.parse(version2)); } }