blob: 34b409c122fc23a8d3bce428ae1b787c59ea6de3 [file] [log] [blame]
Janet Davies0c1a6212018-05-09 15:18:57 -07001= Gerrit Code Review: Developer Setup
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08002
Janet Davies0c1a6212018-05-09 15:18:57 -07003To build a developer instance, you'll need link:https://bazel.build/[Bazel] to
4compile the code.
David Pursehousefec58792013-05-10 15:34:02 +01005
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +02006== Git Setup
7
Edwin Kempinef1b8112019-10-29 09:27:00 +01008[[clone]]
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +02009=== Getting the Source
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080010
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080011Create a new client workspace:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080012
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080013----
David Pursehouseb964ac12018-10-12 14:01:39 +090014 git clone --recurse-submodules https://gerrit.googlesource.com/gerrit
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080015 cd gerrit
16----
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080017
Joerg Zierened45a282019-05-03 11:47:51 +020018The `--recurse-submodules` option is needed on `git clone` to ensure that the
19core plugins, which are included as git submodules, are also cloned.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080020
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020021=== Switching between branches
22
23When using `git checkout` without `--recurse-submodules` to switch between
24branches, submodule revisions are not altered, which can result in:
25
26* Incorrect or unneeded plugin revisions.
27* Missing plugins.
28
29After you switch branches, ensure that you have the correct versions of
30the submodules.
31
32CAUTION: If you store Eclipse or IntelliJ project files in the Gerrit source
33directories, do *_not_* run `git clean -fdx`. Doing so may remove untracked files and damage your project. For more information, see
34link:https://git-scm.com/docs/git-clean[git-clean].
35
36Run the following:
37
38----
39 git submodule update
40 git clean -ffd
41----
42
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010043[[compile_project]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080044== Compiling
David Pursehouse6de7ee22013-05-20 11:08:51 +090045
Janet Davies0c1a6212018-05-09 15:18:57 -070046For details, see <<dev-bazel#,Building with Bazel>>.
David Pursehoused106c8e2013-12-13 15:03:02 +090047
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080048
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020049== Testing
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080050
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020051[[tests]]
52=== Running the acceptance tests
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080053
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020054Gerrit contains acceptance tests that validate the Gerrit daemon via REST, SSH,
55and the Git protocol.
Urs Wolferc0948bd2014-04-27 21:16:25 +020056
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020057A new review site is created for each test and the Gerrit daemon is
58then started on that site. When the test is completed, the Gerrit daemon is
59shut down.
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010060
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020061For instructions on running the acceptance tests with Bazel,
62see <<dev-bazel#tests,Running Unit Tests with Bazel>>.
David Pursehousefec58792013-05-10 15:34:02 +010063
Shawn O. Pearce461c2cc2009-02-25 09:09:31 -080064
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020065== Local server
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080066
67[[init]]
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +020068=== Site Initialization
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080069
Janet Davies0c1a6212018-05-09 15:18:57 -070070After you compile the project <<compile_project,(above)>>, run the Gerrit
71`init`
72command to create a test site:
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080073
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010074----
Ben Rohlfsb65406b2019-05-02 10:43:40 +020075 export GERRIT_SITE=~/gerrit_testsite
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010076 $(bazel info output_base)/external/local_jdk/bin/java \
Ben Rohlfsb65406b2019-05-02 10:43:40 +020077 -jar bazel-bin/gerrit.war init --batch --dev -d $GERRIT_SITE
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010078----
79
80[[special_bazel_java_version]]
Janet Davies0c1a6212018-05-09 15:18:57 -070081NOTE: You must use the same Java version that Bazel used for the build, which
82is available at `$(bazel info output_base)/external/local_jdk/bin/java`.
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +010083
Ben Rohlfs0f007172019-04-29 21:41:05 +020084This command takes two parameters:
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080085
Ben Rohlfs0f007172019-04-29 21:41:05 +020086* `--batch` assigns default values to several Gerrit configuration
87 options. To learn more about these options, see
88 link:config-gerrit.html[Configuration].
89* `--dev` configures the Gerrit server to use the authentication
90 option, `DEVELOPMENT_BECOME_ANY_ACCOUNT`, which enables you to
91 switch between different users to explore how Gerrit works. To learn more
92 about setting up Gerrit for development, see
93 link:dev-readme.html[Gerrit Code Review: Developer Setup].
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -080094
Janet Davies0c1a6212018-05-09 15:18:57 -070095After initializing the test site, Gerrit starts serving in the background. A
96web browser displays the Start page.
Aaron Gable5eab7202016-10-12 11:24:06 -070097
Janet Davies0c1a6212018-05-09 15:18:57 -070098On the Start page, you can:
99
100. Log in as the account you created during the initialization process.
101. Register additional accounts.
102. Create projects.
103
104To shut down the daemon, run:
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800105
106----
Ben Rohlfsb65406b2019-05-02 10:43:40 +0200107 $GERRIT_SITE/bin/gerrit.sh stop
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800108----
109
110
Aaron Gable5eab7202016-10-12 11:24:06 -0700111[[localdev]]
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200112=== Working with the Local Server
Aaron Gable5eab7202016-10-12 11:24:06 -0700113
Janet Davies0c1a6212018-05-09 15:18:57 -0700114To create more accounts on your development instance:
115
116. Click 'become' in the upper right corner.
117. Select 'Switch User'.
118. Register a new account.
brohlfsbdcea6d2019-01-22 10:36:23 +0100119. link:user-upload.html#ssh[Configure your SSH key].
Aaron Gable5eab7202016-10-12 11:24:06 -0700120
121Use the `ssh` protocol to clone from and push to the local server. For
122example, to clone a repository that you've created through the admin
123interface, run:
124
125----
126git clone ssh://username@localhost:29418/projectname
127----
128
Joerg Zieren937d5452019-05-17 10:39:41 +0200129To use the `HTTP` protocol, run:
130
131----
132git clone http://username@localhost:8080/projectname
133----
134
135The default password for user `admin` is `secret`. You can regenerate a
136password in the UI under User Settings -- HTTP credentials. The password can be
137stored locally to avoid retyping it:
138
139----
140git config --global credential.helper store
141git pull
142----
143
Janet Davies0c1a6212018-05-09 15:18:57 -0700144To create changes as users of Gerrit would, run:
Aaron Gable5eab7202016-10-12 11:24:06 -0700145
146----
147git push origin HEAD:refs/for/master
148----
149
Alice Kober-Sotzekd9da89f2016-11-25 12:02:18 +0100150[[run_daemon]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800151=== Running the Daemon
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800152
Janet Davies0c1a6212018-05-09 15:18:57 -0700153The daemon can be launched directly from the build area, without
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800154copying to the test site:
155
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100156----
157 $(bazel info output_base)/external/local_jdk/bin/java \
Ben Rohlfsb65406b2019-05-02 10:43:40 +0200158 -jar bazel-bin/gerrit.war daemon -d $GERRIT_SITE \
Han-Wen Nienhuys0c93bc82017-01-19 15:26:42 +0100159 --console-log
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100160----
161
Janet Davies0c1a6212018-05-09 15:18:57 -0700162NOTE: To learn why using `java -jar` isn't sufficient, see
163<<special_bazel_java_version,this explanation>>.
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100164
Janet Davies0c1a6212018-05-09 15:18:57 -0700165To debug the Gerrit server of this test site:
166
167. Open a debug port (such as port 5005). To do so, insert the following code
168immediately after `-jar` in the previous command. To learn how to attach
169IntelliJ, see <<dev-intellij#remote-debug,Debugging a remote Gerrit server>>.
Alice Kober-Sotzek485a5ff2017-03-02 13:20:32 +0100170
171----
172-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
173----
174
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800175=== Running the Daemon with Gerrit Inspector
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000176
177link:dev-inspector.html[Gerrit Inspector] is an interactive scriptable
Janet Davies0c1a6212018-05-09 15:18:57 -0700178environment you can use to inspect and modify the internal state of the system.
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000179
Janet Davies0c1a6212018-05-09 15:18:57 -0700180Gerrit Inspector appears on the system console whenever the system starts.
181Leaving the Inspector shuts down the Gerrit instance.
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000182
Janet Davies0c1a6212018-05-09 15:18:57 -0700183To troubleshoot, the Inspector enables interactive work as well as running of
184Python scripts.
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000185
Janet Davies0c1a6212018-05-09 15:18:57 -0700186To start the Inspector, add the '-s' option to the daemon start command:
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000187
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100188----
189 $(bazel info output_base)/external/local_jdk/bin/java \
Ben Rohlfsb65406b2019-05-02 10:43:40 +0200190 -jar bazel-bin/gerrit.war daemon -d $GERRIT_SITE -s
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100191----
192
Janet Davies0c1a6212018-05-09 15:18:57 -0700193NOTE: To learn why using `java -jar` isn't sufficient, see
194<<special_bazel_java_version,this explanation>>.
Alice Kober-Sotzek4b92e042016-11-25 10:54:30 +0100195
Janet Davies0c1a6212018-05-09 15:18:57 -0700196Inspector examines Java libraries, loads the initialization scripts, and
197starts a command line prompt on the console:
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000198
199----
200 Welcome to the Gerrit Inspector
201 Enter help() to see the above again, EOF to quit and stop Gerrit
202 Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
Janet Davies0c1a6212018-05-09 15:18:57 -0700203 [OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0 running for
204 Gerrit 2.3-rc0-163-g01967ef
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000205 >>>
206----
207
Janet Davies0c1a6212018-05-09 15:18:57 -0700208When the Inspector is enabled, you can use Gerrit as usual and all
209interfaces (including HTTP and SSH) are available.
Marcin Cieślaked612fb2012-04-17 16:24:34 +0000210
Janet Davies0c1a6212018-05-09 15:18:57 -0700211CAUTION: When using the Inspector, be careful not to modify the internal state
212of the system.
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800213
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800214
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200215== Setup for backend developers
Janet Davies0c1a6212018-05-09 15:18:57 -0700216
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200217=== Configuring Eclipse
Janet Davies0c1a6212018-05-09 15:18:57 -0700218
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200219To use the Eclipse IDE for development, see
220link:dev-eclipse.html[Eclipse Setup].
Janet Davies0c1a6212018-05-09 15:18:57 -0700221
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200222To configure the Eclipse workspace with Bazel, see
223link:dev-bazel.html#eclipse[Eclipse integration with Bazel].
Janet Davies0c1a6212018-05-09 15:18:57 -0700224
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200225=== Configuring IntelliJ IDEA
Shawn Pearced07a6222013-03-21 00:11:45 -0700226
Alice Kober-Sotzeka8029b62019-05-07 19:13:00 +0200227See <<dev-intellij#,IntelliJ Setup>> for details.
228
Alice Kober-Sotzek79290dc2019-05-07 19:26:18 +0200229== Setup for frontend developers
230See link:https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/README.md[Frontend Developer Setup].
231
Shawn Pearced07a6222013-03-21 00:11:45 -0700232
Shawn O. Pearce5500e692009-05-28 15:55:01 -0700233GERRIT
234------
235Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700236
237SEARCHBOX
238---------