Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve latency of CLI plugin commands #35620

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public JBangCatalogService(boolean interactiveMode, MessageWriter output, String
this.jbang = new JBangSupport(interactiveMode, output);
}

public boolean ensureJBangIsInstalled() {
return jbang.ensureJBangIsInstalled();
}

@Override
public JBangCatalog readCatalog(Path path) {
if (!jbang.isAvailable() && !jbang.isInstallable()) {
Expand Down Expand Up @@ -93,8 +97,9 @@ public JBangCatalog readCombinedCatalog(Optional<Path> projectDir, Optional<Path
});
});

//If not catalog have been specified use all available.
if (remoteCatalogs.length == 0) {
if (!jbang.isAvailable()) {
//If jbang is not available, ignore aliases
} else if (remoteCatalogs.length == 0) { //If not catalog have been specified use all available.
aliases.putAll(listAliasesOrFallback(jbang, fallbackCatalog).entrySet()
.stream()
.filter(e -> !aliases.containsKey(e.getKey()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class JBangSupport {
private Path workingDirectory;

private Optional<Boolean> installed = Optional.empty();
private Optional<String> version = Optional.empty();

public JBangSupport(boolean interactiveMode, MessageWriter output) {
this(interactiveMode, output, Paths.get(System.getProperty("user.dir")));
Expand Down Expand Up @@ -138,8 +139,12 @@ public List<String> execute(String... args) {
}

public Optional<String> version() {
return execute("version").stream().findFirst();

if (version.isPresent()) {
return version;
} else {
version = execute("version").stream().findFirst();
}
return version;
}

public boolean isAvailable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ private boolean reconcile(PluginCatalog catalog) {
.orElseThrow(() -> new IllegalArgumentException("Unknwon plugin catalog location."));
List<PluginType> installedTypes = catalog.getPlugins().entrySet().stream().map(Map.Entry::getValue).map(Plugin::getType)
.collect(Collectors.toList());
Map<String, Plugin> installablePlugins = state.getInstallablePlugins().entrySet().stream()
//Let's only fetch installable plugins of the corresponding types.
//This will help us avoid uneeded calls to things like jbang if no jbang plugins are installed
Map<String, Plugin> installablePlugins = state.installablePlugins(installedTypes).entrySet().stream()
.filter(e -> installedTypes.contains(e.getValue().getType()))
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public Map<String, Plugin> getInstallablePlugins() {
public Map<String, Plugin> jbangPlugins() {
boolean isUserScoped = !projectRoot.isPresent();
Map<String, Plugin> jbangPlugins = new HashMap<>();
jbangCatalogService.ensureJBangIsInstalled();
JBangCatalog jbangCatalog = jbangCatalogService.readCombinedCatalog(projectRoot, userHome);
jbangCatalog.getAliases().forEach((location, alias) -> {
String name = util.getName(location);
Expand Down