-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Gradle JDK Automanagement][Intellij plugin] Background tool window #405
Changes from all commits
ed56085
4f9c447
aeb8aa2
e064b41
aab4f19
0d51e59
adb70fd
c20b395
6176a74
1809e29
f529abb
23dc007
aceac47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,18 @@ | |
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.NotificationGroupManager; | ||
import com.intellij.notification.NotificationType; | ||
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.ContentFactory; | ||
import java.io.File; | ||
|
@@ -42,6 +48,9 @@ | |
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; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.plugins.gradle.settings.GradleProjectSettings; | ||
import org.jetbrains.plugins.gradle.settings.GradleSettings; | ||
|
@@ -72,13 +81,22 @@ 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); | ||
Disposer.register(project, newConsoleView); | ||
}); | ||
|
||
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 void maybeSetupGradleJdks() { | ||
if (project.getBasePath() == null) { | ||
logger.warn("Skipping setupGradleJdks because project path is null"); | ||
|
@@ -90,7 +108,28 @@ public void maybeSetupGradleJdks() { | |
"Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript)); | ||
return; | ||
} | ||
setupGradleJdks(); | ||
TasksKt.withBackgroundProgress( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of: https://github.com/JetBrains/intellij-community/blob/99964dd3c76f6cf9eb24018c002a68848e54dddb/platform/core-api/src/com/intellij/openapi/progress/Task.java#L43C8-L43C12 which has obsolescence notice |
||
project, | ||
"Gradle JDK Setup", | ||
(_coroutineScope, continuation) -> { | ||
StepsKt.withProgressText( | ||
"`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...", | ||
(_cor, conti) -> { | ||
setupGradleJdks(); | ||
return conti; | ||
}, | ||
continuation); | ||
return continuation; | ||
}, | ||
new Continuation<>() { | ||
@Override | ||
public @NotNull CoroutineContext getContext() { | ||
return EmptyCoroutineContext.INSTANCE; | ||
} | ||
|
||
@Override | ||
public void resumeWith(@NotNull Object _object) {} | ||
}); | ||
Comment on lines
+111
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
private void setupGradleJdks() { | ||
|
@@ -101,6 +140,7 @@ private void setupGradleJdks() { | |
OSProcessHandler handler = new OSProcessHandler(cli); | ||
handler.startNotify(); | ||
handler.addProcessListener(new ProcessListener() { | ||
|
||
@Override | ||
public void processTerminated(@NotNull ProcessEvent _event) { | ||
updateGradleJvm(); | ||
|
@@ -109,6 +149,16 @@ public void processTerminated(@NotNull ProcessEvent _event) { | |
consoleView.get().attachToProcess(handler); | ||
ProcessTerminatedListener.attach(handler, project, "Gradle JDK setup finished with exit code $EXIT_CODE$"); | ||
handler.waitFor(); | ||
if (handler.getExitCode() != 0) { | ||
Notification notification = NotificationGroupManager.getInstance() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to focus the window on failure. The notification windows are quite quiet. I for some reason barely ever notice the "required plugins" notification lolol and I think it's quite common. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in: aceac47 |
||
.getNotificationGroup("Gradle JDK setup Notifications") | ||
.createNotification( | ||
"Gradle JDK setup", | ||
String.format("Gradle JDK setup failed with exit code %s", handler.getExitCode()), | ||
NotificationType.ERROR); | ||
notification.notify(project); | ||
focusOnWindow(); | ||
} | ||
} catch (ExecutionException e) { | ||
throw new RuntimeException("Failed to setup Gradle JDKs for Intellij", e); | ||
} | ||
|
@@ -126,6 +176,7 @@ private void updateGradleJvm() { | |
"Skipping gradleJvm Configuration because no value was configured in" | ||
+ " `.gradle/config.properties`", | ||
ConsoleViewContentType.LOG_INFO_OUTPUT); | ||
|
||
continue; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this fixes: #394 I wasn't able to repro the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏