-
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 51f2f12
Showing
3 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/com/redhat/devtools/intellij/quarkus/run/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,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; | ||
} | ||
|
||
} |
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
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