Expose acceptance test framework as new plugin artifact

Split the current gerrit-acceptance-tests in two parts:

* framework + some needed deps, that is exposed as additional plugin
artifact
* rest of the gerrit-acceptance-test project

To implement the split and not to pull in too many dependencies, some
refactoring was needed. Particularly, gerrit-server:testutil depends
on gerrit-server:server, that depends on almost everything. Similar
problem was with gerrit-pgm:pgm, that is needed for AbstractDaemonTest
to work. Split the rules in gerrit-pgm to break transitive dependency
chain. We shouldn't ship artifacts twice, in plugin-api and in
acceptance-framework.

This change also partially reverts Ie9e63de622, where
//gerrit-acceptance-tests:lib with all its transitive dependencies was
included in plugin-api artifact.

Expose gerrit-acceptance-framework as new plugin artifact. This allows
us to support unit tests in plugins in three different build modes:

* Buck in tree build mode
* Buck standalone build mode
* Maven build

To install gerrit-acceptance-framework locally, the following command
is used:

  buck build api_install

To deploy gerrit-acceptance-framework to Maven Central, the following
command is used:

  buck build api_deploy

To support unit tests in tree build mode, the following Buck variable
is exposed: GERRIT_TESTS and can be used, e.g.:

  java_test(
    name = 'cookbook_tests',
    srcs = glob(['src/test/java/**/*IT.java']),
    labels = ['cookbook-plugin'],
    source_under_test = [':cookbook-plugin__plugin'],
    deps = GERRIT_PLUGIN_API + GERRIT_TESTS + [
      ':cookbook-plugin__plugin',
    ],
  )

To support unit tests in standalone build mode, acceptance-framework
maven jar is defined in lib/gerrit/BUCK file:

  maven_jar(
    name = 'acceptance-framework',
    id = 'com.google.gerrit:gerrit-acceptance-framework:' + VER,
    license = 'Apache2.0',
    attach_source = False,
    repository = REPO,
  )

bucklets/gerrit_plugin.bucklet is extended with the same variable
that points to the new maven_jar artifact, so that the same Buck
java_test() rule can be used in both modes.

Test plan:

1. run tests in gerrit tree
2. apply corresponding change to cookbook-plugin and run tests in
gerrit tree mode
3. apply corresponding change to bucklets, and run tests for
cookbook-plugin in standalone build mode

Change-Id: I4cadf6616de36ca24712f8b07d282b7a50911105
This commit is contained in:
David Ostrovsky
2015-09-24 21:52:17 +02:00
committed by Hugo Arès
parent aaaf9faea6
commit 947b5e53ac
36 changed files with 253 additions and 119 deletions

3
BUCK
View File

@@ -9,6 +9,9 @@ gerrit_war(name = 'withdocs', docs = True)
gerrit_war(name = 'release', ui = 'ui_optdbg_r', docs = True, context = ['//plugins:core'], visibility = ['//tools/maven:'])
API_DEPS = [
'//gerrit-acceptance-framework:api',
'//gerrit-acceptance-framework:src',
'//gerrit-acceptance-framework:javadoc',
'//gerrit-extension-api:extension-api',
'//gerrit-extension-api:extension-api-src',
'//gerrit-extension-api:extension-api-javadoc',

View File

@@ -14,7 +14,8 @@
# When compiling from standalone cookbook-plugin, bucklets directory points
# to cloned bucklets library that includes real gerrit_plugin.bucklet code.
GERRIT_PLUGIN_API = ['//gerrit-plugin-api:lib']
GERRIT_GWT_API = ['//gerrit-plugin-gwtui/gerrit:gwtui-api']
GERRIT_PLUGIN_API = ['//gerrit-plugin-api:lib']
GERRIT_TESTS = ['//gerrit-acceptance-framework:lib']
STANDALONE_MODE = False

View File

@@ -0,0 +1,77 @@
SRCS = glob(['src/test/java/com/google/gerrit/acceptance/*.java'])
DEPS = [
'//gerrit-gpg:gpg',
'//gerrit-pgm:daemon',
'//gerrit-pgm:util-nodep',
'//gerrit-server:testutil',
'//lib/auto:auto-value',
'//lib/httpcomponents:fluent-hc',
'//lib/httpcomponents:httpclient',
'//lib/httpcomponents:httpcore',
'//lib/jgit:junit',
'//lib/log:impl_log4j',
'//lib/log:log4j',
]
PROVIDED = [
'//gerrit-common:annotations',
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-httpd:httpd',
'//gerrit-lucene:lucene',
'//gerrit-pgm:init',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//lib:gson',
'//lib/jgit:jgit',
'//lib:jsch',
'//lib/mina:sshd',
'//lib:servlet-api-3_1',
]
java_binary(
name = 'api',
deps = [':lib'],
visibility = ['PUBLIC'],
)
java_library(
name = 'lib',
srcs = SRCS,
exported_deps = DEPS + [
'//lib:truth',
],
provided_deps = PROVIDED + [
'//lib:gwtorm',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
],
visibility = ['PUBLIC'],
)
java_sources(
name = 'src',
srcs = SRCS,
visibility = ['PUBLIC'],
)
java_doc(
name = 'javadoc',
title = 'Gerrit Acceptance Test Framework Documentation',
pkgs = [' com.google.gerrit.acceptance'],
paths = ['src/test/java'],
srcs = SRCS,
deps = DEPS + PROVIDED + [
'//lib:guava',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice_library',
'//lib/guice:guice-servlet',
'//lib/guice:javax-inject',
'//lib:gwtorm_client',
'//lib:junit__jar',
'//lib:truth__jar',
],
visibility = ['PUBLIC'],
)

View File

@@ -0,0 +1,59 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.gerrit</groupId>
<artifactId>gerrit-acceptance-framework</artifactId>
<version>2.12-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Gerrit Code Review - Acceptance Test Framework</name>
<description>API for Gerrit Plugins</description>
<url>https://www.gerritcodereview.com/</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://gerrit.googlesource.com/gerrit</url>
<connection>https://gerrit.googlesource.com/gerrit</connection>
</scm>
<developers>
<developer>
<name>Dave Borowitz</name>
</developer>
<developer>
<name>David Pursehouse</name>
</developer>
<developer>
<name>Edwin Kempin</name>
</developer>
<developer>
<name>Martin Fick</name>
</developer>
<developer>
<name>Saša Živkov</name>
</developer>
<developer>
<name>Shawn Pearce</name>
</developer>
</developers>
<mailingLists>
<mailingList>
<name>Repo and Gerrit Discussion</name>
<post>repo-discuss@googlegroups.com</post>
<subscribe>https://groups.google.com/forum/#!forum/repo-discuss</subscribe>
<unsubscribe>https://groups.google.com/forum/#!forum/repo-discuss</unsubscribe>
<archive>https://groups.google.com/forum/#!forum/repo-discuss</archive>
</mailingList>
</mailingLists>
<issueManagement>
<url>http://code.google.com/p/gerrit/issues/list</url>
<system>Google Code Issue Tracker</system>
</issueManagement>
</project>

View File

@@ -2,10 +2,10 @@ java_library(
name = 'lib',
srcs = glob(['src/test/java/com/google/gerrit/acceptance/*.java']),
exported_deps = [
'//gerrit-acceptance-framework:lib',
'//gerrit-common:annotations',
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-gpg:gpg',
'//gerrit-gpg:testutil',
'//gerrit-launcher:launcher',
'//gerrit-lucene:lucene',
@@ -15,8 +15,8 @@ java_library(
'//gerrit-pgm:util',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//gerrit-server/src/main/prolog:common',
'//gerrit-server:testutil',
'//gerrit-server/src/main/prolog:common',
'//gerrit-sshd:sshd',
'//lib:args4j',
@@ -26,21 +26,13 @@ java_library(
'//lib:h2',
'//lib:jsch',
'//lib:servlet-api-3_1',
'//lib:truth',
'//lib/auto:auto-value',
'//lib/bouncycastle:bcpg',
'//lib/bouncycastle:bcprov',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/httpcomponents:fluent-hc',
'//lib/httpcomponents:httpclient',
'//lib/httpcomponents:httpcore',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/log:impl_log4j',
'//lib/log:log4j',
'//lib/mina:sshd',
],
visibility = [

View File

@@ -1,22 +1,23 @@
DEPS = [
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//lib:guava',
'//lib:gwtorm',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
]
java_library(
name = 'gpg',
srcs = glob(['src/main/java/**/*.java']),
deps = [
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//lib:guava',
'//lib:gwtorm',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/log:api',
],
provided_deps = [
'//lib/bouncycastle:bcprov',
provided_deps = DEPS + [
'//lib/bouncycastle:bcpg',
'//lib/bouncycastle:bcprov',
],
visibility = ['PUBLIC'],
)
@@ -28,12 +29,10 @@ TESTUTIL_SRCS = [
java_library(
name = 'testutil',
srcs = TESTUTIL_SRCS,
deps = [
deps = DEPS + [
':gpg',
'//lib:guava',
'//lib/bouncycastle:bcpg',
'//lib/bouncycastle:bcprov',
'//lib/jgit:jgit',
],
visibility = ['PUBLIC'],
)
@@ -44,20 +43,15 @@ java_test(
['src/test/java/**/*.java'],
excludes = TESTUTIL_SRCS,
),
deps = [
deps = DEPS + [
':gpg',
':testutil',
'//gerrit-extension-api:api',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//gerrit-cache-h2:cache-h2',
'//gerrit-lucene:lucene',
'//gerrit-server:testutil',
'//lib:guava',
'//lib:gwtorm',
'//lib:truth',
'//lib/bouncycastle:bcpg',
'//lib/bouncycastle:bcprov',
'//lib/guice:guice',
'//lib/jgit:jgit',
'//lib/jgit:junit',
],
source_under_test = [':gpg'],

View File

@@ -2,6 +2,7 @@ java_library(
name = 'gwtdebug',
srcs = glob(['src/main/java/**/*.java']),
deps = [
'//gerrit-pgm:daemon',
'//gerrit-pgm:pgm',
'//gerrit-pgm:util',
'//gerrit-util-cli:cli',

View File

@@ -53,21 +53,24 @@ java_library(
],
provided_deps = ['//gerrit-launcher:launcher'],
visibility = [
'//gerrit-acceptance-framework/...',
'//gerrit-acceptance-tests/...',
'//gerrit-war:',
],
)
REST_UTIL_DEPS = [
'//gerrit-cache-h2:cache-h2',
'//gerrit-util-cli:cli',
'//lib:args4j',
'//lib:gwtorm',
'//lib/commons:dbcp',
]
java_library(
name = 'util',
srcs = glob([SRCS + 'util/*.java']),
deps = DEPS + [
'//gerrit-cache-h2:cache-h2',
'//gerrit-util-cli:cli',
'//lib:args4j',
'//lib:gwtorm',
'//lib/commons:dbcp',
],
deps = DEPS + REST_UTIL_DEPS,
exported_deps = [':util-nodep'],
visibility = [
'//gerrit-acceptance-tests/...',
'//gerrit-gwtdebug:gwtdebug',
@@ -75,6 +78,15 @@ java_library(
],
)
java_library(
name = 'util-nodep',
srcs = glob([SRCS + 'util/*.java']),
provided_deps = DEPS + REST_UTIL_DEPS,
visibility = [
'//gerrit-acceptance-framework/...',
],
)
java_library(
name = 'http',
srcs = glob([SRCS + 'http/**/*.java']),
@@ -90,30 +102,32 @@ java_library(
visibility = ['//gerrit-war:'],
)
REST_PGM_DEPS = [
':http',
':init',
':init-api',
':util',
'//gerrit-cache-h2:cache-h2',
'//gerrit-gpg:gpg',
'//gerrit-lucene:lucene',
'//gerrit-oauth:oauth',
'//gerrit-openid:openid',
'//lib:args4j',
'//lib:gwtorm',
'//lib:protobuf',
'//lib:servlet-api-3_1',
'//lib/auto:auto-value',
'//lib/prolog:cafeteria',
'//lib/prolog:compiler',
'//lib/prolog:runtime',
]
java_library(
name = 'pgm',
srcs = glob([SRCS + '*.java', SRCS + 'rules/*.java']),
resources = glob([RSRCS + '*']),
deps = DEPS + [
':http',
':init',
':init-api',
':util',
'//gerrit-cache-h2:cache-h2',
'//gerrit-gpg:gpg',
'//gerrit-lucene:lucene',
'//gerrit-oauth:oauth',
'//gerrit-openid:openid',
'//lib:args4j',
'//lib:gwtorm',
'//lib:protobuf',
'//lib:servlet-api-3_1',
'//lib/auto:auto-value',
'//lib/prolog:cafeteria',
'//lib/prolog:compiler',
'//lib/prolog:runtime',
deps = DEPS + REST_PGM_DEPS + [
':daemon',
],
provided_deps = ['//gerrit-launcher:launcher'],
visibility = [
'//:',
'//gerrit-acceptance-tests/...',
@@ -123,6 +137,21 @@ java_library(
],
)
# no transitive deps, used for gerrit-acceptance-framework
java_library(
name = 'daemon',
srcs = glob([SRCS + '*.java', SRCS + 'rules/*.java']),
resources = glob([RSRCS + '*']),
deps = ['//lib/auto:auto-value'],
provided_deps = DEPS + REST_PGM_DEPS + [
'//gerrit-launcher:launcher',
],
visibility = [
'//gerrit-acceptance-framework/...',
'//gerrit-gwtdebug:gwtdebug',
],
)
java_test(
name = 'pgm_tests',
srcs = glob(['src/test/java/**/*.java']),

View File

@@ -20,7 +20,6 @@ java_binary(
java_library(
name = 'lib',
exported_deps = PLUGIN_API + [
'//gerrit-acceptance-tests:lib',
'//gerrit-antlr:query_exception',
'//gerrit-antlr:query_parser',
'//gerrit-common:annotations',

View File

@@ -82,6 +82,26 @@ java_sources(
visibility = ['PUBLIC'],
)
TESTUTIL_DEPS = [
':server',
'//gerrit-common:server',
'//gerrit-cache-h2:cache-h2',
'//gerrit-extension-api:api',
'//gerrit-gpg:gpg',
'//gerrit-lucene:lucene',
'//gerrit-reviewdb:server',
'//lib:gwtorm',
'//lib:h2',
'//lib:truth',
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/log:api',
'//lib/log:impl_log4j',
'//lib/log:log4j',
]
TESTUTIL = glob([
'src/test/java/com/google/gerrit/testutil/**/*.java',
'src/test/java/com/google/gerrit/server/project/Util.java',
@@ -90,25 +110,9 @@ java_library(
name = 'testutil',
srcs = TESTUTIL,
deps = [
':server',
'//gerrit-common:server',
'//gerrit-cache-h2:cache-h2',
'//gerrit-extension-api:api',
'//gerrit-gpg:gpg',
'//gerrit-lucene:lucene',
'//gerrit-reviewdb:server',
'//lib:gwtorm',
'//lib:h2',
'//lib:truth',
'//lib/auto:auto-value',
'//lib/guice:guice',
'//lib/guice:guice-servlet',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/log:api',
'//lib/log:impl_log4j',
'//lib/log:log4j',
],
provided_deps = TESTUTIL_DEPS,
exported_deps = [
'//lib/easymock:easymock',
'//lib/powermock:powermock-api-easymock',
@@ -147,19 +151,10 @@ java_test(
name = 'prolog_tests',
srcs = PROLOG_TESTS,
resources = glob(['src/test/resources/com/google/gerrit/rules/**/*']),
deps = [
deps = TESTUTIL_DEPS + [
':prolog_test_case',
':server',
':testutil',
'//gerrit-common:server',
'//gerrit-reviewdb:server',
'//gerrit-server/src/main/prolog:common',
'//lib:guava',
'//lib:gwtorm',
'//lib:junit',
'//lib:truth',
'//lib/jgit:jgit',
'//lib/guice:guice',
'//lib/prolog:runtime',
],
)
@@ -171,22 +166,13 @@ QUERY_TESTS = glob(
java_test(
name = 'query_tests',
srcs = QUERY_TESTS,
deps = [
':server',
deps = TESTUTIL_DEPS + [
':testutil',
'//gerrit-antlr:query_exception',
'//gerrit-antlr:query_parser',
'//gerrit-common:annotations',
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-reviewdb:server',
'//gerrit-server/src/main/prolog:common',
'//lib:gwtorm',
'//lib:truth',
'//lib/antlr:java_runtime',
'//lib/guice:guice',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/joda:joda-time',
],
source_under_test = [':server'],
@@ -199,25 +185,15 @@ java_test(
['src/test/java/**/*.java'],
excludes = TESTUTIL + PROLOG_TESTS + PROLOG_TEST_CASE + QUERY_TESTS
),
deps = [
':server',
deps = TESTUTIL_DEPS + [
':testutil',
'//gerrit-antlr:query_exception',
'//gerrit-common:annotations',
'//gerrit-common:server',
'//gerrit-extension-api:api',
'//gerrit-gpg:gpg',
'//gerrit-reviewdb:server',
'//gerrit-server/src/main/prolog:common',
'//lib:args4j',
'//lib:grappa',
'//lib:guava',
'//lib:gwtorm',
'//lib:truth',
'//lib/guice:guice',
'//lib/guice:guice-assistedinject',
'//lib/jgit:jgit',
'//lib/jgit:junit',
'//lib/joda:joda-time',
'//lib/prolog:runtime',
],

View File

@@ -10,16 +10,19 @@ maven_package(
url = URL,
version = GERRIT_VERSION,
jar = {
'gerrit-acceptance-framework': '//gerrit-acceptance-framework:api',
'gerrit-extension-api': '//gerrit-extension-api:extension-api',
'gerrit-plugin-api': '//gerrit-plugin-api:plugin-api',
'gerrit-plugin-gwtui': '//gerrit-plugin-gwtui:gwtui-api',
},
src = {
'gerrit-acceptance-framework': '//gerrit-acceptance-framework:src',
'gerrit-extension-api': '//gerrit-extension-api:extension-api-src',
'gerrit-plugin-api': '//gerrit-plugin-api:plugin-api-src',
'gerrit-plugin-gwtui': '//gerrit-plugin-gwtui:gwtui-api-src',
},
doc = {
'gerrit-acceptance-framework': '//gerrit-acceptance-framework:javadoc',
'gerrit-extension-api': '//gerrit-extension-api:extension-api-javadoc',
'gerrit-plugin-api': '//gerrit-plugin-api:plugin-api-javadoc',
'gerrit-plugin-gwtui': '//gerrit-plugin-gwtui:gwtui-api-javadoc',

View File

@@ -45,10 +45,10 @@ def replace_in_file(filename, src_pattern):
src_pattern = re.compile(r'^(\s*<version>)([-.\w]+)(</version>\s*)$',
re.MULTILINE)
for project in ['gerrit-extension-api', 'gerrit-plugin-api',
'gerrit-plugin-archetype', 'gerrit-plugin-gwt-archetype',
'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype',
'gerrit-war']:
for project in ['gerrit-acceptance-framework', 'gerrit-extension-api',
'gerrit-plugin-api', 'gerrit-plugin-archetype',
'gerrit-plugin-gwt-archetype', 'gerrit-plugin-gwtui',
'gerrit-plugin-js-archetype', 'gerrit-war']:
pom = os.path.join(project, 'pom.xml')
replace_in_file(pom, src_pattern)