guice - Using manual registration in a gerrit plugin -
when writing gerrit plugins have choice either use autoregistration (using @listen
, @export
annotations) or use manual registration defining <gerritmodule>
, <gerrit-sshmodule>
and/or <gerrit-httpmodule>
in pom.xml
.
auto-registration shown in this slide set, documentation on how use manual registration sparse. how done?
lets want convert commit-message-length-validator
plugin manual registration. stripped down version of looks this:
@listen @singleton public class commitmessagelengthvalidation implements commitvalidationlistener { public list<commitvalidationmessage> oncommitreceived(commitreceivedevent receiveevent) throws commitvalidationexception { // } }
the <gerritmodule>
entry in pom.xml
or buck build script has point guice module, have create one.
class mymodule extends abstractmodule { @override protected void configure() { // manual registration of commitmessagelengthvalidation dynamicset.bind(binder(), commitvalidationlistener.class) .to(commitmessagelengthvalidation.class); } }
replacing @export
annotation more complicated. ssh command create guice module extending plugincommandmodule
:
class mysshmodule extends plugincommandmodule { @override protected void configurecommands() { command(printhelloworldcommand.class); alias("say-hello", printhelloworldcommand.class); } }
for http servlets use servletmodule
:
public class git2mkshttpmodule extends servletmodule { @override protected void configureservlets() { serve("/servertime").with(servertime.class); } }
Comments
Post a Comment