diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt new file mode 100644 index 0000000000..f79b8c0a74 --- /dev/null +++ b/Documentation/dev-plugins.txt @@ -0,0 +1,40 @@ +Gerrit Code Review - Plugin Development +======================================= + +A plugin in gerrit is tightly coupled code that runs in the same +JVM as gerrit. It has full access to all gerrit internals. Plugins +are coupled to a specific major.minor gerrit version. + +REQUIREMENTS +------------ + +To start development, you may download the sample maven project, which downloads +the following dependencies; + +* gerrit-sdk.jar file that matches the war file you are developing against + + +Manifest +-------- + +Plugins need to include the following data in the jar manifest file; +Gerrit-Plugin = plugin_name +Gerrit-Module = pkg.class + +SSH Commands +------------ + +You may develop plugins which provide commands that can be accessed through the SSH interface. +These commands register themselves as a part of SSH Commands (link). + +Each of your plugins commands needs to extend BaseCommand. + +Any plugin which implements at least one ssh command needs to also provide a class which extends +the PluginCommandModule in order to register the ssh command(s) in its configure method which you +must override. + +Registering is done by calling the command(String commandName).to(ClassName klass) + +GERRIT +------ +Part of link:index.html[Gerrit Code Review] diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/PluginCommandModule.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/PluginCommandModule.java new file mode 100644 index 0000000000..788dfa14b0 --- /dev/null +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/PluginCommandModule.java @@ -0,0 +1,43 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.sshd.commands; + +import com.google.gerrit.sshd.CommandName; +import com.google.gerrit.sshd.Commands; +import com.google.gerrit.sshd.DispatchCommandProvider; +import com.google.inject.AbstractModule; +import com.google.inject.binder.LinkedBindingBuilder; + +import org.apache.sshd.server.Command; + +public abstract class PluginCommandModule extends AbstractModule { + private CommandName command; + + public void initSshModule(String pluginName) { + command = Commands.named(pluginName); + } + + @Override + protected final void configure() { + bind(Commands.key(command)).toProvider(new DispatchCommandProvider(command)); + configureCmds(); + } + + protected abstract void configureCmds(); + + protected LinkedBindingBuilder command(String subCmd) { + return bind(Commands.key(command, subCmd)); + } +}