Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

plugins_extensions.mkd 5.1KB

10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
10 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ## Extension Points
  2. Gitblit offers several extension points for enhancing and customizing it's runtime behavior.
  3. Each available extension point has a sample implementation in the [gitblit-cookbook-plugin (Maven project)](https://github.com/gitblit/gitblit-cookbook-plugin).
  4. **NOTE:**
  5. Gitblit does not yet offer a comprehensize dependency injection architecture. This will be addressed in a subsequent release. For now you may access all of Gitblit's core managers through a static singleton app context:
  6. ```java
  7. import com.gitblit.extensions.GitblitPlugin;
  8. import com.gitblit.servlet.GitblitContext;
  9. import com.gitblit.manager.IRuntimeManager;
  10. import com.gitblit.manager.IUserManager;
  11. import com.gitblit.manager.IAuthenticationManager;
  12. import com.gitblit.manager.INotificationManager;
  13. import com.gitblit.manager.IRepositoryManager;
  14. import com.gitblit.manager.IProjectManager;
  15. import com.gitblit.manager.IFederationManager;
  16. import com.gitblit.manager.IPluginManager;
  17. import com.gitblit.manager.IGitblit;
  18. public class ExamplePlugin extends GitblitPlugin {
  19. @Override
  20. public void start() {
  21. IRuntimeManager runtime = GitblitContext.getManager(IRuntimeManager.class);
  22. IUserManager users = GitblitContext.getManager(IUserManager.class);
  23. IAuthenticationManager auth = GitblitContext.getManager(IAuthenticationManager.class);
  24. INotificationManager notifications = GitblitContext.getManager(INotificationManager.class);
  25. IRepositoryManager repos = GitblitContext.getManager(IRepositoryManager.class);
  26. IProjectManager projects = GitblitContext.getManager(IProjectManager.class);
  27. IFederationManager federation = GitblitContext.getManager(IFederationManager.class);
  28. IPluginManager plugins = GitblitContext.getManager(IPluginManager.class);
  29. IGitblit gitblit = GitblitContext.getManager(IGitblit.class);
  30. }
  31. }
  32. ```
  33. ### SSH Dispatch Command
  34. *SINCE 1.5.0*
  35. You can provide your own custom SSH command hierarchies by subclassing the *DispatchCommand* class.
  36. ```java
  37. import ro.fortsoft.pf4j.Extension;
  38. import org.kohsuke.args4j.Option;
  39. import org.slf4j.Logger;
  40. import org.slf4j.LoggerFactory;
  41. import com.gitblit.models.UserModel;
  42. import com.gitblit.transport.ssh.commands.CommandMetaData;
  43. import com.gitblit.transport.ssh.commands.DispatchCommand;
  44. import com.gitblit.transport.ssh.commands.UsageExample;
  45. @Extension
  46. @CommandMetaData(name = "mycommands", description = "Sample SSH dispatcher")
  47. public class MyDispatcher extends DispatchCommand {
  48. @Override
  49. protected void setup(UserModel user) {
  50. // commands in this dispatcher
  51. register(user, CommandA.class);
  52. register(user, CommandB.class);
  53. // nested dispatchers
  54. register(user, SubDispatcher1.class);
  55. register(user, SubDispatcher2.class);
  56. }
  57. @CommandMetaData(name = "commanda", aliases = { "ca" }, description = "description of command a")
  58. @UsageExample(syntax = "${cmd} --myflag", description = "description of commanda with --myflag")
  59. public static class CommandA extends SshCommand {
  60. protected final Logger log = LoggerFactory.getLogger(getClass());
  61. @Option(name = "--myflag", aliases = { "-m" }, usage = "enable myflag")
  62. boolean myflag;
  63. @Override
  64. public void run() throws Failure {
  65. if (myflag) {
  66. log.info("Run with --myflag");
  67. } else {
  68. log.info("Run without --myflag");
  69. }
  70. }
  71. }
  72. }
  73. ```
  74. ### Pre- and Post- Receive Hook
  75. *SINCE 1.5.0*
  76. You can provide your own custom pre and/or post receive hooks by subclassing the *ReceiveHook* class.
  77. ```java
  78. import com.gitblit.extensions.ReceiveHook;
  79. import java.util.Collection;
  80. import org.eclipse.jgit.transport.ReceiveCommand;
  81. import ro.fortsoft.pf4j.Extension;
  82. @Extension
  83. public class MyReceiveHook extends ReceiveHook {
  84. @Override
  85. public void onPreReceive(GitblitReceivePack receivePack, Collection<ReceiveCommand> commands) {
  86. }
  87. @Override
  88. public void onPostReceive(GitblitReceivePack receivePack, Collection<ReceiveCommand> commands) {
  89. }
  90. }
  91. ```
  92. ### Patchset Hook
  93. *SINCE 1.5.0*
  94. You can provide your own custom patchset hook by subclassing the *PatchsetHook* class.
  95. ```java
  96. import com.gitblit.extensions.PatchsetHook;
  97. import com.gitblit.models.TicketModel;
  98. import ro.fortsoft.pf4j.Extension;
  99. @Extension
  100. public class MyPatchsetHook extends PatchsetHook {
  101. @Override
  102. public void onNewPatchset(TicketModel ticket) {
  103. }
  104. @Override
  105. public void onUpdatePatchset(TicketModel ticket) {
  106. }
  107. @Override
  108. public void onMergePatchset(TicketModel ticket) {
  109. }
  110. }
  111. ```
  112. ### Ticket Hook
  113. *SINCE 1.5.0*
  114. You can provide your own custom ticket hook by subclassing the *TicketHook* class.
  115. ```java
  116. import com.gitblit.extensions.TicketHook;
  117. import com.gitblit.models.TicketModel;
  118. import com.gitblit.models.TicketModel.Change;
  119. import ro.fortsoft.pf4j.Extension;
  120. @Extension
  121. public class MyTicketHook extends TicketHook {
  122. @Override
  123. public void onNewTicket(TicketModel ticket) {
  124. }
  125. @Override
  126. public void onUpdateTicket(TicketModel ticket, Change change) {
  127. }
  128. }
  129. ```