From 32e16158fdea658b485d31db665fad162242e1a8 Mon Sep 17 00:00:00 2001 From: Aniket Kumar Date: Fri, 29 Sep 2023 16:20:35 +0530 Subject: Fix the warning to not appear while loading a plugin Prior to this change, warning [1] was observed in the error logs for a plugin which has exclusively bindings for SshExecuteCommandInterceptor/ SshCreateCommandInterceptor in the ssh module as outlined in the documentation provided in references [2] and [3]. Fix this by skipping the warning if those bindings are found. [1] WARN com.google.gerrit.sshd.SshPluginStarterCallback : Plugin did not define its top-level command nor any DynamicOptions com.google.inject.ConfigurationException: Guice configuration errors: [Guice/MissingImplementation]: No implementation for Command annotated with @CommandName("") was bound. [2] https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ssh-command-creation-interception [3] https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ssh-command-execution-interception Bug: Issue 302408544 Change-Id: I80a2de37f2d38766b66315359779f7678f7062db Release-Notes: Eliminated startup warning for plugins whose SshModule only provides Ssh*CommandInterceptors --- .../google/gerrit/sshd/SshPluginStarterCallback.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java index 6e8590c888..55ecdfeecf 100644 --- a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java +++ b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java @@ -24,6 +24,10 @@ import com.google.inject.Inject; import com.google.inject.Key; import com.google.inject.Provider; import com.google.inject.Singleton; +import com.google.inject.TypeLiteral; +import com.google.inject.internal.MoreTypes; +import java.util.ArrayList; +import java.util.List; import org.apache.sshd.server.command.Command; @Singleton @@ -63,9 +67,9 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe try { return plugin.getSshInjector().getProvider(key); } catch (RuntimeException err) { - if (!providesDynamicOptions(plugin)) { + if (!providesDynamicOptions(plugin) && !providesCommandInterceptor(plugin)) { logger.atWarning().withCause(err).log( - "Plugin %s did not define its top-level command nor any DynamicOptions", + "Plugin %s did not define its top-level command, any DynamicOptions, nor any Ssh*CommandInterceptors", plugin.getName()); } } @@ -76,4 +80,16 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe private boolean providesDynamicOptions(Plugin plugin) { return dynamicBeans.plugins().contains(plugin.getName()); } + + private boolean providesCommandInterceptor(Plugin plugin) { + List> typeLiterals = new ArrayList<>(2); + typeLiterals.add( + MoreTypes.canonicalizeForKey( + (TypeLiteral) TypeLiteral.get(SshExecuteCommandInterceptor.class))); + typeLiterals.add( + MoreTypes.canonicalizeForKey( + (TypeLiteral) TypeLiteral.get(SshCreateCommandInterceptor.class))); + return plugin.getSshInjector().getAllBindings().keySet().stream() + .anyMatch(key -> typeLiterals.contains(key.getTypeLiteral())); + } } -- cgit v1.2.3