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
This commit is contained in:
David Ostrovsky 2015-12-03 23:18:25 +01:00 committed by David Pursehouse
parent 254da3a316
commit 17bb3dbfe8
36 changed files with 95 additions and 61 deletions

View File

@ -22,7 +22,7 @@
[java]
jar_spool_mode = direct_to_jar
src_roots = java, resources
src_roots = java, resources, src
[project]
ignore = .git, eclipse-out
@ -34,3 +34,7 @@
[test]
excluded_labels = manual
[repositories]
jgit = lib/jgit

View File

@ -14,9 +14,9 @@ DEPS = [
'//lib/httpcomponents:httpclient',
'//lib/httpcomponents:httpcore',
'//lib/jetty:servlet',
'//lib/jgit:junit',
'//lib/log:impl_log4j',
'//lib/log:log4j',
'@jgit//:junit',
]
PROVIDED = [
@ -29,10 +29,10 @@ PROVIDED = [
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//lib:gson',
'//lib/jgit:jgit',
'//lib:jsch',
'//lib/mina:sshd',
'//lib:servlet-api-3_1',
'@jgit//:jgit',
]
java_binary(

View File

@ -32,9 +32,9 @@ java_library(
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
'//lib/mina:sshd',
'@jgit//:jgit',
],
visibility = [
'//gerrit-plugin-api/...',

View File

@ -8,8 +8,8 @@ java_library(
'//lib:guava',
'//lib:h2',
'//lib/guice:guice',
'//lib/jgit:jgit',
'//lib/log:api',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -44,9 +44,9 @@ java_library(
'//lib:gwtjsonrpc',
'//lib:gwtorm',
'//lib:guava',
'//lib/jgit:jgit',
'//lib/joda:joda-time',
'//lib/log:api',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -8,8 +8,8 @@ DEPS = [
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
'@jgit//:jgit',
]
java_library(
@ -45,12 +45,12 @@ java_test(
':gpg',
':testutil',
'//gerrit-cache-h2:cache-h2',
'//gerrit-lucene:lucene',
'//gerrit-lucene:lucene',
'//gerrit-server:testutil',
'//lib:truth',
'//lib/bouncycastle:bcpg',
'//lib/bouncycastle:bcprov',
'//lib/jgit:junit',
'@jgit//:junit',
],
source_under_test = [':gpg'],
visibility = ['//tools/eclipse:classpath'],

View File

@ -64,7 +64,7 @@ java_test(
':client',
'//lib:junit',
'//lib/gwt:user',
'//lib/jgit:jgit',
'@jgit//:jgit',
],
source_under_test = [':client'],
vm_args = ['-Xmx512m'],

View File

@ -33,10 +33,10 @@ java_library(
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:jgit-servlet',
'//lib/log:api',
'//lib/lucene:lucene-core-and-backward-codecs',
'@jgit//:jgit',
'@jgit//:jgit-servlet',
],
provided_deps = ['//lib:servlet-api-3_1'],
visibility = ['PUBLIC'],
@ -69,9 +69,9 @@ java_test(
'//lib/easymock:easymock',
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/joda:joda-time',
'@jgit//:jgit',
'@jgit//:junit',
],
source_under_test = [':httpd'],
# TODO(sop) Remove after Buck supports Eclipse

View File

@ -31,11 +31,11 @@ java_library(
'//lib:gwtorm',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/jgit:jgit',
'//lib/log:api',
'//lib/lucene:lucene-analyzers-common',
'//lib/lucene:lucene-core-and-backward-codecs',
'//lib/lucene:lucene-misc',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -19,8 +19,8 @@ java_library(
'//lib/commons:codec',
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -9,12 +9,33 @@ gwt_module(
gwt_xml = SRC + 'JGit.gwt.xml',
deps = [
'//lib:gwtjsonrpc',
'//lib/jgit:Edit',
':Edit',
],
provided_deps = ['//lib/gwt:user'],
visibility = ['PUBLIC'],
)
gwt_module(
name = 'Edit',
srcs = [':jgit_edit_src'],
deps = [':edit_src'],
visibility = ['PUBLIC'],
)
prebuilt_jar(
name = 'edit_src',
binary_jar = ':jgit_edit_src',
)
genrule(
name = 'jgit_edit_src',
cmd = 'unzip -qd $TMP $(location @jgit//:jgit_src) ' +
'org/eclipse/jgit/diff/Edit.java;' +
'cd $TMP;' +
'zip -Dq $OUT org/eclipse/jgit/diff/Edit.java',
out = 'edit.src.zip',
)
java_library(
name = 'server',
srcs = [
@ -25,7 +46,7 @@ java_library(
],
deps = [
'//lib:gson',
'//lib/jgit:jgit',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)
@ -35,8 +56,8 @@ java_test(
srcs = glob(['src/test/java/**/*.java']),
deps = [
':server',
'//lib/jgit:jgit',
'//lib:junit',
'@jgit//:jgit',
],
source_under_test = [':server'],
visibility = ['//tools/eclipse:classpath'],

View File

@ -15,9 +15,9 @@ BASE_JETTY_DEPS = [
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
'//lib/log:log4j',
'@jgit//:jgit',
]
DEPS = BASE_JETTY_DEPS + [
@ -176,8 +176,8 @@ java_test(
'//lib:junit',
'//lib/easymock:easymock',
'//lib/guice:guice',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'@jgit//:jgit',
'@jgit//:junit',
],
source_under_test = [':pgm'],
)

View File

@ -39,10 +39,10 @@ java_library(
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/joda:joda-time',
'//lib/log:api',
'//lib/mina:sshd',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -17,10 +17,10 @@ gwt_module(
exported_deps = [
'//gerrit-extension-api:client',
'//gerrit-patch-jgit:client',
'//gerrit-patch-jgit:Edit',
'//gerrit-reviewdb:client',
'//lib:gwtjsonrpc',
'//lib:gwtjsonrpc_src',
'//lib/jgit:Edit',
],
provided_deps = ['//lib/gwt:user'],
visibility = ['PUBLIC'],
@ -44,7 +44,7 @@ java_library(
'//gerrit-reviewdb:server',
'//lib:guava',
'//lib:gwtjsonrpc',
'//lib/jgit:jgit',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -45,6 +45,7 @@ java_library(
'//lib:mime-util',
'//lib:pegdown',
'//lib:protobuf',
'//lib:tukaani-xz',
'//lib:velocity',
'//lib/antlr:java_runtime',
'//lib/auto:auto-value',
@ -58,8 +59,6 @@ java_library(
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:jgit-archive',
'//lib/joda:joda-time',
'//lib/log:api',
'//lib/log:jsonevent-layout',
@ -71,6 +70,8 @@ java_library(
'//lib/ow2:ow2-asm-tree',
'//lib/ow2:ow2-asm-util',
'//lib/prolog:runtime',
'@jgit//:jgit',
'@jgit//:jgit-archive',
],
provided_deps = [
'//lib:servlet-api-3_1',
@ -97,12 +98,12 @@ TESTUTIL_DEPS = [
'//lib:truth',
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/joda:joda-time',
'//lib/log:api',
'//lib/log:impl_log4j',
'//lib/log:log4j',
'@jgit//:jgit',
'@jgit//:junit',
]
TESTUTIL = glob([

View File

@ -28,8 +28,8 @@ java_library(
'//lib/log:log4j',
'//lib/mina:core',
'//lib/mina:sshd',
'//lib/jgit:jgit',
'//lib/jgit:jgit-archive',
'@jgit//:jgit',
'@jgit//:jgit-archive',
],
provided_deps = [
'//lib/bouncycastle:bcpkix',

View File

@ -15,7 +15,7 @@ java_library(
'//lib:guava',
'//lib:servlet-api-3_1',
'//lib/httpcomponents:httpclient',
'//lib/jgit:jgit',
'@jgit//:jgit',
],
visibility = ['PUBLIC'],
)

View File

@ -24,7 +24,7 @@ java_library(
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/log:api',
'//lib/jgit:jgit',
'@jgit//:jgit',
],
provided_deps = ['//lib:servlet-api-3_1'],
visibility = [

View File

@ -249,7 +249,7 @@ maven_jar(
sha1 = '18a9a2ce6abf32ea1b5fd31dae5210ad93f4e5e3',
license = 'xz',
attach_source = False,
visibility = ['//lib/jgit:jgit-archive'],
visibility = ['//gerrit-server:server'],
)
maven_jar(

3
lib/jgit/.buckconfig Normal file
View File

@ -0,0 +1,3 @@
[cache]
mode = dir
dir = ~/.gerritcodereview/buck-cache/locally-built-artifacts

1
lib/jgit/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/buck-out

View File

@ -39,16 +39,13 @@ maven_jar(
sha1 = 'e599670a9b163182868e2e928e44eb93c5d2b1ab',
license = 'jgit',
repository = REPO,
deps = [':jgit',
'//lib/commons:compress',
'//lib:tukaani-xz',
],
deps = [':jgit'],
unsign = True,
exclude = [
'about.html',
'plugin.properties',
],
)
)
maven_jar(
name = 'junit',
@ -66,24 +63,3 @@ maven_jar(
sha1 = 'eceaf316a8faf0e794296ebe158ae110c7d72a5a',
license = 'Apache2.0',
)
gwt_module(
name = 'Edit',
srcs = [':jgit_edit_src'],
deps = [':edit_src'],
visibility = ['PUBLIC'],
)
prebuilt_jar(
name = 'edit_src',
binary_jar = ':jgit_edit_src',
)
genrule(
name = 'jgit_edit_src',
cmd = 'unzip -qd $TMP $(location :jgit_src) ' +
'org/eclipse/jgit/diff/Edit.java;' +
'cd $TMP;' +
'zip -Dq $OUT org/eclipse/jgit/diff/Edit.java',
out = 'edit.src.zip',
)

6
lib/jgit/lib/BUCK Normal file
View File

@ -0,0 +1,6 @@
include_defs('//lib/maven.defs')
define_license(name = 'Apache2.0')
define_license(name = 'jgit')
define_license(name = 'DO_NOT_DISTRIBUTE')

View File

@ -0,0 +1 @@
../../LICENSE-Apache2.0

View File

@ -0,0 +1 @@
../../LICENSE-DO_NOT_DISTRIBUTE

1
lib/jgit/lib/LICENSE-jgit Symbolic link
View File

@ -0,0 +1 @@
../../LICENSE-jgit

1
lib/jgit/lib/maven.defs Symbolic link
View File

@ -0,0 +1 @@
../../maven.defs

1
lib/jgit/tools/BUCK Symbolic link
View File

@ -0,0 +1 @@
../../../tools/BUCK

1
lib/jgit/tools/__init__.py Symbolic link
View File

@ -0,0 +1 @@
../../../tools/__init__.py

View File

@ -0,0 +1 @@
../../../tools/download_file.py

View File

@ -0,0 +1 @@
../../../tools/merge_jars.py

1
lib/jgit/tools/pack_war.py Symbolic link
View File

@ -0,0 +1 @@
../../../tools/pack_war.py

1
lib/jgit/tools/util.py Symbolic link
View File

@ -0,0 +1 @@
../../../tools/util.py

1
lib/jgit/tools/util_test.py Symbolic link
View File

@ -0,0 +1 @@
../../../tools/util_test.py

View File

@ -128,7 +128,8 @@ def gen_classpath():
continue
m = java_library.match(p)
if m:
# Don't grab the cross-cell JGit libraries as source
if m and not m.group(1).startswith('org.eclipse.jgit'):
src.add(m.group(1))
else:
lib.add(p)

View File

@ -28,6 +28,7 @@ args, ctx = opts.parse_args()
war = args.tmp
jars = set()
basenames = set()
def prune(l):
return [j for e in l for j in e.split(':')]
@ -36,10 +37,19 @@ def link_jars(libs, directory):
makedirs(directory)
for j in libs:
if j not in jars:
# When jgit is consumed from its own cell,
# potential duplicates should be filtered.
# e.g. jsch.jar will be reached through:
# 1. /home/username/projects/gerrit/buck-out/gen/lib/jsch.jar
# 2. /home/username/projects/jgit/buck-out/gen/lib/jsch.jar
if (j.find('jgit/buck-out/gen/lib') > 0
and path.basename(j) in basenames):
continue
jars.add(j)
n = path.basename(j)
if j.find('buck-out/gen/gerrit-') > 0:
n = j[j.find('buck-out'):].split('/')[2] + '-' + n
basenames.add(n)
symlink(j, path.join(directory, n))
if args.lib: