Add support for plugin root level command

Completely generic plugins can be now created:

  @RequiresCapability(
      value = GlobalCapability.ADMINISTRATE_SERVER,
      scope = CapabilityScope.CORE)
  public class ShellCommand extends SshCommand {
    @Override
    protected void parseCommandLine(Object options) throws UnloggedFailure {
      // No op: turn off parsing utility
    }

    @Override
    protected void run() throws UnloggedFailure, IOException {
      String command = getName().substring(getPluginName().length() + 1);
      List<String> c = Lists.newArrayListWithCapacity(getArguments().length + 1);
      c.add(command);
      c.addAll(Arrays.asList(getArguments()));
      ProcessBuilder proc = new ProcessBuilder(c);
      proc.start();
      [...]
    }
  }

SSH module is bound as:

  public class SshModule extends SingleCommandPluginModule {
    @Override
    protected void configure(LinkedBindingBuilder<Command> b) {
      b.to(ShellCommand.class);
    }
  }

If the plugin above is deployed under sh.jar file in $site/plugins
directory, generic commands can be called without specifing the
actually SSH command:

  $ ssh gerrit sh ls -all -R
  $ ssh gerrit sh ps -a -ef

Inspired-by: David Ostrovsky <david@ostrovsky.org>
Change-Id: If0bdce5db82b436723090e17088923c44b5e11eb
1 file changed