70 Commits

Author SHA1 Message Date
David Pursehouse
1111684821 Squash redundant string concatenations introduced by google-java-format
Reformatting the code with google-java-format tool in change Id5f3c6de9
resulted in wrapped lines being unwrapped to the new 100 columns limit.

In cases where the wrapped line was wrapped on a string concatenation,
the resulting long line now includes redundant concatenations. See the
upstream issue [1] for an example of this.

Squash the redundant concatenations with:

  git ls-files | grep java$ | xargs sed -i '' 's/" + "//g'

(note: this also resulted in a couple of unwanted changes; those are
manually undone.)

[1] https://github.com/google/google-java-format/issues/122

Change-Id: I7348413ae460c8c7a0b0c72dab0a1ae7275a2ec3
2017-02-17 08:57:46 +09:00
Dave Borowitz
9189e67c3d Assign unused Future return value to a variable
Error Prone plans to make this pattern into a compile error; this avoids
future breakage.

In some of these cases, it's not obvious that ignoring the return value
is the correct thing to do; the hope is that the construct is ugly
enough to make the author think twice. In many cases though, it's clear
that a locally-created Runnable or Callable already does its own error
handling, so we can leave a comment alongside the ignored return value.

Eventually many of these should be audited again, and we can replace
some of the @SuppressWarnings with Error Prone's @CanIgnoreReturnValue.
That much is left for future cleanup.

Change-Id: Ia989214d85e0d6c387e388a77178e0b5c4bf2498
2017-02-07 10:43:12 -05:00
Dave Borowitz
292fa154c1 Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time.
google-java-format is Google's standard formatter and is somewhat
inspired by gofmt[1]. This commit formats everything using
google-java-format version 1.2.

The downside of this one-off formatting is breaking blame. This can be
somewhat hacked around with a tool like git-hyper-blame[2], but it's
definitely not optimal until/unless this kind of feature makes its way
to git core.

Not in this change:
* Tool support, e.g. Eclipse. The command must be run manually [3].
* Documentation of best practice, e.g. new 100-column default.

[1] https://talks.golang.org/2015/gofmt-en.slide#3
[2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html
[3] git ls-files | grep java$ | xargs google-java-format -i

Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3
Signed-off-by: David Pursehouse <dpursehouse@collab.net>
2017-02-07 10:04:39 +09:00
David Ostrovsky
fdbfcad77d Remove Buck based build
Bug: Issue 5302
Change-Id: I6e860446ef30ff0ad1c7c49fc0e39d39d921820b
2017-01-23 12:44:58 +00:00
David Ostrovsky
fa18907d7f Bazel: Reformat build files
Reformat the Bazel build files with the buildifier tool [1].

The style is different for Bazel files. Most notably, indentation level
is 4 spaces instead of 2, and " is used instead of '.

[1] https://github.com/bazelbuild/buildifier

Change-Id: I95c0c6f11b6d76572797853b4ebb5cee5ebd3c98
2016-12-07 11:33:07 +00:00
Saša Živkov
9c87603a8b Support for setting diskLimit from CacheModule bindings
For some persistent caches we may want a larger default diskLimit than
the overall default of 128MiB.

Change-Id: I9f8c85d7187d2edfe5ba48ea27c7b5f5e37e7abe
2016-09-22 22:51:33 +02:00
Dave Borowitz
e45363dcbd Use some Java 8 features
These suggestions were produced by a refactoring tool that we have;
the particular decisions it made were based on heuristics over which I
have no control. Some suggestions were edited for brevity, and to omit
references to unreleased Guava features.

Change-Id: I9deac0afd6eda8fdc5a369816a4ee2bbe16924ba
2016-09-20 15:39:47 -04:00
David Pursehouse
83ab340d3f Remove redundant specification of type arguments
Change-Id: I5b084440bae3ad66604acb7308426ba2119ce7f3
2016-09-20 10:24:34 +02:00
Edwin Kempin
93d1d753fa Merge "Add advanced H2 option handling" 2016-07-11 12:50:20 +00:00
Björn Pedersen
64af3ad561 Add advanced H2 option handling
Add separate configs for h2CacheSize for the cache tables and
normal persistent H2 dbs. While the caches offer further options
to limit their total size, normal table can grow without bounds,
so different H2 memory cache size seem reasonable.

H2 offers an auto server mode
(http://www.h2database.com/html/features.html#auto_mixed_mode).

Add a flag to enable this mode. This allow to run command line utils
that access the database (e.g.RebuildNoteDb) also for the embedded H2
database.

Add a flag to enable auto-server mode for the H2-based caches as
well.

Change-Id: Id4fe76363bc209064485296d4dd1697e0de0f235
2016-07-11 08:54:25 +00:00
Dave Borowitz
882acb39b3 H2CacheImpl: Ignore errors due to renamed classes
Change-Id: Ifb75d79c4897d22723c889ec176f37e2f5d18fda
2016-07-01 17:44:28 +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
David Pursehouse
65dba820d4 H2CacheFactory: Make logger private
Change-Id: I632aa3d116cf362962f31e3692fcea65dafae2c7
2016-05-07 21:25:36 +09:00
David Pursehouse
45aa8ca215 Add missing newline at end of files
Change-Id: Id7d6ed3ddd68b50c528889ac09d114cbdaef45aa
2016-05-04 13:48:11 +00: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
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 Pursehouse
c5ccbf196f Add missing whitespace around keywords, operators and braces
Change-Id: I47923156c25c36d1755765f06e81bb6cdad6fe03
2016-04-11 19:51:18 +09:00
Saša Živkov
e7ae7f4d2f Merge "Make H2 database cache size configurable" 2016-02-24 10:42:58 +00:00
David Ostrovsky
64d4bdf946 Buck: Emulate real JGit project structure in its own cell
I39f2d5d7 isolated jgit in its own cell, that is based on this JGit
Buck build implementation: [1]. Migration was done seamlessly, meant
that single BUCK file in lib/jgit represents JGit cell root location.
However, the real structure of JGit project is divided to number of
different sub-projects. To map between simplified JGit cell in gerrit
and real JGit project structure in JGit project, java_library() rules
were added to root BUCK file in JGit project that work like proxy to
real rules located in JGit sub-projects. For example //:jgit in JGit
tree was implemented as:

  java_library(
    name = 'jgit',
    exported_deps = ['//org.eclipse.jgit:jgit'],
    visibility = ['PUBLIC'],
  )

Such proxies are needed for every artifact that is referenced from
gerrit build and make Buck build implementation unnecessary verbose.
Moreover this introduced some subtle issues, like using JGit
dependencies in context of java_doc rules, where $(location :foo) macro
is unable to resolve the underlying files because java_library with
exported dependencies only do not have association with output file.
An attempt to replace java_library with only exported dependenies with
prebuilt_jar: [2] that depends on the real artifact introduced another
problem with assembly of gerrit.war, because now jgit.jar is twice in
the classpath (because prebuilt_jar has output file association). To
fix this we would need to filter potential duplicates in the assembly
process of gerrit.war.

Instead of using proxy approach and to try to provide yet another
workaround to subtle problems, emulate the JGit project structure and
reference directly the same artifacts paths within gerrit JGit cell
in gerrit build:

  deps = [
    '@jgit//org.eclipse.jgit:jgit',
  ],

This simplifies JGit Buck build implementation, as we wouldn't need to
proxy all artifacts referenced from gerrit build from the root build
file. And this would fix all remaining issues.

This approach make gerrit build slightly more verbose. JGit upgrade
process would need to touch 4 files instead of only one. But given that
the Gerrit/JGit development integration is important feature, we would
like to support (as this integration attempt shows: [3]) in our build
toolchain, this overhead is justified.

With this change, the root build file in JGit project can be stripped:
[4].

[1] https://git.eclipse.org/r/61938
[2] https://git.eclipse.org/r/66547
[3] https://gerrit-review.googlesource.com/61892
[4] https://git.eclipse.org/r/66562

Change-Id: I2d278f80d0fedc4c5e9943804873f57145877dfe
2016-02-14 11:46:49 +01:00
Saša Živkov
f313457af5 Make H2 database cache size configurable
H2 database by default uses up to the half of the amount of memory
available for the virtual machine (Runtime.getRuntime().maxMemory())
as described in [1]. In some cases this could contribute to an
out-of-memory error in Gerrit.

Introduce a new configuration parameter cache.h2CacheSize to limit
the H2 memory cache size. In this change this parameter is applied
to all persistent caches.

[1] http://www.h2database.com/html/features.html#cache_settings

Change-Id: I0217d4114f528275ca4094e0f3414ef23af80677
2016-02-12 10:21:07 +00:00
David Ostrovsky
17bb3dbfe8 Buck: Allow to consume JGit from its own cell
Consume JGit as first third party library from its own cell. Normally
the cell is defined as lib/jgit directory. It can be easily replaced
with CLI:

  buck build --config repositories.jgit=path/to/dev/jgit gerrit

or tweaking the .buckconfig:

  [repositories]
    jgit = path/to/dev/jgit

The former approach is sufficient to build and run the test from the
CLI, the latter is needed to generate eclipse project.

To isolate the JGit rules in its own cell some refactoring was needed.
JGit patch for GWT module was moved to gerrit-patch-jgit project, and
some symlinks were needed for maven machinery to work. include_defs()
doesn't work for now across cell boundaries, and native `buck fetch`
feature still has some limitations: [1]. Moreover, excluding paths,
unsigning JARs and license linking should be re-implemented on top
of it.

[1] https://github.com/facebook/buck/issues/602

Test Plan:

Normal gerrit build and the build with hijacked JGit cell should work
in both standalone (gerrit.war) and Eclipse environment. Note, that
to test --config repositories.jgit=path/to/dev/jgit use case, the most
recent JGit tree must be used, that contains Buck driven build
implementation.

Change-Id: I39f2d5d75bbac88804406d6242b5e714f4916926
2016-02-09 00:40:08 +00:00
Dave Borowitz
e47caabfa8 H2CacheImpl: Support get(K, Callable<? extends V>)
This method does not come for free from AbstractCache. Fortunately, it
is easy to implement by wrapping the provided Callable.

Change-Id: Ia3ad46dc87e54ddc6e8ee245e065ed4686c72e10
2015-08-07 17:04:18 -07:00
Shawn Pearce
e9a29309e3 Fix H2CacheImpl copyright header
Google did mean to put this under Apache License, Version 2.0.

Change-Id: I04b8843941535da666735281e222c218c566c53d
2015-08-07 17:03:22 -07:00
Urs Wolfer
5e90c63dea Use try-with-resources statements
- instead of finally blocks
- in cases of missing try-finally

Change-Id: I94f481a33d8e6a3180c436245d6e95e4d525280c
2015-06-23 21:11:57 +02:00
David Pursehouse
4aedf71c9f Merge branch 'stable-2.11'
* stable-2.11:
  Correct documentation of required capabilities for listing plugins
  Always show 'Not Current' as state when looking at old patch set
  Log IOExceptions on update of project configuration
  H2: Don't show stack trace when failing to build BloomFilter
  Update CodeMirror to 5.0 and consume from Maven Central
  Add support to consume CodeMirror from org.webjars on Maven Central
  Fix slave cloning issue by binding Scanning rather than Searching /index
  Bump JGit version to 3.7.1.201504261725-r
  Hybrid OpenID/OAuth: Check for session validity during logout
  RestApiServlet: Leave OutputStream open when flushing base64 padding
  RestApiServlet: Flush pending padding as well

Change-Id: Ib7fa8885cafea1e2dc300257c4dbaee3ef132df2
2015-04-30 11:56:32 +09:00
David Pursehouse
bbd54fa065 H2: Don't show stack trace when failing to build BloomFilter
Only show the exception message.

Change-Id: I210ed24e5baaf4f7b6f62f10f5c0fa448e9079d8
2015-04-28 07:43:29 +00:00
Dave Borowitz
62e67bede7 SitePaths: Convert site_path itself to Path
Also convert all remaining references that expect to resolve site_path
to a File, notably LocalDiskRepositoryManager.

Change-Id: I5ef6f6e3d7b3fe0418a470b079b4cc04bc9be4f6
2015-03-03 11:48:05 +09:00
Dave Borowitz
b078dd6308 Convert H2CacheFactory to use Path
Change-Id: I8528d95e2464c4dd0845cdfa5a7b0b1e52902375
2015-02-24 09:19:46 -08:00
Dave Borowitz
9625637eb4 Use AutoCloseable gwtorm/jdbc instances
Bump the gwtorm version, since gwtorm changed Schema and
StatementExecutor to be AutoCloseable. This allows us to simplify many
callers.

While we're in there, fix some usages of more javax.sql classes like
Statement that became AutoCloseable in Java 7.

Change-Id: Icf86fdb52a499563ccf2a7c761cc498ad758d99c
2015-01-13 11:23:40 -08:00
David Pursehouse
41abb376ca Enable and fix Eclipse warnings about redundant type arguments
Since Java 7 it is possible to replace the type arguments required to
invoke the constructor of a generic class with an empty set of type
parameters (<>) as long as the compiler can infer the type arguments
from the context [1].

Enable the Eclipse warning about redundant type arguments, and remove
the ones it warns about.

[1] http://goo.gl/SG21kM

Change-Id: I422882949a6a6a57391580d881f73120b2843a0e
2014-10-31 08:27:01 +00:00
David Pursehouse
75ad80aa57 Remove unnecessary suppression of cast warning in H2CacheFactory
Change-Id: I1d2ef58029d9c439aa0cf0f195d66a4ed63ff40e
2014-10-30 10:06:40 +09:00
David Ostrovsky
8dc720ed9b Move TimeUtil from gerrit-server to gerrit-common
Change-Id: Ib2cfcfd4974ab04e733007e5835fc1364cc36ee9
2014-10-06 07:53:44 -07:00
Saša Živkov
1c48a7ee1c Revert "Use javax.inject.Inject instead of com.google.inject.Inject"
This reverts commit 5db3bba3e2d85662bacedc5d2f215fff7d8d2805.

I was too fast to submit 5db3bba. Besides forgetting to submit the
referenced changes in some submodules some people reported issues
with the interception of the javax.inject.Inject in some JEE containers.

Change-Id: I931ad329d2e7be6f6ce804b8395489a021c8240b
2014-09-30 10:53:50 +02:00
Dave Borowitz
5db3bba3e2 Use javax.inject.Inject instead of com.google.inject.Inject
The Guice team is discouraging use of its specific annotation where
possible, to increase JSR330 compliance.

Leave optional injection alone for now, which needs to be manually
replaced with OptionalBinder.

Change-Id: I4f53a518ba6f36fd67af12f3540dc44cbad07ff8
2014-09-29 16:36:18 -07:00
Saša Živkov
98adfd5c53 Honor expireAfterWrite in the H2CacheImpl
The H2CacheImpl didn't honor the expireAfterWrite. This had an effect
that persisted entries never expired. For example, the web_sessions
cache entries didn't expire after their maxAge was reached.

Change-Id: I3a7c754ee05fe9ac92d96652db4b862bb597eba1
Signed-off-by: Saša Živkov <sasa.zivkov@sap.com>
Signed-off-by: Adrian Görler <adrian.goerler@sap.com>
2014-09-15 16:37:53 +02:00
Edwin Kempin
42c9cf61c8 Add REST endpoint to list caches
GET /config/server/caches/ lists the server caches. Caches defined by
plugins are included.

The implementation of the SSH show-caches was adapted so that it uses
the new REST endpoint to get the information about the caches. This
avoids code duplication.

For disk caches a new interface was introduced in gerrit-server. This
is done because the list caches REST endpoint needs extra information
for disk caches which can only be provided by the disk cache, aka
H2CacheImpl. H2CacheImpl is defined in gerrit-cache-h2, but
gerrit-server doesn't have a dependency on it and hence can't use
instanceof to check whether a cache is a disk cache. Adding this
dependency is not wanted and also not possible (because
gerrit-cache-h2 already depends on gerrit-server and we can't have
cycles in the dependencies).

Change-Id: I21bf6e114310f98051a0a8db01012511f58d4add
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
2014-05-28 09:29:12 +02:00
David Ostrovsky
e73ae61339 Apply "type inference for generic instance creation" Java 7 feature
Change-Id: Ia14802c903ca67b9d94dc6038d70b0e9644bc621
2014-04-26 15:27:57 +02:00
Saša Živkov
218c6b69c2 Allow creation of persistent caches after server is started
2e1cb2b8495761a7e9abc09ebca24ca6bbf2afbe switches from Ehcache to Guava
for providing caching in Gerrit and claims that one of the advantages of
using Guava is that it enables caches to be build at any time, rather
than only at server startup. Therefore, I guess it is OK to remove the
precondition check which prevents creation of caches once the server was
started.

This enables plugins to create own persistent caches when they are
installed.

Change-Id: I28b1a140c58f9967e6d1dacd61ddd021b48c8ad5
2014-03-10 17:22:46 +01:00
David Pursehouse
85c458b4d8 Merge "Remove unused @SuppressWarnings" 2013-11-29 08:08:53 +00:00
Shawn Pearce
74966d5b04 Remove unused @SuppressWarnings
Eclipse Kepler says these are not necessary.

Change-Id: Ie7af85e512532b084a1a13df37792ffec11680fc
2013-11-29 09:03:35 +01:00
Shawn Pearce
72fb6cc514 Remove unused .gitignore
These were necessary only for the Maven based build.

Change-Id: Ie26669e6ccae60a52d2db1b8ad362e2fa88a26f2
2013-11-28 22:56:51 -08:00
David Ostrovsky
c53fd3ae49 Delete eclipse left-over files from the Maven poop era
Change-Id: Ie3a75e8c6a2d274cd39e362259ab20cff474eb8d
2013-11-28 22:55:09 -08:00
alex.ryazantsev
bbf93f85cf Remove unnecessary local variables
Change-Id: I20ee3f7258d7e98b9c57b49c21b1e2d1582f626f
2013-11-19 13:56:25 -08:00
Dave Borowitz
ec6fca88a5 Make LifecycleModule inherit from FactoryModule
Cut down on a bunch of one-offs of install(new *Module() {...}) by
choosing a more appropriate base module class. This doesn't solve all
such cases, for example RpcServletModule must still inherit from
ServletModule, but it does clean up some code. (And who knows, fewer
modules may even mean faster startup time.)

Change-Id: Ie1aed05d0a64f7f11b121c9a637bb30d80e9a595
2013-11-13 16:14:00 +00:00
Shawn Pearce
f5016f461b Merge branch 'stable-2.7' into stable-2.8
* stable-2.7:
  Bump JSch to 1.5.0 to fix Java7 compatibility
  Extend AddBranchResult with toString method implementation
  Get rid of JdbcSQLException while numbers are read from cache

Conflicts:
	gerrit-common/src/main/java/com/google/gerrit/common/data/AddBranchResult.java
	pom.xml

Change-Id: Ic3bae80a40bfa2d8e8eee598bcdbd771b99cbeda
2013-11-05 11:15:47 -08:00
Shawn Pearce
5d1ce02e9d Merge branch 'stable-2.6' into stable-2.7
* stable-2.6:
  Bump JSch to 1.5.0 to fix Java7 compatibility
  Extend AddBranchResult with toString method implementation
  Get rid of JdbcSQLException while numbers are read from cache
2013-11-05 11:14:11 -08:00
Jacek Centkowski
b294b033bb Get rid of JdbcSQLException while numbers are read from cache
Exception org.h2.jdbc.JdbcSQLException: Hexadecimal string with odd
number of characters: "0" is thrown when number with value 0 or string
with value "0" is stored in H2Cache and read is performed.
The fix modifies implementation so that Java de-serialization is
performed even for built-in (e.g. Integer) types.

Change-Id: I953487cb75b3712e8825a74613977425873507a1
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
2013-10-30 07:21:16 -07:00
Dave Borowitz
1d69c2e8ce Add TimeUtil.nowTs() to create a new Timestamp
Change-Id: I5b2457703a5812c99cd71dc2ad87e45ae5d665e2
2013-10-16 10:10:55 -07:00
Dave Borowitz
46b1ac8f07 Use DateTimeUtils.currentTimeMillis() to get current time
This method from joda-time supports replacing the system time provider
with a custom provider for tests. Since it is verbose, and we expect
more related methods, put it in the more succinct TimeUtil.nowMs().

This commit covers the trivial cases in the server side; client-side
code still uses System.currentTimeMillis().

Change-Id: I6c56e8c5bbb0cf7b0271e431d1ebdb532967b9e8
2013-10-16 10:10:55 -07:00
David Pursehouse
99776b87c8 Replace Funnels.stringFunnel with Funnels.unencodedCharsFunnel
In Guava 15.0 the `stringFunnel()` method is deprecated in favor
of `unencodedCharsFunnel()`.

Change-Id: Ie99e3305f5ec497a36033142283dd5994803a254
2013-10-01 12:27:18 +09:00