| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 1 | = Gerrit Code Review - Developer Setup |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 2 | |
| David Ostrovsky | fdbfcad | 2016-11-15 06:35:29 -0800 | [diff] [blame] | 3 | Google Bazel is needed to compile the code, and an SQL database to |
| David Ostrovsky | dcee572 | 2013-05-15 00:10:55 +0200 | [diff] [blame] | 4 | house the review metadata. H2 is recommended for development |
| 5 | databases, as it requires no external server process. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 6 | |
| David Pursehouse | fec5879 | 2013-05-10 15:34:02 +0100 | [diff] [blame] | 7 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 8 | == Getting the Source |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 9 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 10 | Create a new client workspace: |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 11 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 12 | ---- |
| David Pursehouse | 4f2be53 | 2013-05-09 13:47:17 +0100 | [diff] [blame] | 13 | git clone --recursive https://gerrit.googlesource.com/gerrit |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 14 | cd gerrit |
| 15 | ---- |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 16 | |
| David Pursehouse | 4f2be53 | 2013-05-09 13:47:17 +0100 | [diff] [blame] | 17 | The `--recursive` option is needed on `git clone` to ensure that |
| 18 | the core plugins, which are included as git submodules, are also |
| 19 | cloned. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 20 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 21 | [[compile_project]] |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 22 | == Compiling |
| David Pursehouse | 6de7ee2 | 2013-05-20 11:08:51 +0900 | [diff] [blame] | 23 | |
| David Ostrovsky | fdbfcad | 2016-11-15 06:35:29 -0800 | [diff] [blame] | 24 | Please refer to <<dev-bazel#,Building with Bazel>>. |
| David Pursehouse | 6de7ee2 | 2013-05-20 11:08:51 +0900 | [diff] [blame] | 25 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 26 | == Switching between branches |
| David Pursehouse | d106c8e | 2013-12-13 15:03:02 +0900 | [diff] [blame] | 27 | |
| 28 | When switching between branches with `git checkout`, be aware that |
| 29 | submodule revisions are not altered. This may result in the wrong |
| 30 | plugin revisions being present, unneeded plugins being present, or |
| 31 | expected plugins being missing. |
| 32 | |
| 33 | After switching branches, make sure the submodules are at the correct |
| 34 | revisions for the new branch with the commands: |
| 35 | |
| 36 | ---- |
| 37 | git submodule update |
| 38 | git clean -fdx |
| 39 | ---- |
| 40 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 41 | CAUTION: If you decide to store your Eclipse/IntelliJ project files in the |
| 42 | Gerrit source directories, executing `git clean -fdx` will remove them and hence |
| 43 | screw up your project. |
| 44 | |
| David Pursehouse | d106c8e | 2013-12-13 15:03:02 +0900 | [diff] [blame] | 45 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 46 | == Configuring Eclipse |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 47 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 48 | To use the Eclipse IDE for development, please see |
| David Pursehouse | fec5879 | 2013-05-10 15:34:02 +0100 | [diff] [blame] | 49 | link:dev-eclipse.html[Eclipse Setup]. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 50 | |
| David Ostrovsky | fdbfcad | 2016-11-15 06:35:29 -0800 | [diff] [blame] | 51 | For details on how to configure the Eclipse workspace with Bazel, |
| 52 | refer to: link:dev-bazel.html#eclipse[Eclipse integration with Bazel]. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 53 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 54 | |
| Urs Wolfer | c0948bd | 2014-04-27 21:16:25 +0200 | [diff] [blame] | 55 | == Configuring IntelliJ IDEA |
| 56 | |
| Alice Kober-Sotzek | d9da89f | 2016-11-25 12:02:18 +0100 | [diff] [blame] | 57 | Please refer to <<dev-intellij#,IntelliJ Setup>> for detailed |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 58 | instructions. |
| 59 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 60 | == Mac OS X |
| David Pursehouse | fec5879 | 2013-05-10 15:34:02 +0100 | [diff] [blame] | 61 | |
| Khai Do | ea9e4b7 | 2014-03-30 07:43:31 -0700 | [diff] [blame] | 62 | On Mac OS X ensure "Java For Mac OS X 10.5 Update 4" (or later) has |
| 63 | been installed, and that `JAVA_HOME` is set to the |
| 64 | link:install.html#Requirements[required Java version]. |
| Shawn O. Pearce | 461c2cc | 2009-02-25 09:09:31 -0800 | [diff] [blame] | 65 | |
| Khai Do | ea9e4b7 | 2014-03-30 07:43:31 -0700 | [diff] [blame] | 66 | Java installations can typically be found in |
| 67 | "/System/Library/Frameworks/JavaVM.framework/Versions". |
| 68 | |
| 69 | You can check the installed Java version by running `java -version` in |
| 70 | the terminal. |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 71 | |
| 72 | [[init]] |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 73 | == Site Initialization |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 74 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 75 | After compiling <<compile_project,(above)>>, run Gerrit's 'init' command to |
| 76 | create a testing site for development use: |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 77 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 78 | ---- |
| 79 | $(bazel info output_base)/external/local_jdk/bin/java \ |
| 80 | -jar bazel-bin/gerrit.war init -d ../gerrit_testsite |
| 81 | ---- |
| 82 | |
| 83 | [[special_bazel_java_version]] |
| 84 | NOTE: You must use the same Java version that Bazel used for the build. |
| 85 | This Java version is available at |
| 86 | `$(bazel info output_base)/external/local_jdk/bin/java`. |
| 87 | |
| Aaron Gable | 5eab720 | 2016-10-12 11:24:06 -0700 | [diff] [blame] | 88 | During initialization, make two changes to the default settings: |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 89 | |
| Aaron Gable | 5eab720 | 2016-10-12 11:24:06 -0700 | [diff] [blame] | 90 | * Change the listen addresses from '*' to 'localhost' to prevent outside |
| 91 | connections from contacting the development instance; and |
| 92 | * Change the auth type from 'OPENID' to 'DEVELOPMENT_BECOME_ANY_ACCOUNT' to |
| 93 | allow yourself to create and act as arbitrary test accounts on your |
| 94 | development instance. |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 95 | |
| Aaron Gable | 5eab720 | 2016-10-12 11:24:06 -0700 | [diff] [blame] | 96 | Continue through init until it completes. The daemon will automatically start in |
| 97 | the background and a web browser will launch to the start page. From here you |
| 98 | can sign in as the account created during init, register additional accounts, |
| 99 | create projects, and more. |
| 100 | |
| 101 | When you want to shut down the daemon, simply run: |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 102 | |
| 103 | ---- |
| David Pursehouse | 9db2378 | 2013-12-17 11:59:22 +0900 | [diff] [blame] | 104 | ../gerrit_testsite/bin/gerrit.sh stop |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 105 | ---- |
| 106 | |
| 107 | |
| Aaron Gable | 5eab720 | 2016-10-12 11:24:06 -0700 | [diff] [blame] | 108 | [[localdev]] |
| 109 | == Working with the Local Server |
| 110 | |
| 111 | If you need to create additional accounts on your development instance, click |
| 112 | 'become' in the upper right corner, select 'Switch User', and then register |
| 113 | a new account. |
| 114 | |
| 115 | Use the `ssh` protocol to clone from and push to the local server. For |
| 116 | example, to clone a repository that you've created through the admin |
| 117 | interface, run: |
| 118 | |
| 119 | ---- |
| 120 | git clone ssh://username@localhost:29418/projectname |
| 121 | ---- |
| 122 | |
| 123 | Then you'll be able to create changes the same way users do, with |
| 124 | |
| 125 | ---- |
| 126 | git push origin HEAD:refs/for/master |
| 127 | ---- |
| 128 | |
| 129 | |
| 130 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 131 | == Testing |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 132 | |
| David Pursehouse | fec5879 | 2013-05-10 15:34:02 +0100 | [diff] [blame] | 133 | |
| David Pursehouse | 5861a9a | 2013-05-15 10:25:19 +0900 | [diff] [blame] | 134 | [[tests]] |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 135 | === Running the Acceptance Tests |
| Edwin Kempin | 4a3fc3f | 2013-02-27 15:18:43 +0100 | [diff] [blame] | 136 | |
| 137 | Gerrit has a set of integration tests that test the Gerrit daemon via |
| 138 | REST, SSH and the git protocol. |
| 139 | |
| 140 | A new review site is created for each test and the Gerrit daemon is |
| 141 | started on that site. When the test has finished the Gerrit daemon is |
| 142 | shutdown. |
| 143 | |
| David Ostrovsky | fdbfcad | 2016-11-15 06:35:29 -0800 | [diff] [blame] | 144 | For instructions on running the integration tests with Bazel, |
| 145 | please refer to: <<dev-bazel#tests,Running Unit Tests with Bazel>>. |
| Edwin Kempin | 4a3fc3f | 2013-02-27 15:18:43 +0100 | [diff] [blame] | 146 | |
| Alice Kober-Sotzek | d9da89f | 2016-11-25 12:02:18 +0100 | [diff] [blame] | 147 | [[run_daemon]] |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 148 | === Running the Daemon |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 149 | |
| 150 | The daemon can be directly launched from the build area, without |
| 151 | copying to the test site: |
| 152 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 153 | ---- |
| 154 | $(bazel info output_base)/external/local_jdk/bin/java \ |
| Han-Wen Nienhuys | 0c93bc8 | 2017-01-19 15:26:42 +0100 | [diff] [blame] | 155 | -jar bazel-bin/gerrit.war daemon -d ../gerrit_testsite \ |
| 156 | --console-log |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 157 | ---- |
| 158 | |
| 159 | NOTE: Please refer to <<special_bazel_java_version,this explanation>> |
| 160 | for details why using `java -jar` isn't sufficient. |
| 161 | |
| Alice Kober-Sotzek | 485a5ff | 2017-03-02 13:20:32 +0100 | [diff] [blame] | 162 | If you want to debug the Gerrit server of this test site, you can open a debug |
| 163 | port (for example port 5005) by inserting |
| 164 | |
| 165 | ---- |
| 166 | -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 |
| 167 | ---- |
| 168 | |
| 169 | directly after `-jar` of the previous command. Please refer to |
| 170 | <<dev-intellij#remote-debug,Debugging a remote Gerrit server>> for instructions |
| 171 | of how to attach IntelliJ. |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 172 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 173 | === Running the Daemon with Gerrit Inspector |
| Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 174 | |
| 175 | link:dev-inspector.html[Gerrit Inspector] is an interactive scriptable |
| 176 | environment to inspect and modify internal state of the system. |
| 177 | |
| 178 | This environment is available on the system console after |
| 179 | the system starts. Leaving the Inspector will shutdown the Gerrit |
| 180 | instance. |
| 181 | |
| 182 | The environment allows interactive work as well as running of |
| 183 | Python scripts for troubleshooting. |
| 184 | |
| 185 | Gerrit Inspect can be started by adding '-s' option to the |
| 186 | command used to launch the daemon: |
| 187 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 188 | ---- |
| 189 | $(bazel info output_base)/external/local_jdk/bin/java \ |
| 190 | -jar bazel-bin/gerrit.war daemon -d ../gerrit_testsite -s |
| 191 | ---- |
| 192 | |
| 193 | NOTE: Please refer to <<special_bazel_java_version,this explanation>> |
| 194 | for details why using `java -jar` isn't sufficient. |
| 195 | |
| Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 196 | Gerrit Inspector examines Java libraries first, then loads |
| 197 | its initialization scripts and then starts a command line |
| 198 | prompt on the console: |
| 199 | |
| 200 | ---- |
| 201 | Welcome to the Gerrit Inspector |
| 202 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 203 | Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) |
| 204 | [OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0 running for Gerrit 2.3-rc0-163-g01967ef |
| 205 | >>> |
| 206 | ---- |
| 207 | |
| 208 | With the Inspector enabled Gerrit can be used normally and all |
| 209 | interfaces (HTTP, SSH etc.) are available. |
| 210 | |
| 211 | Care must be taken not to modify internal state of the system |
| 212 | when using the Inspector. |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 213 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 214 | === Querying the Database |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 215 | |
| 216 | The embedded H2 database can be queried and updated from the |
| 217 | command line. If the daemon is not currently running: |
| 218 | |
| Alice Kober-Sotzek | 4b92e04 | 2016-11-25 10:54:30 +0100 | [diff] [blame] | 219 | ---- |
| 220 | $(bazel info output_base)/external/local_jdk/bin/java \ |
| 221 | -jar bazel-bin/gerrit.war gsql -d ../gerrit_testsite -s |
| 222 | ---- |
| 223 | |
| 224 | NOTE: Please refer to <<special_bazel_java_version,this explanation>> |
| 225 | for details why using `java -jar` isn't sufficient. |
| 226 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 227 | Or, if it is running and the database is in use, connect over SSH |
| 228 | using an administrator user account: |
| 229 | |
| 230 | ---- |
| 231 | ssh -p 29418 user@localhost gerrit gsql |
| 232 | ---- |
| 233 | |
| 234 | |
| Edwin Kempin | 57fa179 | 2013-03-27 10:43:41 +0100 | [diff] [blame] | 235 | [[debug-javascript]] |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 236 | === Debugging JavaScript |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 237 | |
| Shawn Pearce | d07a622 | 2013-03-21 00:11:45 -0700 | [diff] [blame] | 238 | When debugging browser specific issues add `?dbg=1` to the URL so the |
| 239 | resulting JavaScript more closely matches the Java sources. The debug |
| 240 | pages use the GWT pretty format, where function and variable names |
| 241 | match the Java sources. |
| 242 | |
| 243 | ---- |
| 244 | http://localhost:8080/?dbg=1 |
| 245 | ---- |
| 246 | |
| Shawn O. Pearce | 6ddb6ca | 2009-09-18 18:10:31 -0700 | [diff] [blame] | 247 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 248 | == Client-Server RPC |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 249 | |
| 250 | The client-server RPC implementation is gwtjsonrpc, not the stock RPC |
| 251 | system that comes with GWT. This buys us automatic XSRF protection. |
| 252 | It also makes all of the messages readable and writable by any JSON |
| 253 | implementation, facilitating "mashups" and 3rd party clients. |
| 254 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 255 | The programming API is virtually identical, except service interfaces |
| 256 | extend RemoteJsonService instead of RemoteService. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 257 | |
| 258 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 259 | == Why GWT? |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 260 | |
| 261 | We like it. Plus we can write Java code once and run it both in |
| Shawn O. Pearce | e2bd1b1 | 2009-08-20 11:08:32 -0700 | [diff] [blame] | 262 | the browser and on the server side. |
| Shawn O. Pearce | 5500e69 | 2009-05-28 15:55:01 -0700 | [diff] [blame] | 263 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 264 | |
| Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 265 | == External Links |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 266 | |
| 267 | Google Web Toolkit: |
| 268 | |
| 269 | * http://code.google.com/webtoolkit/download.html[Download] |
| 270 | |
| Shawn O. Pearce | 18f1f7f | 2009-12-16 11:32:39 -0800 | [diff] [blame] | 271 | Apache SSHD: |
| 272 | |
| 273 | * http://mina.apache.org/sshd/[SSHD] |
| 274 | |
| 275 | H2: |
| 276 | |
| 277 | * http://www.h2database.com/[H2] |
| 278 | * http://www.h2database.com/html/grammar.html[SQL Reference] |
| 279 | |
| 280 | PostgreSQL: |
| 281 | |
| 282 | * http://www.postgresql.org/download/[Download] |
| 283 | * http://www.postgresql.org/docs/[Documentation] |
| 284 | |
| 285 | |
| Shawn O. Pearce | 5500e69 | 2009-05-28 15:55:01 -0700 | [diff] [blame] | 286 | GERRIT |
| 287 | ------ |
| 288 | Part of link:index.html[Gerrit Code Review] |
| Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 289 | |
| 290 | SEARCHBOX |
| 291 | --------- |