From ed5608529aa6815275c58ca1a77c4fdb38af019c Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 10 Jul 2024 14:56:07 +0200 Subject: [PATCH 01/12] working --- ...xternalSystemTaskNotificationListener.java | 2 +- .../gradle/jdks/GradleJdksProjectService.java | 40 ++++++++++++++++--- .../jdks/GradleJdksToolWindowService.java | 22 ++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java 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..0f7c29a0 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 @@ -30,7 +30,7 @@ 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(); + id.findProject().getService(GradleJdksProjectService.class).maybeSetupGradleJdks(id.getType()); } } 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 367317b7..c0eaa977 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 @@ -28,9 +28,11 @@ import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ToolWindowId; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; @@ -72,14 +74,14 @@ private ConsoleView initConsoleView() { ContentFactory contentFactory = ContentFactory.getInstance(); Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); toolWindow.getContentManager().addContent(content); - // TODO(crogoz): Focus only when error or takes a long time? - toolWindow.activate(null); + toolWindow.setAvailable(true); + toolWindow.activate(null, true, false); }); return newConsoleView; } - public void maybeSetupGradleJdks() { + public void maybeSetupGradleJdks(ExternalSystemTaskType type) { if (project.getBasePath() == null) { logger.warn("Skipping setupGradleJdks because project path is null"); return; @@ -90,24 +92,50 @@ public void maybeSetupGradleJdks() { "Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); return; } - setupGradleJdks(); + setupGradleJdks(type); } - private void setupGradleJdks() { + private void setupGradleJdks(ExternalSystemTaskType type) { try { + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); + if (toolWindow != null) { + toolWindow.activate(null, true, false); + } + }); + consoleView.get().clear(); GeneralCommandLine cli = new GeneralCommandLine("./gradle/gradle-jdks-setup.sh").withWorkDirectory(project.getBasePath()); OSProcessHandler handler = new OSProcessHandler(cli); handler.startNotify(); handler.addProcessListener(new ProcessListener() { + @Override public void processTerminated(@NotNull ProcessEvent _event) { updateGradleJvm(); } }); consoleView.get().attachToProcess(handler); - ProcessTerminatedListener.attach(handler, project); + ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); handler.waitFor(); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); + if (toolWindow != null) { + if (handler.getProcess().exitValue() != 0) { + toolWindow.activate(null, true, true); + } else { + toolWindow.hide(null); + if (type == ExternalSystemTaskType.EXECUTE_TASK) { + Optional.ofNullable(toolWindowManager.getToolWindow(ToolWindowId.RUN)) + .ifPresent(runWindow -> runWindow.activate(null)); + } else if (type == ExternalSystemTaskType.RESOLVE_PROJECT) { + Optional.ofNullable(toolWindowManager.getToolWindow("Build")) + .ifPresent(runWindow -> runWindow.activate(null)); + } + } + } + }); } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java new file mode 100644 index 00000000..9a1d357c --- /dev/null +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java @@ -0,0 +1,22 @@ +/* + * (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.openapi.components.Service; + +@Service(Service.Level.PROJECT) +public final class GradleJdksToolWindowService {} From 4f9c447d8eaffba243aa962088e98d82390ec485 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 10 Jul 2024 15:12:42 +0200 Subject: [PATCH 02/12] hide/show window managers --- .../gradle/jdks/GradleJdksProjectService.java | 89 +++++-------------- .../jdks/GradleJdksToolWindowService.java | 66 +++++++++++++- 2 files changed, 89 insertions(+), 66 deletions(-) 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 c0eaa977..75c41d16 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 @@ -16,10 +16,8 @@ package com.palantir.gradle.jdks; -import com.google.common.base.Suppliers; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; -import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.process.ProcessListener; @@ -30,12 +28,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowId; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentFactory; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -43,7 +36,6 @@ import java.nio.file.Path; import java.util.Optional; import java.util.Properties; -import java.util.function.Supplier; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.settings.GradleProjectSettings; import org.jetbrains.plugins.gradle.settings.GradleSettings; @@ -52,35 +44,12 @@ public final class GradleJdksProjectService { private final Logger logger = Logger.getInstance(GradleJdksProjectService.class); - private static final String TOOL_WINDOW_NAME = "Gradle JDK Setup"; - private final Project project; - private final Supplier consoleView = Suppliers.memoize(this::initConsoleView); public GradleJdksProjectService(Project project) { this.project = project; } - private ConsoleView initConsoleView() { - ConsoleView newConsoleView = - TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); - - ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); - if (toolWindow == null) { - toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, true, ToolWindowAnchor.BOTTOM); - } - ContentFactory contentFactory = ContentFactory.getInstance(); - Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); - toolWindow.getContentManager().addContent(content); - toolWindow.setAvailable(true); - toolWindow.activate(null, true, false); - }); - - return newConsoleView; - } - public void maybeSetupGradleJdks(ExternalSystemTaskType type) { if (project.getBasePath() == null) { logger.warn("Skipping setupGradleJdks because project path is null"); @@ -97,14 +66,10 @@ public void maybeSetupGradleJdks(ExternalSystemTaskType type) { private void setupGradleJdks(ExternalSystemTaskType type) { try { - ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); - if (toolWindow != null) { - toolWindow.activate(null, true, false); - } - }); - consoleView.get().clear(); + GradleJdksToolWindowService toolWindowService = project.getService(GradleJdksToolWindowService.class); + toolWindowService.focusOnWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); + ConsoleView consoleView = toolWindowService.getConsoleView(); + consoleView.clear(); GeneralCommandLine cli = new GeneralCommandLine("./gradle/gradle-jdks-setup.sh").withWorkDirectory(project.getBasePath()); OSProcessHandler handler = new OSProcessHandler(cli); @@ -113,46 +78,40 @@ private void setupGradleJdks(ExternalSystemTaskType type) { @Override public void processTerminated(@NotNull ProcessEvent _event) { - updateGradleJvm(); + updateGradleJvm(consoleView); } }); - consoleView.get().attachToProcess(handler); + consoleView.attachToProcess(handler); ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); handler.waitFor(); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); - if (toolWindow != null) { - if (handler.getProcess().exitValue() != 0) { - toolWindow.activate(null, true, true); - } else { - toolWindow.hide(null); - if (type == ExternalSystemTaskType.EXECUTE_TASK) { - Optional.ofNullable(toolWindowManager.getToolWindow(ToolWindowId.RUN)) - .ifPresent(runWindow -> runWindow.activate(null)); - } else if (type == ExternalSystemTaskType.RESOLVE_PROJECT) { - Optional.ofNullable(toolWindowManager.getToolWindow("Build")) - .ifPresent(runWindow -> runWindow.activate(null)); - } - } - } - }); + if (handler.getProcess().exitValue() == 0) { + toolWindowService.hideWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); + maybeGetFocusWindowId(type).ifPresent(toolWindowService::focusOnWindow); + } } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); } } - private void updateGradleJvm() { + private Optional maybeGetFocusWindowId(ExternalSystemTaskType type) { + if (type == ExternalSystemTaskType.EXECUTE_TASK) { + return Optional.of(ToolWindowId.RUN); + } else if (type == ExternalSystemTaskType.RESOLVE_PROJECT) { + return Optional.of("Build"); + } + return Optional.empty(); + } + + private void updateGradleJvm(ConsoleView consoleView) { for (GradleProjectSettings projectSettings : GradleSettings.getInstance(project).getLinkedProjectsSettings()) { File gradleConfigFile = Path.of(projectSettings.getExternalProjectPath(), ".gradle/config.properties") .toFile(); if (!gradleConfigFile.exists()) { - consoleView - .get() - .print( - "Skipping gradleJvm Configuration because no value was configured in" - + " `.gradle/config.properties`", - ConsoleViewContentType.LOG_INFO_OUTPUT); + consoleView.print( + "Skipping gradleJvm Configuration because no value was configured in" + + " `.gradle/config.properties`", + ConsoleViewContentType.LOG_INFO_OUTPUT); continue; } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java index 9a1d357c..a96e4a53 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java @@ -16,7 +16,71 @@ package com.palantir.gradle.jdks; +import com.google.common.base.Suppliers; +import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.ui.ConsoleView; import com.intellij.openapi.components.Service; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowAnchor; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentFactory; +import java.util.function.Supplier; @Service(Service.Level.PROJECT) -public final class GradleJdksToolWindowService {} +public final class GradleJdksToolWindowService { + + static final String TOOL_WINDOW_NAME = "Gradle JDK Setup"; + + private final Supplier consoleView = Suppliers.memoize(this::initConsoleView); + private final Project project; + + public GradleJdksToolWindowService(Project project) { + this.project = project; + } + + private ConsoleView initConsoleView() { + ConsoleView newConsoleView = + TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); + + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); + if (toolWindow == null) { + toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, true, ToolWindowAnchor.BOTTOM); + } + ContentFactory contentFactory = ContentFactory.getInstance(); + Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); + toolWindow.getContentManager().addContent(content); + toolWindow.setAvailable(true); + toolWindow.activate(null, true, false); + }); + + return newConsoleView; + } + + public void focusOnWindow(String toolWindowId) { + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId); + if (toolWindow != null) { + toolWindow.activate(null, true, false); + } + }); + } + + public void hideWindow(String toolWindowId) { + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId); + if (toolWindow != null) { + toolWindow.hide(null); + } + }); + } + + public ConsoleView getConsoleView() { + return consoleView.get(); + } +} From aeb8aa21b6fc1e6fe3c47071363dfdfe090786f0 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Wed, 10 Jul 2024 13:25:42 +0000 Subject: [PATCH 03/12] Add generated changelog entries --- changelog/@unreleased/pr-379.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-379.v2.yml diff --git a/changelog/@unreleased/pr-379.v2.yml b/changelog/@unreleased/pr-379.v2.yml new file mode 100644 index 00000000..b18b6fdd --- /dev/null +++ b/changelog/@unreleased/pr-379.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: '[Intellij] Focus on `Gradle Jdk` Tool Window while the setup is running' + links: + - https://github.com/palantir/gradle-jdks/pull/379 From e064b411d86068eb147c5803e2ea23bb3d1d1ee6 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Mon, 26 Aug 2024 21:11:07 +0200 Subject: [PATCH 04/12] show logs sometimes --- .../gradle/jdks/GradleJdksProjectService.java | 59 +++++++++++++++++-- .../jdks/GradleJdksToolWindowService.java | 2 - 2 files changed, 53 insertions(+), 8 deletions(-) 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 75c41d16..e7f6efab 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 @@ -29,6 +29,8 @@ import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.platform.ide.progress.TasksKt; +import com.intellij.platform.util.progress.StepsKt; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -36,6 +38,12 @@ import java.nio.file.Path; import java.util.Optional; import java.util.Properties; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import kotlin.coroutines.Continuation; +import kotlin.coroutines.CoroutineContext; +import kotlin.coroutines.EmptyCoroutineContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.settings.GradleProjectSettings; import org.jetbrains.plugins.gradle.settings.GradleSettings; @@ -61,13 +69,34 @@ public void maybeSetupGradleJdks(ExternalSystemTaskType type) { "Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); return; } - setupGradleJdks(type); + Continuation cont = new Continuation<>() { + @Override + public @NotNull CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resumeWith(@NotNull Object _object) {} + }; + TasksKt.withBackgroundProgress( + project, + "Gradle JDK Setup", + (_coroutineScope, continuation) -> { + StepsKt.withProgressText( + "`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", + (_cor, conti) -> { + setupGradleJdks(type); + return conti; + }, + continuation); + return continuation; + }, + cont); } private void setupGradleJdks(ExternalSystemTaskType type) { try { GradleJdksToolWindowService toolWindowService = project.getService(GradleJdksToolWindowService.class); - toolWindowService.focusOnWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); ConsoleView consoleView = toolWindowService.getConsoleView(); consoleView.clear(); GeneralCommandLine cli = @@ -75,19 +104,37 @@ private void setupGradleJdks(ExternalSystemTaskType type) { OSProcessHandler handler = new OSProcessHandler(cli); handler.startNotify(); handler.addProcessListener(new ProcessListener() { + private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + private static boolean hasChangedFocus = false; + + @SuppressWarnings("FutureReturnValueIgnored") + @Override + public void startNotified(@NotNull ProcessEvent event) { + executorService.schedule( + () -> { + consoleView.print("Is notified", ConsoleViewContentType.NORMAL_OUTPUT); + if (!event.getProcessHandler().isProcessTerminated()) { + toolWindowService.focusOnWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); + } + }, + 10, + TimeUnit.SECONDS); + } @Override public void processTerminated(@NotNull ProcessEvent _event) { + consoleView.print("finished", ConsoleViewContentType.NORMAL_OUTPUT); updateGradleJvm(consoleView); + executorService.shutdown(); + if (handler.getProcess().exitValue() == 0 && hasChangedFocus) { + toolWindowService.hideWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); + maybeGetFocusWindowId(type).ifPresent(toolWindowService::focusOnWindow); + } } }); consoleView.attachToProcess(handler); ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); handler.waitFor(); - if (handler.getProcess().exitValue() == 0) { - toolWindowService.hideWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); - maybeGetFocusWindowId(type).ifPresent(toolWindowService::focusOnWindow); - } } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java index a96e4a53..d3649471 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java @@ -53,8 +53,6 @@ private ConsoleView initConsoleView() { ContentFactory contentFactory = ContentFactory.getInstance(); Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); toolWindow.getContentManager().addContent(content); - toolWindow.setAvailable(true); - toolWindow.activate(null, true, false); }); return newConsoleView; From aab4f19b84a126a0c59bcf72629e40d4a44c3991 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Tue, 27 Aug 2024 11:47:51 +0200 Subject: [PATCH 05/12] jdks --- ...xternalSystemTaskNotificationListener.java | 6 ++- .../gradle/jdks/GradleJdksProjectService.java | 49 ++++++------------- .../jdks/GradleJdksToolWindowService.java | 10 ---- 3 files changed, 19 insertions(+), 46 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 0f7c29a0..6be5cebb 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,10 @@ 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(id.getType()); + Project project = id.findProject(); + if (project != null) { + project.getService(GradleJdksProjectService.class).maybeSetupGradleJdks(); + } } } 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 e7f6efab..d09bbd61 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 @@ -24,11 +24,11 @@ import com.intellij.execution.process.ProcessTerminatedListener; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.notification.NotificationGroupManager; +import com.intellij.notification.NotificationType; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindowId; import com.intellij.platform.ide.progress.TasksKt; import com.intellij.platform.util.progress.StepsKt; import java.io.File; @@ -40,7 +40,6 @@ import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; @@ -58,7 +57,7 @@ public GradleJdksProjectService(Project project) { this.project = project; } - public void maybeSetupGradleJdks(ExternalSystemTaskType type) { + public void maybeSetupGradleJdks() { if (project.getBasePath() == null) { logger.warn("Skipping setupGradleJdks because project path is null"); return; @@ -85,7 +84,7 @@ public void resumeWith(@NotNull Object _object) {} StepsKt.withProgressText( "`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", (_cor, conti) -> { - setupGradleJdks(type); + setupGradleJdks(); return conti; }, continuation); @@ -94,7 +93,7 @@ public void resumeWith(@NotNull Object _object) {} cont); } - private void setupGradleJdks(ExternalSystemTaskType type) { + private void setupGradleJdks() { try { GradleJdksToolWindowService toolWindowService = project.getService(GradleJdksToolWindowService.class); ConsoleView consoleView = toolWindowService.getConsoleView(); @@ -105,50 +104,30 @@ private void setupGradleJdks(ExternalSystemTaskType type) { handler.startNotify(); handler.addProcessListener(new ProcessListener() { private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); - private static boolean hasChangedFocus = false; - - @SuppressWarnings("FutureReturnValueIgnored") - @Override - public void startNotified(@NotNull ProcessEvent event) { - executorService.schedule( - () -> { - consoleView.print("Is notified", ConsoleViewContentType.NORMAL_OUTPUT); - if (!event.getProcessHandler().isProcessTerminated()) { - toolWindowService.focusOnWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); - } - }, - 10, - TimeUnit.SECONDS); - } @Override public void processTerminated(@NotNull ProcessEvent _event) { - consoleView.print("finished", ConsoleViewContentType.NORMAL_OUTPUT); updateGradleJvm(consoleView); executorService.shutdown(); - if (handler.getProcess().exitValue() == 0 && hasChangedFocus) { - toolWindowService.hideWindow(GradleJdksToolWindowService.TOOL_WINDOW_NAME); - maybeGetFocusWindowId(type).ifPresent(toolWindowService::focusOnWindow); - } } }); consoleView.attachToProcess(handler); ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); handler.waitFor(); + if (handler.getExitCode() != 0) { + NotificationGroupManager.getInstance() + .getNotificationGroup("Gradle JDK Setup") + .createNotification( + "Gradle JDK setup", + "Gradle JDK setup failed. Please check logs in the `Gradle JDK setup` tool window", + NotificationType.ERROR) + .notify(project); + } } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); } } - private Optional maybeGetFocusWindowId(ExternalSystemTaskType type) { - if (type == ExternalSystemTaskType.EXECUTE_TASK) { - return Optional.of(ToolWindowId.RUN); - } else if (type == ExternalSystemTaskType.RESOLVE_PROJECT) { - return Optional.of("Build"); - } - return Optional.empty(); - } - private void updateGradleJvm(ConsoleView consoleView) { for (GradleProjectSettings projectSettings : GradleSettings.getInstance(project).getLinkedProjectsSettings()) { diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java index d3649471..49feb079 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java @@ -68,16 +68,6 @@ public void focusOnWindow(String toolWindowId) { }); } - public void hideWindow(String toolWindowId) { - ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId); - if (toolWindow != null) { - toolWindow.hide(null); - } - }); - } - public ConsoleView getConsoleView() { return consoleView.get(); } From 0d51e59becf711ca357a85a53bba9fcb8f4bc3d4 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Tue, 27 Aug 2024 15:24:08 +0200 Subject: [PATCH 06/12] notification for failures --- .../gradle/jdks/GradleJdksProjectService.java | 19 ++++++++++++++----- .../jdks/GradleJdksToolWindowService.java | 4 ++-- .../src/main/resources/META-INF/plugin.xml | 3 +++ 3 files changed, 19 insertions(+), 7 deletions(-) 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 d09bbd61..a09d2976 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 @@ -24,8 +24,11 @@ import com.intellij.execution.process.ProcessTerminatedListener; import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationAction; import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -115,13 +118,19 @@ public void processTerminated(@NotNull ProcessEvent _event) { ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); handler.waitFor(); if (handler.getExitCode() != 0) { - NotificationGroupManager.getInstance() - .getNotificationGroup("Gradle JDK Setup") + Notification notification = NotificationGroupManager.getInstance() + .getNotificationGroup("Gradle JDK setup Notifications") .createNotification( "Gradle JDK setup", - "Gradle JDK setup failed. Please check logs in the `Gradle JDK setup` tool window", - NotificationType.ERROR) - .notify(project); + String.format("Gradle JDK setup failed with exit code %s", handler.getExitCode()), + NotificationType.ERROR); + notification.notify(project); + notification.addAction(new NotificationAction("Show Gradle JDKs setup logs") { + @Override + public void actionPerformed(@NotNull AnActionEvent _event, @NotNull Notification _notification) { + toolWindowService.focusOnWindow(); + } + }); } } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java index 49feb079..d798258e 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java @@ -58,10 +58,10 @@ private ConsoleView initConsoleView() { return newConsoleView; } - public void focusOnWindow(String toolWindowId) { + public void focusOnWindow() { ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowId); + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); if (toolWindow != null) { toolWindow.activate(null, true, false); } diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index c7b153c8..daddf16f 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -12,5 +12,8 @@ + From adb70fd9fac2339c851f5f6b43dcde1bcec275b3 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 28 Aug 2024 12:00:49 +0200 Subject: [PATCH 07/12] . --- .../gradle/jdks/GradleJdksProjectService.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) 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 a09d2976..945b3acc 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 @@ -41,8 +41,6 @@ import java.nio.file.Path; import java.util.Optional; import java.util.Properties; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; @@ -71,15 +69,6 @@ public void maybeSetupGradleJdks() { "Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); return; } - Continuation cont = new Continuation<>() { - @Override - public @NotNull CoroutineContext getContext() { - return EmptyCoroutineContext.INSTANCE; - } - - @Override - public void resumeWith(@NotNull Object _object) {} - }; TasksKt.withBackgroundProgress( project, "Gradle JDK Setup", @@ -93,7 +82,15 @@ public void resumeWith(@NotNull Object _object) {} continuation); return continuation; }, - cont); + new Continuation<>() { + @Override + public @NotNull CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resumeWith(@NotNull Object _object) {} + }); } private void setupGradleJdks() { @@ -106,12 +103,10 @@ private void setupGradleJdks() { OSProcessHandler handler = new OSProcessHandler(cli); handler.startNotify(); handler.addProcessListener(new ProcessListener() { - private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); @Override public void processTerminated(@NotNull ProcessEvent _event) { updateGradleJvm(consoleView); - executorService.shutdown(); } }); consoleView.attachToProcess(handler); From 6176a74ec4fc77bf7ef9ee0180520aa58495590f Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 5 Sep 2024 08:35:08 +0200 Subject: [PATCH 08/12] wip --- .../jdks/GradleJdkToolWindowFactory.java | 40 ++++++++++ .../GradleJdkToolWindowManagerListener.java | 21 +++++ .../gradle/jdks/GradleJdksProjectService.java | 47 +++++++---- .../jdks/GradleJdksToolWindowService.java | 74 ------------------ .../src/main/resources/META-INF/plugin.xml | 2 + .../resources/icons/GradleJDKSetupIcon.png | Bin 0 -> 1072 bytes 6 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java create mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java delete mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java create mode 100644 idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java new file mode 100644 index 00000000..e32ac357 --- /dev/null +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java @@ -0,0 +1,40 @@ +/* + * (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.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowFactory; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentFactory; +import org.jetbrains.annotations.NotNull; + +public final class GradleJdkToolWindowFactory implements ToolWindowFactory, DumbAware { + + @Override + public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { + ConsoleView consoleView = + TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); + + ContentFactory contentFactory = ContentFactory.getInstance(); + Content content = contentFactory.createContent(consoleView.getComponent(), "", false); + toolWindow.getContentManager().addContent(content); + } +} \ No newline at end of file diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java new file mode 100644 index 00000000..807c49c3 --- /dev/null +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java @@ -0,0 +1,21 @@ +/* + * (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.openapi.wm.ex.ToolWindowManagerListener; + +public class GradleJdkToolWindowManagerListener implements ToolWindowManagerListener {} 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 945b3acc..1bc1f657 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 @@ -32,8 +32,12 @@ import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.platform.ide.progress.TasksKt; import com.intellij.platform.util.progress.StepsKt; +import com.intellij.ui.content.Content; +import com.intellij.ui.content.ContentManager; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -59,14 +63,19 @@ public GradleJdksProjectService(Project project) { } public void maybeSetupGradleJdks() { + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + ToolWindow toolWindow = toolWindowManager.getToolWindow("Gradle JDK Setup"); if (project.getBasePath() == null) { logger.warn("Skipping setupGradleJdks because project path is null"); return; } Path gradleSetupScript = Path.of(project.getBasePath(), "gradle/gradle-jdks-setup.sh"); if (!Files.exists(gradleSetupScript)) { - logger.info(String.format( - "Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); + consoleViewApply(toolWindowManager, toolWindow, consoleView -> { + consoleView.clear(); + consoleView.print( + "Gradle JDK setup is not enabled for this repository.", ConsoleViewContentType.LOG_INFO_OUTPUT); + }); return; } TasksKt.withBackgroundProgress( @@ -76,7 +85,7 @@ public void maybeSetupGradleJdks() { StepsKt.withProgressText( "`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", (_cor, conti) -> { - setupGradleJdks(); + setupGradleJdks(toolWindowManager, toolWindow); return conti; }, continuation); @@ -93,11 +102,9 @@ public void resumeWith(@NotNull Object _object) {} }); } - private void setupGradleJdks() { + private void setupGradleJdks(ToolWindowManager toolWindowManager, ToolWindow toolWindow) { try { - GradleJdksToolWindowService toolWindowService = project.getService(GradleJdksToolWindowService.class); - ConsoleView consoleView = toolWindowService.getConsoleView(); - consoleView.clear(); + consoleViewApply(toolWindowManager, toolWindow, ConsoleView::clear); GeneralCommandLine cli = new GeneralCommandLine("./gradle/gradle-jdks-setup.sh").withWorkDirectory(project.getBasePath()); OSProcessHandler handler = new OSProcessHandler(cli); @@ -106,11 +113,11 @@ private void setupGradleJdks() { @Override public void processTerminated(@NotNull ProcessEvent _event) { - updateGradleJvm(consoleView); + updateGradleJvm(); } }); - consoleView.attachToProcess(handler); ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); + consoleViewApply(toolWindowManager, toolWindow, consoleView -> consoleView.attachToProcess(handler)); handler.waitFor(); if (handler.getExitCode() != 0) { Notification notification = NotificationGroupManager.getInstance() @@ -123,7 +130,7 @@ public void processTerminated(@NotNull ProcessEvent _event) { notification.addAction(new NotificationAction("Show Gradle JDKs setup logs") { @Override public void actionPerformed(@NotNull AnActionEvent _event, @NotNull Notification _notification) { - toolWindowService.focusOnWindow(); + toolWindow.activate(null, true, false); } }); } @@ -132,16 +139,12 @@ public void actionPerformed(@NotNull AnActionEvent _event, @NotNull Notification } } - private void updateGradleJvm(ConsoleView consoleView) { + private void updateGradleJvm() { for (GradleProjectSettings projectSettings : GradleSettings.getInstance(project).getLinkedProjectsSettings()) { File gradleConfigFile = Path.of(projectSettings.getExternalProjectPath(), ".gradle/config.properties") .toFile(); if (!gradleConfigFile.exists()) { - consoleView.print( - "Skipping gradleJvm Configuration because no value was configured in" - + " `.gradle/config.properties`", - ConsoleViewContentType.LOG_INFO_OUTPUT); continue; } @@ -156,4 +159,18 @@ private void updateGradleJvm(ConsoleView consoleView) { } } } + + interface ConsoleViewAction { + void apply(ConsoleView consoleView); + } + + private static void consoleViewApply( + ToolWindowManager toolWindowManager, ToolWindow toolWindow, ConsoleViewAction consoleViewAction) { + toolWindowManager.invokeLater(() -> { + ContentManager contentManager = toolWindow.getContentManager(); + Content content = contentManager.getContent(0); + ConsoleView consoleView = (ConsoleView) content.getComponent(); + consoleViewAction.apply(consoleView); + }); + } } diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java deleted file mode 100644 index d798258e..00000000 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdksToolWindowService.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * (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.google.common.base.Suppliers; -import com.intellij.execution.filters.TextConsoleBuilderFactory; -import com.intellij.execution.ui.ConsoleView; -import com.intellij.openapi.components.Service; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowAnchor; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentFactory; -import java.util.function.Supplier; - -@Service(Service.Level.PROJECT) -public final class GradleJdksToolWindowService { - - static final String TOOL_WINDOW_NAME = "Gradle JDK Setup"; - - private final Supplier consoleView = Suppliers.memoize(this::initConsoleView); - private final Project project; - - public GradleJdksToolWindowService(Project project) { - this.project = project; - } - - private ConsoleView initConsoleView() { - ConsoleView newConsoleView = - TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); - - ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); - if (toolWindow == null) { - toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, true, ToolWindowAnchor.BOTTOM); - } - ContentFactory contentFactory = ContentFactory.getInstance(); - Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); - toolWindow.getContentManager().addContent(content); - }); - - return newConsoleView; - } - - public void focusOnWindow() { - ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - toolWindowManager.invokeLater(() -> { - ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); - if (toolWindow != null) { - toolWindow.activate(null, true, false); - } - }); - } - - public ConsoleView getConsoleView() { - return consoleView.get(); - } -} diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index daddf16f..bf1fcdf9 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -15,5 +15,7 @@ + diff --git a/idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png b/idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..7f92c3d5f0ec4a0fc15d071c6ec47c6beaff7d34 GIT binary patch literal 1072 zcmeAS@N?(olHy`uVBq!ia0vp^U^WLEkTt>lKP!-8Nq6*hWMJ6X&;2J6#8*i62=ZlM zs8VBKXlP+z_yrVdc)`F>YQVtoDuIE)Y6b&?c)^@qfi^&imedH(G+$o^Eg+kNft68+ zff>kR1VRQzDF%>fKo)}+qcofy#HayP!^FVQp2@%hRTBlILBIouL3$uG^8!YMi3^zE zs<{?0!`ZwbZBG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZANAafIw@=Hr>m6Sjh!2!gbC7EdmoAQdG z-U511A0(r1sAr%LHyfzc1|(|bUzC{&v>9Z+ouLg_C5jl-9vgj-_kV8DS-mV|9{^1{`TE`@x!j>LT{%Ca(e5uJYUq^ zE+8c6WL4p@;gWZ(%7pOSsrgAw0xV4r4)z6AT%N6vB*59!&UH4Xo9A@d-+i^l`?fbN zV19r0%MLJ-fym8Q@8j-30pE{*t?^Ce^Xj5u9uv5uK3i2qf_@^`Pr^Hef_F$(eK`D zyJmV@V}50?jl;3BD?j!#wsr)Z@LOcD&^uRIxBS%CBh^P|HU{_@%+C2yV7{s?_M+eC z{3TZ+ZtOC2*&Wk&nZLHZ-6dO;%j$hNKUe5eS-l^+U%Wddd+NfX#oK0VEOpv)f#u`z8GrfIPEJ%f`DpEa`M3ACD{gn#tH0da z>0Wr7PG!LKnZ99~UAa4LIreRK6c!1uIs9eXl#@64&pF>X7pa-(X?T& Date: Thu, 5 Sep 2024 16:40:46 +0200 Subject: [PATCH 09/12] print initial messages --- .../jdks/GradleJdkToolWindowFactory.java | 16 +++++++++++++ .../GradleJdkToolWindowManagerListener.java | 21 ------------------ .../src/main/resources/META-INF/plugin.xml | 3 +-- .../resources/icons/GradleJDKSetupIcon.png | Bin 1072 -> 0 bytes 4 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java delete mode 100644 idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java index e32ac357..ef7ffc3f 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java @@ -18,12 +18,16 @@ import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.ui.ConsoleView; +import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowFactory; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; +import java.nio.file.Files; +import java.nio.file.Path; import org.jetbrains.annotations.NotNull; public final class GradleJdkToolWindowFactory implements ToolWindowFactory, DumbAware { @@ -36,5 +40,17 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo ContentFactory contentFactory = ContentFactory.getInstance(); Content content = contentFactory.createContent(consoleView.getComponent(), "", false); toolWindow.getContentManager().addContent(content); + Disposer.register(project, consoleView); + String projectPath = project.getBasePath(); + if (projectPath == null) { + return; + } + Path gradleSetupScript = Path.of(projectPath, "gradle/gradle-jdks-setup.sh"); + if (!Files.exists(gradleSetupScript)) { + consoleView.print( + "Gradle JDK setup is not enabled for this repository.", ConsoleViewContentType.LOG_INFO_OUTPUT); + } else { + consoleView.print("Gradle JDK setup has not run yet.", ConsoleViewContentType.LOG_INFO_OUTPUT); + } } } \ No newline at end of file diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java deleted file mode 100644 index 807c49c3..00000000 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowManagerListener.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * (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.openapi.wm.ex.ToolWindowManagerListener; - -public class GradleJdkToolWindowManagerListener implements ToolWindowManagerListener {} diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index bf1fcdf9..93ccb438 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -15,7 +15,6 @@ - + diff --git a/idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png b/idea-plugin/src/main/resources/icons/GradleJDKSetupIcon.png deleted file mode 100644 index 7f92c3d5f0ec4a0fc15d071c6ec47c6beaff7d34..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1072 zcmeAS@N?(olHy`uVBq!ia0vp^U^WLEkTt>lKP!-8Nq6*hWMJ6X&;2J6#8*i62=ZlM zs8VBKXlP+z_yrVdc)`F>YQVtoDuIE)Y6b&?c)^@qfi^&imedH(G+$o^Eg+kNft68+ zff>kR1VRQzDF%>fKo)}+qcofy#HayP!^FVQp2@%hRTBlILBIouL3$uG^8!YMi3^zE zs<{?0!`ZwbZBG?WUP)qwZeFo6#1NP{E~&-IMVSR9nfZANAafIw@=Hr>m6Sjh!2!gbC7EdmoAQdG z-U511A0(r1sAr%LHyfzc1|(|bUzC{&v>9Z+ouLg_C5jl-9vgj-_kV8DS-mV|9{^1{`TE`@x!j>LT{%Ca(e5uJYUq^ zE+8c6WL4p@;gWZ(%7pOSsrgAw0xV4r4)z6AT%N6vB*59!&UH4Xo9A@d-+i^l`?fbN zV19r0%MLJ-fym8Q@8j-30pE{*t?^Ce^Xj5u9uv5uK3i2qf_@^`Pr^Hef_F$(eK`D zyJmV@V}50?jl;3BD?j!#wsr)Z@LOcD&^uRIxBS%CBh^P|HU{_@%+C2yV7{s?_M+eC z{3TZ+ZtOC2*&Wk&nZLHZ-6dO;%j$hNKUe5eS-l^+U%Wddd+NfX#oK0VEOpv)f#u`z8GrfIPEJ%f`DpEa`M3ACD{gn#tH0da z>0Wr7PG!LKnZ99~UAa4LIreRK6c!1uIs9eXl#@64&pF>X7pa-(X?T& Date: Thu, 5 Sep 2024 16:58:28 +0200 Subject: [PATCH 10/12] fix initial logs --- .../palantir/gradle/jdks/GradleJdkToolWindowFactory.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java index ef7ffc3f..d9d13f74 100644 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java +++ b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java @@ -39,13 +39,17 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo ContentFactory contentFactory = ContentFactory.getInstance(); Content content = contentFactory.createContent(consoleView.getComponent(), "", false); + addInitialLogs(consoleView, project); toolWindow.getContentManager().addContent(content); Disposer.register(project, consoleView); + } + + private static void addInitialLogs(ConsoleView consoleView, Project project) { String projectPath = project.getBasePath(); if (projectPath == null) { return; } - Path gradleSetupScript = Path.of(projectPath, "gradle/gradle-jdks-setup.sh"); + Path gradleSetupScript = Path.of(projectPath).resolve("gradle/gradle-jdks-setup.sh"); if (!Files.exists(gradleSetupScript)) { consoleView.print( "Gradle JDK setup is not enabled for this repository.", ConsoleViewContentType.LOG_INFO_OUTPUT); @@ -53,4 +57,4 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo consoleView.print("Gradle JDK setup has not run yet.", ConsoleViewContentType.LOG_INFO_OUTPUT); } } -} \ No newline at end of file +} From 23dc00746c98962136a4a4abc4f04850312576c4 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Fri, 6 Sep 2024 12:16:13 +0200 Subject: [PATCH 11/12] . --- .../jdks/GradleJdkToolWindowFactory.java | 60 -------------- .../gradle/jdks/GradleJdksProjectService.java | 79 ++++++++++++------- .../src/main/resources/META-INF/plugin.xml | 1 - 3 files changed, 52 insertions(+), 88 deletions(-) delete mode 100644 idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java diff --git a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java b/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java deleted file mode 100644 index d9d13f74..00000000 --- a/idea-plugin/src/main/java/com/palantir/gradle/jdks/GradleJdkToolWindowFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (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.execution.filters.TextConsoleBuilderFactory; -import com.intellij.execution.ui.ConsoleView; -import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowFactory; -import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentFactory; -import java.nio.file.Files; -import java.nio.file.Path; -import org.jetbrains.annotations.NotNull; - -public final class GradleJdkToolWindowFactory implements ToolWindowFactory, DumbAware { - - @Override - public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { - ConsoleView consoleView = - TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); - - ContentFactory contentFactory = ContentFactory.getInstance(); - Content content = contentFactory.createContent(consoleView.getComponent(), "", false); - addInitialLogs(consoleView, project); - toolWindow.getContentManager().addContent(content); - Disposer.register(project, consoleView); - } - - private static void addInitialLogs(ConsoleView consoleView, Project project) { - String projectPath = project.getBasePath(); - if (projectPath == null) { - return; - } - Path gradleSetupScript = Path.of(projectPath).resolve("gradle/gradle-jdks-setup.sh"); - if (!Files.exists(gradleSetupScript)) { - consoleView.print( - "Gradle JDK setup is not enabled for this repository.", ConsoleViewContentType.LOG_INFO_OUTPUT); - } else { - consoleView.print("Gradle JDK setup has not run yet.", ConsoleViewContentType.LOG_INFO_OUTPUT); - } - } -} 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 1bc1f657..e0e1d3f1 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 @@ -16,8 +16,10 @@ package com.palantir.gradle.jdks; +import com.google.common.base.Suppliers; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.execution.filters.TextConsoleBuilderFactory; import com.intellij.execution.process.OSProcessHandler; import com.intellij.execution.process.ProcessEvent; import com.intellij.execution.process.ProcessListener; @@ -32,12 +34,14 @@ import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.platform.ide.progress.TasksKt; import com.intellij.platform.util.progress.StepsKt; import com.intellij.ui.content.Content; -import com.intellij.ui.content.ContentManager; +import com.intellij.ui.content.ContentFactory; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -45,6 +49,7 @@ import java.nio.file.Path; import java.util.Optional; import java.util.Properties; +import java.util.function.Supplier; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlin.coroutines.EmptyCoroutineContext; @@ -56,26 +61,53 @@ public final class GradleJdksProjectService { private final Logger logger = Logger.getInstance(GradleJdksProjectService.class); + private static final String TOOL_WINDOW_NAME = "Gradle JDK Setup"; + private final Project project; + private final Supplier consoleView = Suppliers.memoize(this::initConsoleView); public GradleJdksProjectService(Project project) { this.project = project; } - public void maybeSetupGradleJdks() { + private ConsoleView initConsoleView() { + ConsoleView newConsoleView = + TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); + + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); + if (toolWindow == null) { + toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, true, ToolWindowAnchor.BOTTOM); + } + ContentFactory contentFactory = ContentFactory.getInstance(); + Content content = contentFactory.createContent(newConsoleView.getComponent(), "", false); + toolWindow.getContentManager().addContent(content); + Disposer.register(project, newConsoleView); + }); + + return newConsoleView; + } + + public void focusOnWindow() { ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); - ToolWindow toolWindow = toolWindowManager.getToolWindow("Gradle JDK Setup"); + toolWindowManager.invokeLater(() -> { + ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_NAME); + if (toolWindow != null) { + toolWindow.activate(null, true, false); + } + }); + } + + public void maybeSetupGradleJdks() { if (project.getBasePath() == null) { logger.warn("Skipping setupGradleJdks because project path is null"); return; } Path gradleSetupScript = Path.of(project.getBasePath(), "gradle/gradle-jdks-setup.sh"); if (!Files.exists(gradleSetupScript)) { - consoleViewApply(toolWindowManager, toolWindow, consoleView -> { - consoleView.clear(); - consoleView.print( - "Gradle JDK setup is not enabled for this repository.", ConsoleViewContentType.LOG_INFO_OUTPUT); - }); + logger.info(String.format( + "Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); return; } TasksKt.withBackgroundProgress( @@ -85,7 +117,7 @@ public void maybeSetupGradleJdks() { StepsKt.withProgressText( "`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", (_cor, conti) -> { - setupGradleJdks(toolWindowManager, toolWindow); + setupGradleJdks(); return conti; }, continuation); @@ -102,9 +134,9 @@ public void resumeWith(@NotNull Object _object) {} }); } - private void setupGradleJdks(ToolWindowManager toolWindowManager, ToolWindow toolWindow) { + private void setupGradleJdks() { try { - consoleViewApply(toolWindowManager, toolWindow, ConsoleView::clear); + consoleView.get().clear(); GeneralCommandLine cli = new GeneralCommandLine("./gradle/gradle-jdks-setup.sh").withWorkDirectory(project.getBasePath()); OSProcessHandler handler = new OSProcessHandler(cli); @@ -116,8 +148,8 @@ public void processTerminated(@NotNull ProcessEvent _event) { updateGradleJvm(); } }); + consoleView.get().attachToProcess(handler); ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); - consoleViewApply(toolWindowManager, toolWindow, consoleView -> consoleView.attachToProcess(handler)); handler.waitFor(); if (handler.getExitCode() != 0) { Notification notification = NotificationGroupManager.getInstance() @@ -130,7 +162,7 @@ public void processTerminated(@NotNull ProcessEvent _event) { notification.addAction(new NotificationAction("Show Gradle JDKs setup logs") { @Override public void actionPerformed(@NotNull AnActionEvent _event, @NotNull Notification _notification) { - toolWindow.activate(null, true, false); + focusOnWindow(); } }); } @@ -145,6 +177,13 @@ private void updateGradleJvm() { File gradleConfigFile = Path.of(projectSettings.getExternalProjectPath(), ".gradle/config.properties") .toFile(); if (!gradleConfigFile.exists()) { + consoleView + .get() + .print( + "Skipping gradleJvm Configuration because no value was configured in" + + " `.gradle/config.properties`", + ConsoleViewContentType.LOG_INFO_OUTPUT); + continue; } @@ -159,18 +198,4 @@ private void updateGradleJvm() { } } } - - interface ConsoleViewAction { - void apply(ConsoleView consoleView); - } - - private static void consoleViewApply( - ToolWindowManager toolWindowManager, ToolWindow toolWindow, ConsoleViewAction consoleViewAction) { - toolWindowManager.invokeLater(() -> { - ContentManager contentManager = toolWindow.getContentManager(); - Content content = contentManager.getContent(0); - ConsoleView consoleView = (ConsoleView) content.getComponent(); - consoleViewAction.apply(consoleView); - }); - } } diff --git a/idea-plugin/src/main/resources/META-INF/plugin.xml b/idea-plugin/src/main/resources/META-INF/plugin.xml index 93ccb438..daddf16f 100644 --- a/idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/src/main/resources/META-INF/plugin.xml @@ -15,6 +15,5 @@ - From aceac47034cba90dacecf8fe3f41de79337b5331 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Tue, 10 Sep 2024 16:11:40 +0200 Subject: [PATCH 12/12] focus on failure --- .../palantir/gradle/jdks/GradleJdksProjectService.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) 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 e0e1d3f1..cba27ccf 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 @@ -27,10 +27,8 @@ import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.notification.Notification; -import com.intellij.notification.NotificationAction; import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.components.Service; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -159,12 +157,7 @@ public void processTerminated(@NotNull ProcessEvent _event) { String.format("Gradle JDK setup failed with exit code %s", handler.getExitCode()), NotificationType.ERROR); notification.notify(project); - notification.addAction(new NotificationAction("Show Gradle JDKs setup logs") { - @Override - public void actionPerformed(@NotNull AnActionEvent _event, @NotNull Notification _notification) { - focusOnWindow(); - } - }); + focusOnWindow(); } } catch (ExecutionException e) { throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e);