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 | 1a468f0 | 2015-11-09 13:33:08 -0800 | [diff] [blame] | 39 | -DarchetypeVersion=2.13-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` |
Jiří Engelthaler | 3033a0a | 2015-02-16 09:44:32 +0100 | [diff] [blame] | 277 | can get `com.google.gerrit.pgm.init.api.AllProjectsConfig` injected: |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 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 | |
Doug Kelly | 732ad20 | 2015-11-13 13:11:32 -0800 | [diff] [blame] | 286 | @Inject |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 287 | public MyInitStep(@PluginName String pluginName, ConsoleUI ui, |
| 288 | AllProjectsConfig allProjectsConfig) { |
| 289 | this.pluginName = pluginName; |
| 290 | this.ui = ui; |
| 291 | this.allProjectsConfig = allProjectsConfig; |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void run() throws Exception { |
Edwin Kempin | 93e7d5d | 2014-01-03 09:53:20 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public void postRun() throws Exception { |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 300 | ui.message("\n"); |
| 301 | ui.header(pluginName + " Integration"); |
| 302 | boolean enabled = ui.yesno(true, "By default enabled for all projects"); |
Adrian Görler | d161297 | 2014-10-20 17:06:07 +0200 | [diff] [blame] | 303 | Config cfg = allProjectsConfig.load().getConfig(); |
Edwin Kempin | d4cfac1 | 2013-11-27 11:22:34 +0100 | [diff] [blame] | 304 | if (enabled) { |
| 305 | cfg.setBoolean("plugin", pluginName, "enabled", enabled); |
| 306 | } else { |
| 307 | cfg.unset("plugin", pluginName, "enabled"); |
| 308 | } |
| 309 | allProjectsConfig.save(pluginName, "Initialize " + pluginName + " Integration"); |
| 310 | } |
| 311 | } |
| 312 | ---- |
| 313 | |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 314 | Bear in mind that the Plugin's InitStep class will be loaded but |
| 315 | the standard Gerrit runtime environment is not available and the plugin's |
| 316 | own Guice modules were not initialized. |
| 317 | This means the InitStep for a plugin is not executed in the same way that |
| 318 | the plugin executes within the server, and may mean a plugin author cannot |
| 319 | trivially reuse runtime code during init. |
| 320 | |
| 321 | For instance a plugin that wants to verify connectivity may need to statically |
| 322 | call the constructor of their connection class, passing in values obtained |
| 323 | from the Section.Factory rather than from an injected Config object. |
| 324 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 325 | Plugins' InitSteps are executed during the "Gerrit Plugin init" phase, after |
| 326 | the extraction of the plugins embedded in the distribution .war file into |
| 327 | `$GERRIT_SITE/plugins` and before the DB Schema initialization or upgrade. |
| 328 | |
| 329 | A plugin's InitStep cannot refer to Gerrit's DB Schema or any other Gerrit |
| 330 | runtime objects injected at startup. |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 331 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 332 | [source,java] |
| 333 | ---- |
| 334 | public class MyInitStep implements InitStep { |
| 335 | private final ConsoleUI ui; |
| 336 | private final Section.Factory sections; |
| 337 | private final String pluginName; |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 338 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 339 | @Inject |
| 340 | public GitBlitInitStep(final ConsoleUI ui, Section.Factory sections, @PluginName String pluginName) { |
| 341 | this.ui = ui; |
| 342 | this.sections = sections; |
| 343 | this.pluginName = pluginName; |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 344 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 345 | |
| 346 | @Override |
| 347 | public void run() throws Exception { |
| 348 | ui.header("\nMy plugin"); |
| 349 | |
| 350 | Section mySection = getSection("myplugin", null); |
| 351 | mySection.string("Link name", "linkname", "MyLink"); |
| 352 | } |
Edwin Kempin | 93e7d5d | 2014-01-03 09:53:20 +0100 | [diff] [blame] | 353 | |
| 354 | @Override |
| 355 | public void postRun() throws Exception { |
| 356 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 357 | } |
| 358 | ---- |
Luca Milanesio | 737285d | 2012-09-25 14:26:43 +0100 | [diff] [blame] | 359 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 360 | [[classpath]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 361 | == Classpath |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 362 | |
| 363 | Each plugin is loaded into its own ClassLoader, isolating plugins |
| 364 | from each other. A plugin or extension inherits the Java runtime |
| 365 | and the Gerrit API chosen by `Gerrit-ApiType` (extension or plugin) |
| 366 | from the hosting server. |
| 367 | |
| 368 | Plugins are loaded from a single JAR file. If a plugin needs |
| 369 | additional libraries, it must include those dependencies within |
| 370 | its own JAR. Plugins built using Maven may be able to use the |
| 371 | link:http://maven.apache.org/plugins/maven-shade-plugin/[shade plugin] |
| 372 | to package additional dependencies. Relocating (or renaming) classes |
| 373 | should not be necessary due to the ClassLoader isolation. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 374 | |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 375 | [[events]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 376 | == Listening to Events |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 377 | |
| 378 | Certain operations in Gerrit trigger events. Plugins may receive |
| 379 | notifications of these events by implementing the corresponding |
| 380 | listeners. |
| 381 | |
Martin Fick | 4c72aea | 2014-12-10 14:58:12 -0700 | [diff] [blame] | 382 | * `com.google.gerrit.common.EventListener`: |
Edwin Kempin | 64059f5 | 2013-10-31 13:49:25 +0100 | [diff] [blame] | 383 | + |
Martin Fick | 4c72aea | 2014-12-10 14:58:12 -0700 | [diff] [blame] | 384 | Allows to listen to events. These are the same |
Edwin Kempin | 64059f5 | 2013-10-31 13:49:25 +0100 | [diff] [blame] | 385 | link:cmd-stream-events.html#events[events] that are also streamed by |
| 386 | the link:cmd-stream-events.html[gerrit stream-events] command. |
| 387 | |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 388 | * `com.google.gerrit.extensions.events.LifecycleListener`: |
| 389 | + |
Edwin Kempin | 3e7928a | 2013-12-03 07:39:00 +0100 | [diff] [blame] | 390 | Plugin start and stop |
Edwin Kempin | 9820266 | 2013-09-18 16:03:03 +0200 | [diff] [blame] | 391 | |
| 392 | * `com.google.gerrit.extensions.events.NewProjectCreatedListener`: |
| 393 | + |
| 394 | Project creation |
| 395 | |
| 396 | * `com.google.gerrit.extensions.events.ProjectDeletedListener`: |
| 397 | + |
| 398 | Project deletion |
| 399 | |
Edwin Kempin | b27c939 | 2013-11-19 13:12:43 +0100 | [diff] [blame] | 400 | * `com.google.gerrit.extensions.events.HeadUpdatedListener`: |
| 401 | + |
| 402 | Update of HEAD on a project |
| 403 | |
Stefan Lay | 310d77d | 2014-05-28 13:45:25 +0200 | [diff] [blame] | 404 | * `com.google.gerrit.extensions.events.UsageDataPublishedListener`: |
| 405 | + |
| 406 | Publication of usage data |
| 407 | |
Adrian Görler | f4a4c9a | 2014-08-22 17:09:18 +0200 | [diff] [blame] | 408 | * `com.google.gerrit.extensions.events.GarbageCollectorListener`: |
| 409 | + |
| 410 | Garbage collection ran on a project |
| 411 | |
Yang Zhenhui | 2659d42 | 2013-07-30 16:59:58 +0800 | [diff] [blame] | 412 | [[stream-events]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 413 | == Sending Events to the Events Stream |
Yang Zhenhui | 2659d42 | 2013-07-30 16:59:58 +0800 | [diff] [blame] | 414 | |
| 415 | Plugins may send events to the events stream where consumers of |
| 416 | Gerrit's `stream-events` ssh command will receive them. |
| 417 | |
| 418 | To send an event, the plugin must invoke one of the `postEvent` |
| 419 | methods in the `ChangeHookRunner` class, passing an instance of |
Martin Fick | 4c72aea | 2014-12-10 14:58:12 -0700 | [diff] [blame] | 420 | its own custom event class derived from |
| 421 | `com.google.gerrit.server.events.Event`. |
Yang Zhenhui | 2659d42 | 2013-07-30 16:59:58 +0800 | [diff] [blame] | 422 | |
Martin Fick | 0aef6f1 | 2014-12-11 16:54:21 -0700 | [diff] [blame] | 423 | Plugins which define new Events should register them via the |
| 424 | `com.google.gerrit.server.events.EventTypes.registerClass()` |
| 425 | method. This will make the EventType known to the system. |
Martin Fick | f70c20a | 2014-12-11 17:03:15 -0700 | [diff] [blame] | 426 | Deserialzing events with the |
| 427 | `com.google.gerrit.server.events.EventDeserializer` class requires |
| 428 | that the event be registered in EventTypes. |
Martin Fick | 0aef6f1 | 2014-12-11 16:54:21 -0700 | [diff] [blame] | 429 | |
Edwin Kempin | 3273760 | 2014-01-23 09:04:58 +0100 | [diff] [blame] | 430 | [[validation]] |
David Pursehouse | 91c5f5e | 2014-01-23 18:57:33 +0900 | [diff] [blame] | 431 | == Validation Listeners |
Edwin Kempin | 3273760 | 2014-01-23 09:04:58 +0100 | [diff] [blame] | 432 | |
| 433 | Certain operations in Gerrit can be validated by plugins by |
| 434 | implementing the corresponding link:config-validation.html[listeners]. |
| 435 | |
Saša Živkov | ec85a07 | 2014-01-28 10:08:25 +0100 | [diff] [blame] | 436 | [[receive-pack]] |
| 437 | == Receive Pack Initializers |
| 438 | |
| 439 | Plugins may provide ReceivePack initializers which will be invoked |
| 440 | by Gerrit just before a ReceivePack instance will be used. Usually, |
| 441 | plugins will make use of the setXXX methods on the ReceivePack to |
| 442 | set additional properties on it. |
| 443 | |
Saša Živkov | 626c731 | 2014-02-24 17:15:08 +0100 | [diff] [blame] | 444 | [[post-receive-hook]] |
| 445 | == Post Receive-Pack Hooks |
| 446 | |
| 447 | Plugins may register PostReceiveHook instances in order to get |
| 448 | notified when JGit successfully receives a pack. This may be useful |
| 449 | for those plugins which would like to monitor changes in Git |
| 450 | repositories. |
| 451 | |
Hugo Arès | 572d542 | 2014-06-17 14:22:03 -0400 | [diff] [blame] | 452 | [[pre-upload-hook]] |
| 453 | == Pre Upload-Pack Hooks |
| 454 | |
| 455 | Plugins may register PreUploadHook instances in order to get |
| 456 | notified when JGit is about to upload a pack. This may be useful |
| 457 | for those plugins which would like to monitor usage in Git |
| 458 | repositories. |
| 459 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 460 | [[ssh]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 461 | == SSH Commands |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 462 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 463 | Plugins may provide commands that can be accessed through the SSH |
| 464 | interface (extensions do not have this option). |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 465 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 466 | Command implementations must extend the base class SshCommand: |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 467 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 468 | [source,java] |
| 469 | ---- |
| 470 | import com.google.gerrit.sshd.SshCommand; |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 471 | import com.google.gerrit.sshd.CommandMetaData; |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 472 | |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 473 | @CommandMetaData(name="print", description="Print hello command") |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 474 | class PrintHello extends SshCommand { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 475 | @Override |
| 476 | protected void run() { |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 477 | stdout.print("Hello\n"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 478 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 479 | } |
| 480 | ---- |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 481 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 482 | If no Guice modules are declared in the manifest, SSH commands may |
Edwin Kempin | 948de0f | 2012-07-16 10:34:35 +0200 | [diff] [blame] | 483 | use auto-registration by providing an `@Export` annotation: |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 484 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 485 | [source,java] |
| 486 | ---- |
| 487 | import com.google.gerrit.extensions.annotations.Export; |
| 488 | import com.google.gerrit.sshd.SshCommand; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 489 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 490 | @Export("print") |
| 491 | class PrintHello extends SshCommand { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 492 | @Override |
| 493 | protected void run() { |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 494 | stdout.print("Hello\n"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 495 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 496 | } |
| 497 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 498 | |
| 499 | If explicit registration is being used, a Guice module must be |
| 500 | supplied to register the SSH command and declared in the manifest |
| 501 | with the `Gerrit-SshModule` attribute: |
| 502 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 503 | [source,java] |
| 504 | ---- |
| 505 | import com.google.gerrit.sshd.PluginCommandModule; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 506 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 507 | class MyCommands extends PluginCommandModule { |
Ian Bull | e1a1220 | 2014-02-16 17:15:42 -0800 | [diff] [blame] | 508 | @Override |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 509 | protected void configureCommands() { |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 510 | command(PrintHello.class); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 511 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 512 | } |
| 513 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 514 | |
| 515 | For a plugin installed as name `helloworld`, the command implemented |
| 516 | by PrintHello class will be available to users as: |
| 517 | |
| 518 | ---- |
Keunhong Park | a09a6f1 | 2012-07-10 14:45:02 -0600 | [diff] [blame] | 519 | $ ssh -p 29418 review.example.com helloworld print |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 520 | ---- |
| 521 | |
David Ostrovsky | 79c4d89 | 2014-03-15 13:52:46 +0100 | [diff] [blame] | 522 | [[multiple-commands]] |
| 523 | === Multiple Commands bound to one implementation |
| 524 | |
David Ostrovsky | e3172b3 | 2013-10-13 14:19:13 +0200 | [diff] [blame] | 525 | Multiple SSH commands can be bound to the same implementation class. For |
| 526 | example a Gerrit Shell plugin can bind different shell commands to the same |
| 527 | implementation class: |
| 528 | |
| 529 | [source,java] |
| 530 | ---- |
| 531 | public class SshShellModule extends PluginCommandModule { |
| 532 | @Override |
| 533 | protected void configureCommands() { |
| 534 | command("ls").to(ShellCommand.class); |
| 535 | command("ps").to(ShellCommand.class); |
| 536 | [...] |
| 537 | } |
| 538 | } |
| 539 | ---- |
| 540 | |
| 541 | With the possible implementation: |
| 542 | |
| 543 | [source,java] |
| 544 | ---- |
| 545 | public class ShellCommand extends SshCommand { |
| 546 | @Override |
| 547 | protected void run() throws UnloggedFailure { |
| 548 | String cmd = getName().substring(getPluginName().length() + 1); |
| 549 | ProcessBuilder proc = new ProcessBuilder(cmd); |
| 550 | Process cmd = proc.start(); |
| 551 | [...] |
| 552 | } |
| 553 | } |
| 554 | ---- |
| 555 | |
| 556 | And the call: |
| 557 | |
| 558 | ---- |
| 559 | $ ssh -p 29418 review.example.com shell ls |
| 560 | $ ssh -p 29418 review.example.com shell ps |
| 561 | ---- |
| 562 | |
David Ostrovsky | 79c4d89 | 2014-03-15 13:52:46 +0100 | [diff] [blame] | 563 | [[root-level-commands]] |
| 564 | === Root Level Commands |
| 565 | |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 566 | Single command plugins are also supported. In this scenario plugin binds |
| 567 | SSH command to its own name. `SshModule` must inherit from |
| 568 | `SingleCommandPluginModule` class: |
| 569 | |
| 570 | [source,java] |
| 571 | ---- |
| 572 | public class SshModule extends SingleCommandPluginModule { |
| 573 | @Override |
| 574 | protected void configure(LinkedBindingBuilder<Command> b) { |
| 575 | b.to(ShellCommand.class); |
| 576 | } |
| 577 | } |
| 578 | ---- |
| 579 | |
| 580 | 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] | 581 | directory, generic commands can be called without specifying the |
David Ostrovsky | b7d9775 | 2013-11-09 05:23:26 +0100 | [diff] [blame] | 582 | actual SSH command. Note in the example below, that the called commands |
| 583 | `ls` and `ps` was not explicitly bound: |
| 584 | |
| 585 | ---- |
| 586 | $ ssh -p 29418 review.example.com sh ls |
| 587 | $ ssh -p 29418 review.example.com sh ps |
| 588 | ---- |
| 589 | |
Martin Fick | 5f622291 | 2015-11-12 14:52:50 -0700 | [diff] [blame] | 590 | [[search_operators]] |
| 591 | === Search Operators === |
| 592 | |
| 593 | Plugins can define new search operators to extend change searching by |
| 594 | implementing the `ChangeQueryBuilder.ChangeOperatorFactory` interface |
| 595 | and registering it to an operator name in the plugin module's |
| 596 | `configure()` method. The search operator name is defined during |
| 597 | registration via the DynamicMap annotation mechanism. The plugin |
| 598 | name will get appended to the annotated name, with an underscore |
| 599 | in between, leading to the final operator name. An example |
| 600 | registration looks like this: |
| 601 | |
| 602 | bind(ChangeOperatorFactory.class) |
| 603 | .annotatedWith(Exports.named("sample")) |
| 604 | .to(SampleOperator.class); |
| 605 | |
| 606 | If this is registered in the `myplugin` plugin, then the resulting |
| 607 | operator will be named `sample_myplugin`. |
| 608 | |
| 609 | The search operator itself is implemented by ensuring that the |
| 610 | `create()` method of the class implementing the |
| 611 | `ChangeQueryBuilder.ChangeOperatorFactory` interface returns a |
| 612 | `Predicate<ChangeData>`. Here is a sample operator factory |
| 613 | defintion which creates a `MyPredicate`: |
| 614 | |
| 615 | [source,java] |
| 616 | ---- |
| 617 | @Singleton |
| 618 | public class SampleOperator |
| 619 | implements ChangeQueryBuilder.ChangeOperatorFactory { |
| 620 | public static class MyPredicate extends OperatorPredicate<ChangeData> { |
| 621 | ... |
| 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public Predicate<ChangeData> create(ChangeQueryBuilder builder, String value) |
| 626 | throws QueryParseException { |
| 627 | return new MyPredicate(value); |
| 628 | } |
| 629 | } |
| 630 | ---- |
| 631 | |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 632 | [[simple-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 633 | == Simple Configuration in `gerrit.config` |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 634 | |
| 635 | In Gerrit, global configuration is stored in the `gerrit.config` file. |
| 636 | If a plugin needs global configuration, this configuration should be |
| 637 | stored in a `plugin` subsection in the `gerrit.config` file. |
| 638 | |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 639 | This approach of storing the plugin configuration is only suitable for |
| 640 | plugins that have a simple configuration that only consists of |
| 641 | key-value pairs. With this approach it is not possible to have |
| 642 | subsections in the plugin configuration. Plugins that require a complex |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 643 | configuration need to store their configuration in their |
| 644 | link:#configuration[own configuration file] where they can make use of |
| 645 | subsections. On the other hand storing the plugin configuration in a |
| 646 | 'plugin' subsection in the `gerrit.config` file has the advantage that |
| 647 | administrators have all configuration parameters in one file, instead |
| 648 | of having one configuration file per plugin. |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 649 | |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 650 | To avoid conflicts with other plugins, it is recommended that plugins |
| 651 | only use the `plugin` subsection with their own name. For example the |
| 652 | `helloworld` plugin should store its configuration in the |
| 653 | `plugin.helloworld` subsection: |
| 654 | |
| 655 | ---- |
| 656 | [plugin "helloworld"] |
| 657 | language = Latin |
| 658 | ---- |
| 659 | |
Sasa Zivkov | acdf533 | 2013-09-20 14:05:15 +0200 | [diff] [blame] | 660 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 661 | plugin can easily access its configuration and there is no need for a |
| 662 | plugin to parse the `gerrit.config` file on its own: |
| 663 | |
| 664 | [source,java] |
| 665 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 666 | @Inject |
| 667 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 668 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 669 | [...] |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 670 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 671 | String language = cfg.getFromGerritConfig("helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 672 | .getString("language", "English"); |
Edwin Kempin | f7bfff8 | 2013-09-17 13:34:20 +0200 | [diff] [blame] | 673 | ---- |
| 674 | |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 675 | [[configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 676 | == Configuration in own config file |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 677 | |
| 678 | Plugins can store their configuration in an own configuration file. |
| 679 | This makes sense if the plugin configuration is rather complex and |
| 680 | requires the usage of subsections. Plugins that have a simple |
| 681 | key-value pair configuration can store their configuration in a |
| 682 | link:#simple-configuration[`plugin` subsection of the `gerrit.config` |
| 683 | file]. |
| 684 | |
| 685 | The plugin configuration file must be named after the plugin and must |
| 686 | be located in the `etc` folder of the review site. For example a |
| 687 | configuration file for a `default-reviewer` plugin could look like |
| 688 | this: |
| 689 | |
| 690 | .$site_path/etc/default-reviewer.config |
| 691 | ---- |
| 692 | [branch "refs/heads/master"] |
| 693 | reviewer = Project Owners |
| 694 | reviewer = john.doe@example.com |
| 695 | [match "file:^.*\.txt"] |
| 696 | reviewer = My Info Developers |
| 697 | ---- |
| 698 | |
| 699 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 700 | plugin can easily access its configuration: |
| 701 | |
| 702 | [source,java] |
| 703 | ---- |
| 704 | @Inject |
| 705 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 706 | |
| 707 | [...] |
| 708 | |
| 709 | String[] reviewers = cfg.getGlobalPluginConfig("default-reviewer") |
| 710 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 711 | ---- |
| 712 | |
Edwin Kempin | 78ca094 | 2013-10-30 11:24:06 +0100 | [diff] [blame] | 713 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 714 | [[simple-project-specific-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 715 | == Simple Project Specific Configuration in `project.config` |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 716 | |
| 717 | In Gerrit, project specific configuration is stored in the project's |
| 718 | `project.config` file on the `refs/meta/config` branch. If a plugin |
| 719 | needs configuration on project level (e.g. to enable its functionality |
| 720 | only for certain projects), this configuration should be stored in a |
| 721 | `plugin` subsection in the project's `project.config` file. |
| 722 | |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 723 | This approach of storing the plugin configuration is only suitable for |
| 724 | plugins that have a simple configuration that only consists of |
| 725 | key-value pairs. With this approach it is not possible to have |
| 726 | subsections in the plugin configuration. Plugins that require a complex |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 727 | configuration need to store their configuration in their |
| 728 | link:#project-specific-configuration[own configuration file] where they |
| 729 | can make use of subsections. On the other hand storing the plugin |
| 730 | configuration in a 'plugin' subsection in the `project.config` file has |
| 731 | the advantage that project owners have all configuration parameters in |
| 732 | one file, instead of having one configuration file per plugin. |
Edwin Kempin | c9b6860 | 2013-10-30 09:32:43 +0100 | [diff] [blame] | 733 | |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 734 | To avoid conflicts with other plugins, it is recommended that plugins |
| 735 | only use the `plugin` subsection with their own name. For example the |
| 736 | `helloworld` plugin should store its configuration in the |
| 737 | `plugin.helloworld` subsection: |
| 738 | |
| 739 | ---- |
| 740 | [plugin "helloworld"] |
| 741 | enabled = true |
| 742 | ---- |
| 743 | |
| 744 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 745 | plugin can easily access its project specific configuration and there |
| 746 | is no need for a plugin to parse the `project.config` file on its own: |
| 747 | |
| 748 | [source,java] |
| 749 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 750 | @Inject |
| 751 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 752 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 753 | [...] |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 754 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 755 | boolean enabled = cfg.getFromProjectConfig(project, "helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 756 | .getBoolean("enabled", false); |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 757 | ---- |
| 758 | |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 759 | It is also possible to get missing configuration parameters inherited |
| 760 | from the parent projects: |
| 761 | |
| 762 | [source,java] |
| 763 | ---- |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 764 | @Inject |
| 765 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 766 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 767 | [...] |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 768 | |
Edwin Kempin | 122622d | 2013-10-29 16:45:44 +0100 | [diff] [blame] | 769 | boolean enabled = cfg.getFromProjectConfigWithInheritance(project, "helloworld") |
David Pursehouse | 529ec25 | 2013-09-27 13:45:14 +0900 | [diff] [blame] | 770 | .getBoolean("enabled", false); |
Edwin Kempin | ca7ad8e | 2013-09-16 16:43:05 +0200 | [diff] [blame] | 771 | ---- |
| 772 | |
Edwin Kempin | 7b2f4cc | 2013-08-26 15:44:19 +0200 | [diff] [blame] | 773 | Project owners can edit the project configuration by fetching the |
| 774 | `refs/meta/config` branch, editing the `project.config` file and |
| 775 | pushing the commit back. |
| 776 | |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 777 | Plugin configuration values that are stored in the `project.config` |
| 778 | file can be exposed in the ProjectInfoScreen to allow project owners |
| 779 | to see and edit them from the UI. |
| 780 | |
| 781 | For this an instance of `ProjectConfigEntry` needs to be bound for each |
| 782 | parameter. The export name must be a valid Git variable name. The |
| 783 | variable name is case-insensitive, allows only alphanumeric characters |
| 784 | and '-', and must start with an alphabetic character. |
| 785 | |
Edwin Kempin | a6c1c45 | 2013-11-28 16:55:22 +0100 | [diff] [blame] | 786 | The example below shows how the parameters `plugin.helloworld.enabled` |
| 787 | and `plugin.helloworld.language` are bound to be editable from the |
David Pursehouse | a1d633b | 2014-05-02 17:21:02 +0900 | [diff] [blame] | 788 | Web UI. For the parameter `plugin.helloworld.enabled` "Enable Greeting" |
Edwin Kempin | a6c1c45 | 2013-11-28 16:55:22 +0100 | [diff] [blame] | 789 | is provided as display name and the default value is set to `true`. |
| 790 | For the parameter `plugin.helloworld.language` "Preferred Language" |
| 791 | is provided as display name and "en" is set as default value. |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 792 | |
| 793 | [source,java] |
| 794 | ---- |
| 795 | class Module extends AbstractModule { |
| 796 | @Override |
| 797 | protected void configure() { |
| 798 | bind(ProjectConfigEntry.class) |
Edwin Kempin | a6c1c45 | 2013-11-28 16:55:22 +0100 | [diff] [blame] | 799 | .annotatedWith(Exports.named("enabled")) |
| 800 | .toInstance(new ProjectConfigEntry("Enable Greeting", true)); |
| 801 | bind(ProjectConfigEntry.class) |
Edwin Kempin | 9ce4f55 | 2013-11-15 16:00:00 +0100 | [diff] [blame] | 802 | .annotatedWith(Exports.named("language")) |
| 803 | .toInstance(new ProjectConfigEntry("Preferred Language", "en")); |
| 804 | } |
| 805 | } |
| 806 | ---- |
| 807 | |
Edwin Kempin | b64d397 | 2013-11-17 18:55:48 +0100 | [diff] [blame] | 808 | By overwriting the `onUpdate` method of `ProjectConfigEntry` plugins |
| 809 | can be notified when this configuration parameter is updated on a |
| 810 | project. |
| 811 | |
Janice Agustin | e5a9d01 | 2015-08-24 09:05:56 -0400 | [diff] [blame] | 812 | [[configuring-groups]] |
| 813 | === Referencing groups in `project.config` |
| 814 | |
| 815 | Plugins can refer to groups so that when they are renamed, the project |
| 816 | config will also be updated in this section. The proper format to use is |
| 817 | the string representation of a GroupReference, as shown below. |
| 818 | |
| 819 | ---- |
| 820 | Group[group_name / group_uuid] |
| 821 | ---- |
| 822 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 823 | [[project-specific-configuration]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 824 | == Project Specific Configuration in own config file |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 825 | |
| 826 | Plugins can store their project specific configuration in an own |
| 827 | configuration file in the projects `refs/meta/config` branch. |
| 828 | This makes sense if the plugins project specific configuration is |
| 829 | rather complex and requires the usage of subsections. Plugins that |
| 830 | have a simple key-value pair configuration can store their project |
| 831 | specific configuration in a link:#simple-project-specific-configuration[ |
| 832 | `plugin` subsection of the `project.config` file]. |
| 833 | |
| 834 | The plugin configuration file in the `refs/meta/config` branch must be |
| 835 | named after the plugin. For example a configuration file for a |
| 836 | `default-reviewer` plugin could look like this: |
| 837 | |
| 838 | .default-reviewer.config |
| 839 | ---- |
| 840 | [branch "refs/heads/master"] |
| 841 | reviewer = Project Owners |
| 842 | reviewer = john.doe@example.com |
| 843 | [match "file:^.*\.txt"] |
| 844 | reviewer = My Info Developers |
| 845 | ---- |
| 846 | |
| 847 | Via the `com.google.gerrit.server.config.PluginConfigFactory` class a |
| 848 | plugin can easily access its project specific configuration: |
| 849 | |
| 850 | [source,java] |
| 851 | ---- |
| 852 | @Inject |
| 853 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 854 | |
| 855 | [...] |
| 856 | |
| 857 | String[] reviewers = cfg.getProjectPluginConfig(project, "default-reviewer") |
| 858 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 859 | ---- |
| 860 | |
Edwin Kempin | 762da38 | 2013-10-30 14:50:01 +0100 | [diff] [blame] | 861 | It is also possible to get missing configuration parameters inherited |
| 862 | from the parent projects: |
| 863 | |
| 864 | [source,java] |
| 865 | ---- |
| 866 | @Inject |
| 867 | private com.google.gerrit.server.config.PluginConfigFactory cfg; |
| 868 | |
| 869 | [...] |
| 870 | |
David Ostrovsky | 468e4c3 | 2014-03-22 06:05:35 -0700 | [diff] [blame] | 871 | String[] reviewers = cfg.getProjectPluginConfigWithInheritance(project, "default-reviewer") |
Edwin Kempin | 762da38 | 2013-10-30 14:50:01 +0100 | [diff] [blame] | 872 | .getStringList("branch", "refs/heads/master", "reviewer"); |
| 873 | ---- |
| 874 | |
Edwin Kempin | 705f284 | 2013-10-30 14:25:31 +0100 | [diff] [blame] | 875 | Project owners can edit the project configuration by fetching the |
| 876 | `refs/meta/config` branch, editing the `<plugin-name>.config` file and |
| 877 | pushing the commit back. |
| 878 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 879 | == React on changes in project configuration |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 880 | |
| 881 | If a plugin wants to react on changes in the project configuration, it |
| 882 | can implement a `GitReferenceUpdatedListener` and filter on events for |
| 883 | the `refs/meta/config` branch: |
| 884 | |
| 885 | [source,java] |
| 886 | ---- |
| 887 | public class MyListener implements GitReferenceUpdatedListener { |
| 888 | |
| 889 | private final MetaDataUpdate.Server metaDataUpdateFactory; |
| 890 | |
| 891 | @Inject |
| 892 | MyListener(MetaDataUpdate.Server metaDataUpdateFactory) { |
| 893 | this.metaDataUpdateFactory = metaDataUpdateFactory; |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public void onGitReferenceUpdated(Event event) { |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 898 | if (event.getRefName().equals(RefNames.REFS_CONFIG)) { |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 899 | Project.NameKey p = new Project.NameKey(event.getProjectName()); |
| 900 | try { |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 901 | ProjectConfig oldCfg = parseConfig(p, event.getOldObjectId()); |
| 902 | ProjectConfig newCfg = parseConfig(p, event.getNewObjectId()); |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 903 | |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 904 | if (oldCfg != null && newCfg != null |
| 905 | && !oldCfg.getProject().getSubmitType().equals(newCfg.getProject().getSubmitType())) { |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 906 | // submit type has changed |
| 907 | ... |
| 908 | } |
| 909 | } catch (IOException | ConfigInvalidException e) { |
| 910 | ... |
| 911 | } |
| 912 | } |
| 913 | } |
Edwin Kempin | a951ba5 | 2014-01-03 14:07:28 +0100 | [diff] [blame] | 914 | |
| 915 | private ProjectConfig parseConfig(Project.NameKey p, String idStr) |
| 916 | throws IOException, ConfigInvalidException, RepositoryNotFoundException { |
| 917 | ObjectId id = ObjectId.fromString(idStr); |
| 918 | if (ObjectId.zeroId().equals(id)) { |
| 919 | return null; |
| 920 | } |
| 921 | return ProjectConfig.read(metaDataUpdateFactory.create(p), id); |
| 922 | } |
Edwin Kempin | a46b6c9 | 2013-12-04 21:05:24 +0100 | [diff] [blame] | 923 | } |
| 924 | ---- |
| 925 | |
| 926 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 927 | [[capabilities]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 928 | == Plugin Owned Capabilities |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 929 | |
| 930 | Plugins may provide their own capabilities and restrict usage of SSH |
Dariusz Luksza | 112d93a | 2014-06-01 16:52:23 +0200 | [diff] [blame] | 931 | commands or `UiAction` to the users who are granted those capabilities. |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 932 | |
| 933 | Plugins define the capabilities by overriding the `CapabilityDefinition` |
| 934 | abstract class: |
| 935 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 936 | [source,java] |
| 937 | ---- |
| 938 | public class PrintHelloCapability extends CapabilityDefinition { |
| 939 | @Override |
| 940 | public String getDescription() { |
| 941 | return "Print Hello"; |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 942 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 943 | } |
| 944 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 945 | |
Dariusz Luksza | 112d93a | 2014-06-01 16:52:23 +0200 | [diff] [blame] | 946 | If no Guice modules are declared in the manifest, capability may |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 947 | use auto-registration by providing an `@Export` annotation: |
| 948 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 949 | [source,java] |
| 950 | ---- |
| 951 | @Export("printHello") |
| 952 | public class PrintHelloCapability extends CapabilityDefinition { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 953 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 954 | } |
| 955 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 956 | |
| 957 | Otherwise the capability must be bound in a plugin module: |
| 958 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 959 | [source,java] |
| 960 | ---- |
| 961 | public class HelloWorldModule extends AbstractModule { |
| 962 | @Override |
| 963 | protected void configure() { |
| 964 | bind(CapabilityDefinition.class) |
| 965 | .annotatedWith(Exports.named("printHello")) |
| 966 | .to(PrintHelloCapability.class); |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 967 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 968 | } |
| 969 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 970 | |
| 971 | 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] | 972 | 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] | 973 | this capability in the usual way, using the `RequiresCapability` annotation: |
| 974 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 975 | [source,java] |
| 976 | ---- |
| 977 | @RequiresCapability("printHello") |
| 978 | @CommandMetaData(name="print", description="Print greeting in different languages") |
| 979 | public final class PrintHelloWorldCommand extends SshCommand { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 980 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 981 | } |
| 982 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 983 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 984 | Or with `UiAction`: |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 985 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 986 | [source,java] |
| 987 | ---- |
| 988 | @RequiresCapability("printHello") |
| 989 | public class SayHelloAction extends UiAction<RevisionResource> |
| 990 | implements RestModifyView<RevisionResource, SayHelloAction.Input> { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 991 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 992 | } |
| 993 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 994 | |
| 995 | Capability scope was introduced to differentiate between plugin-owned |
David Pursehouse | bf05334 | 2013-09-05 14:55:29 +0900 | [diff] [blame] | 996 | capabilities and core capabilities. Per default the scope of the |
| 997 | `@RequiresCapability` annotation is `CapabilityScope.CONTEXT`, that means: |
| 998 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 999 | * when `@RequiresCapability` is used within a plugin the scope of the |
| 1000 | capability is assumed to be that plugin. |
David Pursehouse | bf05334 | 2013-09-05 14:55:29 +0900 | [diff] [blame] | 1001 | |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 1002 | * If `@RequiresCapability` is used within the core Gerrit Code Review server |
| 1003 | (and thus is outside of a plugin) the scope is the core server and will use |
| 1004 | the `GlobalCapability` known to Gerrit Code Review server. |
| 1005 | |
| 1006 | If a plugin needs to use a core capability name (e.g. "administrateServer") |
| 1007 | this can be specified by setting `scope = CapabilityScope.CORE`: |
| 1008 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1009 | [source,java] |
| 1010 | ---- |
| 1011 | @RequiresCapability(value = "administrateServer", scope = |
| 1012 | CapabilityScope.CORE) |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1013 | [...] |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1014 | ---- |
David Ostrovsky | 7066cc0 | 2013-06-15 14:46:23 +0200 | [diff] [blame] | 1015 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1016 | [[ui_extension]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1017 | == UI Extension |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1018 | |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1019 | [[panels]] |
| 1020 | === Panels |
| 1021 | |
| 1022 | GWT plugins can contribute panels to Gerrit screens. |
| 1023 | |
| 1024 | Gerrit screens define extension points where plugins can add GWT |
| 1025 | panels with custom controls: |
| 1026 | |
| 1027 | * Change Screen: |
Edwin Kempin | 2a8c515 | 2015-07-08 14:28:57 +0200 | [diff] [blame] | 1028 | ** `GerritUiExtensionPoint.CHANGE_SCREEN_HEADER`: |
| 1029 | + |
| 1030 | Panel will be shown in the header bar to the right of the change |
| 1031 | status. |
| 1032 | |
Edwin Kempin | 745021e | 2015-07-09 13:09:44 +0200 | [diff] [blame] | 1033 | ** `GerritUiExtensionPoint.CHANGE_SCREEN_HEADER_RIGHT_OF_BUTTONS`: |
| 1034 | + |
| 1035 | Panel will be shown in the header bar on the right side of the buttons. |
| 1036 | |
Edwin Kempin | cbc9525 | 2015-07-09 11:37:53 +0200 | [diff] [blame] | 1037 | ** `GerritUiExtensionPoint.CHANGE_SCREEN_HEADER_RIGHT_OF_POP_DOWNS`: |
| 1038 | + |
| 1039 | Panel will be shown in the header bar on the right side of the pop down |
| 1040 | buttons. |
| 1041 | |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1042 | ** `GerritUiExtensionPoint.CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK`: |
| 1043 | + |
| 1044 | Panel will be shown below the change info block. |
| 1045 | |
| 1046 | ** The following parameters are provided: |
Edwin Kempin | 5d683cc | 2015-07-10 15:47:14 +0200 | [diff] [blame] | 1047 | *** `GerritUiExtensionPoint.Key.CHANGE_INFO`: |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1048 | + |
Edwin Kempin | 5d683cc | 2015-07-10 15:47:14 +0200 | [diff] [blame] | 1049 | The link:rest-api-changes.html#change-info[ChangeInfo] entity for the |
| 1050 | current change. |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1051 | |
Edwin Kempin | 88b947a | 2015-07-08 09:03:56 +0200 | [diff] [blame] | 1052 | * Project Info Screen: |
| 1053 | ** `GerritUiExtensionPoint.PROJECT_INFO_SCREEN_TOP`: |
| 1054 | + |
| 1055 | Panel will be shown at the top of the screen. |
| 1056 | |
| 1057 | ** `GerritUiExtensionPoint.PROJECT_INFO_SCREEN_BOTTOM`: |
| 1058 | + |
| 1059 | Panel will be shown at the bottom of the screen. |
| 1060 | |
| 1061 | ** The following parameters are provided: |
| 1062 | *** `GerritUiExtensionPoint.Key.PROJECT_NAME`: |
| 1063 | + |
| 1064 | The name of the project. |
| 1065 | |
Edwin Kempin | 241d9db | 2015-07-08 13:53:50 +0200 | [diff] [blame] | 1066 | * User Password Screen: |
| 1067 | ** `GerritUiExtensionPoint.PASSWORD_SCREEN_BOTTOM`: |
| 1068 | + |
| 1069 | Panel will be shown at the bottom of the screen. |
| 1070 | |
Edwin Kempin | 30c6f47 | 2015-07-09 14:27:52 +0200 | [diff] [blame] | 1071 | ** The following parameters are provided: |
| 1072 | *** `GerritUiExtensionPoint.Key.ACCOUNT_INFO`: |
| 1073 | + |
| 1074 | The link:rest-api-accounts.html#account-info[AccountInfo] entity for |
| 1075 | the current user. |
| 1076 | |
Edwin Kempin | 1cd95f9 | 2015-07-14 08:27:20 +0200 | [diff] [blame] | 1077 | * User Preferences Screen: |
| 1078 | ** `GerritUiExtensionPoint.PREFERENCES_SCREEN_BOTTOM`: |
| 1079 | + |
| 1080 | Panel will be shown at the bottom of the screen. |
| 1081 | |
| 1082 | ** The following parameters are provided: |
| 1083 | *** `GerritUiExtensionPoint.Key.ACCOUNT_INFO`: |
| 1084 | + |
| 1085 | The link:rest-api-accounts.html#account-info[AccountInfo] entity for |
| 1086 | the current user. |
| 1087 | |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1088 | * User Profile Screen: |
| 1089 | ** `GerritUiExtensionPoint.PROFILE_SCREEN_BOTTOM`: |
| 1090 | + |
| 1091 | Panel will be shown at the bottom of the screen below the grid with the |
| 1092 | profile data. |
| 1093 | |
Edwin Kempin | 30c6f47 | 2015-07-09 14:27:52 +0200 | [diff] [blame] | 1094 | ** The following parameters are provided: |
| 1095 | *** `GerritUiExtensionPoint.Key.ACCOUNT_INFO`: |
| 1096 | + |
| 1097 | The link:rest-api-accounts.html#account-info[AccountInfo] entity for |
| 1098 | the current user. |
| 1099 | |
Edwin Kempin | 52f79ac | 2015-07-07 16:37:50 +0200 | [diff] [blame] | 1100 | Example panel: |
| 1101 | [source,java] |
| 1102 | ---- |
| 1103 | public class MyPlugin extends PluginEntryPoint { |
| 1104 | @Override |
| 1105 | public void onPluginLoad() { |
| 1106 | Plugin.get().panel(GerritUiExtensionPoint.CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK, |
| 1107 | new Panel.EntryPoint() { |
| 1108 | @Override |
| 1109 | public void onLoad(Panel panel) { |
| 1110 | panel.setWidget(new InlineLabel("My Panel for change " |
| 1111 | + panel.getInt(GerritUiExtensionPoint.Key.CHANGE_ID, -1)); |
| 1112 | } |
| 1113 | }); |
| 1114 | } |
| 1115 | } |
| 1116 | ---- |
| 1117 | |
| 1118 | [[actions]] |
| 1119 | === Actions |
| 1120 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1121 | Plugins can contribute UI actions on core Gerrit pages. This is useful |
| 1122 | for workflow customization or exposing plugin functionality through the |
| 1123 | UI in addition to SSH commands and the REST API. |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1124 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1125 | For instance a plugin to integrate Jira with Gerrit changes may |
| 1126 | contribute a "File bug" button to allow filing a bug from the change |
| 1127 | page or plugins to integrate continuous integration systems may |
| 1128 | contribute a "Schedule" button to allow a CI build to be scheduled |
| 1129 | manually from the patch set panel. |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1130 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1131 | Two different places on core Gerrit pages are supported: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1132 | |
| 1133 | * Change screen |
| 1134 | * Project info screen |
| 1135 | |
| 1136 | Plugins contribute UI actions by implementing the `UiAction` interface: |
| 1137 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1138 | [source,java] |
| 1139 | ---- |
| 1140 | @RequiresCapability("printHello") |
| 1141 | class HelloWorldAction implements UiAction<RevisionResource>, |
| 1142 | RestModifyView<RevisionResource, HelloWorldAction.Input> { |
| 1143 | static class Input { |
| 1144 | boolean french; |
| 1145 | String message; |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1146 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1147 | |
| 1148 | private Provider<CurrentUser> user; |
| 1149 | |
| 1150 | @Inject |
| 1151 | HelloWorldAction(Provider<CurrentUser> user) { |
| 1152 | this.user = user; |
| 1153 | } |
| 1154 | |
| 1155 | @Override |
| 1156 | public String apply(RevisionResource rev, Input input) { |
| 1157 | final String greeting = input.french |
| 1158 | ? "Bonjour" |
| 1159 | : "Hello"; |
| 1160 | return String.format("%s %s from change %s, patch set %d!", |
| 1161 | greeting, |
| 1162 | Strings.isNullOrEmpty(input.message) |
| 1163 | ? Objects.firstNonNull(user.get().getUserName(), "world") |
| 1164 | : input.message, |
| 1165 | rev.getChange().getId().toString(), |
| 1166 | rev.getPatchSet().getPatchSetId()); |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
| 1170 | public Description getDescription( |
| 1171 | RevisionResource resource) { |
| 1172 | return new Description() |
| 1173 | .setLabel("Say hello") |
| 1174 | .setTitle("Say hello in different languages"); |
| 1175 | } |
| 1176 | } |
| 1177 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1178 | |
David Ostrovsky | 450eefe | 2013-10-21 21:18:11 +0200 | [diff] [blame] | 1179 | Sometimes plugins may want to be able to change the state of a patch set or |
| 1180 | change in the `UiAction.apply()` method and reflect these changes on the core |
| 1181 | UI. For example a buildbot plugin which exposes a 'Schedule' button on the |
| 1182 | patch set panel may want to disable that button after the build was scheduled |
| 1183 | and update the tooltip of that button. But because of Gerrit's caching |
| 1184 | strategy the following must be taken into consideration. |
| 1185 | |
| 1186 | The browser is allowed to cache the `UiAction` information until something on |
| 1187 | the change is modified. More accurately the change row needs to be modified in |
| 1188 | the database to have a more recent `lastUpdatedOn` or a new `rowVersion`, or |
| 1189 | the +refs/meta/config+ of the project or any parents needs to change to a new |
| 1190 | SHA-1. The ETag SHA-1 computation code can be found in the |
| 1191 | `ChangeResource.getETag()` method. |
| 1192 | |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1193 | 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] | 1194 | |
| 1195 | [source,java] |
| 1196 | ---- |
| 1197 | @Override |
| 1198 | public Object apply(RevisionResource rcrs, Input in) { |
| 1199 | // schedule a build |
| 1200 | [...] |
| 1201 | // update change |
| 1202 | ReviewDb db = dbProvider.get(); |
| 1203 | db.changes().beginTransaction(change.getId()); |
| 1204 | try { |
| 1205 | change = db.changes().atomicUpdate( |
| 1206 | change.getId(), |
| 1207 | new AtomicUpdate<Change>() { |
| 1208 | @Override |
| 1209 | public Change update(Change change) { |
| 1210 | ChangeUtil.updated(change); |
| 1211 | return change; |
| 1212 | } |
| 1213 | }); |
| 1214 | db.commit(); |
| 1215 | } finally { |
| 1216 | db.rollback(); |
| 1217 | } |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1218 | [...] |
David Ostrovsky | 450eefe | 2013-10-21 21:18:11 +0200 | [diff] [blame] | 1219 | } |
| 1220 | ---- |
| 1221 | |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1222 | `UiAction` must be bound in a plugin module: |
| 1223 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1224 | [source,java] |
| 1225 | ---- |
| 1226 | public class Module extends AbstractModule { |
| 1227 | @Override |
| 1228 | protected void configure() { |
| 1229 | install(new RestApiModule() { |
| 1230 | @Override |
| 1231 | protected void configure() { |
| 1232 | post(REVISION_KIND, "say-hello") |
| 1233 | .to(HelloWorldAction.class); |
| 1234 | } |
| 1235 | }); |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1236 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1237 | } |
| 1238 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1239 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1240 | The module above must be declared in the `pom.xml` for Maven driven |
| 1241 | plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1242 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1243 | [source,xml] |
| 1244 | ---- |
| 1245 | <manifestEntries> |
| 1246 | <Gerrit-Module>com.googlesource.gerrit.plugins.cookbook.Module</Gerrit-Module> |
| 1247 | </manifestEntries> |
| 1248 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1249 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1250 | or in the `BUCK` configuration file for Buck driven plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1251 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1252 | [source,python] |
| 1253 | ---- |
| 1254 | manifest_entries = [ |
| 1255 | 'Gerrit-Module: com.googlesource.gerrit.plugins.cookbook.Module', |
| 1256 | ] |
| 1257 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1258 | |
| 1259 | In some use cases more user input must be gathered, for that `UiAction` can be |
| 1260 | combined with the JavaScript API. This would display a small popup near the |
| 1261 | activation button to gather additional input from the user. The JS file is |
| 1262 | typically put in the `static` folder within the plugin's directory: |
| 1263 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1264 | [source,javascript] |
| 1265 | ---- |
| 1266 | Gerrit.install(function(self) { |
| 1267 | function onSayHello(c) { |
| 1268 | var f = c.textfield(); |
| 1269 | var t = c.checkbox(); |
| 1270 | var b = c.button('Say hello', {onclick: function(){ |
| 1271 | c.call( |
| 1272 | {message: f.value, french: t.checked}, |
| 1273 | function(r) { |
| 1274 | c.hide(); |
| 1275 | window.alert(r); |
| 1276 | c.refresh(); |
| 1277 | }); |
| 1278 | }}); |
| 1279 | c.popup(c.div( |
| 1280 | c.prependLabel('Greeting message', f), |
| 1281 | c.br(), |
| 1282 | c.label(t, 'french'), |
| 1283 | c.br(), |
| 1284 | b)); |
| 1285 | f.focus(); |
| 1286 | } |
| 1287 | self.onAction('revision', 'say-hello', onSayHello); |
| 1288 | }); |
| 1289 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1290 | |
| 1291 | The JS module must be exposed as a `WebUiPlugin` and bound as |
| 1292 | an HTTP Module: |
| 1293 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1294 | [source,java] |
| 1295 | ---- |
| 1296 | public class HttpModule extends HttpPluginModule { |
| 1297 | @Override |
| 1298 | protected void configureServlets() { |
| 1299 | DynamicSet.bind(binder(), WebUiPlugin.class) |
| 1300 | .toInstance(new JavaScriptPlugin("hello.js")); |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1301 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1302 | } |
| 1303 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1304 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1305 | The HTTP module above must be declared in the `pom.xml` for Maven |
| 1306 | driven plugins: |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1307 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1308 | [source,xml] |
| 1309 | ---- |
| 1310 | <manifestEntries> |
| 1311 | <Gerrit-HttpModule>com.googlesource.gerrit.plugins.cookbook.HttpModule</Gerrit-HttpModule> |
| 1312 | </manifestEntries> |
| 1313 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1314 | |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1315 | or in the `BUCK` configuration file for Buck driven plugins |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1316 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1317 | [source,python] |
| 1318 | ---- |
| 1319 | manifest_entries = [ |
| 1320 | 'Gerrit-HttpModule: com.googlesource.gerrit.plugins.cookbook.HttpModule', |
| 1321 | ] |
| 1322 | ---- |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 1323 | |
| 1324 | If `UiAction` is annotated with the `@RequiresCapability` annotation, then the |
| 1325 | capability check is done during the `UiAction` gathering, so the plugin author |
| 1326 | doesn't have to set `UiAction.Description.setVisible()` explicitly in this |
| 1327 | case. |
| 1328 | |
| 1329 | The following prerequisities must be met, to satisfy the capability check: |
| 1330 | |
| 1331 | * user is authenticated |
Edwin Kempin | 7afa73c | 2013-11-08 07:48:47 +0100 | [diff] [blame] | 1332 | * 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] | 1333 | * user is a member of a group which has the required capability |
| 1334 | |
| 1335 | The `apply` method is called when the button is clicked. If `UiAction` is |
| 1336 | combined with JavaScript API (its own JavaScript function is provided), |
| 1337 | then a popup dialog is normally opened to gather additional user input. |
| 1338 | A new button is placed on the popup dialog to actually send the request. |
| 1339 | |
| 1340 | Every `UiAction` exposes a REST API endpoint. The endpoint from the example above |
| 1341 | can be accessed from any REST client, i. e.: |
| 1342 | |
| 1343 | ==== |
| 1344 | curl -X POST -H "Content-Type: application/json" \ |
| 1345 | -d '{message: "François", french: true}' \ |
| 1346 | --digest --user joe:secret \ |
| 1347 | http://host:port/a/changes/1/revisions/1/cookbook~say-hello |
| 1348 | "Bonjour François from change 1, patch set 1!" |
| 1349 | ==== |
| 1350 | |
David Pursehouse | 4224582 | 2013-09-24 09:48:20 +0900 | [diff] [blame] | 1351 | 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] | 1352 | particularly useful for `DELETE` requests: |
David Ostrovsky | c6d19ed | 2013-09-20 21:30:18 +0200 | [diff] [blame] | 1353 | |
| 1354 | [source,java] |
| 1355 | ---- |
| 1356 | public class Module extends AbstractModule { |
| 1357 | @Override |
| 1358 | protected void configure() { |
| 1359 | install(new RestApiModule() { |
| 1360 | @Override |
| 1361 | protected void configure() { |
| 1362 | delete(PROJECT_KIND) |
| 1363 | .to(DeleteProject.class); |
| 1364 | } |
| 1365 | }); |
| 1366 | } |
| 1367 | } |
| 1368 | ---- |
| 1369 | |
David Pursehouse | 4224582 | 2013-09-24 09:48:20 +0900 | [diff] [blame] | 1370 | For a `UiAction` bound this way, a JS API function can be provided. |
| 1371 | |
| 1372 | Currently only one restriction exists: per plugin only one `UiAction` |
David Ostrovsky | c6d19ed | 2013-09-20 21:30:18 +0200 | [diff] [blame] | 1373 | can be bound per resource without view name. To define a JS function |
| 1374 | for the `UiAction`, "/" must be used as the name: |
| 1375 | |
| 1376 | [source,javascript] |
| 1377 | ---- |
| 1378 | Gerrit.install(function(self) { |
| 1379 | function onDeleteProject(c) { |
| 1380 | [...] |
| 1381 | } |
| 1382 | self.onAction('project', '/', onDeleteProject); |
| 1383 | }); |
| 1384 | ---- |
| 1385 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1386 | [[top-menu-extensions]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1387 | == Top Menu Extensions |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1388 | |
| 1389 | Plugins can contribute items to Gerrit's top menu. |
| 1390 | |
| 1391 | A single top menu extension can have multiple elements and will be put as |
| 1392 | the last element in Gerrit's top menu. |
| 1393 | |
| 1394 | Plugins define the top menu entries by implementing `TopMenu` interface: |
| 1395 | |
| 1396 | [source,java] |
| 1397 | ---- |
| 1398 | public class MyTopMenuExtension implements TopMenu { |
| 1399 | |
| 1400 | @Override |
| 1401 | public List<MenuEntry> getEntries() { |
| 1402 | return Lists.newArrayList( |
| 1403 | new MenuEntry("Top Menu Entry", Lists.newArrayList( |
| 1404 | new MenuItem("Gerrit", "http://gerrit.googlecode.com/")))); |
| 1405 | } |
| 1406 | } |
| 1407 | ---- |
| 1408 | |
Edwin Kempin | 77f2324 | 2013-09-30 14:53:20 +0200 | [diff] [blame] | 1409 | Plugins can also add additional menu items to Gerrit's top menu entries |
| 1410 | by defining a `MenuEntry` that has the same name as a Gerrit top menu |
| 1411 | entry: |
| 1412 | |
| 1413 | [source,java] |
| 1414 | ---- |
| 1415 | public class MyTopMenuExtension implements TopMenu { |
| 1416 | |
| 1417 | @Override |
| 1418 | public List<MenuEntry> getEntries() { |
| 1419 | return Lists.newArrayList( |
Dariusz Luksza | 2d3afab | 2013-10-01 11:07:13 +0200 | [diff] [blame] | 1420 | new MenuEntry(GerritTopMenu.PROJECTS, Lists.newArrayList( |
Edwin Kempin | 77f2324 | 2013-09-30 14:53:20 +0200 | [diff] [blame] | 1421 | new MenuItem("Browse Repositories", "https://gerrit.googlesource.com/")))); |
| 1422 | } |
| 1423 | } |
| 1424 | ---- |
| 1425 | |
Dariusz Luksza | e8de74f | 2014-06-04 19:39:20 +0200 | [diff] [blame] | 1426 | `MenuItems` that are bound for the `MenuEntry` with the name |
| 1427 | `GerritTopMenu.PROJECTS` can contain a `${projectName}` placeholder |
| 1428 | which is automatically replaced by the actual project name. |
| 1429 | |
| 1430 | E.g. plugins may register an link:#http[HTTP Servlet] to handle project |
| 1431 | specific requests and add an menu item for this: |
| 1432 | |
| 1433 | [source,java] |
| 1434 | --- |
| 1435 | new MenuItem("My Screen", "/plugins/myplugin/project/${projectName}"); |
| 1436 | --- |
| 1437 | |
| 1438 | This also enables plugins to provide menu items for project aware |
| 1439 | screens: |
| 1440 | |
| 1441 | [source,java] |
| 1442 | --- |
| 1443 | new MenuItem("My Screen", "/x/my-screen/for/${projectName}"); |
| 1444 | --- |
| 1445 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1446 | If no Guice modules are declared in the manifest, the top menu extension may use |
| 1447 | auto-registration by providing an `@Listen` annotation: |
| 1448 | |
| 1449 | [source,java] |
| 1450 | ---- |
| 1451 | @Listen |
| 1452 | public class MyTopMenuExtension implements TopMenu { |
David Pursehouse | d128c89 | 2013-10-22 21:52:21 +0900 | [diff] [blame] | 1453 | [...] |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1454 | } |
| 1455 | ---- |
| 1456 | |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1457 | Otherwise the top menu extension must be bound in the plugin module used |
| 1458 | for the Gerrit system injector (Gerrit-Module entry in MANIFEST.MF): |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1459 | |
| 1460 | [source,java] |
| 1461 | ---- |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1462 | package com.googlesource.gerrit.plugins.helloworld; |
| 1463 | |
Dariusz Luksza | 589ba00aa | 2013-05-07 17:21:23 +0200 | [diff] [blame] | 1464 | public class HelloWorldModule extends AbstractModule { |
| 1465 | @Override |
| 1466 | protected void configure() { |
| 1467 | DynamicSet.bind(binder(), TopMenu.class).to(MyTopMenuExtension.class); |
| 1468 | } |
| 1469 | } |
| 1470 | ---- |
| 1471 | |
Luca Milanesio | cb23040 | 2013-10-11 08:49:56 +0100 | [diff] [blame] | 1472 | [source,manifest] |
| 1473 | ---- |
| 1474 | Gerrit-ApiType: plugin |
| 1475 | Gerrit-Module: com.googlesource.gerrit.plugins.helloworld.HelloWorldModule |
| 1476 | ---- |
| 1477 | |
Edwin Kempin | b2e926a | 2013-11-11 16:38:30 +0100 | [diff] [blame] | 1478 | It is also possible to show some menu entries only if the user has a |
| 1479 | certain capability: |
| 1480 | |
| 1481 | [source,java] |
| 1482 | ---- |
| 1483 | public class MyTopMenuExtension implements TopMenu { |
| 1484 | private final String pluginName; |
| 1485 | private final Provider<CurrentUser> userProvider; |
| 1486 | private final List<MenuEntry> menuEntries; |
| 1487 | |
| 1488 | @Inject |
| 1489 | public MyTopMenuExtension(@PluginName String pluginName, |
| 1490 | Provider<CurrentUser> userProvider) { |
| 1491 | this.pluginName = pluginName; |
| 1492 | this.userProvider = userProvider; |
| 1493 | menuEntries = new ArrayList<TopMenu.MenuEntry>(); |
| 1494 | |
| 1495 | // add menu entry that is only visible to users with a certain capability |
| 1496 | if (canSeeMenuEntry()) { |
| 1497 | menuEntries.add(new MenuEntry("Top Menu Entry", Collections |
| 1498 | .singletonList(new MenuItem("Gerrit", "http://gerrit.googlecode.com/")))); |
| 1499 | } |
| 1500 | |
| 1501 | // add menu entry that is visible to all users (even anonymous users) |
| 1502 | menuEntries.add(new MenuEntry("Top Menu Entry", Collections |
| 1503 | .singletonList(new MenuItem("Documentation", "/plugins/myplugin/")))); |
| 1504 | } |
| 1505 | |
| 1506 | private boolean canSeeMenuEntry() { |
| 1507 | if (userProvider.get().isIdentifiedUser()) { |
| 1508 | CapabilityControl ctl = userProvider.get().getCapabilities(); |
| 1509 | return ctl.canPerform(pluginName + "-" + MyCapability.ID) |
| 1510 | || ctl.canAdministrateServer(); |
| 1511 | } else { |
| 1512 | return false; |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | @Override |
| 1517 | public List<MenuEntry> getEntries() { |
| 1518 | return menuEntries; |
| 1519 | } |
| 1520 | } |
| 1521 | ---- |
| 1522 | |
Edwin Kempin | 3c024ea | 2013-11-11 10:43:46 +0100 | [diff] [blame] | 1523 | [[gwt_ui_extension]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1524 | == GWT UI Extension |
Edwin Kempin | 3c024ea | 2013-11-11 10:43:46 +0100 | [diff] [blame] | 1525 | Plugins can extend the Gerrit UI with own GWT code. |
| 1526 | |
| 1527 | The Maven archetype 'gerrit-plugin-gwt-archetype' can be used to |
| 1528 | generate a GWT plugin skeleton. How to use the Maven plugin archetypes |
| 1529 | is described in the link:#getting-started[Getting started] section. |
| 1530 | |
| 1531 | The generated GWT plugin has a link:#top-menu-extensions[top menu] that |
| 1532 | opens a GWT dialog box when the user clicks on it. |
| 1533 | |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1534 | In addition to the Gerrit-Plugin API a GWT plugin depends on |
| 1535 | `gerrit-plugin-gwtui`. This dependency must be specified in the |
| 1536 | `pom.xml`: |
| 1537 | |
| 1538 | [source,xml] |
| 1539 | ---- |
| 1540 | <dependency> |
| 1541 | <groupId>com.google.gerrit</groupId> |
| 1542 | <artifactId>gerrit-plugin-gwtui</artifactId> |
| 1543 | <version>${Gerrit-ApiVersion}</version> |
| 1544 | </dependency> |
| 1545 | ---- |
| 1546 | |
| 1547 | A GWT plugin must contain a GWT module file, e.g. `HelloPlugin.gwt.xml`, |
| 1548 | that bundles together all the configuration settings of the GWT plugin: |
| 1549 | |
| 1550 | [source,xml] |
| 1551 | ---- |
| 1552 | <?xml version="1.0" encoding="UTF-8"?> |
| 1553 | <module rename-to="hello_gwt_plugin"> |
| 1554 | <!-- Inherit the core Web Toolkit stuff. --> |
| 1555 | <inherits name="com.google.gwt.user.User"/> |
| 1556 | <!-- Other module inherits --> |
| 1557 | <inherits name="com.google.gerrit.Plugin"/> |
| 1558 | <inherits name="com.google.gwt.http.HTTP"/> |
| 1559 | <!-- Using GWT built-in themes adds a number of static --> |
| 1560 | <!-- resources to the plugin. No theme inherits lines were --> |
| 1561 | <!-- added in order to make this plugin as simple as possible --> |
| 1562 | <!-- Specify the app entry point class. --> |
| 1563 | <entry-point class="${package}.client.HelloPlugin"/> |
| 1564 | <stylesheet src="hello.css"/> |
| 1565 | </module> |
| 1566 | ---- |
| 1567 | |
| 1568 | The GWT module must inherit `com.google.gerrit.Plugin` and |
| 1569 | `com.google.gwt.http.HTTP`. |
| 1570 | |
| 1571 | To register the GWT module a `GwtPlugin` needs to be bound. |
| 1572 | |
| 1573 | If no Guice modules are declared in the manifest, the GWT plugin may |
| 1574 | use auto-registration by using the `@Listen` annotation: |
| 1575 | |
| 1576 | [source,java] |
| 1577 | ---- |
| 1578 | @Listen |
| 1579 | public class MyExtension extends GwtPlugin { |
| 1580 | public MyExtension() { |
| 1581 | super("hello_gwt_plugin"); |
| 1582 | } |
| 1583 | } |
| 1584 | ---- |
| 1585 | |
| 1586 | Otherwise the binding must be done in an `HttpModule`: |
| 1587 | |
| 1588 | [source,java] |
| 1589 | ---- |
| 1590 | public class HttpModule extends HttpPluginModule { |
| 1591 | |
| 1592 | @Override |
| 1593 | protected void configureServlets() { |
| 1594 | DynamicSet.bind(binder(), WebUiPlugin.class) |
| 1595 | .toInstance(new GwtPlugin("hello_gwt_plugin")); |
| 1596 | } |
| 1597 | } |
| 1598 | ---- |
| 1599 | |
| 1600 | The HTTP module above must be declared in the `pom.xml` for Maven |
| 1601 | driven plugins: |
| 1602 | |
| 1603 | [source,xml] |
| 1604 | ---- |
| 1605 | <manifestEntries> |
| 1606 | <Gerrit-HttpModule>com.googlesource.gerrit.plugins.myplugin.HttpModule</Gerrit-HttpModule> |
| 1607 | </manifestEntries> |
| 1608 | ---- |
| 1609 | |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1610 | The name that is provided to the `GwtPlugin` must match the GWT |
| 1611 | module name compiled into the plugin. The name of the GWT module |
| 1612 | can be explicitly set in the GWT module XML file by specifying |
| 1613 | the `rename-to` attribute on the module. It is important that the |
| 1614 | module name be unique across all plugins installed on the server, |
| 1615 | as the module name determines the JavaScript namespace used by the |
| 1616 | compiled plugin code. |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1617 | |
| 1618 | [source,xml] |
| 1619 | ---- |
| 1620 | <module rename-to="hello_gwt_plugin"> |
| 1621 | ---- |
| 1622 | |
| 1623 | The actual GWT code must be implemented in a class that extends |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1624 | `com.google.gerrit.plugin.client.PluginEntryPoint`: |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1625 | |
| 1626 | [source,java] |
| 1627 | ---- |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1628 | public class HelloPlugin extends PluginEntryPoint { |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1629 | |
| 1630 | @Override |
Shawn Pearce | c8e96ad | 2013-12-09 08:20:44 -0800 | [diff] [blame] | 1631 | public void onPluginLoad() { |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1632 | // Create the dialog box |
| 1633 | final DialogBox dialogBox = new DialogBox(); |
| 1634 | |
| 1635 | // The content of the dialog comes from a User specified Preference |
| 1636 | dialogBox.setText("Hello from GWT Gerrit UI plugin"); |
| 1637 | dialogBox.setAnimationEnabled(true); |
| 1638 | Button closeButton = new Button("Close"); |
| 1639 | VerticalPanel dialogVPanel = new VerticalPanel(); |
| 1640 | dialogVPanel.setWidth("100%"); |
| 1641 | dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER); |
| 1642 | dialogVPanel.add(closeButton); |
| 1643 | |
| 1644 | closeButton.addClickHandler(new ClickHandler() { |
| 1645 | public void onClick(ClickEvent event) { |
| 1646 | dialogBox.hide(); |
| 1647 | } |
| 1648 | }); |
| 1649 | |
| 1650 | // Set the contents of the Widget |
| 1651 | dialogBox.setWidget(dialogVPanel); |
| 1652 | |
| 1653 | RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); |
| 1654 | rootPanel.getElement().removeAttribute("href"); |
| 1655 | rootPanel.addDomHandler(new ClickHandler() { |
| 1656 | @Override |
| 1657 | public void onClick(ClickEvent event) { |
| 1658 | dialogBox.center(); |
| 1659 | dialogBox.show(); |
| 1660 | } |
| 1661 | }, ClickEvent.getType()); |
| 1662 | } |
| 1663 | } |
| 1664 | ---- |
| 1665 | |
| 1666 | This class must be set as entry point in the GWT module: |
| 1667 | |
| 1668 | [source,xml] |
| 1669 | ---- |
| 1670 | <entry-point class="${package}.client.HelloPlugin"/> |
| 1671 | ---- |
| 1672 | |
| 1673 | In addition this class must be defined as module in the `pom.xml` for the |
| 1674 | `gwt-maven-plugin` and the `webappDirectory` option of `gwt-maven-plugin` |
| 1675 | must be set to `${project.build.directory}/classes/static`: |
| 1676 | |
| 1677 | [source,xml] |
| 1678 | ---- |
| 1679 | <plugin> |
| 1680 | <groupId>org.codehaus.mojo</groupId> |
| 1681 | <artifactId>gwt-maven-plugin</artifactId> |
David Pursehouse | 7ab8173 | 2015-05-07 12:00:47 +0900 | [diff] [blame] | 1682 | <version>2.7.0</version> |
Edwin Kempin | b74daa9 | 2013-11-11 11:28:16 +0100 | [diff] [blame] | 1683 | <configuration> |
| 1684 | <module>com.googlesource.gerrit.plugins.myplugin.HelloPlugin</module> |
| 1685 | <disableClassMetadata>true</disableClassMetadata> |
| 1686 | <disableCastChecking>true</disableCastChecking> |
| 1687 | <webappDirectory>${project.build.directory}/classes/static</webappDirectory> |
| 1688 | </configuration> |
| 1689 | <executions> |
| 1690 | <execution> |
| 1691 | <goals> |
| 1692 | <goal>compile</goal> |
| 1693 | </goals> |
| 1694 | </execution> |
| 1695 | </executions> |
| 1696 | </plugin> |
| 1697 | ---- |
| 1698 | |
| 1699 | To attach a GWT widget defined by the plugin to the Gerrit core UI |
| 1700 | `com.google.gwt.user.client.ui.RootPanel` can be used to manipulate the |
| 1701 | Gerrit core widgets: |
| 1702 | |
| 1703 | [source,java] |
| 1704 | ---- |
| 1705 | RootPanel rootPanel = RootPanel.get(HelloMenu.MENU_ID); |
| 1706 | rootPanel.getElement().removeAttribute("href"); |
| 1707 | rootPanel.addDomHandler(new ClickHandler() { |
| 1708 | @Override |
| 1709 | public void onClick(ClickEvent event) { |
| 1710 | dialogBox.center(); |
| 1711 | dialogBox.show(); |
| 1712 | } |
| 1713 | }, ClickEvent.getType()); |
| 1714 | ---- |
| 1715 | |
| 1716 | GWT plugins can come with their own css file. This css file must have a |
| 1717 | unique name and must be registered in the GWT module: |
| 1718 | |
| 1719 | [source,xml] |
| 1720 | ---- |
| 1721 | <stylesheet src="hello.css"/> |
| 1722 | ---- |
| 1723 | |
Edwin Kempin | 2570b10 | 2013-11-11 11:44:50 +0100 | [diff] [blame] | 1724 | 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] | 1725 | `com.google.gerrit.plugin.client.rpc.RestApi` to construct the URL |
Edwin Kempin | 2570b10 | 2013-11-11 11:44:50 +0100 | [diff] [blame] | 1726 | path and to trigger the REST calls. |
| 1727 | |
| 1728 | Example for invoking a Gerrit core REST endpoint: |
| 1729 | |
| 1730 | [source,java] |
| 1731 | ---- |
| 1732 | new RestApi("projects").id(projectName).view("description") |
| 1733 | .put("new description", new AsyncCallback<JavaScriptObject>() { |
| 1734 | |
| 1735 | @Override |
| 1736 | public void onSuccess(JavaScriptObject result) { |
| 1737 | // TODO |
| 1738 | } |
| 1739 | |
| 1740 | @Override |
| 1741 | public void onFailure(Throwable caught) { |
| 1742 | // never invoked |
| 1743 | } |
| 1744 | }); |
| 1745 | ---- |
| 1746 | |
| 1747 | Example for invoking a REST endpoint defined by a plugin: |
| 1748 | |
| 1749 | [source,java] |
| 1750 | ---- |
| 1751 | new RestApi("projects").id(projectName).view("myplugin", "myview") |
| 1752 | .get(new AsyncCallback<JavaScriptObject>() { |
| 1753 | |
| 1754 | @Override |
| 1755 | public void onSuccess(JavaScriptObject result) { |
| 1756 | // TODO |
| 1757 | } |
| 1758 | |
| 1759 | @Override |
| 1760 | public void onFailure(Throwable caught) { |
| 1761 | // never invoked |
| 1762 | } |
| 1763 | }); |
| 1764 | ---- |
| 1765 | |
| 1766 | The `onFailure(Throwable)` of the provided callback is never invoked. |
| 1767 | If an error occurs, it is shown in an error dialog. |
| 1768 | |
| 1769 | In order to be able to do REST calls the GWT module must inherit |
| 1770 | `com.google.gwt.json.JSON`: |
| 1771 | |
| 1772 | [source,xml] |
| 1773 | ---- |
| 1774 | <inherits name="com.google.gwt.json.JSON"/> |
| 1775 | ---- |
| 1776 | |
Edwin Kempin | 1519979 | 2014-04-23 16:22:05 +0200 | [diff] [blame] | 1777 | [[screen]] |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 1778 | == Add Screen |
Edwin Kempin | 1519979 | 2014-04-23 16:22:05 +0200 | [diff] [blame] | 1779 | A link:#gwt_ui_extension[GWT plugin] can link:#top-menu-extensions[add |
| 1780 | a menu item] that opens a screen that is implemented by the plugin. |
| 1781 | This way plugin screens can be fully integrated into the Gerrit UI. |
Shawn Pearce | d5c844f | 2013-12-26 15:32:26 -0800 | [diff] [blame] | 1782 | |
| 1783 | Example menu item: |
| 1784 | [source,java] |
| 1785 | ---- |
| 1786 | public class MyMenu implements TopMenu { |
| 1787 | private final List<MenuEntry> menuEntries; |
| 1788 | |
| 1789 | @Inject |
| 1790 | public MyMenu(@PluginName String name) { |
| 1791 | menuEntries = Lists.newArrayList(); |
| 1792 | menuEntries.add(new MenuEntry("My Menu", Collections.singletonList( |
| 1793 | new MenuItem("My Screen", "#/x/" + name + "/my-screen", "")))); |
| 1794 | } |
| 1795 | |
| 1796 | @Override |
| 1797 | public List<MenuEntry> getEntries() { |
| 1798 | return menuEntries; |
| 1799 | } |
| 1800 | } |
| 1801 | ---- |
| 1802 | |
| 1803 | Example screen: |
| 1804 | [source,java] |
| 1805 | ---- |
| 1806 | public class MyPlugin extends PluginEntryPoint { |
| 1807 | @Override |
| 1808 | public void onPluginLoad() { |
| 1809 | Plugin.get().screen("my-screen", new Screen.EntryPoint() { |
| 1810 | @Override |
| 1811 | public void onLoad(Screen screen) { |
| 1812 | screen.add(new InlineLabel("My Screen"); |
| 1813 | screen.show(); |
| 1814 | } |
| 1815 | }); |
| 1816 | } |
| 1817 | } |
| 1818 | ---- |
| 1819 | |
Edwin Kempin | 70e1112 | 2015-07-08 13:28:40 +0200 | [diff] [blame] | 1820 | [[user-settings-screen]] |
| 1821 | == Add User Settings Screen |
| 1822 | |
| 1823 | A link:#gwt_ui_extension[GWT plugin] can implement a user settings |
| 1824 | screen that is integrated into the Gerrit user settings menu. |
| 1825 | |
| 1826 | Example settings screen: |
| 1827 | [source,java] |
| 1828 | ---- |
| 1829 | public class MyPlugin extends PluginEntryPoint { |
| 1830 | @Override |
| 1831 | public void onPluginLoad() { |
| 1832 | Plugin.get().settingsScreen("my-preferences", "My Preferences", |
| 1833 | new Screen.EntryPoint() { |
| 1834 | @Override |
| 1835 | public void onLoad(Screen screen) { |
| 1836 | screen.setPageTitle("Settings"); |
| 1837 | screen.add(new InlineLabel("My Preferences")); |
| 1838 | screen.show(); |
| 1839 | } |
| 1840 | }); |
| 1841 | } |
| 1842 | } |
| 1843 | ---- |
| 1844 | |
Edwin Kempin | fa0d494 | 2015-07-16 12:38:52 +0200 | [diff] [blame] | 1845 | By defining an link:config-gerrit.html#urlAlias[urlAlias] Gerrit |
| 1846 | administrators can map plugin screens into the Gerrit URL namespace or |
| 1847 | even replace Gerrit screens by plugin screens. |
| 1848 | |
Edwin Kempin | b1e6a3a | 2015-07-22 15:36:56 +0200 | [diff] [blame] | 1849 | Plugins may also programatically add URL aliases in the preferences of |
| 1850 | of a user. This way certain screens can be replaced for certain users. |
| 1851 | E.g. the plugin may offer a user preferences setting for choosing a |
| 1852 | screen that then sets/unsets a URL alias for the user. |
| 1853 | |
Edwin Kempin | 289f1a0 | 2014-02-04 16:08:25 +0100 | [diff] [blame] | 1854 | [[settings-screen]] |
| 1855 | == Plugin Settings Screen |
| 1856 | |
| 1857 | If a plugin implements a screen for administrating its settings that is |
| 1858 | available under "#/x/<plugin-name>/settings" it is automatically linked |
| 1859 | from the plugin list screen. |
| 1860 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1861 | [[http]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1862 | == HTTP Servlets |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1863 | |
| 1864 | Plugins or extensions may register additional HTTP servlets, and |
| 1865 | wrap them with HTTP filters. |
| 1866 | |
| 1867 | Servlets may use auto-registration to declare the URL they handle: |
| 1868 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1869 | [source,java] |
| 1870 | ---- |
| 1871 | import com.google.gerrit.extensions.annotations.Export; |
| 1872 | import com.google.inject.Singleton; |
| 1873 | import javax.servlet.http.HttpServlet; |
| 1874 | import javax.servlet.http.HttpServletRequest; |
| 1875 | import javax.servlet.http.HttpServletResponse; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1876 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1877 | @Export("/print") |
| 1878 | @Singleton |
| 1879 | class HelloServlet extends HttpServlet { |
| 1880 | protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { |
| 1881 | res.setContentType("text/plain"); |
| 1882 | res.setCharacterEncoding("UTF-8"); |
| 1883 | res.getWriter().write("Hello"); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1884 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1885 | } |
| 1886 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1887 | |
Edwin Kempin | 8aa650f | 2012-07-18 11:25:48 +0200 | [diff] [blame] | 1888 | The auto registration only works for standard servlet mappings like |
Jonathan Nieder | 5758f18 | 2015-03-30 11:28:55 -0700 | [diff] [blame] | 1889 | `/foo` or `+/foo/*+`. Regex style bindings must use a Guice ServletModule |
Edwin Kempin | 8aa650f | 2012-07-18 11:25:48 +0200 | [diff] [blame] | 1890 | to register the HTTP servlets and declare it explicitly in the manifest |
| 1891 | with the `Gerrit-HttpModule` attribute: |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1892 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1893 | [source,java] |
| 1894 | ---- |
| 1895 | import com.google.inject.servlet.ServletModule; |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1896 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1897 | class MyWebUrls extends ServletModule { |
| 1898 | protected void configureServlets() { |
| 1899 | serve("/print").with(HelloServlet.class); |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1900 | } |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1901 | } |
| 1902 | ---- |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 1903 | |
| 1904 | For a plugin installed as name `helloworld`, the servlet implemented |
| 1905 | by HelloServlet class will be available to users as: |
| 1906 | |
| 1907 | ---- |
| 1908 | $ curl http://review.example.com/plugins/helloworld/print |
| 1909 | ---- |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 1910 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 1911 | [[data-directory]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1912 | == Data Directory |
Edwin Kempin | 41f6391 | 2012-07-17 12:33:55 +0200 | [diff] [blame] | 1913 | |
Dave Borowitz | 9e15875 | 2015-02-24 10:17:04 -0800 | [diff] [blame] | 1914 | Plugins can request a data directory with a `@PluginData` Path (or File, |
| 1915 | deprecated) dependency. A data directory will be created automatically |
| 1916 | by the server in `$site_path/data/$plugin_name` and passed to the |
| 1917 | plugin. |
Edwin Kempin | 41f6391 | 2012-07-17 12:33:55 +0200 | [diff] [blame] | 1918 | |
| 1919 | Plugins can use this to store any data they want. |
| 1920 | |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1921 | [source,java] |
| 1922 | ---- |
| 1923 | @Inject |
Dave Borowitz | 9e15875 | 2015-02-24 10:17:04 -0800 | [diff] [blame] | 1924 | MyType(@PluginData java.nio.file.Path myDir) { |
| 1925 | this.in = Files.newInputStream(myDir.resolve("my.config")); |
David Pursehouse | 68153d7 | 2013-09-04 10:09:17 +0900 | [diff] [blame] | 1926 | } |
| 1927 | ---- |
Edwin Kempin | 41f6391 | 2012-07-17 12:33:55 +0200 | [diff] [blame] | 1928 | |
Dariusz Luksza | ebab92a | 2014-09-10 11:14:19 +0200 | [diff] [blame] | 1929 | [[secure-store]] |
| 1930 | == SecureStore |
| 1931 | |
| 1932 | SecureStore allows to change the way Gerrit stores sensitive data like |
| 1933 | passwords. |
| 1934 | |
| 1935 | In order to replace the default SecureStore (no-op) implementation, |
| 1936 | a class that extends `com.google.gerrit.server.securestore.SecureStore` |
| 1937 | needs to be provided (with dependencies) in a separate jar file. Then |
| 1938 | link:pgm-SwitchSecureStore.html[SwitchSecureStore] must be run to |
| 1939 | switch implementations. |
| 1940 | |
| 1941 | The SecureStore implementation is instantiated using a Guice injector |
| 1942 | which binds the `File` annotated with the `@SitePath` annotation. |
| 1943 | This means that a SecureStore implementation class can get access to |
| 1944 | the `site_path` like in the following example: |
| 1945 | |
| 1946 | [source,java] |
| 1947 | ---- |
| 1948 | @Inject |
| 1949 | MySecureStore(@SitePath java.io.File sitePath) { |
| 1950 | // your code |
| 1951 | } |
| 1952 | ---- |
| 1953 | |
| 1954 | No Guice bindings or modules are required. Gerrit will automatically |
| 1955 | discover and bind the implementation. |
| 1956 | |
Michael Ochmann | 2461265 | 2016-02-12 17:26:18 +0100 | [diff] [blame^] | 1957 | [[accountcreation]] |
| 1958 | == Account Creation |
| 1959 | |
| 1960 | Plugins can hook into the |
| 1961 | link:rest-api-accounts.html#create-account[account creation] REST API and |
| 1962 | inject additional external identifiers for an account that represents a user |
| 1963 | in some external user store. For that, an implementation of the extension |
| 1964 | point `com.google.gerrit.server.api.accounts.AccountExternalIdCreator` |
| 1965 | must be registered. |
| 1966 | |
| 1967 | [source,java] |
| 1968 | ---- |
| 1969 | class MyExternalIdCreator implements AccountExternalIdCreator { |
| 1970 | @Override |
| 1971 | public List<AccountExternalId> create(Account.Id id, String username, |
| 1972 | String email) { |
| 1973 | // your code |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | bind(AccountExternalIdCreator.class) |
| 1978 | .annotatedWith(UniqueAnnotations.create()) |
| 1979 | .to(MyExternalIdCreator.class); |
| 1980 | } |
| 1981 | ---- |
| 1982 | |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1983 | [[download-commands]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1984 | == Download Commands |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1985 | |
Edwin Kempin | eafde88 | 2015-05-11 15:40:44 +0200 | [diff] [blame] | 1986 | Gerrit offers commands for downloading changes and cloning projects |
| 1987 | using different download schemes (e.g. for downloading via different |
| 1988 | network protocols). Plugins can contribute download schemes, download |
| 1989 | commands and clone commands by implementing |
| 1990 | `com.google.gerrit.extensions.config.DownloadScheme`, |
| 1991 | `com.google.gerrit.extensions.config.DownloadCommand` and |
| 1992 | `com.google.gerrit.extensions.config.CloneCommand`. |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1993 | |
Edwin Kempin | eafde88 | 2015-05-11 15:40:44 +0200 | [diff] [blame] | 1994 | The download schemes, download commands and clone commands which are |
| 1995 | used most often are provided by the Gerrit core plugin |
| 1996 | `download-commands`. |
Edwin Kempin | ea62148 | 2013-10-16 12:58:24 +0200 | [diff] [blame] | 1997 | |
Edwin Kempin | 78279ba | 2015-05-22 15:22:41 +0200 | [diff] [blame] | 1998 | [[included-in]] |
| 1999 | == Included In |
| 2000 | |
| 2001 | For merged changes the link:user-review-ui.html#included-in[Included In] |
| 2002 | drop-down panel shows the branches and tags in which the change is |
| 2003 | included. |
| 2004 | |
| 2005 | Plugins can add additional systems in which the change can be included |
| 2006 | by implementing `com.google.gerrit.extensions.config.ExternalIncludedIn`, |
| 2007 | e.g. a plugin can provide a list of servers on which the change was |
| 2008 | deployed. |
| 2009 | |
Sven Selberg | ae1a10c | 2014-02-14 14:24:29 +0100 | [diff] [blame] | 2010 | [[links-to-external-tools]] |
| 2011 | == Links To External Tools |
| 2012 | |
| 2013 | Gerrit has extension points that enables development of a |
| 2014 | light-weight plugin that links commits to external |
| 2015 | tools (GitBlit, CGit, company specific resources etc). |
| 2016 | |
| 2017 | PatchSetWebLinks will appear to the right of the commit-SHA1 in the UI. |
| 2018 | |
| 2019 | [source, java] |
| 2020 | ---- |
| 2021 | import com.google.gerrit.extensions.annotations.Listen; |
| 2022 | import com.google.gerrit.extensions.webui.PatchSetWebLink;; |
Sven Selberg | a85e64d | 2014-09-24 10:52:21 +0200 | [diff] [blame] | 2023 | import com.google.gerrit.extensions.webui.WebLinkTarget; |
Sven Selberg | ae1a10c | 2014-02-14 14:24:29 +0100 | [diff] [blame] | 2024 | |
| 2025 | @Listen |
| 2026 | public class MyWeblinkPlugin implements PatchSetWebLink { |
| 2027 | |
| 2028 | private String name = "MyLink"; |
| 2029 | private String placeHolderUrlProjectCommit = "http://my.tool.com/project=%s/commit=%s"; |
Sven Selberg | 5548420 | 2014-06-26 08:48:51 +0200 | [diff] [blame] | 2030 | private String imageUrl = "http://placehold.it/16x16.gif"; |
Sven Selberg | ae1a10c | 2014-02-14 14:24:29 +0100 | [diff] [blame] | 2031 | |
| 2032 | @Override |
Jonathan Nieder | b3cd690 | 2015-03-12 16:19:15 -0700 | [diff] [blame] | 2033 | public WebLinkInfo getPatchSetWebLink(String projectName, String commit) { |
Sven Selberg | a85e64d | 2014-09-24 10:52:21 +0200 | [diff] [blame] | 2034 | return new WebLinkInfo(name, |
| 2035 | imageUrl, |
| 2036 | String.format(placeHolderUrlProjectCommit, project, commit), |
| 2037 | WebLinkTarget.BLANK); |
Edwin Kempin | ceeed6b | 2014-09-11 17:07:33 +0200 | [diff] [blame] | 2038 | } |
Sven Selberg | ae1a10c | 2014-02-14 14:24:29 +0100 | [diff] [blame] | 2039 | } |
| 2040 | ---- |
| 2041 | |
Edwin Kempin | b3696c8 | 2014-09-11 09:41:42 +0200 | [diff] [blame] | 2042 | FileWebLinks will appear in the side-by-side diff screen on the right |
| 2043 | side of the patch selection on each side. |
| 2044 | |
Edwin Kempin | 8cdce50 | 2014-12-06 10:55:38 +0100 | [diff] [blame] | 2045 | DiffWebLinks will appear in the side-by-side and unified diff screen in |
| 2046 | the header next to the navigation icons. |
| 2047 | |
Edwin Kempin | ea00475 | 2014-04-11 15:56:02 +0200 | [diff] [blame] | 2048 | ProjectWebLinks will appear in the project list in the |
| 2049 | `Repository Browser` column. |
| 2050 | |
Edwin Kempin | 0f697bd | 2014-09-10 18:23:29 +0200 | [diff] [blame] | 2051 | BranchWebLinks will appear in the branch list in the last column. |
| 2052 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 2053 | [[documentation]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 2054 | == Documentation |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 2055 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2056 | If a plugin does not register a filter or servlet to handle URLs |
Jonathan Nieder | 5758f18 | 2015-03-30 11:28:55 -0700 | [diff] [blame] | 2057 | `+/Documentation/*+` or `+/static/*+`, the core Gerrit server will |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2058 | automatically export these resources over HTTP from the plugin JAR. |
| 2059 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 2060 | Static resources under the `static/` directory in the JAR will be |
Dave Borowitz | b893ac8 | 2013-03-27 10:03:55 -0400 | [diff] [blame] | 2061 | available as `/plugins/helloworld/static/resource`. This prefix is |
| 2062 | configurable by setting the `Gerrit-HttpStaticPrefix` attribute. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2063 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 2064 | Documentation files under the `Documentation/` directory in the JAR |
Dave Borowitz | b893ac8 | 2013-03-27 10:03:55 -0400 | [diff] [blame] | 2065 | will be available as `/plugins/helloworld/Documentation/resource`. This |
| 2066 | prefix is configurable by setting the `Gerrit-HttpDocumentationPrefix` |
| 2067 | attribute. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2068 | |
Christian Aistleitner | 040cf82 | 2015-03-26 21:09:09 +0100 | [diff] [blame] | 2069 | Documentation may be written in the Markdown flavor |
| 2070 | link:https://github.com/sirthias/pegdown[pegdown] |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2071 | if the file name ends with `.md`. Gerrit will automatically convert |
| 2072 | Markdown to HTML if accessed with extension `.html`. |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 2073 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 2074 | [[macros]] |
Edwin Kempin | c78777d | 2012-07-16 15:55:11 +0200 | [diff] [blame] | 2075 | Within the Markdown documentation files macros can be used that allow |
| 2076 | to write documentation with reasonably accurate examples that adjust |
| 2077 | automatically based on the installation. |
| 2078 | |
| 2079 | The following macros are supported: |
| 2080 | |
| 2081 | [width="40%",options="header"] |
| 2082 | |=================================================== |
| 2083 | |Macro | Replacement |
| 2084 | |@PLUGIN@ | name of the plugin |
| 2085 | |@URL@ | Gerrit Web URL |
| 2086 | |@SSH_HOST@ | SSH Host |
| 2087 | |@SSH_PORT@ | SSH Port |
| 2088 | |=================================================== |
| 2089 | |
| 2090 | The macros will be replaced when the documentation files are rendered |
| 2091 | from Markdown to HTML. |
| 2092 | |
| 2093 | Macros that start with `\` such as `\@KEEP@` will render as `@KEEP@` |
| 2094 | even if there is an expansion for `KEEP` in the future. |
| 2095 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 2096 | [[auto-index]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 2097 | === Automatic Index |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 2098 | |
| 2099 | If a plugin does not handle its `/` URL itself, Gerrit will |
| 2100 | redirect clients to the plugin's `/Documentation/index.html`. |
| 2101 | Requests for `/Documentation/` (bare directory) will also redirect |
| 2102 | to `/Documentation/index.html`. |
| 2103 | |
| 2104 | If neither resource `Documentation/index.html` or |
| 2105 | `Documentation/index.md` exists in the plugin JAR, Gerrit will |
| 2106 | automatically generate an index page for the plugin's documentation |
| 2107 | tree by scanning every `*.md` and `*.html` file in the Documentation/ |
| 2108 | directory. |
| 2109 | |
| 2110 | For any discovered Markdown (`*.md`) file, Gerrit will parse the |
| 2111 | header of the file and extract the first level one title. This |
| 2112 | title text will be used as display text for a link to the HTML |
| 2113 | version of the page. |
| 2114 | |
| 2115 | For any discovered HTML (`*.html`) file, Gerrit will use the name |
| 2116 | of the file, minus the `*.html` extension, as the link text. Any |
| 2117 | hyphens in the file name will be replaced with spaces. |
| 2118 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 2119 | If a discovered file is named `about.md` or `about.html`, its |
| 2120 | content will be inserted in an 'About' section at the top of the |
| 2121 | auto-generated index page. If both `about.md` and `about.html` |
| 2122 | exist, only the first discovered file will be used. |
| 2123 | |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 2124 | If a discovered file name beings with `cmd-` it will be clustered |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 2125 | into a 'Commands' section of the generated index page. |
| 2126 | |
David Pursehouse | fe52915 | 2013-08-14 16:35:06 +0900 | [diff] [blame] | 2127 | If a discovered file name beings with `servlet-` it will be clustered |
| 2128 | into a 'Servlets' section of the generated index page. |
| 2129 | |
| 2130 | If a discovered file name beings with `rest-api-` it will be clustered |
| 2131 | into a 'REST APIs' section of the generated index page. |
| 2132 | |
David Pursehouse | 6853b5a | 2013-07-10 11:38:03 +0900 | [diff] [blame] | 2133 | All other files are clustered under a 'Documentation' section. |
Shawn O. Pearce | 795167c | 2012-05-12 11:20:18 -0700 | [diff] [blame] | 2134 | |
| 2135 | Some optional information from the manifest is extracted and |
| 2136 | displayed as part of the index page, if present in the manifest: |
| 2137 | |
| 2138 | [width="40%",options="header"] |
| 2139 | |=================================================== |
| 2140 | |Field | Source Attribute |
| 2141 | |Name | Implementation-Title |
| 2142 | |Vendor | Implementation-Vendor |
| 2143 | |Version | Implementation-Version |
| 2144 | |URL | Implementation-URL |
| 2145 | |API Version | Gerrit-ApiVersion |
| 2146 | |=================================================== |
| 2147 | |
Edwin Kempin | f5a7733 | 2012-07-18 11:17:53 +0200 | [diff] [blame] | 2148 | [[deployment]] |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 2149 | == Deployment |
Nasser Grainawi | e033b26 | 2012-05-09 17:54:21 -0700 | [diff] [blame] | 2150 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 2151 | Compiled plugins and extensions can be deployed to a running Gerrit |
| 2152 | server using the link:cmd-plugin-install.html[plugin install] command. |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2153 | |
David Pursehouse | a1d633b | 2014-05-02 17:21:02 +0900 | [diff] [blame] | 2154 | Web UI plugins distributed as single `.js` file can be deployed |
Dariusz Luksza | 357a242 | 2012-11-12 06:16:26 +0100 | [diff] [blame] | 2155 | without the overhead of JAR packaging, for more information refer to |
| 2156 | link:cmd-plugin-install.html[plugin install] command. |
| 2157 | |
Shawn O. Pearce | da4919a | 2012-05-10 16:54:28 -0700 | [diff] [blame] | 2158 | Plugins can also be copied directly into the server's |
Dariusz Luksza | 357a242 | 2012-11-12 06:16:26 +0100 | [diff] [blame] | 2159 | directory at `$site_path/plugins/$name.(jar|js)`. The name of |
| 2160 | 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] | 2161 | plugin name. Unless disabled, servers periodically scan this |
| 2162 | directory for updated plugins. The time can be adjusted by |
| 2163 | link:config-gerrit.html#plugins.checkFrequency[plugins.checkFrequency]. |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 2164 | |
Edwin Kempin | f729574 | 2012-07-16 15:03:46 +0200 | [diff] [blame] | 2165 | For disabling plugins the link:cmd-plugin-remove.html[plugin remove] |
| 2166 | command can be used. |
| 2167 | |
Brad Larson | d5e87c3 | 2012-07-11 12:18:49 -0500 | [diff] [blame] | 2168 | Disabled plugins can be re-enabled using the |
| 2169 | link:cmd-plugin-enable.html[plugin enable] command. |
| 2170 | |
Edwin Kempin | c1a2510 | 2015-06-22 14:47:36 +0200 | [diff] [blame] | 2171 | == Known issues and bugs |
| 2172 | |
| 2173 | === Error handling in UI when using the REST API |
| 2174 | |
| 2175 | When a plugin invokes a REST endpoint in the UI, it provides an |
| 2176 | `AsyncCallback` to handle the result. At the moment the |
| 2177 | `onFailure(Throwable)` of the callback is never invoked, even if there |
| 2178 | is an error. Errors are always handled by the Gerrit core UI which |
| 2179 | shows the error dialog. This means currently plugins cannot do any |
| 2180 | error handling and e.g. ignore expected errors. |
| 2181 | |
| 2182 | In the following example the REST endpoint would return '404 Not Found' |
| 2183 | if there is no HTTP password and the Gerrit core UI would display an |
| 2184 | error dialog for this. However having no HTTP password is not an error |
| 2185 | and the plugin may like to handle this case. |
| 2186 | |
| 2187 | [source,java] |
| 2188 | ---- |
| 2189 | new RestApi("accounts").id("self").view("password.http") |
| 2190 | .get(new AsyncCallback<NativeString>() { |
| 2191 | |
| 2192 | @Override |
| 2193 | public void onSuccess(NativeString httpPassword) { |
| 2194 | // TODO |
| 2195 | } |
| 2196 | |
| 2197 | @Override |
| 2198 | public void onFailure(Throwable caught) { |
| 2199 | // never invoked |
| 2200 | } |
| 2201 | }); |
| 2202 | ---- |
| 2203 | |
| 2204 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 2205 | == SEE ALSO |
David Ostrovsky | f86bae5 | 2013-09-01 09:10:39 +0200 | [diff] [blame] | 2206 | |
| 2207 | * link:js-api.html[JavaScript API] |
| 2208 | * link:dev-rest-api.html[REST API Developers' Notes] |
| 2209 | |
Deniz Türkoglu | eb78b60 | 2012-05-07 14:02:36 -0700 | [diff] [blame] | 2210 | GERRIT |
| 2211 | ------ |
| 2212 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 2213 | |
| 2214 | SEARCHBOX |
| 2215 | --------- |