diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/run/QarkusRunDashboardCustomizer.java b/src/main/java/com/redhat/devtools/intellij/quarkus/run/QarkusRunDashboardCustomizer.java new file mode 100644 index 000000000..8cf9189cd --- /dev/null +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/run/QarkusRunDashboardCustomizer.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2023 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package com.redhat.devtools.intellij.quarkus.run; + +import com.intellij.execution.RunnerAndConfigurationSettings; +import com.intellij.execution.dashboard.RunDashboardCustomizer; +import com.intellij.execution.dashboard.RunDashboardRunConfigurationNode; +import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.ui.RunContentDescriptor; +import com.intellij.ide.BrowserUtil; +import com.intellij.ide.projectView.PresentationData; +import com.intellij.ui.SimpleTextAttributes; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +/** + * Dashboard customizer for Quarkus to provide: + * + * + */ +public class QarkusRunDashboardCustomizer extends RunDashboardCustomizer { + + @Override + public boolean isApplicable(@NotNull RunnerAndConfigurationSettings settings, @Nullable RunContentDescriptor descriptor) { + return settings.getConfiguration() instanceof QuarkusRunConfiguration; + } + + @Override + public boolean updatePresentation(@NotNull PresentationData presentation, @NotNull RunDashboardRunConfigurationNode node) { + if (!(node.getConfigurationSettings().getConfiguration() instanceof QuarkusRunConfiguration)) { + return false; + } + node.putUserData(RunDashboardCustomizer.NODE_LINKS, null); + RunContentDescriptor descriptor = node.getDescriptor(); + if (descriptor != null) { + ProcessHandler processHandler = descriptor.getProcessHandler(); + if (processHandler != null && !processHandler.isProcessTerminated()) { + // The Quarkus run configuration is running, add links for: + // - Opening quarkus application in a browser + // - Opening DevUI in a browser + QuarkusRunConfiguration quarkusRunConfiguration = (QuarkusRunConfiguration) node.getConfigurationSettings().getConfiguration(); + QuarkusRunContext runContext = new QuarkusRunContext(quarkusRunConfiguration.getModule()); + + final String applicationUrl = runContext.getApplicationURL(); + presentation.addText(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES); + presentation.addText(applicationUrl, SimpleTextAttributes.LINK_ATTRIBUTES); + + Map links = new HashMap(); + links.put(applicationUrl, new Runnable() { + @Override + public void run() { + BrowserUtil.browse(applicationUrl); + } + }); + node.putUserData(RunDashboardCustomizer.NODE_LINKS, links); + } + } + return true; + } + +} diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/run/QuarkusRunConfiguration.java b/src/main/java/com/redhat/devtools/intellij/quarkus/run/QuarkusRunConfiguration.java index 37955c1e5..6a1670af7 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/run/QuarkusRunConfiguration.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/run/QuarkusRunConfiguration.java @@ -10,13 +10,7 @@ ******************************************************************************/ package com.redhat.devtools.intellij.quarkus.run; -import com.intellij.execution.DefaultExecutionTarget; -import com.intellij.execution.ExecutionException; -import com.intellij.execution.ExecutionManager; -import com.intellij.execution.ExecutionTarget; -import com.intellij.execution.Executor; -import com.intellij.execution.RunManager; -import com.intellij.execution.RunnerAndConfigurationSettings; +import com.intellij.execution.*; import com.intellij.execution.configurations.ConfigurationFactory; import com.intellij.execution.configurations.ModuleBasedConfiguration; import com.intellij.execution.configurations.RunConfiguration; @@ -133,12 +127,13 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn telemetry.property("kind", executor.getId()); BuildToolDelegate toolDelegate = BuildToolDelegate.getDelegate(getModule()); allocateLocalPort(); + RunProfileState state = null; if (toolDelegate != null) { telemetry.property("tool", toolDelegate.getDisplay()); RunnerAndConfigurationSettings settings = toolDelegate.getConfigurationDelegate(getModule(), this); if (settings != null) { long groupId = ExecutionEnvironment.getNextUnusedExecutionId(); - doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null, + state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null, desc -> desc.getComponent().putClientProperty(QuarkusConstants.QUARKUS_RUN_CONTEXT_KEY, new QuarkusRunContext(getModule()))); } } else { @@ -153,7 +148,7 @@ public void run(@NotNull ProgressIndicator indicator) { } }); } - return null; + return state; } private void waitForPortAvailable(int port, ProgressIndicator monitor) throws IOException { @@ -212,21 +207,19 @@ public int getPort() { return port; } - private static void doRunConfiguration(@NotNull RunnerAndConfigurationSettings configuration, - @NotNull Executor executor, - @Nullable ExecutionTarget targetOrNullForDefault, - @Nullable Long executionId, - @Nullable DataContext dataContext, - ProgramRunner.Callback callback) { + private static RunProfileState doRunConfiguration(@NotNull RunnerAndConfigurationSettings configuration, + @NotNull Executor executor, + @Nullable ExecutionTarget targetOrNullForDefault, + @Nullable Long executionId, + @Nullable DataContext dataContext, + ProgramRunner.Callback callback) throws ExecutionException { ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration); if (builder == null) { - return; + return null; } - if (targetOrNullForDefault != null) { builder.target(targetOrNullForDefault); - } - else { + } else { builder.activeTarget(); } if (executionId != null) { @@ -235,7 +228,7 @@ private static void doRunConfiguration(@NotNull RunnerAndConfigurationSettings c if (dataContext != null) { builder.dataContext(dataContext); } - ExecutionManager.getInstance(configuration.getConfiguration().getProject()).restartRunProfile(builder.build(callback)); + return configuration.getConfiguration().getState(executor, builder.build(callback)); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index da049d7f1..55ee76f32 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -338,9 +338,12 @@ + + +