diff --git a/.buckconfig b/.buckconfig index 2a96c741e2..bcefa2a7dd 100644 --- a/.buckconfig +++ b/.buckconfig @@ -1,5 +1,7 @@ [alias] api = //:api + api_deploy = //:api_deploy + api_install = //:api_install download = //:download download_sources = //:download_sources gerrit = //:gerrit diff --git a/BUCK b/BUCK index ee5ba75430..98a85a1405 100644 --- a/BUCK +++ b/BUCK @@ -6,19 +6,24 @@ gerrit_war(name = 'firefox', ui = 'ui_firefox') gerrit_war(name = 'withdocs', context = DOCS) gerrit_war(name = 'release', context = DOCS + ['//plugins:core.zip']) +API_DEPS = [ + ':extension-api', + ':extension-api-src', + ':plugin-api', + ':plugin-api-src', +] + genrule( name = 'api', cmd = '', srcs = [], - deps = [ - ':extension-api', - ':extension-api-src', - ':plugin-api', - ':plugin-api-src', - ], + deps = API_DEPS, out = '__fake.api__', ) +maven_install(deps = API_DEPS) +maven_deploy(deps = API_DEPS) + java_binary(name = 'extension-api', deps = [':extension-lib']) java_library( name = 'extension-lib', diff --git a/Documentation/dev-buck.txt b/Documentation/dev-buck.txt index 329459d10c..dbb9006853 100644 --- a/Documentation/dev-buck.txt +++ b/Documentation/dev-buck.txt @@ -126,6 +126,21 @@ The output JAR files will be placed in: buck-out/gen/{extension,plugin}-api.jar ---- +Install {extension,plugin}-api to the local maven repository: + +---- + buck build api_install +---- + +Deploy {extension,plugin}-api to the remote maven repository + +---- + buck build api_deploy +---- + +The type of the repo is induced from the Gerrit version name, i.e. +* 2.8-SNAPSHOT: shapshot repo +* 2.8: release repo Plugins ~~~~~~~ @@ -283,7 +298,9 @@ archetypes to support creating a new plugin, but existing plugins can develop against the API JAR(s) if they are installed into a Maven repository. tools/deploy_api.sh is how we did this for release versions of Gerrit. Something similar probably still be used with BUCK -to publish the precompiled JARs. +to publish the precompiled JARs. (Note: this is partially done with the +target: `buck build api_install`; after issuing this command the new API +version can be consumed by Maven driven custom plugins). + The third option is to support a BUCK based plugin build outside of the Gerrit tree. This is harder because there is functionality diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..359b6d9c77 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +GERRIT_VER = '2.8-SNAPSHOT' diff --git a/tools/BUCK b/tools/BUCK index 5f371f1c2d..405d60da15 100644 --- a/tools/BUCK +++ b/tools/BUCK @@ -17,6 +17,13 @@ python_binary( visibility = ['PUBLIC'], ) +python_binary( + name = 'maven_deploy', + main = 'maven_deploy.py', + deps = [':util'], + visibility = ['PUBLIC'], +) + python_library( name = 'util', srcs = ['util.py'], diff --git a/tools/build.defs b/tools/build.defs index bbea5add63..3ff82d1fd6 100644 --- a/tools/build.defs +++ b/tools/build.defs @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +include_defs('//VERSION') DOCS = ['//Documentation:html.zip'] LIBS = [ @@ -77,3 +78,33 @@ def gerrit_war(name, ui = 'ui_optdbg', context = []): '//gerrit-gwtui:' + ui + '.zip', ] + context, ) + +def maven_deploy( + deps + ): + _maven_util('deploy', deps) + +def maven_install( + deps + ): + _maven_util( + name = 'install', + deps = deps) + +def _maven_util( + name, + deps + ): + cmd = [ + '${//tools:maven_deploy}', + '-a', name, + '-v', GERRIT_VER, + '-d', '"$DEPS"' + ] + genrule( + name = 'api_%s' % name, + cmd = ' '.join(cmd), + srcs = [], + deps = deps + ['//tools:maven_deploy'], + out = '__fake.api_%s__' % name + ) diff --git a/tools/maven_deploy.py b/tools/maven_deploy.py new file mode 100644 index 0000000000..4779abe577 --- /dev/null +++ b/tools/maven_deploy.py @@ -0,0 +1,92 @@ +#!/usr/bin/python +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function +from optparse import OptionParser +from os.path import exists +from sys import stderr +from util import check_output + +opts = OptionParser() +opts.add_option('-a', help='action (valid actions are: install,deploy)') +opts.add_option('-v', help='gerrit version') +opts.add_option('-d', help='dependencies (jars artifacts)') + +args, ctx = opts.parse_args() +action = args.a +if action not in ['deploy', 'install']: + print("unknown action : %s" % action, file=stderr) + exit(1) + +deps = args.d.split() +if not deps: + print('dependencies are empty') + exit(1) + +extension_jar = [x for x in deps if "extension-api.jar" in x][0] +extension_src = [x for x in deps if "extension-api-src.jar" in x][0] +plugin_jar = [x for x in deps if "plugin-api.jar" in x][0] +plugin_src = [x for x in deps if "plugin-api-src.jar" in x][0] + +version = args.v +if not version: + print('version is empty') + exit(1) + +REPO_TYPE = 'snapshot' if version.endswith("SNAPSHOT") else 'release' +URL = 's3://gerrit-api@commondatastorage.googleapis.com/%s' % REPO_TYPE + +plugin = ['-DartifactId=gerrit-plugin-api'] +extension = ['-DartifactId=gerrit-extension-api'] +common = [ + '-DgroupId=com.google.gerrit', + '-Dversion=%s' % version, +] +jar = ['-Dpackaging=jar'] +src = ['-Dpackaging=java-source'] + +cmd = { + 'deploy': ['mvn', + 'deploy:deploy-file', + '-DrepositoryId=gerrit-api-repository', + '-Durl=%s' % URL], + 'install': ['mvn', + 'install:install-file'], + } + +try: + check_output(cmd[action] + + plugin + + common + + jar + + ['-Dfile=%s' % plugin_jar]) + check_output(cmd[action] + + plugin + + common + + src + + ['-Dfile=%s' % plugin_src]) + check_output(cmd[action] + + extension + + common + + jar + + ['-Dfile=%s' % extension_jar]) + check_output(cmd[action] + + extension + + common + + src + + ['-Dfile=%s' % extension_src]) +except Exception as e: + print('%s command failed: %s' % (action, e), file=stderr) + exit(1)