|
18 | 18 | import com.intellij.ide.projectView.PresentationData; |
19 | 19 | import com.intellij.openapi.module.Module; |
20 | 20 | import com.intellij.openapi.project.Project; |
| 21 | +import com.intellij.openapi.util.Key; |
21 | 22 | import com.intellij.ui.SimpleColoredComponent; |
22 | 23 | import com.intellij.ui.SimpleTextAttributes; |
23 | 24 | import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.project.PsiMicroProfileProject; |
|
29 | 30 | import org.jetbrains.annotations.NotNull; |
30 | 31 | import org.jetbrains.annotations.Nullable; |
31 | 32 |
|
| 33 | +import java.lang.reflect.Method; |
32 | 34 | import java.util.HashMap; |
33 | 35 | import java.util.Map; |
34 | 36 |
|
|
42 | 44 | */ |
43 | 45 | public class QuarkusRunDashboardCustomizer extends RunDashboardCustomizer { |
44 | 46 |
|
| 47 | + private static final @Nullable Method putUserData = getPutUserDataMethod(); |
| 48 | + |
| 49 | + private static final @Nullable Key<Map<Object, Object>> NODE_LINKS = getNODE_LINKS(); |
| 50 | + |
45 | 51 | @Override |
46 | 52 | public boolean isApplicable(@NotNull RunnerAndConfigurationSettings settings, @Nullable RunContentDescriptor descriptor) { |
47 | 53 | return settings.getConfiguration() instanceof QuarkusRunConfiguration; |
48 | 54 | } |
49 | 55 |
|
50 | 56 | @Override |
51 | 57 | public boolean updatePresentation(@NotNull PresentationData presentation, @NotNull RunDashboardRunConfigurationNode node) { |
52 | | - if (!(node.getConfigurationSettings().getConfiguration() instanceof QuarkusRunConfiguration)) { |
| 58 | + var quarkusRunConfiguration = node.getConfigurationSettings().getConfiguration() instanceof QuarkusRunConfiguration config ? config : null; |
| 59 | + if (quarkusRunConfiguration == null) { |
53 | 60 | return false; |
54 | 61 | } |
55 | 62 | RunContentDescriptor descriptor = node.getDescriptor(); |
56 | 63 | if (descriptor != null) { |
57 | 64 | ProcessHandler processHandler = descriptor.getProcessHandler(); |
58 | 65 | if (processHandler != null && !processHandler.isProcessTerminated()) { |
59 | 66 | // The Quarkus run configuration is running |
60 | | - QuarkusRunConfiguration quarkusRunConfiguration = (QuarkusRunConfiguration) node.getConfigurationSettings().getConfiguration(); |
61 | 67 | Module module = quarkusRunConfiguration.getModule(); |
62 | 68 | if (QuarkusModuleUtil.isQuarkusWebAppModule(module)) { |
63 | 69 | PsiMicroProfileProject mpProject = PsiMicroProfileProjectManager.getInstance(module.getProject()).getMicroProfileProject(module); |
@@ -95,11 +101,41 @@ public void run() { |
95 | 101 | TelemetryManager.instance().send(TelemetryEventName.UI_OPEN_DEV_UI); |
96 | 102 | } |
97 | 103 | }); |
98 | | - node.putUserData(RunDashboardCustomizer.NODE_LINKS, links); |
| 104 | + updateLinks(node, links); |
99 | 105 | } |
100 | 106 | } |
101 | 107 | } |
102 | 108 | return true; |
103 | 109 | } |
104 | 110 |
|
| 111 | + private void updateLinks(@NotNull RunDashboardRunConfigurationNode node, Map<Object, Object> links) { |
| 112 | + if (putUserData == null) { |
| 113 | + return; |
| 114 | + } |
| 115 | + try { |
| 116 | + putUserData.invoke(node, NODE_LINKS, links); |
| 117 | + } catch (Exception e) { |
| 118 | + |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + private static @Nullable Method getPutUserDataMethod() { |
| 123 | + try { |
| 124 | + // We need to use Java Reflection since IU 2025.3 has removed RunDashboardRunConfigurationNode.putUserData |
| 125 | + return RunDashboardRunConfigurationNode.class.getMethod("putUserData", Key.class, Object.class); |
| 126 | + } catch (Exception e) { |
| 127 | + return null; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + private static @Nullable Key<Map<Object, Object>> getNODE_LINKS() { |
| 132 | + try { |
| 133 | + // We need to use Java Reflection since IU 2025.3 has removed RunDashboardCustomizer.NODE_LINKS |
| 134 | + var field = RunDashboardCustomizer.class.getDeclaredField("NODE_LINKS"); |
| 135 | + return (Key<Map<Object, Object>>) field.get(RunDashboardCustomizer.class); |
| 136 | + } catch (Exception e) { |
| 137 | + return null; |
| 138 | + } |
| 139 | + } |
| 140 | + |
105 | 141 | } |
0 commit comments