Bazel: Produce headless war
This change creates the archive with: lib pgm-lib default web assets but without: GWT UI PolyGerrit UI Plugins Documentation TEST PLAN: bazel build :headless java -jar bazel-bin/headless.war init -d ../test_site_bazel Change-Id: I53987b10a5863aee0298bd2ea29405c26dbacb0c
This commit is contained in:
19
BUILD
19
BUILD
@@ -1,4 +1,5 @@
|
|||||||
load('//tools/bzl:genrule2.bzl', 'genrule2')
|
load('//tools/bzl:genrule2.bzl', 'genrule2')
|
||||||
|
load('//tools/bzl:pkg_war.bzl', 'pkg_war')
|
||||||
|
|
||||||
genrule2(
|
genrule2(
|
||||||
name = 'version',
|
name = 'version',
|
||||||
@@ -7,3 +8,21 @@ genrule2(
|
|||||||
out = 'version.txt',
|
out = 'version.txt',
|
||||||
visibility = ['//visibility:public'],
|
visibility = ['//visibility:public'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pkg_war(
|
||||||
|
name = 'headless',
|
||||||
|
context = [
|
||||||
|
'//gerrit-main:main_bin_deploy.jar',
|
||||||
|
'//gerrit-war:webapp_assets',
|
||||||
|
],
|
||||||
|
libs = [
|
||||||
|
'//gerrit-war:init',
|
||||||
|
'//gerrit-war:log4j-config',
|
||||||
|
'//gerrit-war:version',
|
||||||
|
'//lib:postgresql',
|
||||||
|
'//lib/log:impl_log4j',
|
||||||
|
],
|
||||||
|
pgmlibs = [
|
||||||
|
'//gerrit-pgm:pgm'
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@@ -716,3 +716,9 @@ maven_jar(
|
|||||||
artifact = 'xerces:xercesImpl:2.8.1',
|
artifact = 'xerces:xercesImpl:2.8.1',
|
||||||
sha1 = '25101e37ec0c907db6f0612cbf106ee519c1aef1',
|
sha1 = '25101e37ec0c907db6f0612cbf106ee519c1aef1',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
maven_jar(
|
||||||
|
name = 'postgresql',
|
||||||
|
artifact = 'postgresql:postgresql:9.1-901-1.jdbc4',
|
||||||
|
sha1 = '9bfabe48876ec38f6cbaa6931bad05c64a9ea942',
|
||||||
|
)
|
||||||
|
@@ -231,3 +231,9 @@ java_library(
|
|||||||
exports = [ '@icu4j//jar' ],
|
exports = [ '@icu4j//jar' ],
|
||||||
visibility = ['//visibility:public'],
|
visibility = ['//visibility:public'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
java_library(
|
||||||
|
name = 'postgresql',
|
||||||
|
exports = ['@postgresql//jar'],
|
||||||
|
visibility = ['//visibility:public'],
|
||||||
|
)
|
||||||
|
113
tools/bzl/pkg_war.bzl
Normal file
113
tools/bzl/pkg_war.bzl
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# Copyright (C) 2016 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.
|
||||||
|
|
||||||
|
# War packaging.
|
||||||
|
|
||||||
|
jar_filetype = FileType(['.jar'])
|
||||||
|
|
||||||
|
def _add_context(in_file, output):
|
||||||
|
input_path = in_file.path
|
||||||
|
return [
|
||||||
|
'unzip -qd %s %s' % (output, input_path)
|
||||||
|
]
|
||||||
|
|
||||||
|
def _add_file(in_file, output):
|
||||||
|
output_path = output
|
||||||
|
input_path = in_file.path
|
||||||
|
short_path = in_file.short_path
|
||||||
|
n = in_file.basename
|
||||||
|
|
||||||
|
# TODO(davido): Drop this when provided_deps added to java_library
|
||||||
|
if n.find('-jdk15on-') != -1:
|
||||||
|
return []
|
||||||
|
|
||||||
|
if short_path.startswith('gerrit-'):
|
||||||
|
n = short_path.split('/')[0] + '-' + n
|
||||||
|
|
||||||
|
output_path += n
|
||||||
|
return [
|
||||||
|
'test -L %s || ln -s $(pwd)/%s %s' % (output_path, input_path, output_path)
|
||||||
|
]
|
||||||
|
|
||||||
|
def _make_war(input_dir, output):
|
||||||
|
return ''.join([
|
||||||
|
'(root=$(pwd) && ',
|
||||||
|
'cd %s && ' % input_dir,
|
||||||
|
'zip -9qr ${root}/%s .)' % (output.path),
|
||||||
|
])
|
||||||
|
|
||||||
|
def _war_impl(ctx):
|
||||||
|
war = ctx.outputs.war
|
||||||
|
build_output = war.path + '.build_output'
|
||||||
|
inputs = []
|
||||||
|
|
||||||
|
# Create war layout
|
||||||
|
cmd = [
|
||||||
|
'set -e;rm -rf ' + build_output,
|
||||||
|
'mkdir -p ' + build_output,
|
||||||
|
'mkdir -p %s/WEB-INF/lib' % build_output,
|
||||||
|
'mkdir -p %s/WEB-INF/pgm-lib' % build_output,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Add lib
|
||||||
|
transitive_lib_deps = set()
|
||||||
|
for l in ctx.attr.libs:
|
||||||
|
transitive_lib_deps += l.java.transitive_runtime_deps
|
||||||
|
|
||||||
|
for dep in transitive_lib_deps:
|
||||||
|
cmd += _add_file(dep, build_output + '/WEB-INF/lib/')
|
||||||
|
inputs.append(dep)
|
||||||
|
|
||||||
|
# Add pgm lib
|
||||||
|
transitive_pgmlib_deps = set()
|
||||||
|
for l in ctx.attr.pgmlibs:
|
||||||
|
transitive_pgmlib_deps += l.java.transitive_runtime_deps
|
||||||
|
|
||||||
|
for dep in transitive_pgmlib_deps:
|
||||||
|
if dep not in inputs:
|
||||||
|
cmd += _add_file(dep, build_output + '/WEB-INF/pgm-lib/')
|
||||||
|
inputs.append(dep)
|
||||||
|
|
||||||
|
# Add context
|
||||||
|
transitive_context_deps = set()
|
||||||
|
if ctx.attr.context:
|
||||||
|
for jar in ctx.attr.context:
|
||||||
|
if hasattr(jar, 'java'):
|
||||||
|
transitive_context_deps += jar.java.transitive_runtime_deps
|
||||||
|
elif hasattr(jar, 'files'):
|
||||||
|
transitive_context_deps += jar.files
|
||||||
|
for dep in transitive_context_deps:
|
||||||
|
cmd += _add_context(dep, build_output)
|
||||||
|
inputs.append(dep)
|
||||||
|
|
||||||
|
# Add zip war
|
||||||
|
cmd.append(_make_war(build_output, war))
|
||||||
|
|
||||||
|
ctx.action(
|
||||||
|
inputs = inputs,
|
||||||
|
outputs = [war],
|
||||||
|
mnemonic = 'WAR',
|
||||||
|
command = '\n'.join(cmd),
|
||||||
|
use_default_shell_env = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
pkg_war = rule(
|
||||||
|
attrs = {
|
||||||
|
'context': attr.label_list(allow_files = True),
|
||||||
|
'libs': attr.label_list(allow_files = jar_filetype),
|
||||||
|
'pgmlibs': attr.label_list(allow_files = False),
|
||||||
|
},
|
||||||
|
implementation = _war_impl,
|
||||||
|
outputs = {'war' : '%{name}.war'},
|
||||||
|
)
|
Reference in New Issue
Block a user