Skip to content

Commit

Permalink
Merge pull request #43192 from iocanel/plug-remove-43036
Browse files Browse the repository at this point in the history
Fix Quarkus plugin syncing
  • Loading branch information
gsmet authored Oct 16, 2024
2 parents 43fdb84 + 0ae451c commit 3c82a86
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 23 deletions.
5 changes: 4 additions & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/QuarkusCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public int run(String... args) throws Exception {
boolean noCommand = args.length == 0 || args[0].startsWith("-");
boolean helpCommand = Arrays.stream(args).anyMatch(arg -> arg.equals("--help"));
boolean pluginCommand = args.length >= 1 && (args[0].equals("plug") || args[0].equals("plugin"));
boolean pluginSyncCommand = pluginCommand && args.length >= 2 && args[1].equals("sync");

try {
Optional<String> missingCommand = checkMissingCommand(cmd, args);
Expand All @@ -117,7 +118,9 @@ public int run(String... args) throws Exception {
}
PluginCommandFactory pluginCommandFactory = new PluginCommandFactory(output);
PluginManager pluginManager = pluginManager(output, testDir, interactiveMode);
pluginManager.syncIfNeeded();
if (!pluginSyncCommand) { // Let`s not sync before the actual command
pluginManager.syncIfNeeded();
}
Map<String, Plugin> plugins = new HashMap<>(pluginManager.getInstalledPlugins());
pluginCommandFactory.populateCommands(cmd, plugins);
missingCommand.filter(m -> !plugins.containsKey(m)).ifPresent(m -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ private Optional<PluginCommand> createPluginCommand(Plugin plugin) {
return plugin.getLocation().map(l -> new JBangCommand(l, output));
case executable:
return plugin.getLocation().map(l -> new ShellCommand(plugin.getName(), Paths.get(l), output));
case extension:
if (PluginUtil.checkGACTV(plugin.getLocation()).isPresent()) {
return plugin.getLocation().flatMap(PluginUtil::checkGACTV).map(g -> new JBangCommand(toGAVC(g), output));
} else if (plugin.getLocation().filter(l -> l.endsWith(".jar")).isPresent()) {
return plugin.getLocation().map(l -> new JBangCommand(l, output));
}
default:
throw new IllegalStateException("Unknown plugin type!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public Plugin withCatalogLocation(Optional<Path> catalogLocation) {
return new Plugin(name, type, location, description, catalogLocation, inUserCatalog);
}

public Plugin withType(PluginType type) {
return new Plugin(name, type, location, description, catalogLocation, inUserCatalog);
}

public Plugin inUserCatalog() {
return new Plugin(name, type, location, description, catalogLocation, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public boolean reconcile() {
*/
private boolean reconcile(PluginCatalog catalog) {
Path location = catalog.getCatalogLocation()
.orElseThrow(() -> new IllegalArgumentException("Unknwon plugin catalog location."));
.orElseThrow(() -> new IllegalArgumentException("Unknown plugin catalog location."));
List<PluginType> installedTypes = catalog.getPlugins().entrySet().stream().map(Map.Entry::getValue).map(Plugin::getType)
.collect(Collectors.toList());
//Let's only fetch installable plugins of the corresponding types.
Expand Down Expand Up @@ -279,24 +279,31 @@ private boolean reconcile(PluginCatalog catalog) {
* @return true if changes any catalog was modified.
*/
public boolean sync() {
boolean catalogModified = reconcile();
Map<String, Plugin> installedPlugins = getInstalledPlugins();
Map<String, Plugin> extensionPlugins = state.getExtensionPlugins();
Map<String, Plugin> pluginsToInstall = extensionPlugins.entrySet().stream()
.filter(e -> !installedPlugins.containsKey(e.getKey()))
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
catalogModified = catalogModified || !pluginsToInstall.isEmpty();
pluginsToInstall.forEach((name, plugin) -> {
addPlugin(plugin);
});
state.invalidate();
if (!catalogModified) {
PluginCatalogService pluginCatalogService = state.getPluginCatalogService();
PluginCatalog catalog = state.pluginCatalog(false);
pluginCatalogService.writeCatalog(catalog);
// here we are just touching the catalog, no need to invalidate
if (state.isSynced()) {
return false;
}
try {
boolean catalogModified = reconcile();
Map<String, Plugin> installedPlugins = getInstalledPlugins();
Map<String, Plugin> extensionPlugins = state.getExtensionPlugins();
Map<String, Plugin> pluginsToInstall = extensionPlugins.entrySet().stream()
.filter(e -> !installedPlugins.containsKey(e.getKey()))
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
catalogModified = catalogModified || !pluginsToInstall.isEmpty();
pluginsToInstall.forEach((name, plugin) -> {
addPlugin(plugin);
});
state.invalidate();
if (!catalogModified) {
PluginCatalogService pluginCatalogService = state.getPluginCatalogService();
PluginCatalog catalog = state.pluginCatalog(false);
pluginCatalogService.writeCatalog(catalog);
// here we are just touching the catalog, no need to invalidate
}
return catalogModified;
} finally {
state.synced();
}
return catalogModified;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class PluginMangerState {

private PluginCatalog _combinedCatalog;

private boolean synced;

public PluginCatalogService getPluginCatalogService() {
return pluginCatalogService;
}
Expand Down Expand Up @@ -119,6 +121,9 @@ public Map<String, Plugin> installablePlugins(List<PluginType> types) {
case executable:
installablePlugins.putAll(executablePlugins());
break;
case extension:
installablePlugins.putAll(extensionPlugins());
break;
}
}
installablePlugins.putAll(executablePlugins().entrySet().stream().filter(e -> types.contains(e.getValue().getType()))
Expand Down Expand Up @@ -186,8 +191,8 @@ public Map<String, Plugin> extensionPlugins() {
for (ArtifactKey key : allKeys) {
Extension extension = allExtensions.get(key);
for (String cliPlugin : ExtensionProcessor.getCliPlugins(extension)) {
Plugin plugin = cliPlugin.contains(ALIAS_SEPARATOR) ? util.fromAlias(cliPlugin)
: util.fromLocation(cliPlugin);
Plugin plugin = (cliPlugin.contains(ALIAS_SEPARATOR) ? util.fromAlias(cliPlugin)
: util.fromLocation(cliPlugin)).withType(PluginType.extension);
extensionPlugins.put(plugin.getName(), plugin);
}
}
Expand Down Expand Up @@ -249,6 +254,14 @@ public Optional<Path> getProjectRoot() {
return this.projectRoot;
}

public boolean isSynced() {
return synced;
}

public void synced() {
this.synced = true;
}

public void invalidateCatalogs() {
_projectCatalog = null;
_userCatalog = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum PluginType {
java,
maven,
executable,
jbang;
jbang,
extension
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static boolean shouldRemove(Plugin p) {
if (checkUrl(p.getLocation()).isPresent()) { //We don't want to remove remotely located plugins
return false;
}
if (checkGACTV(p.getLocation()).isPresent()) { //We don't want to remove remotely located plugins
if (checkGACTV(p.getLocation()).isPresent() && p.getType() != PluginType.extension) { //We don't want to remove remotely located plugins
return false;
}
if (p.getLocation().map(PluginUtil::isLocalFile).orElse(false)) {
Expand Down

0 comments on commit 3c82a86

Please sign in to comment.