-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Connect Quarkus run configuration with Services view support
Fixes #1265 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
653fb62
commit 11d2486
Showing
3 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...java/com/redhat/devtools/intellij/quarkus/run/dashboard/QarkusRunDashboardCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/******************************************************************************* | ||
* 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.dashboard; | ||
|
||
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 com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration; | ||
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunContext; | ||
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()); | ||
|
||
// Add application Url as hyperlink | ||
String applicationUrl = runContext.getApplicationURL(); | ||
String applicationLabel = applicationUrl; | ||
presentation.addText(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES); | ||
presentation.addText(applicationLabel, SimpleTextAttributes.LINK_ATTRIBUTES); | ||
|
||
// Add DevUI Url as hyperlink | ||
String devUIUrl = runContext.getDevUIURL(); | ||
String devUILabel = "Open DevUI"; | ||
presentation.addText(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES); | ||
presentation.addText(devUILabel, SimpleTextAttributes.LINK_ATTRIBUTES); | ||
|
||
Map<Object, Object> links = new HashMap(); | ||
openInBrowser(applicationLabel, applicationUrl, links); | ||
openInBrowser(devUILabel, devUIUrl, links); | ||
node.putUserData(RunDashboardCustomizer.NODE_LINKS, links); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private static void openInBrowser(String label, String url, Map<Object, Object> links) { | ||
links.put(label, new Runnable() { | ||
@Override | ||
public void run() { | ||
BrowserUtil.browse(url); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters