Skip to content

Commit

Permalink
chore: make JBang Catalog calls from CLI not fatal.
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Sep 22, 2023
1 parent b0d4118 commit a5a8125
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.cli.plugin;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -22,6 +23,7 @@ public class JBangCatalogService extends CatalogService<JBangCatalog> {
private final String fallbackCatalog;
private final String[] remoteCatalogs;
private final JBangSupport jbang;
private final MessageWriter output;

public JBangCatalogService(MessageWriter output) {
this(output, "quarkus-", "quarkusio");
Expand All @@ -38,6 +40,7 @@ public JBangCatalogService(boolean interactiveMode, MessageWriter output, String
this.fallbackCatalog = fallbackCatalog;
this.remoteCatalogs = remoteCatalogs;
this.jbang = new JBangSupport(interactiveMode, output);
this.output = output;
}

public boolean ensureJBangIsInstalled() {
Expand Down Expand Up @@ -92,7 +95,12 @@ public JBangCatalog readCombinedCatalog(Optional<Path> projectDir, Optional<Path
Optional<String> catalogFile = projectDir
.map(d -> RELATIVE_PLUGIN_CATALOG.apply(d).toAbsolutePath().toString());
catalogFile.ifPresent(f -> {
List<String> lines = jbang.execute("alias", "list", "-f", f, "--verbose");
List<String> lines = new ArrayList<>();
try {
lines.addAll(jbang.execute("alias", "list", "-f", f, "--verbose"));
} catch (Exception e) {
output.debug("Failed to read catalog file: " + f + ". Ignoring.");
}
aliases.putAll(readAliases(lines));
});
});
Expand All @@ -116,14 +124,25 @@ public JBangCatalog readCombinedCatalog(Optional<Path> projectDir, Optional<Path
}

private Map<String, JBangAlias> listAliases(JBangSupport jbang, String remoteCatalog) {
List<String> lines = jbang.execute("alias", "list", "--verbose", remoteCatalog);
List<String> lines = new ArrayList<>();
try {
lines.addAll(jbang.execute("alias", "list", "--verbose", remoteCatalog));
} catch (Exception e) {
this.output.debug("Failed to list aliases from remote catalog: " + remoteCatalog + ". Ignorning.");
}

return readAliases(lines);
}

private Map<String, JBangAlias> listAliasesOrFallback(JBangSupport jbang, String fallbackCatalog) {
List<String> localCatalogs = jbang.execute("catalog", "list").stream()
.map(l -> l.substring(0, l.indexOf(" ")))
.collect(Collectors.toList());
List<String> localCatalogs = new ArrayList<>();
try {
for (String catalog : jbang.execute("catalog", "list")) {
localCatalogs.add(catalog.substring(0, catalog.indexOf(" ")));
}
} catch (Exception e) {
this.output.debug("Failed to list jbang catalogs. Ignoring.");
}

//If there are locally installed catalogs, then go through every single one of them
//and collect the aliases.
Expand Down

0 comments on commit a5a8125

Please sign in to comment.