blob: 79febe49d91af302cbcff2b64efe5752db27d6cb [file] [log] [blame]
Marian Harbachebeb1542019-12-13 10:42:46 +01001:linkattrs:
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08002= Gerrit Code Review - Eclipse Setup
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08003
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -08004This document is about configuring Gerrit Code Review into an
David Ostrovsky7163dac2017-07-29 06:49:38 +02005Eclipse workspace for development.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08006
Luca Milanesio911611a2020-10-06 14:49:01 +01007Java 11 or later SDK is required.
8Otherwise, java 8 can still be used for now as described below.
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -08009
David Pursehouse2b16f6a2015-08-28 09:38:50 +090010[[setup]]
11== Project Setup
12
Marian Harbach34253372019-12-10 18:01:31 +010013In your Eclipse installation's link:https://wiki.eclipse.org/Eclipse.ini[`eclipse.ini`,role=external,window=_blank] file,
Eryk Szymanski6c5e6432017-04-24 10:32:52 +020014add the following line in the `vmargs` section:
David Pursehousec20dff22015-08-28 09:41:14 +090015
16----
17 -DmaxCompiledUnitsAtOnce=10000
18----
19
20Without this setting, annotation processing does not work reliably and the
21build is likely to fail with errors like:
22
23----
24 Could not write generated class ... javax.annotation.processing.FilerException: Source file already created
25----
26
David Pursehouse1023b262016-08-19 16:26:43 +090027and
28
29----
30 AutoAnnotation_Commands_named cannot be resolved to a type
31----
32
Eryk Szymanski49c76f52017-04-24 10:12:01 +020033First, generate the Eclipse project by running the `tools/eclipse/project.py` script.
Luca Milanesio911611a2020-10-06 14:49:01 +010034
Eryk Szymanski49c76f52017-04-24 10:12:01 +020035Then, in Eclipse, choose 'Import existing project' and select the `gerrit` project
David Pursehouse2b16f6a2015-08-28 09:38:50 +090036from the current working directory.
37
David Ostrovskyfdbfcad2016-11-15 06:35:29 -080038Expand the `gerrit` project, right-click on the `eclipse-out` folder, select
David Pursehouse2b16f6a2015-08-28 09:38:50 +090039'Properties', and then under 'Attributes' check 'Derived'.
40
41Note that if you make any changes in the project configuration
42that get saved to the `.project` file, for example adding Resource
43Filters on a folder, they will be overwritten the next time you run
44`tools/eclipse/project.py`.
45
Saša Živkovf5f0d612020-07-30 17:43:42 +020046=== Eclipse project on MacOS
47
48By default, bazel uses `/private/var/tmp` as the
49link:https://docs.bazel.build/versions/master/output_directories.html[outputRoot on MacOS].
50This means that the eclipse project will reference libraries stored under that directory.
51However, MacOS runs periodic cleanup task which deletes the content under `/private/var/tmp`
52which wasn't accessed or modified for some days, by default 3 days. This can lead to a broken
53Eclipse project as referenced libraries get deleted.
54
55There are two possibilities to mitigate this issue.
56
57==== Change the location of the bazel output directory
58On Linux, the output directory defaults to `$HOME/.cache/bazel` and the same can be configured
59on Mac too. Edit, or create, the `$HOME/.bazelrc` file and add the following line:
60----
61startup --output_user_root=/Users/johndoe/.cache/bazel
62----
63
64==== Increase the treshold for the cleanup of temporary files
65The default treshold for the cleanup can be overriden by creating a configuration file under
66`/etc/periodic.conf` and setting a larger value for the `daily_clean_tmps_days`.
67
68An example `/etc/periodic.conf` file:
69
70----
71# This file overrides the settings from /etc/defaults/periodic.conf
72daily_clean_tmps_days="45" # If not accessed for
73----
74
75For more details about the proposed workaround see link:https://superuser.com/a/187105[this post]
76
Sven Selberg4076e822017-12-21 15:41:02 +010077=== Eclipse project with custom plugins ===
78
79To add custom plugins to the eclipse project add them to `tools/bzl/plugins.bzl`
80the same way you would when
81link:dev-build-plugins.html#_bundle_custom_plugin_in_release_war[bundling in release.war]
82and run `tools/eclipse/project.py`.
83
Luca Milanesio911611a2020-10-06 14:49:01 +010084== Java Versions
David Ostrovsky8aae31c2018-06-25 23:45:15 +020085
Luca Milanesio911611a2020-10-06 14:49:01 +010086Java 11 is supported as a default, but some adjustments must be done for other JDKs:
David Ostrovsky8aae31c2018-06-25 23:45:15 +020087
88* Add JRE, e.g.: directory: /usr/lib64/jvm/java-9-openjdk, name: java-9-openjdk-9
Marco Miller0b7e9982019-11-01 13:29:08 -040089* Change execution environment for gerrit project to: JavaSE-9 (java-9-openjdk-9)
David Ostrovsky8aae31c2018-06-25 23:45:15 +020090* Check that compiler compliance level in gerrit project is set to: 9
David Pursehouse2b16f6a2015-08-28 09:38:50 +090091
Luca Milanesio911611a2020-10-06 14:49:01 +010092Moreover, the actual java 11 language features are not supported yet.
93
Martin Fick081fa512011-08-12 11:22:45 -060094[[Formatting]]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080095== Code Formatter Settings
Shawn O. Pearcee89544b2009-04-28 07:59:44 -070096
David Ostrovsky248b7092017-02-09 22:13:44 +010097To format source code, Gerrit uses the
Marian Harbach34253372019-12-10 18:01:31 +010098link:https://github.com/google/google-java-format[`google-java-format`,role=external,window=_blank]
Dave Borowitz3efa1052019-01-28 07:21:29 -080099tool (version 1.7), which automatically formats code to follow the
Marco Millerd71da9b2019-11-22 15:00:46 -0500100style guide. See link:dev-crafting-changes.html#style[Code Style] for the
David Ostrovsky248b7092017-02-09 22:13:44 +0100101instruction how to set up command line tool that uses this formatter.
102The Eclipse plugin is provided that allows to format with the same
103formatter from within the Eclipse IDE. See
Marian Harbach34253372019-12-10 18:01:31 +0100104link:https://github.com/google/google-java-format#eclipse[Eclipse plugin,role=external,window=_blank]
David Ostrovsky248b7092017-02-09 22:13:44 +0100105for details how to install it. It's important to use the same plugin version
106as the `google-java-format` script.
Shawn O. Pearcee89544b2009-04-28 07:59:44 -0700107
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800108== Site Initialization
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800109
David Ostrovskydcee5722013-05-15 00:10:55 +0200110Build once on the command line with
David Ostrovskyfdbfcad2016-11-15 06:35:29 -0800111link:dev-bazel.html#build[Bazel] and then follow
David Pursehouse6de7ee22013-05-20 11:08:51 +0900112link:dev-readme.html#init[Site Initialization] in the
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800113Developer Setup guide to configure a local site for testing.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800114
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800115
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800116== Testing
Shawn O. Pearce8d2f1842009-05-13 07:59:04 -0700117
Frank Borden10249882022-08-24 21:24:51 +0200118=== The Gerrit web app UI is served by `Web Dev Server`. To launch it,
David Ostrovskyadd163f2020-02-13 22:32:08 +0100119run this command:
120
121----
Frank Borden10249882022-08-24 21:24:51 +0200122 $ npm run start
David Ostrovskyadd163f2020-02-13 22:32:08 +0100123----
124
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -0800125=== Running the Daemon
Shawn O. Pearce8d2f1842009-05-13 07:59:04 -0700126
David Pursehouse584af672013-05-20 11:15:18 +0900127Duplicate the existing launch configuration:
Shawn O. Pearce8d2f1842009-05-13 07:59:04 -0700128
David Pursehouse44eed242015-01-08 11:42:35 +0900129* In Eclipse select Run -> Debug Configurations ...
Shawn Pearcecda21212013-11-28 20:49:42 -0800130* Java Application -> `gerrit_daemon`
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800131* Right click, Duplicate
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800132* Modify the name to be unique.
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800133* Switch to Arguments tab.
Shawn O. Pearce955d00e2009-12-19 13:38:19 -0800134* Edit the `-d` program argument flag to match the path used during
David Pursehouse44eed242015-01-08 11:42:35 +0900135 'init'. The template launch configuration resolves to `../gerrit_testsite`
Shawn O. Pearce955d00e2009-12-19 13:38:19 -0800136 since that is what the documentation recommends.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800137
Shawn O. Pearce18f1f7f2009-12-16 11:32:39 -0800138* Switch to Common tab.
139* Change Save as to be Local file.
David Pursehouse3800abd2013-05-08 09:24:29 +0100140* Close the Debug Configurations dialog and save the changes when prompted.
Shawn O. Pearce06b48c32009-05-10 16:21:05 -0700141
Shawn O. Pearce5500e692009-05-28 15:55:01 -0700142GERRIT
143------
144Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700145
146SEARCHBOX
147---------