Reputation: 529
When writing gerrit plugins you have the choice to either use AutoRegistration (using the @Listen
and @Export
annotations) or to use manual registration by defining <GerritModule>
, <Gerrit-SshModule>
and/or <Gerrit-HttpModule>
in the pom.xml
.
Auto-Registration is shown in this slide set, but documentation on how to use manual registration is sparse. So how is it done?
Upvotes: 0
Views: 190
Reputation: 529
Lets say we want to convert the commit-message-length-validator
plugin to manual registration. A stripped down version of it looks like this:
@Listen
@Singleton
public class CommitMessageLengthValidation implements CommitValidationListener {
public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
throws CommitValidationException {
// do something
}
}
The <GerritModule>
entry in the pom.xml
or buck build script has to point to a Guice module, so we have to create one.
class MyModule extends AbstractModule {
@Override
protected void configure() {
// this does manual registration of CommitMessageLengthValidation
DynamicSet.bind(binder(), CommitValidationListener.class)
.to(CommitMessageLengthValidation.class);
}
}
Replacing a @Export
annotation is slightly more complicated. For a SSH command create a Guice module by extending PluginCommandModule
:
class MySshModule extends PluginCommandModule {
@Override
protected void configureCommands() {
command(PrintHelloWorldCommand.class);
alias("say-hello", PrintHelloWorldCommand.class);
}
}
For HTTP Servlets use a ServletModule
:
public class Git2MksHttpModule extends ServletModule {
@Override
protected void configureServlets() {
serve("/servertime").with(ServerTime.class);
}
}
Upvotes: 1