Skip to content

Commit

Permalink
feat: Extension plguin type and fix sync ext plugs
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 11, 2024
1 parent 9f917a7 commit 0ae451c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,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 @@ -188,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
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 0ae451c

Please sign in to comment.