Skip to content

Commit

Permalink
disposable
Browse files Browse the repository at this point in the history
  • Loading branch information
crogoz committed Oct 7, 2024
1 parent c27b2aa commit 2523e7a
Showing 1 changed file with 2 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.ide.plugins.CannotUnloadPluginException;
import com.intellij.ide.plugins.DynamicPluginListener;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.Disposable;
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.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
Expand All @@ -52,7 +48,6 @@
import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.CoroutineContext;
Expand All @@ -62,12 +57,11 @@
import org.jetbrains.plugins.gradle.settings.GradleSettings;

@Service(Service.Level.PROJECT)
public final class GradleJdksProjectService implements Disposable, DynamicPluginListener {
public final class GradleJdksProjectService implements Disposable {

private final Logger logger = Logger.getInstance(GradleJdksProjectService.class);
private static final String TOOL_WINDOW_NAME = "Gradle JDK Setup";

private AtomicBoolean executingFlag = new AtomicBoolean(false);
private final Project project;
private final Supplier<ConsoleView> consoleView = Suppliers.memoize(this::initConsoleView);

Expand Down Expand Up @@ -114,10 +108,6 @@ public void maybeSetupGradleJdks() {
"Skipping setupGradleJdks because gradle JDK setup is not found %s", gradleSetupScript));
return;
}
if (!this.executingFlag.compareAndSet(false, true)) {
logger.warn("executing flag was true, another update action should be already running");
// TODO(crogoz): figure out a way to wait on the existing background process if it is still running.
}
TasksKt.withBackgroundProgress(
project,
"Gradle JDK Setup",
Expand All @@ -126,11 +116,7 @@ public void maybeSetupGradleJdks() {
StepsKt.withProgressText(
"`Gradle JDK Setup` is running. Logs in the `Gradle JDK Setup` window ...",
(_cor, conti) -> {
try {
setupGradleJdks();
} finally {
executingFlag.set(false);
}
setupGradleJdks();
return conti;
},
continuation);
Expand Down Expand Up @@ -209,18 +195,9 @@ private void updateGradleJvm() {

@Override
public void dispose() {
executingFlag.set(false);
ConsoleView view = consoleView.get();
if (view != null) {
view.dispose();
}
}

@Override
public void checkUnloadPlugin(IdeaPluginDescriptor ideaPluginDescriptor) {
PluginId pluginId = PluginId.getId("palantir-gradle-jdks");
if (ideaPluginDescriptor.getPluginId().equals(pluginId) && executingFlag.get()) {
throw new CannotUnloadPluginException("Gradle JDK Setup is still in progress...");
}
}
}

0 comments on commit 2523e7a

Please sign in to comment.