|
3 | 3 | import java.nio.file.Path; |
4 | 4 | import java.nio.file.Paths; |
5 | 5 | import java.util.ArrayList; |
| 6 | +import java.util.HashMap; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.Map; |
8 | 9 | import java.util.Set; |
@@ -71,7 +72,8 @@ void createBuildTimeActions(BuildProducer<BuildTimeActionBuildItem> buildTimeAct |
71 | 72 |
|
72 | 73 | BuildTimeActionBuildItem buildTimeActions = new BuildTimeActionBuildItem(NAMESPACE); |
73 | 74 | getCategories(buildTimeActions); |
74 | | - getInstallableExtensions(buildTimeActions); |
| 75 | + getInstallableExtensions(buildTimeActions); // For Dev UI |
| 76 | + listInstallableExtensions(buildTimeActions); // For Dev MCP |
75 | 77 | getInstalledNamespaces(buildTimeActions); |
76 | 78 | removeExtension(buildTimeActions); |
77 | 79 | addExtension(buildTimeActions); |
@@ -104,34 +106,59 @@ private void getCategories(BuildTimeActionBuildItem buildTimeActions) { |
104 | 106 | } |
105 | 107 |
|
106 | 108 | private void getInstallableExtensions(BuildTimeActionBuildItem buildTimeActions) { |
| 109 | + buildTimeActions |
| 110 | + .actionBuilder().methodName(new Object() { |
| 111 | + }.getClass().getEnclosingMethod().getName()) |
| 112 | + .function(ignored -> { |
| 113 | + return CompletableFuture.supplyAsync(() -> { |
| 114 | + return listExtensionInQuarkusProject(); |
| 115 | + }); |
| 116 | + }) |
| 117 | + .build(); |
| 118 | + } |
| 119 | + |
| 120 | + private void listInstallableExtensions(BuildTimeActionBuildItem buildTimeActions) { |
107 | 121 | buildTimeActions |
108 | 122 | .actionBuilder().methodName(new Object() { |
109 | 123 | }.getClass().getEnclosingMethod().getName()) |
110 | 124 | .description( |
111 | 125 | "Get all extensions that can be added to the current project (i.e it's not currently added to the pom)") |
112 | 126 | .function(ignored -> { |
113 | 127 | return CompletableFuture.supplyAsync(() -> { |
114 | | - try { |
115 | | - QuarkusCommandOutcome outcome = new ListExtensions(getQuarkusProject()) |
116 | | - .installed(false) |
117 | | - .all(false) |
118 | | - .format("object") |
119 | | - .execute(); |
120 | 128 |
|
121 | | - if (outcome.isSuccess()) { |
122 | | - return outcome.getResult(); |
123 | | - } |
124 | | - |
125 | | - return null; |
126 | | - } catch (QuarkusCommandException e) { |
127 | | - throw new RuntimeException(e); |
| 129 | + List<Map<String, String>> filtered = new ArrayList<>(); |
| 130 | + for (io.quarkus.registry.catalog.Extension e : listExtensionInQuarkusProject()) { |
| 131 | + Map<String, String> entry = new HashMap<>(); |
| 132 | + entry.put("name", e.getName()); |
| 133 | + entry.put("description", e.getDescription()); |
| 134 | + entry.put("extensionArtifactId", e.getArtifact().toCompactCoords()); |
| 135 | + filtered.add(entry); |
128 | 136 | } |
| 137 | + return filtered; |
129 | 138 | }); |
130 | 139 | }) |
131 | 140 | .enableMcpFuctionByDefault() |
132 | 141 | .build(); |
133 | 142 | } |
134 | 143 |
|
| 144 | + private List<io.quarkus.registry.catalog.Extension> listExtensionInQuarkusProject() throws RuntimeException { |
| 145 | + try { |
| 146 | + QuarkusCommandOutcome outcome = new ListExtensions(getQuarkusProject()) |
| 147 | + .installed(false) |
| 148 | + .all(false) |
| 149 | + .format("object") |
| 150 | + .execute(); |
| 151 | + |
| 152 | + if (outcome.isSuccess()) { |
| 153 | + return (List) outcome.getResult(); |
| 154 | + } |
| 155 | + |
| 156 | + return null; |
| 157 | + } catch (QuarkusCommandException e) { |
| 158 | + throw new RuntimeException(e); |
| 159 | + } |
| 160 | + } |
| 161 | + |
135 | 162 | private void getInstalledNamespaces(BuildTimeActionBuildItem buildTimeActions) { |
136 | 163 | buildTimeActions |
137 | 164 | .actionBuilder().methodName(new Object() { |
@@ -188,12 +215,7 @@ private void removeExtension(BuildTimeActionBuildItem buildTimeActions) { |
188 | 215 | QuarkusCommandOutcome outcome = new RemoveExtensions(getQuarkusProject()) |
189 | 216 | .extensions(Set.of(extensionArtifactId)) |
190 | 217 | .execute(); |
191 | | - |
192 | | - if (outcome.isSuccess()) { |
193 | | - return true; |
194 | | - } else { |
195 | | - return false; |
196 | | - } |
| 218 | + return outcome.isSuccess(); |
197 | 219 | } catch (QuarkusCommandException e) { |
198 | 220 | throw new RuntimeException(e); |
199 | 221 | } |
|
0 commit comments