Skip to content

Commit

Permalink
feat:warn when add/rm plug in both usr/prj scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Apr 1, 2023
1 parent 2979ec6 commit af82ec7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Integer addPlugin() throws IOException {
PluginListTable table = new PluginListTable(List.of(new PluginListItem(true, plugin)), false);
output.info("Added plugin:");
output.info(table.getContent());
if (!plugin.isInUserCatalog() && userPluginManager().getInstalledPlugins().containsKey(plugin.getName())) {
output.warn(
"Plugin was added in the project scope, but another with the same name exists in the user scope!\nThe project scoped one will take precedence when invoked from within the project!");
}
return CommandLine.ExitCode.OK;
}).orElseGet(() -> {
output.error("No plugin available at: " + this.nameOrLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ public PluginManager pluginManager() {
catalogOptions.user ? Optional.empty() : quarkusProject(),
p -> type.map(t -> t == p.getType()).orElse(true));
}

public PluginManager userPluginManager() {
Set<String> registries = Registries.getRegistries(registryClient, "quarkusio");
PluginManagerSettings settings = PluginManagerSettings.defaultSettings()
.withCatalogs(registries)
.withInteractivetMode(!output.isCliTest());

return new PluginManager(settings, output,
catalogOptions.userDirectory.or(() -> Optional.ofNullable(Paths.get(System.getProperty("user.home")))),
Optional.empty(),
Optional.empty(),
p -> type.map(t -> t == p.getType()).orElse(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ public Integer call() {

Integer removePlugin() throws IOException {
PluginManager pluginManager = pluginManager();
Plugin toRemove = pluginManager.getInstalledPlugins().get(name);
Optional<Plugin> removedPlugin = pluginManager.removePlugin(name);

return removedPlugin.map(plugin -> {
PluginListTable table = new PluginListTable(List.of(new PluginListItem(false, plugin)), false);
output.info("Removed plugin:");
output.info(table.getContent());
if (!plugin.isInUserCatalog()) {
if (userPluginManager().getInstalledPlugins().containsKey(plugin.getName())) {
output.warn(
"The removed plugin was available both in user and project scopes. It was removed from the project but will remain available in the user scope!");
}
}
return CommandLine.ExitCode.OK;
}).orElseGet(() -> {
output.error("Plugin: " + name + " not found in catalog!");
Expand All @@ -61,4 +68,5 @@ void dryRunRemove(CommandLine.Help help) {
dryRunOutput.put("Plugin to remove", name);
output.info(help.createTextTable(dryRunOutput).toString());
};

}

0 comments on commit af82ec7

Please sign in to comment.