Fix deadlocks in SubIndex shutdown

Because WorkQueue.Module and LuceneIndexModule are in the same
Injector, the ordering of their LifecycleListeners' stop() methods is
not defined. Tasks on the queue, e.g. background mergeability checks,
might try to perform index writes after the SubIndex is shut down.

Shutting down the SubIndex stops the ControlledRealTimeReopenThread,
which immediately sets the generation to Long.MAX_VALUE and notifies
any callers currently waiting on a generation. But the call sites
using NrtFutures in LuceneChangeIndex are not calling NrtFuture.get,
which waits on a generation; they are using Futures.allAsList, which
depends on addListener.

So, we need to check the generation number in the call to addListener
as well as in in get.

This may also improve performance, since futures in some cases will
not need to wait for a reopen thread refresh cycle before notifying
their listeners.

Change-Id: I0ec3e315638a90dd5da3cf7f0d2cc50599a5bb36
Ensure NrtFutures are notified promptly of new search generation

The internal waiting generation counter in
ControlledRealTimeReopenThread is only increased when
waitForGeneration is called. This controls whether the min or max
refresh time is used for waiting. Because NrtFuture.get is not called
directly and listeners may be used instead, this was not guaranteed
to happen, leading to long delays. Fix this by doing a dummy wait for
0ms at future construction time.

Change the order of refresh listener initialization so any
removeIfDone calls are made only after the internal listener within
ControlledRealTimeReopenThread updates its searching generation.

Change-Id: I0edf4a3d38a160496afaf0587cf14b6fee2f2aa5
Prevent draft changes from being abandoned

When a draft change is abandoned it is currently published to all
users by setting the status to ABANDONED.  Restoring the change will
effectively publish the change as /restore sets the status to NEW.

To not complicate the workflow, prevent draft changes from being
abandoned.

Change-Id: If747264fa66a2139e0d8f13987125d853ec3bed9
Don't show the submit button for draft patch sets

Currently the button is enabled for all open changes, but if
the patch set is a draft, pressing it results in an error.

Change-Id: I382fc9330b73d357c00ba0209f18d2c1584e9256
Do not refresh group list if filter did not change

Every time key up event is raised in the group list filter box, the
group list was getting refreshed even if the filter did not change
(e.g. moving the cursor was refreshing the list).

Only call the refresh if the filter is changed or enter is pressed.

Change-Id: I64d24eeae08f35723b401fffd9a3e8ed84c8d00c
Add option 'n' and 'S' to groups REST API to limit group results.

List groups endpoint now has an option to limit the number of results
returned and a start to define nonzero offset in order to support
groups pagination.

Add and document 'n' and 'S' function to allow query group list from
a specified limit and start.

Both options will then be used to render group list with pagination
in web UI.

Change-Id: Ibf244b1cfe83c56dc1c23aabf70a55697b52c835
Implement pagination in group list screen

Group list screen now uses pagination similar to project list screen.
The number of groups displayed is determined by the 'Maximum Page
Size' in user preferences.

Change-Id: Id4649fda4b06ef62bf9d630460aeefc1c5f65989
Enable automatic close changes on 'refs/meta/config'

Bug: issue 2569
Change-Id: Ic192daa21cfcc1f26fa9f00feb14f41013a29fb9
rest-api-groups.txt: Correct input examples to use [] for lists

Change-Id: I109bced2f9309dd20a7962d5fdbcd999fa6f87ff
(cherry picked from commit a2bf824fa154b7cb51e8f89df8321d02c25f3425)
Fix REST example for removing included groups from a group

Change-Id: I8047fa702c12150232ebf62bcd16a27eb638c5e8
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
Fix: Wrong exception mapping in ReceiveCommmits

When IOException is thrown in insertPatchSet() or
insertChange(), e.g. ClosedByInterruptException thrown
from AutoCommitWriter.manualFlush(), it will be
mapped to OrmException with error message
"Error updating database" by ORM_EXCEPTION, this becomes
misleading when the administrator analyzes the error log.

Fixed. Replaced the ORM_EXCEPTION with INSERT_EXCEPTION.

Change-Id: I49a6dfea7e49df72db775989a3a0501f60db76d2
Bump SSHD version to 0.10.1 and enable nio2 backend

46f8488a78742799a4f5f781279c8955460e7964 removed nio2 backend because of
a bug [1].  Given that the bug is fixed and released, enable it again.

Another problem was also fixed and released [2].

Upgrade to the official version 0.10.1 makes Gerrit's own custom patch of
SSHD and hosting it on Google bucket unnecessary.

[1] https://issues.apache.org/jira/browse/SSHD-252
[2] https://issues.apache.org/jira/browse/SSHD-255

Bug: Issue 2406
Change-Id: I6668f6194427f153e1982e14b3936d2f3132fa7d
Update sshd to 0.11.0

Fixes a few issues including a null pointer exception [1] that causes
ssh commands to hang.

It also adds server driven rekeying after 1G bytes of data transferred,
which is a useful security feature.

[1] https://issues.apache.org/jira/browse/SSHD-307

Change-Id: I441995eaf76e4fe53f7991f5aef00e062900791b
Fix: wrongly throw 'commit already exists' exception

The reason is the ReplaceRequest.validate() should compare
to 'newCommit' of ReplaceRequest instance, else when
ReceiveCommits.autoCloseChanges() working on the second one
of a series of commits, the 'commit already exists(in the project)'
will be thrown wrongly.

Fixed.

Bug: issue 2607
Change-Id: Ib4db351d39f85d57ccf532da4d6422bdcbb88105
Remove "Click to" from topic edit button's tooltip

Making it more consistent with the tooltips on the other
buttons.

Change-Id: I3f26b08866452eb666da2a23be7201528b5f81a7
Merge changes I441995ea,I6668f619 into stable-2.8

* changes:
  Update sshd to 0.11.0
  Bump SSHD version to 0.10.1 and enable nio2 backend
SideBySide2: Fix failure to load from "ISE EditIterator out of bounds"

Intraline edit information can include a negative delta on the B
side of an edit, for example:

  {
    a: [...],
    b: [...],
    edit_a: [[4, 11], [14, 12]]
    edit_b: [[4, 66], [37, 41], [-2, 1]]
  }

In the edit_a or edit_b block the list pairs are the number of
characters to advance since the last position. -2 encodes the edit
iterator has to go back 2 positions to return the correct value.

This situation arose from an intraline edit list of:

  REPLACE( 4-15,  4- 70),
  REPLACE(29-41,107-148),
  INSERT (62-62,146-147)

The EditList is sorted by the beginA values, where 29 < 62. This
forced the final INSERT to sort in the edit_b list after the REPLACE
at 107. Since 146 < 148 the final edit_b entry was encoded with a
negative delta (148 - 146 = -2).

Update the UI code to accept a negative delta in the iterator. There
are already many /diff responses with negative delta that will be
cached by browsers for 7 days.

There may be other issues with the intraline diff algorithm that
allows it to create this final INSERT span within the REPLACE
span, but the code is essentially unchanged for many years in
Gerrit Code Review. Handle the corner case for now in the UI while
the server code is investigated further.

Change-Id: Ibec0fc845356af7c02f25acac23c4e709f7c3a34
Added global request handlers to SshDaemon

Since sshd 0.10.0 the handling of global requests
is refactored out of [1] ServerConnectionService.globalRequest
method to AbstractConnectionService.globalRequest.
The implementation has been refactored into a list
of RequestHandlers, one for each type of request.

These handlers are never set in SshDaemon constructor
as they should be.

See SshServer.getUpDefaultServer line 503

Change-Id: I7a38145c021538838d11427950db66eb57a50582
Bump bouncycastle verison to 1.49

Many bugs were fixed since version 1.44 that we are using[1].

JARs artifacts were renamed.

[1] http://www.bouncycastle.org/releasenotes.html

Change-Id: Ie2b22328c77b0100dfff61139b737894b88e7664
Install open ssl jar into Gerrit site for bouncycastle crypto provider

937d527ac0e4ee685fccb60ae604406a6638daec upgraded bouncy castle to 1.49.

The old JAR artifact was renamed and split to number of files. For Gerrit
two libraries must be downloaded and be available under `$gerrit_site/lib`:

* bcprov-jdk15on-149.jar
* bcpkix-jdk15on-149.jar

Update download logic to support a basic concept of required dependencies,
ensuring BC provider is downloaded if the SSL library is installed by init.

Change-Id: I60092ebe136f78a5649fe8512737275f50195a34