Skip to content

Commit

Permalink
fix: Connect Quarkus run configuration with Services view support
Browse files Browse the repository at this point in the history
Fixes #1265

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Nov 21, 2023
1 parent 653fb62 commit 51f2f12
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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:
*
* <ul>
* <li>Open quarkus application in a browser.</li>
* <li>Open quarkus DevUI in a browser.</li>
* </ul>
*/
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<Object, Object> links = new HashMap();
links.put(applicationUrl, new Runnable() {
@Override
public void run() {
BrowserUtil.browse(applicationUrl);
}
});
node.putUserData(RunDashboardCustomizer.NODE_LINKS, links);
}
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -153,7 +148,7 @@ public void run(@NotNull ProgressIndicator indicator) {
}
});
}
return null;
return state;
}

private void waitForPortAvailable(int port, ProgressIndicator monitor) throws IOException {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}

}
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,12 @@
<projectService serviceImplementation="com.redhat.devtools.intellij.lsp4mp4ij.classpath.ClasspathResourceChangedManager"/>
<projectService serviceImplementation="com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProjectManager"/>
<projectService serviceImplementation="com.redhat.devtools.intellij.quarkus.QuarkusDeploymentSupport"/>

<!--Quarkus run config -->
<projectService serviceImplementation="com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfigurationManager" />
<configurationType implementation="com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfigurationType"/>
<consoleActionsPostProcessor implementation="com.redhat.devtools.intellij.quarkus.run.QuarkusRunConsolePostProcessor"/>
<runDashboardCustomizer implementation="com.redhat.devtools.intellij.quarkus.run.QarkusRunDashboardCustomizer"/>

<!-- Qute -->
<facetType implementation="com.redhat.devtools.intellij.qute.facet.QuteFacetType"/>
Expand Down

0 comments on commit 51f2f12

Please sign in to comment.