Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Plugin Development |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 2 | |
Edwin Kempin | af27532 | 2012-07-16 11:04:01 +0200 | [diff] [blame] | 3 | The Gerrit server functionality can be extended by installing plugins. |
| 4 | This page describes how plugins for Gerrit can be developed. |
| 5 | |
| 6 | Depending on how tightly the extension code is coupled with the Gerrit |
| 7 | server code, there is a distinction between `plugins` and `extensions`. |
| 8 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 9 | [[plugin]] |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 10 | A `plugin` in Gerrit is tightly coupled code that runs in the same |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 11 | JVM as Gerrit. It has full access to all server internals. Plugins |
| 12 | are tightly coupled to a specific major.minor server version and |
| 13 | may require source code changes to compile against a different |
| 14 | server version. |
| 15 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 16 | [[extension]] |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 17 | An `extension` in Gerrit runs inside of the same JVM as Gerrit |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 18 | in the same way as a plugin, but has limited visibility to the |
Edwin Kempin | fd19bfb | 2012-07-16 10:44:17 +0200 | [diff] [blame] | 19 | server's internals. The limited visibility reduces the extension's |
| 20 | dependencies, enabling it to be compatible across a wider range |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 21 | of server versions. |
| 22 | |
| 23 | Most of this documentation refers to either type as a plugin. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 24 | |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 25 | [[getting-started]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 26 | == Getting started |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 27 | |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 28 | To get started with the development of a plugin there are two |
| 29 | recommended ways: |
Dave Borowitz | 5cc8f66 | 2012-05-21 09:51:36 -0700 | [diff] [blame] | 30 | |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 31 | . use the Gerrit Plugin Maven archetype to create a new plugin project: |
| 32 | + |
| 33 | With the Gerrit Plugin Maven archetype you can create a skeleton for a |
| 34 | plugin project. |
| 35 | + |
| 36 | ---- |
| 37 | mvn archetype:generate -DarchetypeGroupId=com.google.gerrit \ |
| 38 | -DarchetypeArtifactId=gerrit-plugin-archetype \ |
David Pursehouse | 62864b7 | 2013-10-17 23:05:08 +0900 | [diff] [blame] | 39 | -DarchetypeVersion=2.9-SNAPSHOT \ |
Edwin Kempin | 91155c2 | 2013-12-02 20:25:18 +0100 | [diff] [blame] | 40 | -DgroupId=com.googlesource.gerrit.plugins.testplugin \ |
| 41 | -DartifactId=testplugin |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 42 | ---- |
| 43 | + |
| 44 | Maven will ask for additional properties and then create the plugin in |
| 45 | the current directory. To change the default property values answer 'n' |
| 46 | when Maven asks to confirm the properties configuration. It will then |
| 47 | ask again for all properties including those with predefined default |
| 48 | values. |
| 49 | |
David Pursehouse | 2cf0cb5 | 2013-08-27 16:09:53 +0900 | [diff] [blame] | 50 | . clone the sample plugin: |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 51 | + |
David Pursehouse | 2cf0cb5 | 2013-08-27 16:09:53 +0900 | [diff] [blame] | 52 | This is a project that demonstrates the various features of the |
| 53 | plugin API. It can be taken as an example to develop an own plugin. |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 54 | + |
Dave Borowitz | 5cc8f66 | 2012-05-21 09:51:36 -0700 | [diff] [blame] | 55 | ---- |
David Pursehouse | 2cf0cb5 | 2013-08-27 16:09:53 +0900 | [diff] [blame] | 56 | $ git clone https://gerrit.googlesource.com/plugins/cookbook-plugin |
Dave Borowitz | 5cc8f66 | 2012-05-21 09:51:36 -0700 | [diff] [blame] | 57 | ---- |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 58 | + |
| 59 | When starting from this example one should take care to adapt the |
| 60 | `Gerrit-ApiVersion` in the `pom.xml` to the version of Gerrit for which |
| 61 | the plugin is developed. If the plugin is developed for a released |
| 62 | Gerrit version (no `SNAPSHOT` version) then the URL for the |
| 63 | `gerrit-api-repository` in the `pom.xml` needs to be changed to |
Shawn Pearce | d500500 | 2013-06-21 11:01:45 -0700 | [diff] [blame] | 64 | `https://gerrit-api.storage.googleapis.com/release/`. |
Dave Borowitz | 5cc8f66 | 2012-05-21 09:51:36 -0700 | [diff] [blame] | 65 | |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 66 | [[API]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 67 | == API |
Edwin Kempin | f878c4b | 2012-07-18 09:34:25 +0200 | [diff] [blame] | 68 | |
| 69 | There are two different API formats offered against which plugins can |
| 70 | be developed: |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 71 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 72 | gerrit-extension-api.jar:: |
| 73 | A stable but thin interface. Suitable for extensions that need |
| 74 | to be notified of events, but do not require tight coupling to |
| 75 | the internals of Gerrit. Extensions built against this API can |
| 76 | expect to be binary compatible across a wide range of server |
| 77 | versions. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 78 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 79 | gerrit-plugin-api.jar:: |
| 80 | The complete internals of the Gerrit server, permitting a |
| 81 | plugin to tightly couple itself and provide additional |
| 82 | functionality that is not possible as an extension. Plugins |
| 83 | built against this API are expected to break at the source |
| 84 | code level between every major.minor Gerrit release. A plugin |
| 85 | that compiles against 2.5 will probably need source code level |
| 86 | changes to work with 2.6, 2.7, and so on. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 87 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 88 | == Manifest |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 89 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 90 | Plugins may provide optional description information with standard |
| 91 | manifest fields: |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 92 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 93 | ==== |
| 94 | Implementation-Title: Example plugin showing examples |
| 95 | Implementation-Version: 1.0 |
| 96 | Implementation-Vendor: Example, Inc. |
| 97 | Implementation-URL: http://example.com/opensource/plugin-foo/ |
| 98 | ==== |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 99 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 100 | === ApiType |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 101 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 102 | Plugins using the tightly coupled `gerrit-plugin-api.jar` must |
| 103 | declare this API dependency in the manifest to gain access to server |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 104 | internals. If no `Gerrit-ApiType` is specified the stable `extension` |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 105 | API will be assumed. This may cause ClassNotFoundExceptions when |
| 106 | loading a plugin that needs the plugin API. |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 107 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 108 | ==== |
| 109 | Gerrit-ApiType: plugin |
| 110 | ==== |
| 111 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 112 | === Explicit Registration |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 113 | |
| 114 | Plugins that use explicit Guice registration must name the Guice |
| 115 | modules in the manifest. Up to three modules can be named in the |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 116 | manifest. `Gerrit-Module` supplies bindings to the core server; |
| 117 | `Gerrit-SshModule` supplies SSH commands to the SSH server (if |
| 118 | enabled); `Gerrit-HttpModule` supplies servlets and filters to the HTTP |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 119 | server (if enabled). If no modules are named automatic registration |
| 120 | will be performed by scanning all classes in the plugin JAR for |
| 121 | `@Listen` and `@Export("")` annotations. |
| 122 | |
| 123 | ==== |
| 124 | Gerrit-Module: tld.example.project.CoreModuleClassName |
| 125 | Gerrit-SshModule: tld.example.project.SshModuleClassName |
| 126 | Gerrit-HttpModule: tld.example.project.HttpModuleClassName |
| 127 | ==== |
| 128 | |
David Ostrovsky | 366ad0e | 2013-09-05 19:59:09 +0200 | [diff] [blame] | 129 | [[plugin_name]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 130 | === Plugin Name |
David Ostrovsky | 366ad0e | 2013-09-05 19:59:09 +0200 | [diff] [blame] | 131 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 132 | A plugin can optionally provide its own plugin name. |
David Ostrovsky | 366ad0e | 2013-09-05 19:59:09 +0200 | [diff] [blame] | 133 | |
| 134 | ==== |
| 135 | Gerrit-PluginName: replication |
| 136 | ==== |
| 137 | |
| 138 | This is useful for plugins that contribute plugin-owned capabilities that |
| 139 | are stored in the `project.config` file. Another use case is to be able to put |
| 140 | project specific plugin configuration section in `project.config`. In this |
| 141 | case it is advantageous to reserve the plugin name to access the configuration |
| 142 | section in the `project.config` file. |
| 143 | |
| 144 | If `Gerrit-PluginName` is omitted, then the plugin's name is determined from |
| 145 | the plugin file name. |
| 146 | |
| 147 | If a plugin provides its own name, then that plugin cannot be deployed |
| 148 | multiple times under different file names on one Gerrit site. |
| 149 | |
| 150 | For Maven driven plugins, the following line must be included in the pom.xml |
| 151 | file: |
| 152 | |
| 153 | [source,xml] |
| 154 | ---- |
| 155 | <manifestEntries> |
| 156 | <Gerrit-PluginName>name</Gerrit-PluginName> |
| 157 | </manifestEntries> |
| 158 | ---- |
| 159 | |
| 160 | For Buck driven plugins, the following line must be included in the BUCK |
| 161 | configuration file: |
| 162 | |
| 163 | [source,python] |
| 164 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 165 | manifest_entries = [ |
| 166 | 'Gerrit-PluginName: name', |
| 167 | ] |
David Ostrovsky | 366ad0e | 2013-09-05 19:59:09 +0200 | [diff] [blame] | 168 | ---- |
| 169 | |
Edwin Kempin | c0b1b0e | 2013-10-01 14:13:54 +0200 | [diff] [blame] | 170 | A plugin can get its own name injected at runtime: |
| 171 | |
| 172 | [source,java] |
| 173 | ---- |
| 174 | public class MyClass { |
| 175 | |
| 176 | private final String pluginName; |
| 177 | |
| 178 | @Inject |
| 179 | public MyClass(@PluginName String pluginName) { |
| 180 | this.pluginName = pluginName; |
| 181 | } |
| 182 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 183 | [...] |
Edwin Kempin | c0b1b0e | 2013-10-01 14:13:54 +0200 | [diff] [blame] | 184 | } |
| 185 | ---- |
| 186 | |
David Pursehouse | 8ed0d92 | 2013-10-18 18:57:56 +0900 | [diff] [blame] | 187 | A plugin can get its canonical web URL injected at runtime: |
| 188 | |
| 189 | [source,java] |
| 190 | ---- |
| 191 | public class MyClass { |
| 192 | |
| 193 | private final String url; |
| 194 | |
| 195 | @Inject |
| 196 | public MyClass(@PluginCanonicalWebUrl String url) { |
| 197 | this.url = url; |
| 198 | } |
| 199 | |
| 200 | [...] |
| 201 | } |
| 202 | ---- |
| 203 | |
| 204 | The URL is composed of the server's canonical web URL and the plugin's |
| 205 | name, i.e. `http://review.example.com:8080/plugin-name`. |
| 206 | |
| 207 | The canonical web URL may be injected into any .jar plugin regardless of |
| 208 | whether or not the plugin provides an HTTP servlet. |
| 209 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 210 | [[reload_method]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 211 | === Reload Method |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 212 | |
| 213 | If a plugin holds an exclusive resource that must be released before |
| 214 | loading the plugin again (for example listening on a network port or |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 215 | acquiring a file lock) the manifest must declare `Gerrit-ReloadMode` |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 216 | to be `restart`. Otherwise the preferred method of `reload` will |
| 217 | be used, as it enables the server to hot-patch an updated plugin |
| 218 | with no down time. |
| 219 | |
| 220 | ==== |
| 221 | Gerrit-ReloadMode: restart |
| 222 | ==== |
| 223 | |
| 224 | In either mode ('restart' or 'reload') any plugin or extension can |
| 225 | be updated without restarting the Gerrit server. The difference is |
| 226 | how Gerrit handles the upgrade: |
| 227 | |
| 228 | restart:: |
| 229 | The old plugin is completely stopped. All registrations of SSH |
| 230 | commands and HTTP servlets are removed. All registrations of any |
| 231 | extension points are removed. All registered LifecycleListeners |
| 232 | have their `stop()` method invoked in reverse order. The new |
| 233 | plugin is started, and registrations are made from the new |
| 234 | plugin. There is a brief window where neither the old nor the |
| 235 | new plugin is connected to the server. This means SSH commands |
| 236 | and HTTP servlets will return not found errors, and the plugin |
| 237 | will not be notified of events that occurred during the restart. |
| 238 | |
| 239 | reload:: |
| 240 | The new plugin is started. Its LifecycleListeners are permitted |
| 241 | to perform their `start()` methods. All SSH and HTTP registrations |
| 242 | are atomically swapped out from the old plugin to the new plugin, |
| 243 | ensuring the server never returns a not found error. All extension |
| 244 | point listeners are atomically swapped out from the old plugin to |
| 245 | the new plugin, ensuring no events are missed (however some events |
| 246 | may still route to the old plugin if the swap wasn't complete yet). |
| 247 | The old plugin is stopped. |
| 248 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 249 | To reload/restart a plugin the link:cmd-plugin-reload.html[plugin reload] |
| 250 | command can be used. |
| 251 | |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 252 | [[init_step]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 253 | === Init step |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 254 | |
| 255 | Plugins can contribute their own "init step" during the Gerrit init |
| 256 | wizard. This is useful for guiding the Gerrit administrator through |
David Pursehouse | 659860f | 2013-12-16 14:50:04 +0900 | [diff] [blame] | 257 | the settings needed by the plugin to work properly. |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 258 | |
| 259 | For instance plugins to integrate Jira issues to Gerrit changes may |
| 260 | contribute their own "init step" to allow configuring the Jira URL, |
| 261 | credentials and possibly verify connectivity to validate them. |
| 262 | |
| 263 | ==== |
| 264 | Gerrit-InitStep: tld.example.project.MyInitStep |
| 265 | ==== |
| 266 | |
| 267 | MyInitStep needs to follow the standard Gerrit InitStep syntax |
David Pursehouse | 9246356 | 2013-06-24 10:16:28 +0900 | [diff] [blame] | 268 | and behavior: writing to the console using the injected ConsoleUI |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 269 | and accessing / changing configuration settings using Section.Factory. |
| 270 | |
| 271 | In addition to the standard Gerrit init injections, plugins receive |
| 272 | the @PluginName String injection containing their own plugin name. |
| 273 | |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 274 | During their initialization plugins may get access to the |
| 275 | `project.config` file of the `All-Projects` project and they are able |
| 276 | to store configuration parameters in it. For this a plugin `InitStep` |
| 277 | can get `com.google.gerrit.pgm.init.AllProjectsConfig` injected: |
| 278 | |
| 279 | [source,java] |
| 280 | ---- |
| 281 | public class MyInitStep implements InitStep { |
| 282 | private final String pluginName; |
| 283 | private final ConsoleUI ui; |
| 284 | private final AllProjectsConfig allProjectsConfig; |
| 285 | |
| 286 | public MyInitStep(@PluginName String pluginName, ConsoleUI ui, |
| 287 | AllProjectsConfig allProjectsConfig) { |
| 288 | this.pluginName = pluginName; |
| 289 | this.ui = ui; |
| 290 | this.allProjectsConfig = allProjectsConfig; |
| 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void run() throws Exception { |
Edwin Kempin | 93e7d5d | 2014-01-03 09:53:20 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public void postRun() throws Exception { |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 299 | ui.message("\n"); |
| 300 | ui.header(pluginName + " Integration"); |
| 301 | boolean enabled = ui.yesno(true, "By default enabled for all projects"); |
| 302 | Config cfg = allProjectsConfig.load(); |
| 303 | if (enabled) { |
| 304 | cfg.setBoolean("plugin", pluginName, "enabled", enabled); |
| 305 | } else { |
| 306 | cfg.unset("plugin", pluginName, "enabled"); |
| 307 | } |
| 308 | allProjectsConfig.save(pluginName, "Initialize " + pluginName + " Integration"); |
| 309 | } |
| 310 | } |
| 311 | ---- |
| 312 | |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 313 | Bear in mind that the Plugin's InitStep class will be loaded but |
| 314 | the standard Gerrit runtime environment is not available and the plugin's |
| 315 | own Guice modules were not initialized. |
| 316 | This means the InitStep for a plugin is not executed in the same way that |
| 317 | the plugin executes within the server, and may mean a plugin author cannot |
| 318 | trivially reuse runtime code during init. |
| 319 | |
| 320 | For instance a plugin that wants to verify connectivity may need to statically |
| 321 | call the constructor of their connection class, passing in values obtained |
| 322 | from the Section.Factory rather than from an injected Config object. |
| 323 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 324 | Plugins' InitSteps are executed during the "Gerrit Plugin init" phase, after |
| 325 | the extraction of the plugins embedded in the distribution .war file into |
| 326 | `$GERRIT_SITE/plugins` and before the DB Schema initialization or upgrade. |
| 327 | |
| 328 | A plugin's InitStep cannot refer to Gerrit's DB Schema or any other Gerrit |
| 329 | runtime objects injected at startup. |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 330 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 331 | [source,java] |
| 332 | ---- |
| 333 | public class MyInitStep implements InitStep { |
| 334 | private final ConsoleUI ui; |
| 335 | private final Section.Factory sections; |
| 336 | private final String pluginName; |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 337 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 338 | @Inject |
| 339 | public GitBlitInitStep(final ConsoleUI ui, Section.Factory sections, @PluginName String pluginName) { |
| 340 | this.ui = ui; |
| 341 | this.sections = sections; |
| 342 | this.pluginName = pluginName; |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 343 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 344 | |
| 345 | @Override |
| 346 | public void run() throws Exception { |
| 347 | ui.header("\nMy plugin"); |
| 348 | |
| 349 | Section mySection = getSection("myplugin", null); |
| 350 | mySection.string("Link name", "linkname", "MyLink"); |
| 351 | } |
Edwin Kempin | 93e7d5d | 2014-01-03 09:53:20 +0100 | [diff] [blame] | 352 | |
| 353 | @Override |
| 354 | public void postRun() throws Exception { |
| 355 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 356 | } |
| 357 | ---- |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 358 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 359 | [[classpath]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 360 | == Classpath |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 361 | |
| 362 | Each plugin is loaded into its own ClassLoader, isolating plugins |
| 363 | from each other. A plugin or extension inherits the Java runtime |
| 364 | and the Gerrit API chosen by `Gerrit-ApiType` (extension or plugin) |
| 365 | from the hosting server. |
| 366 | |
| 367 | Plugins are loaded from a single JAR file. If a plugin needs |
| 368 | additional libraries, it must include those dependencies within |
| 369 | its own JAR. Plugins built using Maven may be able to use the |
| 370 | link:http://maven.apache.org/plugins/maven-shade-plugin/[shade plugin] |
| 371 | to package additional dependencies. Relocating (or renaming) classes |
| 372 | should not be necessary due to the ClassLoader isolation. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 373 | |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 374 | [[events]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 375 | == Listening to Events |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 376 | |
| 377 | Certain operations in Gerrit trigger events. Plugins may receive |
| 378 | notifications of these events by implementing the corresponding |
| 379 | listeners. |
| 380 | |
Edwin Kempin | 64059f5 | 2013-10-31 13:49:25 +0100 | [diff] [blame] | 381 | * `com.google.gerrit.common.ChangeListener`: |
| 382 | + |
| 383 | Allows to listen to change events. These are the same |
| 384 | link:cmd-stream-events.html#events[events] that are also streamed by |
| 385 | the link:cmd-stream-events.html[gerrit stream-events] command. |
| 386 | |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 387 | * `com.google.gerrit.extensions.events.LifecycleListener`: |
| 388 | + |
Edwin Kempin | 3e7928a | 2013-12-03 07:39:00 +0100 | [diff] [blame] | 389 | Plugin start and stop |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 390 | |
| 391 | * `com.google.gerrit.extensions.events.NewProjectCreatedListener`: |
| 392 | + |
| 393 | Project creation |
| 394 | |
| 395 | * `com.google.gerrit.extensions.events.ProjectDeletedListener`: |
| 396 | + |
| 397 | Project deletion |
| 398 | |
Edwin Kempin | b27c939 | 2013-11-19 13:12:43 +0100 | [diff] [blame] | 399 | * `com.google.gerrit.extensions.events.HeadUpdatedListener`: |
| 400 | + |
| 401 | Update of HEAD on a project |
| 402 | |
Yang Zhenhui | 2659d42 | 2013-07-30 16:59:58 +0800 | [diff] [blame] | 403 | [[stream-events]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 404 | == Sending Events to the Events Stream |
Yang Zhenhui | 2659d42 | 2013-07-30 16:59:58 +0800 | [diff] [blame] | 405 | |
| 406 | Plugins may send events to the events stream where consumers of |
| 407 | Gerrit's `stream-events` ssh command will receive them. |
| 408 | |
| 409 | To send an event, the plugin must invoke one of the `postEvent` |
| 410 | methods in the `ChangeHookRunner` class, passing an instance of |
| 411 | its own custom event class derived from `ChangeEvent`. |
| 412 | |
Edwin Kempin | 3273760 | 2014-01-23 09:04:58 +0100 | [diff] [blame] | 413 | [[validation]] |
David Pursehouse | 91c5f5e | 2014-01-23 18:57:33 +0900 | [diff] [blame] | 414 | == Validation Listeners |
Edwin Kempin | 3273760 | 2014-01-23 09:04:58 +0100 | [diff] [blame] | 415 | |
| 416 | Certain operations in Gerrit can be validated by plugins by |
| 417 | implementing the corresponding link:config-validation.html[listeners]. |
| 418 | |
Saša Živkov | ec85a07 | 2014-01-28 10:08:25 +0100 | [diff] [blame] | 419 | [[receive-pack]] |
| 420 | == Receive Pack Initializers |
| 421 | |
| 422 | Plugins may provide ReceivePack initializers which will be invoked |
| 423 | by Gerrit just before a ReceivePack instance will be used. Usually, |
| 424 | plugins will make use of the setXXX methods on the ReceivePack to |
| 425 | set additional properties on it. |
| 426 | |
Saša Živkov | 626c731 | 2014-02-24 17:15:08 +0100 | [diff] [blame] | 427 | [[post-receive-hook]] |
| 428 | == Post Receive-Pack Hooks |
| 429 | |
| 430 | Plugins may register PostReceiveHook instances in order to get |
| 431 | notified when JGit successfully receives a pack. This may be useful |
| 432 | for those plugins which would like to monitor changes in Git |
| 433 | repositories. |
| 434 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 435 | [[ssh]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 436 | == SSH Commands |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 437 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 438 | Plugins may provide commands that can be accessed through the SSH |
| 439 | interface (extensions do not have this option). |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 440 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 441 | Command implementations must extend the base class SshCommand: |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 442 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 443 | [source,java] |
| 444 | ---- |
| 445 | import com.google.gerrit.sshd.SshCommand; |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 446 | import com.google.gerrit.sshd.CommandMetaData; |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 447 | |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 448 | @CommandMetaData(name="print", description="Print hello command") |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 449 | class PrintHello extends SshCommand { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 450 | @Override |
| 451 | protected void run() { |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 452 | stdout.print("Hello\n"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 453 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 454 | } |
| 455 | ---- |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 456 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 457 | If no Guice modules are declared in the manifest, SSH commands may |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 458 | use auto-registration by providing an `@Export` annotation: |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 459 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 460 | [source,java] |
| 461 | ---- |
| 462 | import com.google.gerrit.extensions.annotations.Export; |
| 463 | import com.google.gerrit.sshd.SshCommand; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 464 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 465 | @Export("print") |
| 466 | class PrintHello extends SshCommand { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 467 | @Override |
| 468 | protected void run() { |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 469 | stdout.print("Hello\n"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 470 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 471 | } |
| 472 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 473 | |
| 474 | If explicit registration is being used, a Guice module must be |
| 475 | supplied to register the SSH command and declared in the manifest |
| 476 | with the `Gerrit-SshModule` attribute: |
| 477 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 478 | [source,java] |
| 479 | ---- |
| 480 | import com.google.gerrit.sshd.PluginCommandModule; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 481 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 482 | class MyCommands extends PluginCommandModule { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 483 | @Override |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 484 | protected void configureCommands() { |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 485 | command(PrintHello.class); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 486 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 487 | } |
| 488 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 489 | |
| 490 | For a plugin installed as name `helloworld`, the command implemented |
| 491 | by PrintHello class will be available to users as: |
| 492 | |
| 493 | ---- |
Keunhong Park | a09a6f1 | 2012-07-10 14:45:02 -0600 | [diff] [blame] | 494 | $ ssh -p 29418 review.example.com helloworld print |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 495 | ---- |
| 496 | |
David Ostrovsky | 79c4d89 | 2014-03-15 13:52:46 +0100 | [diff] [blame] | 497 | [[multiple-commands]] |
| 498 | === Multiple Commands bound to one implementation |
| 499 | |
David Ostrovsky | e3172b3 | 2013-10-13 14:19:13 +0200 | [diff] [blame] | 500 | Multiple SSH commands can be bound to the same implementation class. For |
| 501 | example a Gerrit Shell plugin can bind different shell commands to the same |
| 502 | implementation class: |
| 503 | |
| 504 | [source,java] |
| 505 | ---- |
| 506 | public class SshShellModule extends PluginCommandModule { |
| 507 | @Override |
| 508 | protected void configureCommands() { |
| 509 | command("ls").to(ShellCommand.class); |
| 510 | command("ps").to(ShellCommand.class); |
| 511 | [...] |
| 512 | } |
| 513 | } |
| 514 | ---- |
| 515 | |
| 516 | With the possible implementation: |
| 517 | |
| 518 | [source,java] |
| 519 | ---- |
| 520 | public class ShellCommand extends SshCommand { |
| 521 | @Override |
| 522 | protected void run() throws UnloggedFailure { |
| 523 | String cmd = getName().substring(getPluginName().length() + 1); |
| 524 | ProcessBuilder proc = new ProcessBuilder(cmd); |
| 525 | Process cmd = proc.start(); |
| 526 | [...] |
| 527 | } |
| 528 | } |
| 529 | ---- |
| 530 | |
| 531 | And the call: |
| 532 | |
| 533 | ---- |
| 534 | $ ssh -p 29418 review.example.com shell ls |
| 535 | $ ssh -p 29418 review.example.com shell ps |
| 536 | ---- |
| 537 | |
David Ostrovsky | 79c4d89 | 2014-03-15 13:52:46 +0100 | [diff] [blame] | 538 | [[root-level-commands]] |
| 539 | === Root Level Commands |
| 540 | |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 541 | Single command plugins are also supported. In this scenario plugin binds |
| 542 | SSH command to its own name. `SshModule` must inherit from |
| 543 | `SingleCommandPluginModule` class: |
| 544 | |
| 545 | [source,java] |
| 546 | ---- |
| 547 | public class SshModule extends SingleCommandPluginModule { |
| 548 | @Override |
| 549 | protected void configure(LinkedBindingBuilder<Command> b) { |
| 550 | b.to(ShellCommand.class); |
| 551 | } |
| 552 | } |
| 553 | ---- |
| 554 | |
| 555 | If the plugin above is deployed under sh.jar file in `$site/plugins` |
David Pursehouse | 659860f | 2013-12-16 14:50:04 +0900 | [diff] [blame] | 556 | directory, generic commands can be called without specifying the |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 557 | actual SSH command. Note in the example below, that the called commands |
| 558 | `ls` and `ps` was not explicitly bound: |
| 559 | |
| 560 | ---- |
| 561 | $ ssh -p 29418 review.example.com sh ls |
| 562 | $ ssh -p 29418 review.example.com sh ps |
| 563 | ---- |
| 564 | |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 565 | [[simple-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 566 | == Simple Configuration in `gerrit.config` |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 567 | |
| 568 | In Gerrit, global configuration is stored in the `gerrit.config` file. |
| 569 | If a plugin needs global configuration, this configuration should be |
| 570 | stored in a `plugin` subsection in the `gerrit.config` file. |
| 571 | |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 572 | This approach of storing the plugin configuration is only suitable for |
| 573 | plugins that have a simple configuration that only consists of |
| 574 | key-value pairs. With this approach it is not possible to have |
| 575 | subsections in the plugin configuration. Plugins that require a complex |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 576 | configuration need to store their configuration in their |
| 577 | link:#configuration[own configuration file] where they can make use of |
| 578 | subsections. On the other hand storing the plugin configuration in a |
| 579 | 'plugin' subsection in the `gerrit.config` file has the advantage that |
| 580 | administrators have all configuration parameters in one file, instead |
| 581 | of having one configuration file per plugin. |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 582 | |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 583 | To avoid conflicts with other plugins, it is recommended that plugins |
| 584 | only use the `plugin` subsection with their own name. For example the |
| 585 | `helloworld` plugin should store its configuration in the |
| 586 | `plugin.helloworld` subsection: |
| 587 | |
| 588 | ---- |
| 589 | [plugin "helloworld"] |
| 590 | language = Latin |
| 591 | ---- |
| 592 | |
Sasa Zivkov | acdf533 | 2013-09-20 14:05:15 +0200 | [diff] [blame] | 593 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 594 | plugin can easily access its configuration and there is no need for a |
| 595 | plugin to parse the `gerrit.config` file on its own: |
| 596 | |
| 597 | [source,java] |
| 598 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 599 | @Inject |
| 600 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 601 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 602 | [...] |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 603 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 604 | String language = cfg.getFromGerritConfig("helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 605 | .getString("language", "English"); |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 606 | ---- |
| 607 | |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 608 | [[configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 609 | == Configuration in own config file |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 610 | |
| 611 | Plugins can store their configuration in an own configuration file. |
| 612 | This makes sense if the plugin configuration is rather complex and |
| 613 | requires the usage of subsections. Plugins that have a simple |
| 614 | key-value pair configuration can store their configuration in a |
| 615 | link:#simple-configuration[`plugin` subsection of the `gerrit.config` |
| 616 | file]. |
| 617 | |
| 618 | The plugin configuration file must be named after the plugin and must |
| 619 | be located in the `etc` folder of the review site. For example a |
| 620 | configuration file for a `default-reviewer` plugin could look like |
| 621 | this: |
| 622 | |
| 623 | .$site_path/etc/default-reviewer.config |
| 624 | ---- |
| 625 | [branch "refs/heads/master"] |
| 626 | reviewer = Project Owners |
| 627 | reviewer = john.doe@example.com |
| 628 | [match "file:^.*\.txt"] |
| 629 | reviewer = My Info Developers |
| 630 | ---- |
| 631 | |
| 632 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 633 | plugin can easily access its configuration: |
| 634 | |
| 635 | [source,java] |
| 636 | ---- |
| 637 | @Inject |
| 638 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 639 | |
| 640 | [...] |
| 641 | |
| 642 | String[] reviewers = cfg.getGlobalPluginConfig("default-reviewer") |
| 643 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 644 | ---- |
| 645 | |
| 646 | The plugin configuration is loaded only once and is then cached. |
| 647 | Similar to changes in 'gerrit.config', changes to the plugin |
| 648 | configuration file will only become effective after a Gerrit restart. |
| 649 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 650 | [[simple-project-specific-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 651 | == Simple Project Specific Configuration in `project.config` |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 652 | |
| 653 | In Gerrit, project specific configuration is stored in the project's |
| 654 | `project.config` file on the `refs/meta/config` branch. If a plugin |
| 655 | needs configuration on project level (e.g. to enable its functionality |
| 656 | only for certain projects), this configuration should be stored in a |
| 657 | `plugin` subsection in the project's `project.config` file. |
| 658 | |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 659 | This approach of storing the plugin configuration is only suitable for |
| 660 | plugins that have a simple configuration that only consists of |
| 661 | key-value pairs. With this approach it is not possible to have |
| 662 | subsections in the plugin configuration. Plugins that require a complex |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 663 | configuration need to store their configuration in their |
| 664 | link:#project-specific-configuration[own configuration file] where they |
| 665 | can make use of subsections. On the other hand storing the plugin |
| 666 | configuration in a 'plugin' subsection in the `project.config` file has |
| 667 | the advantage that project owners have all configuration parameters in |
| 668 | one file, instead of having one configuration file per plugin. |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 669 | |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 670 | To avoid conflicts with other plugins, it is recommended that plugins |
| 671 | only use the `plugin` subsection with their own name. For example the |
| 672 | `helloworld` plugin should store its configuration in the |
| 673 | `plugin.helloworld` subsection: |
| 674 | |
| 675 | ---- |
| 676 | [plugin "helloworld"] |
| 677 | enabled = true |
| 678 | ---- |
| 679 | |
| 680 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 681 | plugin can easily access its project specific configuration and there |
| 682 | is no need for a plugin to parse the `project.config` file on its own: |
| 683 | |
| 684 | [source,java] |
| 685 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 686 | @Inject |
| 687 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 688 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 689 | [...] |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 690 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 691 | boolean enabled = cfg.getFromProjectConfig(project, "helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 692 | .getBoolean("enabled", false); |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 693 | ---- |
| 694 | |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 695 | It is also possible to get missing configuration parameters inherited |
| 696 | from the parent projects: |
| 697 | |
| 698 | [source,java] |
| 699 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 700 | @Inject |
| 701 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 702 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 703 | [...] |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 704 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 705 | boolean enabled = cfg.getFromProjectConfigWithInheritance(project, "helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 706 | .getBoolean("enabled", false); |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 707 | ---- |
| 708 | |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 709 | Project owners can edit the project configuration by fetching the |
| 710 | `refs/meta/config` branch, editing the `project.config` file and |
| 711 | pushing the commit back. |
| 712 | |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 713 | Plugin configuration values that are stored in the `project.config` |
| 714 | file can be exposed in the ProjectInfoScreen to allow project owners |
| 715 | to see and edit them from the UI. |
| 716 | |
| 717 | For this an instance of `ProjectConfigEntry` needs to be bound for each |
| 718 | parameter. The export name must be a valid Git variable name. The |
| 719 | variable name is case-insensitive, allows only alphanumeric characters |
| 720 | and '-', and must start with an alphabetic character. |
| 721 | |
Edwin Kempin | a6c1c45 | 2013-11-28 16:55:22 +0100 | [diff] [blame] | 722 | The example below shows how the parameters `plugin.helloworld.enabled` |
| 723 | and `plugin.helloworld.language` are bound to be editable from the |
| 724 | WebUI. For the parameter `plugin.helloworld.enabled` "Enable Greeting" |
| 725 | is provided as display name and the default value is set to `true`. |
| 726 | For the parameter `plugin.helloworld.language` "Preferred Language" |
| 727 | is provided as display name and "en" is set as default value. |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 728 | |
| 729 | [source,java] |
| 730 | ---- |
| 731 | class Module extends AbstractModule { |
| 732 | @Override |
| 733 | protected void configure() { |
| 734 | bind(ProjectConfigEntry.class) |
Edwin Kempin | a6c1c45 | 2013-11-28 16:55:22 +0100 | [diff] [blame] | 735 | .annotatedWith(Exports.named("enabled")) |
| 736 | .toInstance(new ProjectConfigEntry("Enable Greeting", true)); |
| 737 | bind(ProjectConfigEntry.class) |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 738 | .annotatedWith(Exports.named("language")) |
| 739 | .toInstance(new ProjectConfigEntry("Preferred Language", "en")); |
| 740 | } |
| 741 | } |
| 742 | ---- |
| 743 | |
Edwin Kempin | b64d397 | 2013-11-17 18:55:48 +0100 | [diff] [blame] | 744 | By overwriting the `onUpdate` method of `ProjectConfigEntry` plugins |
| 745 | can be notified when this configuration parameter is updated on a |
| 746 | project. |
| 747 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 748 | [[project-specific-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 749 | == Project Specific Configuration in own config file |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 750 | |
| 751 | Plugins can store their project specific configuration in an own |
| 752 | configuration file in the projects `refs/meta/config` branch. |
| 753 | This makes sense if the plugins project specific configuration is |
| 754 | rather complex and requires the usage of subsections. Plugins that |
| 755 | have a simple key-value pair configuration can store their project |
| 756 | specific configuration in a link:#simple-project-specific-configuration[ |
| 757 | `plugin` subsection of the `project.config` file]. |
| 758 | |
| 759 | The plugin configuration file in the `refs/meta/config` branch must be |
| 760 | named after the plugin. For example a configuration file for a |
| 761 | `default-reviewer` plugin could look like this: |
| 762 | |
| 763 | .default-reviewer.config |
| 764 | ---- |
| 765 | [branch "refs/heads/master"] |
| 766 | reviewer = Project Owners |
| 767 | reviewer = john.doe@example.com |
| 768 | [match "file:^.*\.txt"] |
| 769 | reviewer = My Info Developers |
| 770 | ---- |
| 771 | |
| 772 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 773 | plugin can easily access its project specific configuration: |
| 774 | |
| 775 | [source,java] |
| 776 | ---- |
| 777 | @Inject |
| 778 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 779 | |
| 780 | [...] |
| 781 | |
| 782 | String[] reviewers = cfg.getProjectPluginConfig(project, "default-reviewer") |
| 783 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 784 | ---- |
| 785 | |
Edwin Kempin | 762da38 | 2013-10-30 14:50:01 +0100 | [diff] [blame] | 786 | It is also possible to get missing configuration parameters inherited |
| 787 | from the parent projects: |
| 788 | |
| 789 | [source,java] |
| 790 | ---- |
| 791 | @Inject |
| 792 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 793 | |
| 794 | [...] |
| 795 | |
David Ostrovsky | 468e4c3 | 2014-03-22 06:05:35 -0700 | [diff] [blame] | 796 | String[] reviewers = cfg.getProjectPluginConfigWithInheritance(project, "default-reviewer") |
Edwin Kempin | 762da38 | 2013-10-30 14:50:01 +0100 | [diff] [blame] | 797 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 798 | ---- |
| 799 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 800 | Project owners can edit the project configuration by fetching the |
| 801 | `refs/meta/config` branch, editing the `<plugin-name>.config` file and |
| 802 | pushing the commit back. |
| 803 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 804 | == React on changes in project configuration |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 805 | |
| 806 | If a plugin wants to react on changes in the project configuration, it |
| 807 | can implement a `GitReferenceUpdatedListener` and filter on events for |
| 808 | the `refs/meta/config` branch: |
| 809 | |
| 810 | [source,java] |
| 811 | ---- |
| 812 | public class MyListener implements GitReferenceUpdatedListener { |
| 813 | |
| 814 | private final MetaDataUpdate.Server metaDataUpdateFactory; |
| 815 | |
| 816 | @Inject |
| 817 | MyListener(MetaDataUpdate.Server metaDataUpdateFactory) { |
| 818 | this.metaDataUpdateFactory = metaDataUpdateFactory; |
| 819 | } |
| 820 | |
| 821 | @Override |
| 822 | public void onGitReferenceUpdated(Event event) { |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 823 | if (event.getRefName().equals(RefNames.REFS_CONFIG)) { |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 824 | Project.NameKey p = new Project.NameKey(event.getProjectName()); |
| 825 | try { |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 826 | ProjectConfig oldCfg = parseConfig(p, event.getOldObjectId()); |
| 827 | ProjectConfig newCfg = parseConfig(p, event.getNewObjectId()); |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 828 | |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 829 | if (oldCfg != null && newCfg != null |
| 830 | && !oldCfg.getProject().getSubmitType().equals(newCfg.getProject().getSubmitType())) { |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 831 | // submit type has changed |
| 832 | ... |
| 833 | } |
| 834 | } catch (IOException | ConfigInvalidException e) { |
| 835 | ... |
| 836 | } |
| 837 | } |
| 838 | } |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 839 | |
| 840 | private ProjectConfig parseConfig(Project.NameKey p, String idStr) |
| 841 | throws IOException, ConfigInvalidException, RepositoryNotFoundException { |
| 842 | ObjectId id = ObjectId.fromString(idStr); |
| 843 | if (ObjectId.zeroId().equals(id)) { |
| 844 | return null; |
| 845 | } |
| 846 | return ProjectConfig.read(metaDataUpdateFactory.create(p), id); |
| 847 | } |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 848 | } |
| 849 | ---- |
| 850 | |
| 851 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 852 | [[capabilities]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 853 | == Plugin Owned Capabilities |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 854 | |
| 855 | Plugins may provide their own capabilities and restrict usage of SSH |
| 856 | commands to the users who are granted those capabilities. |
| 857 | |
| 858 | Plugins define the capabilities by overriding the `CapabilityDefinition` |
| 859 | abstract class: |
| 860 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 861 | [source,java] |
| 862 | ---- |
| 863 | public class PrintHelloCapability extends CapabilityDefinition { |
| 864 | @Override |
| 865 | public String getDescription() { |
| 866 | return "Print Hello"; |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 867 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 868 | } |
| 869 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 870 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 871 | If no Guice modules are declared in the manifest, UI actions may |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 872 | use auto-registration by providing an `@Export` annotation: |
| 873 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 874 | [source,java] |
| 875 | ---- |
| 876 | @Export("printHello") |
| 877 | public class PrintHelloCapability extends CapabilityDefinition { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 878 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 879 | } |
| 880 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 881 | |
| 882 | Otherwise the capability must be bound in a plugin module: |
| 883 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 884 | [source,java] |
| 885 | ---- |
| 886 | public class HelloWorldModule extends AbstractModule { |
| 887 | @Override |
| 888 | protected void configure() { |
| 889 | bind(CapabilityDefinition.class) |
| 890 | .annotatedWith(Exports.named("printHello")) |
| 891 | .to(PrintHelloCapability.class); |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 892 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 893 | } |
| 894 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 895 | |
| 896 | With a plugin-owned capability defined in this way, it is possible to restrict |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 897 | usage of an SSH command or `UiAction` to members of the group that were granted |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 898 | this capability in the usual way, using the `RequiresCapability` annotation: |
| 899 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 900 | [source,java] |
| 901 | ---- |
| 902 | @RequiresCapability("printHello") |
| 903 | @CommandMetaData(name="print", description="Print greeting in different languages") |
| 904 | public final class PrintHelloWorldCommand extends SshCommand { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 905 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 906 | } |
| 907 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 908 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 909 | Or with `UiAction`: |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 910 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 911 | [source,java] |
| 912 | ---- |
| 913 | @RequiresCapability("printHello") |
| 914 | public class SayHelloAction extends UiAction<RevisionResource> |
| 915 | implements RestModifyView<RevisionResource, SayHelloAction.Input> { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 916 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 917 | } |
| 918 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 919 | |
| 920 | Capability scope was introduced to differentiate between plugin-owned |
David Pursehouse | bf05334 | 2013-09-05 14:55:29 +0900 | [diff] [blame] | 921 | capabilities and core capabilities. Per default the scope of the |
| 922 | `@RequiresCapability` annotation is `CapabilityScope.CONTEXT`, that means: |
| 923 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 924 | * when `@RequiresCapability` is used within a plugin the scope of the |
| 925 | capability is assumed to be that plugin. |
David Pursehouse | bf05334 | 2013-09-05 14:55:29 +0900 | [diff] [blame] | 926 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 927 | * If `@RequiresCapability` is used within the core Gerrit Code Review server |
| 928 | (and thus is outside of a plugin) the scope is the core server and will use |
| 929 | the `GlobalCapability` known to Gerrit Code Review server. |
| 930 | |
| 931 | If a plugin needs to use a core capability name (e.g. "administrateServer") |
| 932 | this can be specified by setting `scope = CapabilityScope.CORE`: |
| 933 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 934 | [source,java] |
| 935 | ---- |
| 936 | @RequiresCapability(value = "administrateServer", scope = |
| 937 | CapabilityScope.CORE) |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 938 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 939 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 940 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 941 | [[ui_extension]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 942 | == UI Extension |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 943 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 944 | Plugins can contribute UI actions on core Gerrit pages. This is useful |
| 945 | for workflow customization or exposing plugin functionality through the |
| 946 | UI in addition to SSH commands and the REST API. |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 947 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 948 | For instance a plugin to integrate Jira with Gerrit changes may |
| 949 | contribute a "File bug" button to allow filing a bug from the change |
| 950 | page or plugins to integrate continuous integration systems may |
| 951 | contribute a "Schedule" button to allow a CI build to be scheduled |
| 952 | manually from the patch set panel. |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 953 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 954 | Two different places on core Gerrit pages are supported: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 955 | |
| 956 | * Change screen |
| 957 | * Project info screen |
| 958 | |
| 959 | Plugins contribute UI actions by implementing the `UiAction` interface: |
| 960 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 961 | [source,java] |
| 962 | ---- |
| 963 | @RequiresCapability("printHello") |
| 964 | class HelloWorldAction implements UiAction<RevisionResource>, |
| 965 | RestModifyView<RevisionResource, HelloWorldAction.Input> { |
| 966 | static class Input { |
| 967 | boolean french; |
| 968 | String message; |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 969 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 970 | |
| 971 | private Provider<CurrentUser> user; |
| 972 | |
| 973 | @Inject |
| 974 | HelloWorldAction(Provider<CurrentUser> user) { |
| 975 | this.user = user; |
| 976 | } |
| 977 | |
| 978 | @Override |
| 979 | public String apply(RevisionResource rev, Input input) { |
| 980 | final String greeting = input.french |
| 981 | ? "Bonjour" |
| 982 | : "Hello"; |
| 983 | return String.format("%s %s from change %s, patch set %d!", |
| 984 | greeting, |
| 985 | Strings.isNullOrEmpty(input.message) |
| 986 | ? Objects.firstNonNull(user.get().getUserName(), "world") |
| 987 | : input.message, |
| 988 | rev.getChange().getId().toString(), |
| 989 | rev.getPatchSet().getPatchSetId()); |
| 990 | } |
| 991 | |
| 992 | @Override |
| 993 | public Description getDescription( |
| 994 | RevisionResource resource) { |
| 995 | return new Description() |
| 996 | .setLabel("Say hello") |
| 997 | .setTitle("Say hello in different languages"); |
| 998 | } |
| 999 | } |
| 1000 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1001 | |
David Ostrovsky | 450eefe | 2013-10-21 21:18:11 +0200 | [diff] [blame] | 1002 | Sometimes plugins may want to be able to change the state of a patch set or |
| 1003 | change in the `UiAction.apply()` method and reflect these changes on the core |
| 1004 | UI. For example a buildbot plugin which exposes a 'Schedule' button on the |
| 1005 | patch set panel may want to disable that button after the build was scheduled |
| 1006 | and update the tooltip of that button. But because of Gerrit's caching |
| 1007 | strategy the following must be taken into consideration. |
| 1008 | |
| 1009 | The browser is allowed to cache the `UiAction` information until something on |
| 1010 | the change is modified. More accurately the change row needs to be modified in |
| 1011 | the database to have a more recent `lastUpdatedOn` or a new `rowVersion`, or |
| 1012 | the +refs/meta/config+ of the project or any parents needs to change to a new |
| 1013 | SHA-1. The ETag SHA-1 computation code can be found in the |
| 1014 | `ChangeResource.getETag()` method. |
| 1015 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1016 | The easiest way to accomplish this is to update `lastUpdatedOn` of the change: |
David Ostrovsky | 450eefe | 2013-10-21 21:18:11 +0200 | [diff] [blame] | 1017 | |
| 1018 | [source,java] |
| 1019 | ---- |
| 1020 | @Override |
| 1021 | public Object apply(RevisionResource rcrs, Input in) { |
| 1022 | // schedule a build |
| 1023 | [...] |
| 1024 | // update change |
| 1025 | ReviewDb db = dbProvider.get(); |
| 1026 | db.changes().beginTransaction(change.getId()); |
| 1027 | try { |
| 1028 | change = db.changes().atomicUpdate( |
| 1029 | change.getId(), |
| 1030 | new AtomicUpdate<Change>() { |
| 1031 | @Override |
| 1032 | public Change update(Change change) { |
| 1033 | ChangeUtil.updated(change); |
| 1034 | return change; |
| 1035 | } |
| 1036 | }); |
| 1037 | db.commit(); |
| 1038 | } finally { |
| 1039 | db.rollback(); |
| 1040 | } |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1041 | [...] |
David Ostrovsky | 450eefe | 2013-10-21 21:18:11 +0200 | [diff] [blame] | 1042 | } |
| 1043 | ---- |
| 1044 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1045 | `UiAction` must be bound in a plugin module: |
| 1046 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1047 | [source,java] |
| 1048 | ---- |
| 1049 | public class Module extends AbstractModule { |
| 1050 | @Override |
| 1051 | protected void configure() { |
| 1052 | install(new RestApiModule() { |
| 1053 | @Override |
| 1054 | protected void configure() { |
| 1055 | post(REVISION_KIND, "say-hello") |
| 1056 | .to(HelloWorldAction.class); |
| 1057 | } |
| 1058 | }); |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1059 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1060 | } |
| 1061 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1062 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1063 | The module above must be declared in the `pom.xml` for Maven driven |
| 1064 | plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1065 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1066 | [source,xml] |
| 1067 | ---- |
| 1068 | <manifestEntries> |
| 1069 | <Gerrit-Module>com.googlesource.gerrit.plugins.cookbook.Module</Gerrit-Module> |
| 1070 | </manifestEntries> |
| 1071 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1072 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1073 | or in the `BUCK` configuration file for Buck driven plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1074 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1075 | [source,python] |
| 1076 | ---- |
| 1077 | manifest_entries = [ |
| 1078 | 'Gerrit-Module: com.googlesource.gerrit.plugins.cookbook.Module', |
| 1079 | ] |
| 1080 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1081 | |
| 1082 | In some use cases more user input must be gathered, for that `UiAction` can be |
| 1083 | combined with the JavaScript API. This would display a small popup near the |
| 1084 | activation button to gather additional input from the user. The JS file is |
| 1085 | typically put in the `static` folder within the plugin's directory: |
| 1086 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1087 | [source,javascript] |
| 1088 | ---- |
| 1089 | Gerrit.install(function(self) { |
| 1090 | function onSayHello(c) { |
| 1091 | var f = c.textfield(); |
| 1092 | var t = c.checkbox(); |
| 1093 | var b = c.button('Say hello', {onclick: function(){ |
| 1094 | c.call( |
| 1095 | {message: f.value, french: t.checked}, |
| 1096 | function(r) { |
| 1097 | c.hide(); |
| 1098 | window.alert(r); |
| 1099 | c.refresh(); |
| 1100 | }); |
| 1101 | }}); |
| 1102 | c.popup(c.div( |
| 1103 | c.prependLabel('Greeting message', f), |
| 1104 | c.br(), |
| 1105 | c.label(t, 'french'), |
| 1106 | c.br(), |
| 1107 | b)); |
| 1108 | f.focus(); |
| 1109 | } |
| 1110 | self.onAction('revision', 'say-hello', onSayHello); |
| 1111 | }); |
| 1112 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1113 | |
| 1114 | The JS module must be exposed as a `WebUiPlugin` and bound as |
| 1115 | an HTTP Module: |
| 1116 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1117 | [source,java] |
| 1118 | ---- |
| 1119 | public class HttpModule extends HttpPluginModule { |
| 1120 | @Override |
| 1121 | protected void configureServlets() { |
| 1122 | DynamicSet.bind(binder(), WebUiPlugin.class) |
| 1123 | .toInstance(new JavaScriptPlugin("hello.js")); |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1124 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1125 | } |
| 1126 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1127 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1128 | The HTTP module above must be declared in the `pom.xml` for Maven |
| 1129 | driven plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1130 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1131 | [source,xml] |
| 1132 | ---- |
| 1133 | <manifestEntries> |
| 1134 | <Gerrit-HttpModule>com.googlesource.gerrit.plugins.cookbook.HttpModule</Gerrit-HttpModule> |
| 1135 | </manifestEntries> |
| 1136 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1137 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1138 | or in the `BUCK` configuration file for Buck driven plugins |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1139 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1140 | [source,python] |
| 1141 | ---- |
| 1142 | manifest_entries = [ |
| 1143 | 'Gerrit-HttpModule: com.googlesource.gerrit.plugins.cookbook.HttpModule', |
| 1144 | ] |
| 1145 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1146 | |
| 1147 | If `UiAction` is annotated with the `@RequiresCapability` annotation, then the |
| 1148 | capability check is done during the `UiAction` gathering, so the plugin author |
| 1149 | doesn't have to set `UiAction.Description.setVisible()` explicitly in this |
| 1150 | case. |
| 1151 | |
| 1152 | The following prerequisities must be met, to satisfy the capability check: |
| 1153 | |
| 1154 | * user is authenticated |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1155 | * user is a member of a group which has the `Administrate Server` capability, or |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1156 | * user is a member of a group which has the required capability |
| 1157 | |
| 1158 | The `apply` method is called when the button is clicked. If `UiAction` is |
| 1159 | combined with JavaScript API (its own JavaScript function is provided), |
| 1160 | then a popup dialog is normally opened to gather additional user input. |
| 1161 | A new button is placed on the popup dialog to actually send the request. |
| 1162 | |
| 1163 | Every `UiAction` exposes a REST API endpoint. The endpoint from the example above |
| 1164 | can be accessed from any REST client, i. e.: |
| 1165 | |
| 1166 | ==== |
| 1167 | curl -X POST -H "Content-Type: application/json" \ |
| 1168 | -d '{message: "François", french: true}' \ |
| 1169 | --digest --user joe:secret \ |
| 1170 | http://host:port/a/changes/1/revisions/1/cookbook~say-hello |
| 1171 | "Bonjour François from change 1, patch set 1!" |
| 1172 | ==== |
| 1173 | |
David Pursehouse | 4224582 | 2013-09-24 09:48:20 +0900 | [diff] [blame] | 1174 | A special case is to bind an endpoint without a view name. This is |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1175 | particularly useful for `DELETE` requests: |
David Ostrovsky | c6d19ed | 2013-09-20 21:30:18 +0200 | [diff] [blame] | 1176 | |
| 1177 | [source,java] |
| 1178 | ---- |
| 1179 | public class Module extends AbstractModule { |
| 1180 | @Override |
| 1181 | protected void configure() { |
| 1182 | install(new RestApiModule() { |
| 1183 | @Override |
| 1184 | protected void configure() { |
| 1185 | delete(PROJECT_KIND) |
| 1186 | .to(DeleteProject.class); |
| 1187 | } |
| 1188 | }); |
| 1189 | } |
| 1190 | } |
| 1191 | ---- |
| 1192 | |
David Pursehouse | 4224582 | 2013-09-24 09:48:20 +0900 | [diff] [blame] | 1193 | For a `UiAction` bound this way, a JS API function can be provided. |
| 1194 | |
| 1195 | Currently only one restriction exists: per plugin only one `UiAction` |
David Ostrovsky | c6d19ed | 2013-09-20 21:30:18 +0200 | [diff] [blame] | 1196 | can be bound per resource without view name. To define a JS function |
| 1197 | for the `UiAction`, "/" must be used as the name: |
| 1198 | |
| 1199 | [source,javascript] |
| 1200 | ---- |
| 1201 | Gerrit.install(function(self) { |
| 1202 | function onDeleteProject(c) { |
| 1203 | [...] |
| 1204 | } |
| 1205 | self.onAction('project', '/', onDeleteProject); |
| 1206 | }); |
| 1207 | ---- |
| 1208 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1209 | [[top-menu-extensions]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1210 | == Top Menu Extensions |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1211 | |
| 1212 | Plugins can contribute items to Gerrit's top menu. |
| 1213 | |
| 1214 | A single top menu extension can have multiple elements and will be put as |
| 1215 | the last element in Gerrit's top menu. |
| 1216 | |
| 1217 | Plugins define the top menu entries by implementing `TopMenu` interface: |
| 1218 | |
| 1219 | [source,java] |
| 1220 | ---- |
| 1221 | public class MyTopMenuExtension implements TopMenu { |
| 1222 | |
| 1223 | @Override |
| 1224 | public List<MenuEntry> getEntries() { |
| 1225 | return Lists.newArrayList( |
| 1226 | new MenuEntry("Top Menu Entry", Lists.newArrayList( |
| 1227 | new MenuItem("Gerrit", "http://gerrit.googlecode.com/")))); |
| 1228 | } |
| 1229 | } |
| 1230 | ---- |
| 1231 | |
Edwin Kempin | 77f2324 | 2013-09-30 14:53:20 +0200 | [diff] [blame] | 1232 | Plugins can also add additional menu items to Gerrit's top menu entries |
| 1233 | by defining a `MenuEntry` that has the same name as a Gerrit top menu |
| 1234 | entry: |
| 1235 | |
| 1236 | [source,java] |
| 1237 | ---- |
| 1238 | public class MyTopMenuExtension implements TopMenu { |
| 1239 | |
| 1240 | @Override |
| 1241 | public List<MenuEntry> getEntries() { |
| 1242 | return Lists.newArrayList( |
Dariusz Luksza | 2d3afab | 2013-10-01 11:07:13 +0200 | [diff] [blame] | 1243 | new MenuEntry(GerritTopMenu.PROJECTS, Lists.newArrayList( |
Edwin Kempin | 77f2324 | 2013-09-30 14:53:20 +0200 | [diff] [blame] | 1244 | new MenuItem("Browse Repositories", "https://gerrit.googlesource.com/")))); |
| 1245 | } |
| 1246 | } |
| 1247 | ---- |
| 1248 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1249 | If no Guice modules are declared in the manifest, the top menu extension may use |
| 1250 | auto-registration by providing an `@Listen` annotation: |
| 1251 | |
| 1252 | [source,java] |
| 1253 | ---- |
| 1254 | @Listen |
| 1255 | public class MyTopMenuExtension implements TopMenu { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1256 | [...] |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1257 | } |
| 1258 | ---- |
| 1259 | |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1260 | Otherwise the top menu extension must be bound in the plugin module used |
| 1261 | for the Gerrit system injector (Gerrit-Module entry in MANIFEST.MF): |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1262 | |
| 1263 | [source,java] |
| 1264 | ---- |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1265 | package com.googlesource.gerrit.plugins.helloworld; |
| 1266 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1267 | public class HelloWorldModule extends AbstractModule { |
| 1268 | @Override |
| 1269 | protected void configure() { |
| 1270 | DynamicSet.bind(binder(), TopMenu.class).to(MyTopMenuExtension.class); |
| 1271 | } |
| 1272 | } |
| 1273 | ---- |
| 1274 | |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1275 | [source,manifest] |
| 1276 | ---- |
| 1277 | Gerrit-ApiType: plugin |
| 1278 | Gerrit-Module: com.googlesource.gerrit.plugins.helloworld.HelloWorldModule |
| 1279 | ---- |
| 1280 | |
Edwin Kempin | b2e926a | 2013-11-11 16:38:30 +0100 | [diff] [blame] | 1281 | It is also possible to show some menu entries only if the user has a |
| 1282 | certain capability: |
| 1283 | |
| 1284 | [source,java] |
| 1285 | ---- |
| 1286 | public class MyTopMenuExtension implements TopMenu { |
| 1287 | private final String pluginName; |
| 1288 | private final Provider<CurrentUser> userProvider; |
| 1289 | private final List<MenuEntry> menuEntries; |
| 1290 | |
| 1291 | @Inject |
| 1292 | public MyTopMenuExtension(@PluginName String pluginName, |
| 1293 | Provider<CurrentUser> userProvider) { |
| 1294 | this.pluginName = pluginName; |
| 1295 | this.userProvider = userProvider; |
| 1296 | menuEntries = new ArrayList<TopMenu.MenuEntry>(); |
| 1297 | |
| 1298 | // add menu entry that is only visible to users with a certain capability |
| 1299 | if (canSeeMenuEntry()) { |
| 1300 | menuEntries.add(new MenuEntry("Top Menu Entry", Collections |
| 1301 | .singletonList(new MenuItem("Gerrit", "http://gerrit.googlecode.com/")))); |
| 1302 | } |
| 1303 | |
| 1304 | // add menu entry that is visible to all users (even anonymous users) |
| 1305 | menuEntries.add(new MenuEntry("Top Menu Entry", Collections |
| 1306 | .singletonList(new MenuItem("Documentation", "/plugins/myplugin/")))); |
| 1307 | } |
| 1308 | |
| 1309 | private boolean canSeeMenuEntry() { |
| 1310 | if (userProvider.get().isIdentifiedUser()) { |
| 1311 | CapabilityControl ctl = userProvider.get().getCapabilities(); |
| 1312 | return ctl.canPerform(pluginName + "-" + MyCapability.ID) |
| 1313 | || ctl.canAdministrateServer(); |
| 1314 | } else { |
| 1315 | return false; |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | @Override |
| 1320 | public List<MenuEntry> getEntries() { |
| 1321 | return menuEntries; |
| 1322 | } |
| 1323 | } |
| 1324 | ---- |
| 1325 | |
Edwin Kempin | 3c024ea | 2013-11-11 10:43:46 +0100 | [diff] [blame] | 1326 | [[gwt_ui_extension]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1327 | == GWT UI Extension |
Edwin Kempin | 3c024ea | 2013-11-11 10:43:46 +0100 | [diff] [blame] | 1328 | Plugins can extend the Gerrit UI with own GWT code. |
| 1329 | |
| 1330 | The Maven archetype 'gerrit-plugin-gwt-archetype' can be used to |
| 1331 | generate a GWT plugin skeleton. How to use the Maven plugin archetypes |
| 1332 | is described in the link:#getting-started[Getting started] section. |
| 1333 | |
| 1334 | The generated GWT plugin has a link:#top-menu-extensions[top menu] that |
| 1335 | opens a GWT dialog box when the user clicks on it. |
| 1336 | |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1337 | In addition to the Gerrit-Plugin API a GWT plugin depends on |
| 1338 | `gerrit-plugin-gwtui`. This dependency must be specified in the |
| 1339 | `pom.xml`: |
| 1340 | |
| 1341 | [source,xml] |
| 1342 | ---- |
| 1343 | <dependency> |
| 1344 | <groupId>com.google.gerrit</groupId> |
| 1345 | <artifactId>gerrit-plugin-gwtui</artifactId> |
| 1346 | <version>${Gerrit-ApiVersion}</version> |
| 1347 | </dependency> |
| 1348 | ---- |
| 1349 | |
| 1350 | A GWT plugin must contain a GWT module file, e.g. `HelloPlugin.gwt.xml`, |
| 1351 | that bundles together all the configuration settings of the GWT plugin: |
| 1352 | |
| 1353 | [source,xml] |
| 1354 | ---- |
| 1355 | <?xml version="1.0" encoding="UTF-8"?> |
| 1356 | <module rename-to="hello_gwt_plugin"> |
| 1357 | <!-- Inherit the core Web Toolkit stuff. --> |
| 1358 | <inherits name="com.google.gwt.user.User"/> |
| 1359 | <!-- Other module inherits --> |
| 1360 | <inherits name="com.google.gerrit.Plugin"/> |
| 1361 | <inherits name="com.google.gwt.http.HTTP"/> |
| 1362 | <!-- Using GWT built-in themes adds a number of static --> |
| 1363 | <!-- resources to the plugin. No theme inherits lines were --> |
| 1364 | <!-- added in order to make this plugin as simple as possible --> |
| 1365 | <!-- Specify the app entry point class. --> |
| 1366 | <entry-point class="${package}.client.HelloPlugin"/> |
| 1367 | <stylesheet src="hello.css"/> |
| 1368 | </module> |
| 1369 | ---- |
| 1370 | |
| 1371 | The GWT module must inherit `com.google.gerrit.Plugin` and |
| 1372 | `com.google.gwt.http.HTTP`. |
| 1373 | |
| 1374 | To register the GWT module a `GwtPlugin` needs to be bound. |
| 1375 | |
| 1376 | If no Guice modules are declared in the manifest, the GWT plugin may |
| 1377 | use auto-registration by using the `@Listen` annotation: |
| 1378 | |
| 1379 | [source,java] |
| 1380 | ---- |
| 1381 | @Listen |
| 1382 | public class MyExtension extends GwtPlugin { |
| 1383 | public MyExtension() { |
| 1384 | super("hello_gwt_plugin"); |
| 1385 | } |
| 1386 | } |
| 1387 | ---- |
| 1388 | |
| 1389 | Otherwise the binding must be done in an `HttpModule`: |
| 1390 | |
| 1391 | [source,java] |
| 1392 | ---- |
| 1393 | public class HttpModule extends HttpPluginModule { |
| 1394 | |
| 1395 | @Override |
| 1396 | protected void configureServlets() { |
| 1397 | DynamicSet.bind(binder(), WebUiPlugin.class) |
| 1398 | .toInstance(new GwtPlugin("hello_gwt_plugin")); |
| 1399 | } |
| 1400 | } |
| 1401 | ---- |
| 1402 | |
| 1403 | The HTTP module above must be declared in the `pom.xml` for Maven |
| 1404 | driven plugins: |
| 1405 | |
| 1406 | [source,xml] |
| 1407 | ---- |
| 1408 | <manifestEntries> |
| 1409 | <Gerrit-HttpModule>com.googlesource.gerrit.plugins.myplugin.HttpModule</Gerrit-HttpModule> |
| 1410 | </manifestEntries> |
| 1411 | ---- |
| 1412 | |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1413 | The name that is provided to the `GwtPlugin` must match the GWT |
| 1414 | module name compiled into the plugin. The name of the GWT module |
| 1415 | can be explicitly set in the GWT module XML file by specifying |
| 1416 | the `rename-to` attribute on the module. It is important that the |
| 1417 | module name be unique across all plugins installed on the server, |
| 1418 | as the module name determines the JavaScript namespace used by the |
| 1419 | compiled plugin code. |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1420 | |
| 1421 | [source,xml] |
| 1422 | ---- |
| 1423 | <module rename-to="hello_gwt_plugin"> |
| 1424 | ---- |
| 1425 | |
| 1426 | The actual GWT code must be implemented in a class that extends |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1427 | `com.google.gerrit.plugin.client.PluginEntryPoint`: |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1428 | |
| 1429 | [source,java] |
| 1430 | ---- |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1431 | public class HelloPlugin extends PluginEntryPoint { |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1432 | |
| 1433 | @Override |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1434 | public void onPluginLoad() { |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1435 | // Create the dialog box |
| 1436 | final DialogBox dialogBox = new DialogBox(); |
| 1437 | |
| 1438 | // The content of the dialog comes from a User specified Preference |
| 1439 | dialogBox.setText("Hello from GWT Gerrit UI plugin"); |
| 1440 | dialogBox.setAnimationEnabled(true); |
| 1441 | Button closeButton = new Button("Close"); |
| 1442 | VerticalPanel dialogVPanel = new VerticalPanel(); |
| 1443 | dialogVPanel.setWidth("100%"); |
| 1444 | dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); |
| 1445 | dialogVPanel.add(closeButton); |
| 1446 | |
| 1447 | closeButton.addClickHandler(new ClickHandler() { |
| 1448 | public void onClick(ClickEvent event) { |
| 1449 | dialogBox.hide(); |
| 1450 | } |
| 1451 | }); |
| 1452 | |
| 1453 | // Set the contents of the Widget |
| 1454 | dialogBox.setWidget(dialogVPanel); |
| 1455 | |
| 1456 | RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); |
| 1457 | rootPanel.getElement().removeAttribute("href"); |
| 1458 | rootPanel.addDomHandler(new ClickHandler() { |
| 1459 | @Override |
| 1460 | public void onClick(ClickEvent event) { |
| 1461 | dialogBox.center(); |
| 1462 | dialogBox.show(); |
| 1463 | } |
| 1464 | }, ClickEvent.getType()); |
| 1465 | } |
| 1466 | } |
| 1467 | ---- |
| 1468 | |
| 1469 | This class must be set as entry point in the GWT module: |
| 1470 | |
| 1471 | [source,xml] |
| 1472 | ---- |
| 1473 | <entry-point class="${package}.client.HelloPlugin"/> |
| 1474 | ---- |
| 1475 | |
| 1476 | In addition this class must be defined as module in the `pom.xml` for the |
| 1477 | `gwt-maven-plugin` and the `webappDirectory` option of `gwt-maven-plugin` |
| 1478 | must be set to `${project.build.directory}/classes/static`: |
| 1479 | |
| 1480 | [source,xml] |
| 1481 | ---- |
| 1482 | <plugin> |
| 1483 | <groupId>org.codehaus.mojo</groupId> |
| 1484 | <artifactId>gwt-maven-plugin</artifactId> |
| 1485 | <version>2.5.1</version> |
| 1486 | <configuration> |
| 1487 | <module>com.googlesource.gerrit.plugins.myplugin.HelloPlugin</module> |
| 1488 | <disableClassMetadata>true</disableClassMetadata> |
| 1489 | <disableCastChecking>true</disableCastChecking> |
| 1490 | <webappDirectory>${project.build.directory}/classes/static</webappDirectory> |
| 1491 | </configuration> |
| 1492 | <executions> |
| 1493 | <execution> |
| 1494 | <goals> |
| 1495 | <goal>compile</goal> |
| 1496 | </goals> |
| 1497 | </execution> |
| 1498 | </executions> |
| 1499 | </plugin> |
| 1500 | ---- |
| 1501 | |
| 1502 | To attach a GWT widget defined by the plugin to the Gerrit core UI |
| 1503 | `com.google.gwt.user.client.ui.RootPanel` can be used to manipulate the |
| 1504 | Gerrit core widgets: |
| 1505 | |
| 1506 | [source,java] |
| 1507 | ---- |
| 1508 | RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); |
| 1509 | rootPanel.getElement().removeAttribute("href"); |
| 1510 | rootPanel.addDomHandler(new ClickHandler() { |
| 1511 | @Override |
| 1512 | public void onClick(ClickEvent event) { |
| 1513 | dialogBox.center(); |
| 1514 | dialogBox.show(); |
| 1515 | } |
| 1516 | }, ClickEvent.getType()); |
| 1517 | ---- |
| 1518 | |
| 1519 | GWT plugins can come with their own css file. This css file must have a |
| 1520 | unique name and must be registered in the GWT module: |
| 1521 | |
| 1522 | [source,xml] |
| 1523 | ---- |
| 1524 | <stylesheet src="hello.css"/> |
| 1525 | ---- |
| 1526 | |
Edwin Kempin | 2570b10 | 2013-11-11 11:44:50 +0100 | [diff] [blame] | 1527 | If a GWT plugin wants to invoke the Gerrit REST API it can use |
David Pursehouse | 3a38831 | 2014-02-25 16:41:47 +0900 | [diff] [blame] | 1528 | `com.google.gerrit.plugin.client.rpc.RestApi` to construct the URL |
Edwin Kempin | 2570b10 | 2013-11-11 11:44:50 +0100 | [diff] [blame] | 1529 | path and to trigger the REST calls. |
| 1530 | |
| 1531 | Example for invoking a Gerrit core REST endpoint: |
| 1532 | |
| 1533 | [source,java] |
| 1534 | ---- |
| 1535 | new RestApi("projects").id(projectName).view("description") |
| 1536 | .put("new description", new AsyncCallback<JavaScriptObject>() { |
| 1537 | |
| 1538 | @Override |
| 1539 | public void onSuccess(JavaScriptObject result) { |
| 1540 | // TODO |
| 1541 | } |
| 1542 | |
| 1543 | @Override |
| 1544 | public void onFailure(Throwable caught) { |
| 1545 | // never invoked |
| 1546 | } |
| 1547 | }); |
| 1548 | ---- |
| 1549 | |
| 1550 | Example for invoking a REST endpoint defined by a plugin: |
| 1551 | |
| 1552 | [source,java] |
| 1553 | ---- |
| 1554 | new RestApi("projects").id(projectName).view("myplugin", "myview") |
| 1555 | .get(new AsyncCallback<JavaScriptObject>() { |
| 1556 | |
| 1557 | @Override |
| 1558 | public void onSuccess(JavaScriptObject result) { |
| 1559 | // TODO |
| 1560 | } |
| 1561 | |
| 1562 | @Override |
| 1563 | public void onFailure(Throwable caught) { |
| 1564 | // never invoked |
| 1565 | } |
| 1566 | }); |
| 1567 | ---- |
| 1568 | |
| 1569 | The `onFailure(Throwable)` of the provided callback is never invoked. |
| 1570 | If an error occurs, it is shown in an error dialog. |
| 1571 | |
| 1572 | In order to be able to do REST calls the GWT module must inherit |
| 1573 | `com.google.gwt.json.JSON`: |
| 1574 | |
| 1575 | [source,xml] |
| 1576 | ---- |
| 1577 | <inherits name="com.google.gwt.json.JSON"/> |
| 1578 | ---- |
| 1579 | |
Edwin Kempin | 1519979 | 2014-04-23 16:22:05 +0200 | [diff] [blame^] | 1580 | [[screen]] |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 1581 | == Add Screen |
Edwin Kempin | 1519979 | 2014-04-23 16:22:05 +0200 | [diff] [blame^] | 1582 | A link:#gwt_ui_extension[GWT plugin] can link:#top-menu-extensions[add |
| 1583 | a menu item] that opens a screen that is implemented by the plugin. |
| 1584 | This way plugin screens can be fully integrated into the Gerrit UI. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 1585 | |
| 1586 | Example menu item: |
| 1587 | [source,java] |
| 1588 | ---- |
| 1589 | public class MyMenu implements TopMenu { |
| 1590 | private final List<MenuEntry> menuEntries; |
| 1591 | |
| 1592 | @Inject |
| 1593 | public MyMenu(@PluginName String name) { |
| 1594 | menuEntries = Lists.newArrayList(); |
| 1595 | menuEntries.add(new MenuEntry("My Menu", Collections.singletonList( |
| 1596 | new MenuItem("My Screen", "#/x/" + name + "/my-screen", "")))); |
| 1597 | } |
| 1598 | |
| 1599 | @Override |
| 1600 | public List<MenuEntry> getEntries() { |
| 1601 | return menuEntries; |
| 1602 | } |
| 1603 | } |
| 1604 | ---- |
| 1605 | |
| 1606 | Example screen: |
| 1607 | [source,java] |
| 1608 | ---- |
| 1609 | public class MyPlugin extends PluginEntryPoint { |
| 1610 | @Override |
| 1611 | public void onPluginLoad() { |
| 1612 | Plugin.get().screen("my-screen", new Screen.EntryPoint() { |
| 1613 | @Override |
| 1614 | public void onLoad(Screen screen) { |
| 1615 | screen.add(new InlineLabel("My Screen"); |
| 1616 | screen.show(); |
| 1617 | } |
| 1618 | }); |
| 1619 | } |
| 1620 | } |
| 1621 | ---- |
| 1622 | |
Edwin Kempin | 289f1a0 | 2014-02-04 16:08:25 +0100 | [diff] [blame] | 1623 | [[settings-screen]] |
| 1624 | == Plugin Settings Screen |
| 1625 | |
| 1626 | If a plugin implements a screen for administrating its settings that is |
| 1627 | available under "#/x/<plugin-name>/settings" it is automatically linked |
| 1628 | from the plugin list screen. |
| 1629 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1630 | [[http]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1631 | == HTTP Servlets |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1632 | |
| 1633 | Plugins or extensions may register additional HTTP servlets, and |
| 1634 | wrap them with HTTP filters. |
| 1635 | |
| 1636 | Servlets may use auto-registration to declare the URL they handle: |
| 1637 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1638 | [source,java] |
| 1639 | ---- |
| 1640 | import com.google.gerrit.extensions.annotations.Export; |
| 1641 | import com.google.inject.Singleton; |
| 1642 | import javax.servlet.http.HttpServlet; |
| 1643 | import javax.servlet.http.HttpServletRequest; |
| 1644 | import javax.servlet.http.HttpServletResponse; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1645 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1646 | @Export("/print") |
| 1647 | @Singleton |
| 1648 | class HelloServlet extends HttpServlet { |
| 1649 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { |
| 1650 | res.setContentType("text/plain"); |
| 1651 | res.setCharacterEncoding("UTF-8"); |
| 1652 | res.getWriter().write("Hello"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1653 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1654 | } |
| 1655 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1656 | |
Edwin Kempin | 8aa650f | 2012-07-18 11:25:48 +0200 | [diff] [blame] | 1657 | The auto registration only works for standard servlet mappings like |
| 1658 | `/foo` or `/foo/*`. Regex style bindings must use a Guice ServletModule |
| 1659 | to register the HTTP servlets and declare it explicitly in the manifest |
| 1660 | with the `Gerrit-HttpModule` attribute: |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1661 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1662 | [source,java] |
| 1663 | ---- |
| 1664 | import com.google.inject.servlet.ServletModule; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1665 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1666 | class MyWebUrls extends ServletModule { |
| 1667 | protected void configureServlets() { |
| 1668 | serve("/print").with(HelloServlet.class); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1669 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1670 | } |
| 1671 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1672 | |
| 1673 | For a plugin installed as name `helloworld`, the servlet implemented |
| 1674 | by HelloServlet class will be available to users as: |
| 1675 | |
| 1676 | ---- |
| 1677 | $ curl http://review.example.com/plugins/helloworld/print |
| 1678 | ---- |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 1679 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1680 | [[data-directory]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1681 | == Data Directory |
Edwin Kempin | 41f6391 | 2012-07-17 12:33:55 +0200 | [diff] [blame] | 1682 | |
| 1683 | Plugins can request a data directory with a `@PluginData` File |
| 1684 | dependency. A data directory will be created automatically by the |
| 1685 | server in `$site_path/data/$plugin_name` and passed to the plugin. |
| 1686 | |
| 1687 | Plugins can use this to store any data they want. |
| 1688 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1689 | [source,java] |
| 1690 | ---- |
| 1691 | @Inject |
| 1692 | MyType(@PluginData java.io.File myDir) { |
| 1693 | new FileInputStream(new File(myDir, "my.config")); |
| 1694 | } |
| 1695 | ---- |
Edwin Kempin | 41f6391 | 2012-07-17 12:33:55 +0200 | [diff] [blame] | 1696 | |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1697 | [[download-commands]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1698 | == Download Commands |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1699 | |
| 1700 | Gerrit offers commands for downloading changes using different |
| 1701 | download schemes (e.g. for downloading via different network |
| 1702 | protocols). Plugins can contribute download schemes and download |
| 1703 | commands by implementing |
| 1704 | `com.google.gerrit.extensions.config.DownloadScheme` and |
| 1705 | `com.google.gerrit.extensions.config.DownloadCommand`. |
| 1706 | |
| 1707 | The download schemes and download commands which are used most often |
| 1708 | are provided by the Gerrit core plugin `download-commands`. |
| 1709 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1710 | [[documentation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1711 | == Documentation |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 1712 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1713 | If a plugin does not register a filter or servlet to handle URLs |
| 1714 | `/Documentation/*` or `/static/*`, the core Gerrit server will |
| 1715 | automatically export these resources over HTTP from the plugin JAR. |
| 1716 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 1717 | Static resources under the `static/` directory in the JAR will be |
Dave Borowitz | b893ac8 | 2013-03-27 10:03:55 -0400 | [diff] [blame] | 1718 | available as `/plugins/helloworld/static/resource`. This prefix is |
| 1719 | configurable by setting the `Gerrit-HttpStaticPrefix` attribute. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1720 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 1721 | Documentation files under the `Documentation/` directory in the JAR |
Dave Borowitz | b893ac8 | 2013-03-27 10:03:55 -0400 | [diff] [blame] | 1722 | will be available as `/plugins/helloworld/Documentation/resource`. This |
| 1723 | prefix is configurable by setting the `Gerrit-HttpDocumentationPrefix` |
| 1724 | attribute. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1725 | |
| 1726 | Documentation may be written in |
| 1727 | link:http://daringfireball.net/projects/markdown/[Markdown] style |
| 1728 | if the file name ends with `.md`. Gerrit will automatically convert |
| 1729 | Markdown to HTML if accessed with extension `.html`. |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 1730 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1731 | [[macros]] |
Edwin Kempin | c78777d | 2012-07-16 15:55:11 +0200 | [diff] [blame] | 1732 | Within the Markdown documentation files macros can be used that allow |
| 1733 | to write documentation with reasonably accurate examples that adjust |
| 1734 | automatically based on the installation. |
| 1735 | |
| 1736 | The following macros are supported: |
| 1737 | |
| 1738 | [width="40%",options="header"] |
| 1739 | |=================================================== |
| 1740 | |Macro | Replacement |
| 1741 | |@PLUGIN@ | name of the plugin |
| 1742 | |@URL@ | Gerrit Web URL |
| 1743 | |@SSH_HOST@ | SSH Host |
| 1744 | |@SSH_PORT@ | SSH Port |
| 1745 | |=================================================== |
| 1746 | |
| 1747 | The macros will be replaced when the documentation files are rendered |
| 1748 | from Markdown to HTML. |
| 1749 | |
| 1750 | Macros that start with `\` such as `\@KEEP@` will render as `@KEEP@` |
| 1751 | even if there is an expansion for `KEEP` in the future. |
| 1752 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1753 | [[auto-index]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1754 | === Automatic Index |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 1755 | |
| 1756 | If a plugin does not handle its `/` URL itself, Gerrit will |
| 1757 | redirect clients to the plugin's `/Documentation/index.html`. |
| 1758 | Requests for `/Documentation/` (bare directory) will also redirect |
| 1759 | to `/Documentation/index.html`. |
| 1760 | |
| 1761 | If neither resource `Documentation/index.html` or |
| 1762 | `Documentation/index.md` exists in the plugin JAR, Gerrit will |
| 1763 | automatically generate an index page for the plugin's documentation |
| 1764 | tree by scanning every `*.md` and `*.html` file in the Documentation/ |
| 1765 | directory. |
| 1766 | |
| 1767 | For any discovered Markdown (`*.md`) file, Gerrit will parse the |
| 1768 | header of the file and extract the first level one title. This |
| 1769 | title text will be used as display text for a link to the HTML |
| 1770 | version of the page. |
| 1771 | |
| 1772 | For any discovered HTML (`*.html`) file, Gerrit will use the name |
| 1773 | of the file, minus the `*.html` extension, as the link text. Any |
| 1774 | hyphens in the file name will be replaced with spaces. |
| 1775 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 1776 | If a discovered file is named `about.md` or `about.html`, its |
| 1777 | content will be inserted in an 'About' section at the top of the |
| 1778 | auto-generated index page. If both `about.md` and `about.html` |
| 1779 | exist, only the first discovered file will be used. |
| 1780 | |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 1781 | If a discovered file name beings with `cmd-` it will be clustered |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 1782 | into a 'Commands' section of the generated index page. |
| 1783 | |
David Pursehouse | fe52915 | 2013-08-14 16:35:06 +0900 | [diff] [blame] | 1784 | If a discovered file name beings with `servlet-` it will be clustered |
| 1785 | into a 'Servlets' section of the generated index page. |
| 1786 | |
| 1787 | If a discovered file name beings with `rest-api-` it will be clustered |
| 1788 | into a 'REST APIs' section of the generated index page. |
| 1789 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 1790 | All other files are clustered under a 'Documentation' section. |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 1791 | |
| 1792 | Some optional information from the manifest is extracted and |
| 1793 | displayed as part of the index page, if present in the manifest: |
| 1794 | |
| 1795 | [width="40%",options="header"] |
| 1796 | |=================================================== |
| 1797 | |Field | Source Attribute |
| 1798 | |Name | Implementation-Title |
| 1799 | |Vendor | Implementation-Vendor |
| 1800 | |Version | Implementation-Version |
| 1801 | |URL | Implementation-URL |
| 1802 | |API Version | Gerrit-ApiVersion |
| 1803 | |=================================================== |
| 1804 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1805 | [[deployment]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1806 | == Deployment |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 1807 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 1808 | Compiled plugins and extensions can be deployed to a running Gerrit |
| 1809 | server using the link:cmd-plugin-install.html[plugin install] command. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1810 | |
Dariusz Luksza | 357a242 | 2012-11-12 06:16:26 +0100 | [diff] [blame] | 1811 | WebUI plugins distributed as single `.js` file can be deployed |
| 1812 | without the overhead of JAR packaging, for more information refer to |
| 1813 | link:cmd-plugin-install.html[plugin install] command. |
| 1814 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1815 | Plugins can also be copied directly into the server's |
Dariusz Luksza | 357a242 | 2012-11-12 06:16:26 +0100 | [diff] [blame] | 1816 | directory at `$site_path/plugins/$name.(jar|js)`. The name of |
| 1817 | the JAR file, minus the `.jar` or `.js` extension, will be used as the |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1818 | plugin name. Unless disabled, servers periodically scan this |
| 1819 | directory for updated plugins. The time can be adjusted by |
| 1820 | link:config-gerrit.html#plugins.checkFrequency[plugins.checkFrequency]. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 1821 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 1822 | For disabling plugins the link:cmd-plugin-remove.html[plugin remove] |
| 1823 | command can be used. |
| 1824 | |
Brad Larson | d5e87c3 | 2012-07-11 12:18:49 -0500 | [diff] [blame] | 1825 | Disabled plugins can be re-enabled using the |
| 1826 | link:cmd-plugin-enable.html[plugin enable] command. |
| 1827 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1828 | == SEE ALSO |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1829 | |
| 1830 | * link:js-api.html[JavaScript API] |
| 1831 | * link:dev-rest-api.html[REST API Developers' Notes] |
| 1832 | |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 1833 | GERRIT |
| 1834 | ------ |
| 1835 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 1836 | |
| 1837 | SEARCHBOX |
| 1838 | --------- |