920 Commits

Author SHA1 Message Date
Edwin Kempin
b644ff8fcf Merge "Implement Bazel build" 2016-06-24 10:51:33 +00:00
Edwin Kempin
94732bfa19 Reindex account whenever account is evicted from cache
Change-Id: I025cabc9be98628777066cda7aa97186f5a0da15
Signed-off-by: Edwin Kempin <ekempin@google.com>
2016-06-22 16:55:32 +02:00
David Pursehouse
8219d818a7 PutConfig: move static inner Input class to extension API
Also rename the existing PutDescriptionInput to DescriptionInput.

Change-Id: I8291e970353b8ae6ed4f0cbe5dce746007e25291
2016-06-21 16:30:43 +09:00
David Ostrovsky
b81b4f75ae Implement Bazel build
To run the tests:

  bazel test //...

To build the Gerrit plugin API, run:

  bazel build gerrit-plugin-api:plugin-api_deploy.jar

To build the Gerrit extension API, run:

  bazel build gerrit-extension-api:extension-api_deploy.jar

TODOs:

Licenses
Reduce visibility (all public for now)
Generate HTML Documentation
Core plugins
gerrit_plugin() rule to build plugins in tree and standalone modes
GWT UI (only gwt_module() skylark rule is provided, no gwt_binary())
PolyGerrit UI
WAR
Publish artifacts to Maven Central
Ask Bazel team to add Gerrit to their CI on ci.bazel.io

Contributed-By: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I9a86e670882a44a5c966579cdeb8ed79b1590de3
2016-06-14 21:12:02 +02:00
Jonathan Nieder
b273cfd04d Consistently annotate changeCache as @Nullable
The changeCache is null when in the context of BatchProgramModule.
The only consumer of changeCache, VisibleRefFilter, is prepared to
handle a null value, so in all code paths it is okay for it to be
null.

This makes reindex work again.  Regression introduced in
a758640bc33c20cead19b86a32db075c776c4140 (VisibleRefFilter: Avoid
touching the database for drafts, 2016-06-03):

 $ java -jar buck-out/gen/gerrit/gerrit.war reindex -d ../gerrit-testsite
[...]
 Reindexing changes: projects: 66% (2/3)[2016-06-06 16:18:36,781] [Index-Batch-3] WARN  com.google.gerrit.server.index.change.AllChangesIndexer : Failed to index change 18
 com.google.inject.ProvisionException: Unable to provision, see the following errors:

 1) null returned by binding at com.google.gerrit.pgm.util.BatchProgramModule.configure(BatchProgramModule.java:126)
  but parameter 8 of com.google.gerrit.server.project.ProjectControl.<init>() is not @Nullable
   while locating com.google.gerrit.server.git.SearchingChangeCacheImpl
     for parameter 8 at com.google.gerrit.server.project.ProjectControl.<init>(ProjectControl.java:177)
   while locating com.google.gerrit.server.project.ProjectControl annotated with @com.google.inject.internal.UniqueAnnotations$Internal(value=4)

Reported-by: Viktar Donich <viktard@google.com>
Change-Id: Ia0ca0e0e153c9f357e5ebc6edf4b1962a2490f2d
2016-06-06 18:50:47 -07:00
Dave Borowitz
02167dbee7 Merge changes I64000a57,Icc7c7586
* changes:
  ChangeIndexer: Disable auto-rebuilding changes
  ChangeNotes: Log when recheckUpToDate finds it wasn't
2016-06-06 19:19:38 +00:00
Dave Borowitz
a758640bc3 VisibleRefFilter Avoid touching the database for drafts
This is an analogous problem to the one with search results fixed in
Ie54b9e2d. VisibleRefFilter is a little trickier because it was using
ChangeCache, which only returned Changes, not the reviewer set. Change
SearchingChangeCacheImpl to cache a different value type and return
ChangeDatas from its search method so we can use the cached
ReviewerSet where appropriate.

Unfortunately for the Reindex program we still need to support not
having a SearchingChangeCacheImpl, which means we have a completely
separate codepath for reading changes from the database.

Change-Id: Ic432a8e48a2bafc8d142b84b25101d95ffb674b7
2016-06-06 12:42:38 -04:00
Dave Borowitz
a6ec1245b4 ChangeIndexer: Disable auto-rebuilding changes
When a DFS ref update of a NoteDb meta ref fails due to a transient
error in the storage backend, we don't want to incur an additional
write to the ref during reindexing, as it may just fail again. Worse,
while BatchUpdate knows to ignore NoteDb write updates when executing
its NoteDbUpdateManager, it can't as easily ignore them while getting
its index futures. Thus an error that was successfully ignored is
likely to be followed by one that can't be.

Work around this for the case of NoteDb writes enabled but reads
disabled, by explicitly turning off auto-rebuilding from
ChangeIndexer. This doesn't help us in the case of NoteDb reads being
enabled, where we have to be able to read the latest NoteDb data from
the ref in order to reindex.

Change-Id: I64000a57ffcf73a9cbef42a6130e1fb4bc8e98f0
2016-06-06 11:22:27 -04:00
David Pursehouse
323247227d Enable and fix 'Statement unnecessarily nested within else clause' warnings
Change-Id: Ida6df4593fc2ab3c11581309b2b4a638229ea093
2016-06-02 10:20:37 +09:00
David Pursehouse
3f99e4e96f Initial implementation of SSH command to index changes
The initial implementation allows to index specified changes. In future
this could be extended to allow indexing of changes by project/branch.

Change-Id: Ia66b086b8bd8d49fe536332d96e3292087fefa01
2016-05-26 16:57:00 +09:00
David Pursehouse
e643ae86b3 SetReviewersCommand: Factor code out to ChangeArgumentParser
Factor code to parse changes from the argument list out to a new
utility class.

Change-Id: I277981f3128d9f958eda2e8ebc7d5d2ca988d18c
2016-05-26 13:49:09 +09:00
David Pursehouse
9dbf755935 Remove 'runsAt = MASTER' from @CommandMetaData annotations
MASTER is the default and does not need to be explicitly specified.

Change-Id: I3dd5812fc7065085d6f668f36548898343e38322
2016-05-25 15:07:19 +00:00
David Pursehouse
b553a48f3b SetReviewersCommand: Fix metaVar for arguments
Change-Id: Ib2c6e7776605b6dad7656b096c6c735dafc6b84b
2016-05-25 15:07:07 +00:00
David Pursehouse
64d0b4cad6 BaseCommand: Add writeError utility method
Move writeError from SetReviewersCommand to BaseCommand. Remove the
similar method from ReviewCommand and adapt the code to the slightly
different signature.

Change-Id: Ie6f326198ff87892f2f7dd6b1ec309d24cb35549
2016-05-25 15:06:32 +00:00
David Pursehouse
34a238048c Consolidate error reporting in SSH commands
Make the commands use the "die" method from BaseCommand, where possible.

Change-Id: I5d2e4d03d59fa62ec988b1e68c60072c5981c10f
2016-05-25 11:00:54 +09:00
Saša Živkov
5177bd1622 ShowQueue: rename taskNameWidth to maxCommandWidth
The taskNameWidth was actually used to limit the width of the command column
value(s). Therefore, rename it to maxCommandWidth.

Change-Id: I473aa0f2efe5c486b7d079581f68528cf38a3df1
2016-05-09 16:26:36 +02:00
David Pursehouse
ccdeae8e64 Use native constructors instead of Guava to instantiate empty collections
It's not necessary to use Guava's helper methods when instantiating
empty collections. Just use the native constructors.

Change-Id: I7f454909b15924ee49e149edf9f053da9f718502
2016-05-04 22:41:39 +09:00
Edwin Kempin
0d67c8427d Merge "Always set VisibleRefFilter on UploadPack" 2016-05-03 10:56:24 +00:00
Edwin Kempin
07952c069a Store SSH keys in git
The public SSH keys of a user are now stored in an authorized_keys
file in the All-Users repository in the refs/users/CD/ABCD branch of
the user.

Storing SSH keys in an authorized_keys file is the standard way for
SSH to store public keys. Each key is stored on a separate line.

The order of the keys in the file determines the sequence numbers of
the keys.

Invalid keys are marked with the prefix '# INVALID'.

To keep the sequence numbers intact when a key is deleted, a
'# DELETED' line is inserted at the position where the key was
deleted.

Other comment lines are ignored on read, and are not written back when
the file is modified.

Supporting a 2-step live migration for a multi-master Gerrit
installation is not needed since the googlesource.com instances do not
use SSH and there are no other multi-master installations.

On creation of an SSH key, RFC 4716 style keys need to be converted to
OpenSSH style keys. Also before adding a key it should be checked that
the key is parseable. Both of this requires classes from SSH libs that
are only available in the SSH layer. This is why the SSH key creation
must be done there. So far this was done in SshKeyCacheImpl, but since
SshKeyCacheImpl needs VersionedAuthorizedKeys to load keys and to mark
keys as invalid, VersionedAuthorizedKeys cannot not depend on
SshKeyCacheImpl as this would be a cyclic dependency. Instead split
out the SSH key creation from SshKeyCacheImpl into SshKeyCreatorImpl.
This way SshKeyCacheImpl depends on VersionedAuthorizedKeys and
VersionedAuthorizedKeys depends on SshKeyCreatorImpl, and there is no
dependency circle.

Change-Id: I8fcc3c0f27e034fc2c8e8ae3612068099075467d
Signed-off-by: Edwin Kempin <ekempin@google.com>
2016-05-02 20:46:54 +02:00
Edwin Kempin
b961a7d03d Always set VisibleRefFilter on UploadPack
There was an optimization to not add VisibleRefFilter if all refs of
the project were visible to the calling user, because in this case it
is not needed to evaluate all rules. This optimization is unneeded
because a similar optimization exists within VisibleRefFilter.
VisibleRefFilter checks if all refs except refs/meta/config are
visible to the calling user and if yes only one separate permission
check for refs/meta/config is done.

Removing the optimization for the case where all refs are visible to
the calling user makes this case only slightly slower, since there is
only one additional permission check for the refs/meta/config branch
now. On the other hand the case where a user can see all refs except
refs/meta/config is a little faster now, since the check if all refs
are visible is removed.

By having VisibleRefFilter invoked always, we can now use it to add
magic refs to the advertised ref set, which is e.g. required to
support a magic refs/users/self ref (implemented in the follow-up
change).

Change-Id: Ic8f29b41f3abf23f99b59260956d543f815253cc
Signed-off-by: Edwin Kempin <ekempin@google.com>
2016-05-02 13:16:28 +02:00
Dave Borowitz
7e638dc280 Support generic indexes in LuceneVersionManager
The original change Id6c58a595 wasn't ready and broke master.
The revert was I5d56a163; this reverts the revert.

Due to a mistake in a condition in LuceneVersionManager#start()
method writer index was never initialized and thus reindexing
of changes was broken. All tests were still passing because the
tests are using SingleVersionModule and not MultiVersionModule.

This reverts commit 6247b52f4129213c62b93bd7f3e5ce9a32084978.

Change-Id: I5856d3ca2ae6d9549b00aa575abd074ea1ff0bd9
2016-04-26 07:52:36 +00:00
David Ostrovsky
08ea694499 Buck: Remove jgit cell
Cross cell support in Buck is considered as experimental feature, with
number of open issues: [1], [2], [3].  Moreover, to make Maven Central
machinery work, it was needed to create symbolic links in source tree.
That broke `buck targets` feature.

Remove it for now, and re-consider to add it later.

[1] https://github.com/facebook/buck/issues/656
[2] https://github.com/facebook/buck/issues/658
[3] https://github.com/facebook/buck/issues/717

Bug: Issue 3954
Change-Id: Ic621a07771f926001df181b46b2169e214ce208a
2016-04-20 22:02:49 +02:00
David Ostrovsky
e3d68ae823 SSH: Don't use providers in commands
SSH commands are created in request scope. That why it's not needed to
use providers for current user and review db, that are also provided in
the same scope. Providers are needed when data is used across scope
boundaries, e.g. PatchSetParser that is bound in singleton scope must
use providers to access current user and review db.

Change-Id: I53b5d1c4004cd0fbbc6b5f6cdb798b2201e2a9be
2016-04-18 20:03:19 +00:00
David Ostrovsky
d4befb84f2 SSH: Don't use singletons with providers
Change-Id: Id2c9b488950a9dd21dff92a960161f00b607695e
2016-04-15 09:21:19 +02:00
David Pursehouse
03974f783e Merge changes from topic 'checkstyle-cleanup-1'
* changes:
  Remove explicit initialization of default values
  Remove redundant 'public' modifiers
  Remove redundant 'final' modifiers
2016-04-13 08:05:24 +00:00
David Pursehouse
0fc9c1a341 Merge changes from topic 'checkstyle-cleanup'
* changes:
  Remove redundant modifiers from interfaces' methods
  Remove redundant 'final' modifier from private native methods
  Checkstyle config: Enable "redundant modifier" and "redundant import"
2016-04-13 07:52:01 +00:00
Dave Borowitz
2e7f2e9a7d Merge "Allow to tag reviews" 2016-04-12 13:55:11 +00:00
Dariusz Luksza
c70e862596 Allow to tag reviews
In order to be able to filter out non-human comments and votes we need
to tag them.

This change introduces new property to the ReviewInput object called
'tag'. This allows us to add some meta information about where this vote
come from. Then in the UI we can show/hide comments and votes that have
different tags.

Also ApprovalInfo, CommentInfo and ChangeMessageInfo were extended to
include value of 'tag' property read from DB.

To be able to persist those data new column (tag) was introduced to
change_messages, patch_set_comments and patch_set_approvals tables.

Change-Id: If6378c5a9f4e0673c00ab348297549f27a06110b
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
2016-04-12 09:49:57 -04:00
David Pursehouse
60ebcdb18e Remove explicit initialization of default values
Default values are false for boolean, 0 for int and char, and null
for object references.

Explicitly initializing a variable to the default value causes it
to be initialized twice.

Enable the Checkstyle warning, and fix occurences of it.

Change-Id: I1971e438fc506c18458b1402fcb01e43fa61ff8c
2016-04-12 21:48:52 +09:00
David Pursehouse
d79c03a7f6 Remove redundant 'public' modifiers
CheckStyle reports 'public' being redundant on the constructor of
ApproveOption#Handler, but removing it causes test failures due to
org.kohsuke.args4j.Option requiring an explicitly public constructor.

Add a suppression for that one, and remove the 'public' in other
places where it's reported.

Change-Id: Ifbcf279ffa783d33b81efc1c675f468c3ea39135
2016-04-12 21:46:12 +09:00
David Pursehouse
e7996de77f Remove redundant 'final' modifiers
The 'final' modifier is redundant on private members, and
on members of 'final' classes.

Change-Id: Ib89f00f3c839cc58be26bc58a2acae8d095bcbc7
2016-04-12 21:45:53 +09:00
David Pursehouse
cbc52bd366 Remove redundant modifiers from interfaces' methods
Change-Id: I64766b8ad8818fbd666cfd960f4460eb5488aa04
2016-04-12 21:44:27 +09:00
David Pursehouse
ad0e4bfe7d Remove redundant 'static' modifiers
enums, interfaces, and field members in interfaces are by default
static, so don't need to be explicitly declared so.

Change-Id: I29270c28be30965767519ad0105a7d93a24e0ab4
2016-04-11 20:24:44 +09:00
David Pursehouse
e0648b43ee Change class modifier order to follow Java Language Spec
Change-Id: I2ac48ef07216bde9d4ba2064bbc979f52c255bde
2016-04-11 19:51:18 +09:00
David Pursehouse
c5ccbf196f Add missing whitespace around keywords, operators and braces
Change-Id: I47923156c25c36d1755765f06e81bb6cdad6fe03
2016-04-11 19:51:18 +09:00
David Pursehouse
a96c5535f7 gerrit-sshd: Remove usages of Throwables#propagate
Change Ic0e0819b5 added some calls to Throwables#propagate, but I
overlooked that previously existing usages had been replaced in
change Id148cb961 due to intention of Guava to deprecate it.

Change-Id: I90e513c85da4fecbe22679ebbf45badbf3a9edde
2016-04-07 15:27:01 +00:00
Alex Blewitt
9b738ddbc4 Enable kerberos authentication to use lower-case
When a kerberos principal authenticates with Gerrit using GSSAPI,
the kerberos identity is typically always in lower case. However,
if it is not in lower case, the authentication will always fail
because auth.userNameToLowerCase is not respected.

Teach the GerritGSSAuthenticator to respect the auth.userNameToLowerCase
option to allow mixed-case kerberos principals to authenticate when
this setting is enabled.

Change-Id: I45783e1ebb4b77cacd248afe657559f243ca069d
Signed-off-by: Alex Blewitt <alex.blewitt@credit-suisse.com>
2016-04-06 09:11:12 +01:00
Alex Blewitt
c7902b4985 Reformat injected parameters in constructor
Split out the injected parameters in the counstructor so that they
are on individual lines. Remove `final` in accordance with the
developer guide.

Change-Id: I266be4322be5dbdec32c11948a9bb7f82faf770a
Signed-off-by: Alex Blewitt <alex.blewitt@credit-suisse.com>
2016-04-06 09:11:12 +01:00
David Pursehouse
97a95031d2 Merge changes from topic 'sshd-1.2.0'
* changes:
  Revert "Add '-T' switch to the SSH connectivity check examples"
  Bump SSHD version to 1.2.0
2016-04-06 06:29:35 +00:00
David Ostrovsky
c0a9d010d4 Bump SSHD version to 1.2.0
This version fixed some regressions from 1.0 release, most notably,
mina backend is fixed again: [1], [2]. It was reported, though,
that this backend is suffering from connection leaks: [3], [4].

Due to [5]  we can now remove GerritServerSession, because we can
register listener for the CloseFuture directly on ServerSession.

Update to minor API changes: [6]. Particularly, Command#destroy()
throws now Exception, that gets propagated into runtime exception.

[1] https://issues.apache.org/jira/browse/SSHD-626
[2] https://issues.apache.org/jira/browse/SSHD-639
[3] https://issues.apache.org/jira/browse/SSHD-595
[4] https://issues.apache.org/jira/browse/DIRMINA-1021
[5] https://issues.apache.org/jira/browse/SSHD-652
[6] 97b73947d5

Change-Id: Ic0e0819b5ddd1bf96cd82f3a142bf1b3375a564a
2016-04-05 19:46:08 +02:00
David Pursehouse
998cacb548 Factor creation of RawInput instances out to RawInputUtil
There are several places where a new RawInput is created. Factor these
out to static methods in a new RawInputUtil class in gerrit-common.

Inspired-by: David Ostrovsky <david@ostrovsky.org>
Change-Id: I10b099e269427b0f887bfb41bbb3f10f46cf2620
2016-04-05 14:22:13 +00:00
Michael Zhou
6247b52f41 Revert "Support generic indexes in LuceneVersionManager"
This reverts commit 1762bacf0cab5b2138432032177339a62f502dc7.

This seems to have broken master. New changes are not shown on the
ChangeScreen when pushed. git-bisect indicates that
Id6c58a595086e7dc22cbc7302169d96c4ccf1aa4 caused the problem.

Change-Id: I5d56a1630224242078b2109941adccc6d6d8d721
2016-03-25 21:20:01 +00:00
Dave Borowitz
1762bacf0c Support generic indexes in LuceneVersionManager
We now loop over all IndexDefinitions and support online reindexing
for each of them independently. They share the single configured
batch indexing threadpool, so running an arbitrary (small) number of
them shouldn't affect performance more than running one of them.

The markReady implementation still does not correctly respect multiple
indexes; this obviously needs to be fixed before adding any new index
types.

Change-Id: Id6c58a595086e7dc22cbc7302169d96c4ccf1aa4
2016-03-20 10:29:58 +01:00
David Pursehouse
f5118d8338 Extract SshKeyInfo from GetSshKeys to extension API
Change-Id: I900a527a5b0d1d2635f54e200fdb5a2f32c0596d
2016-03-16 19:14:53 +09:00
David Pursehouse
4ea3568ff3 Merge branch 'stable-2.12'
* stable-2.12:
  Add tests for reviewing and submitting refs/meta/config changes
  Update 2.11.8 release notes
  Prevent NPE in the SshLog
  Clear the input box after cancelling add reviewer action
  ReviewCommand: Don't add message twice on abandon or restore
  Correct schema migration instructions for MySQL in 2.12.1 release notes
  Documentation: remove submitted status from user search and review
  RebaseChangeOp: adding not null check for PatchSet groups
  Set version to 2.11.8
  Release notes for Gerrit 2.11.8
  Fix keyboard shortcuts for non-US keyboards
  Update commons-collections to 3.2.2
  Update commons-collections to 3.2.2
  Update 2.12.1 release notes
  Fix various formatting glitches in the 2.12.1 release notes
  Set version to 2.12.1
  Update 2.12.1 release notes
  Move the logic out of SuggestReviewers and make super class
  Submit: Point at problematic other commits in tooltip

Change-Id: Icf745ad1c95e7410ae638cfa9e5f0094541de094
2016-03-10 15:22:46 +09:00
David Pursehouse
3d76ce374e Merge branch 'stable-2.11' into stable-2.12
* stable-2.11:
  Update 2.11.8 release notes
  Prevent NPE in the SshLog
  Clear the input box after cancelling add reviewer action
  ReviewCommand: Don't add message twice on abandon or restore
  Set version to 2.11.8
  Release notes for Gerrit 2.11.8
  Fix keyboard shortcuts for non-US keyboards
  Update commons-collections to 3.2.2

Change-Id: Ieef066a51f72556958be6850276361f4ab526fec
2016-03-09 11:22:25 +09:00
Hugo Arès
bc1093d901 Define an extension for user scoped event listeners
There are 2 types of event listeners: unrestricted, which see all
events, and restricted, which only see the events of a particular user.

The unrestricted listeners are registered using an EventListener
extension point and are held in a DynamicSet. The restricted listeners
were not defined by an extension point, needed to be registered using
the EventSource interface and were held in the instance implementing
that interface. In fact, the EventSource interface only existed to
allow to register restricted listeners. The EventDispatcher is
notifying both type of listeners when an event is posted.

The main motivation for defining EventSource and EventDispatcher
interfaces was to eventually allow a plugin to replace their core
implementations. The problem is, if the listeners are held in the
instance of EventSource provided by the core, they will no longer be
notified when an EventSource instance is loaded from a plugin since all
the listeners will be registered to the wrong instance.

Fix the inconsistency between both type of listeners by removing the
EventSource interface. Create a sub-interface of EventListener called
UserScopedEventListener and expose it also as an extension point.

Now that both type of listeners are held in a DynamicSet maintained by
the core, a plugin will be able to replace the core EventDispatcher.

Change-Id: Ieecb1d6f0ec64d43a0350ec1c133b6ecc189db67
2016-03-08 13:28:33 -05:00
Dariusz Luksza
586c141db0 Prevent NPE in the SshLog
This NPE can happen when command was destroyed (probably by user
canceling the ssh operation) using CommandFactoryProvider.onDestroy
before it was even logged. In this case we provide meaningful audit
entry instead of not-so-nice NPE with stack trace in the logs.

Change-Id: If15a9475a4d98ade9a263b4ed4dcf5a1dd694731
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
2016-03-08 15:42:59 +01:00
David Pursehouse
8c49edc4d3 ReviewCommand: Don't add message twice on abandon or restore
When abandoning or restoring a change via the --abandon or --restore
option, and giving a message with the --message option, the message was
being added twice. Once by the 'review' and once by the abandon or
restore.

This was already fixed once in change I9c7e81599 which was included in
Gerrit version 2.6, but was then re-introduced by I2240759ba which was
included in version 2.9.

Fix it, and add an acceptance test to make sure it doesn't get broken
again.

Change-Id: I92f8fd98d75c2b1dd96c91f404be3943109c3519
2016-03-08 05:05:44 +00:00
Luca Milanesio
fc1ed9cb90 Set default sshd backend to NIO2
The Apache Mina project recommends NIO2; since If047c3a2 the sshd MINA
backend is partly broken as well, one more reason to abandon it as
default value.

Using a more stable and recommended backend provides a better 
out-of-the-box experience for the new Gerrit installations.

Change-Id: I48c69dd3e6c9c05afe5da35a84c9b2de826e01e6
2016-03-01 23:09:08 +00:00