|
10 | 10 | import java.util.List;
|
11 | 11 | import java.util.Map;
|
12 | 12 | import java.util.Optional;
|
| 13 | +import java.util.Set; |
13 | 14 | import java.util.concurrent.Callable;
|
| 15 | +import java.util.function.Supplier; |
14 | 16 |
|
15 | 17 | import jakarta.inject.Inject;
|
16 | 18 |
|
|
25 | 27 | import io.quarkus.cli.plugin.PluginManager;
|
26 | 28 | import io.quarkus.cli.plugin.PluginManagerSettings;
|
27 | 29 | import io.quarkus.cli.registry.RegistryClientMixin;
|
28 |
| -import io.quarkus.cli.utils.Registries; |
29 | 30 | import io.quarkus.devtools.project.BuildTool;
|
30 | 31 | import io.quarkus.devtools.project.QuarkusProject;
|
31 | 32 | import io.quarkus.devtools.project.QuarkusProjectHelper;
|
@@ -95,18 +96,23 @@ public int run(String... args) throws Exception {
|
95 | 96 | try {
|
96 | 97 | Optional<String> missing = checkMissingCommand(cmd, args);
|
97 | 98 | missing.ifPresent(m -> {
|
98 |
| - Map<String, Plugin> installable = pluginManager.getInstallablePlugins(); |
99 |
| - if (installable.containsKey(m)) { |
100 |
| - Plugin candidate = installable.get(m); |
101 |
| - PluginListItem item = new PluginListItem(false, candidate); |
102 |
| - PluginListTable table = new PluginListTable(List.of(item)); |
103 |
| - output.info("Command %s not installed but the following plugin is available:\n%s", m, table.getContent()); |
104 |
| - if (interactiveMode && Prompt.yesOrNo(true, |
105 |
| - "Would you like to install it now ?", |
106 |
| - args)) { |
107 |
| - pluginManager.addPlugin(m).ifPresent(added -> plugins.put(added.getName(), added)); |
108 |
| - pluginCommandFactory.populateCommands(cmd, plugins); |
| 99 | + try { |
| 100 | + Map<String, Plugin> installable = pluginManager.getInstallablePlugins(); |
| 101 | + if (installable.containsKey(m)) { |
| 102 | + Plugin candidate = installable.get(m); |
| 103 | + PluginListItem item = new PluginListItem(false, candidate); |
| 104 | + PluginListTable table = new PluginListTable(List.of(item)); |
| 105 | + output.info("Command %s not installed but the following plugin is available:\n%s", m, |
| 106 | + table.getContent()); |
| 107 | + if (interactiveMode && Prompt.yesOrNo(true, |
| 108 | + "Would you like to install it now ?", |
| 109 | + args)) { |
| 110 | + pluginManager.addPlugin(m).ifPresent(added -> plugins.put(added.getName(), added)); |
| 111 | + pluginCommandFactory.populateCommands(cmd, plugins); |
| 112 | + } |
109 | 113 | }
|
| 114 | + } catch (Exception e) { |
| 115 | + output.error("Command %s is missing and can't be installed.", m); |
110 | 116 | }
|
111 | 117 | });
|
112 | 118 | } catch (MutuallyExclusiveArgsException e) {
|
@@ -241,25 +247,26 @@ private Optional<Path> getProjectRoot(Optional<String> testDir) {
|
241 | 247 | return Optional.ofNullable(projectRoot);
|
242 | 248 | }
|
243 | 249 |
|
244 |
| - private Optional<QuarkusProject> quarkusProject(Optional<String> testDir) { |
245 |
| - try { |
246 |
| - Path root = getProjectRoot(testDir).orElseThrow(); |
247 |
| - BuildTool buildTool = QuarkusProjectHelper.detectExistingBuildTool(root); |
248 |
| - if (buildTool == null) { |
249 |
| - return Optional.empty(); |
250 |
| - } |
251 |
| - return Optional |
252 |
| - .ofNullable(registryClient.createQuarkusProject(root, new TargetQuarkusPlatformGroup(), buildTool, output)); |
253 |
| - } catch (Exception e) { |
254 |
| - return Optional.empty(); |
| 250 | + private Supplier<QuarkusProject> quarkusProject(Optional<String> testDir) { |
| 251 | + Path root = getProjectRoot(testDir).orElseThrow(); |
| 252 | + BuildTool buildTool = QuarkusProjectHelper.detectExistingBuildTool(root); |
| 253 | + if (buildTool == null) { |
| 254 | + return () -> null; |
255 | 255 | }
|
| 256 | + return () -> { |
| 257 | + try { |
| 258 | + return registryClient.createQuarkusProject(root, new TargetQuarkusPlatformGroup(), buildTool, output); |
| 259 | + } catch (Exception e) { |
| 260 | + return null; |
| 261 | + } |
| 262 | + }; |
256 | 263 | }
|
257 | 264 |
|
258 | 265 | private PluginManager pluginManager(OutputOptionMixin output, Optional<String> testDir, boolean interactiveMode) {
|
259 | 266 | PluginManagerSettings settings = PluginManagerSettings.defaultSettings()
|
260 |
| - .withCatalogs(Registries.getRegistries(registryClient, "quarkusio")) |
| 267 | + .withCatalogs(Set.<String> of("quarkusio")) |
261 | 268 | .withInteractivetMode(interactiveMode); // Why not just getting it from output.isClieTest ? Cause args have not been parsed yet.
|
262 |
| - return new PluginManager(settings, output, Optional.ofNullable(Paths.get(System.getProperty("user.home"))), |
263 |
| - getProjectRoot(testDir), quarkusProject(testDir), p -> true); |
| 269 | + return PluginManager.create(settings, output, Optional.ofNullable(Paths.get(System.getProperty("user.home"))), |
| 270 | + getProjectRoot(testDir), quarkusProject(testDir)); |
264 | 271 | }
|
265 | 272 | }
|
0 commit comments