Merge "lib/lucene: merge jars using a java_binary rule" into stable-2.16

This commit is contained in:
Han-Wen Nienhuys
2020-01-09 15:22:27 +00:00
committed by Gerrit Code Review
3 changed files with 18 additions and 64 deletions

View File

@@ -1,17 +1,28 @@
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_import", "java_library")
load("//tools/bzl:maven.bzl", "merge_maven_jars")
package(default_visibility = ["//visibility:public"])
# core and backward-codecs both provide
# META-INF/services/org.apache.lucene.codecs.Codec, so they must be merged.
merge_maven_jars(
name = "lucene-core-and-backward-codecs",
srcs = [
# Merge jars so
# META-INF/services/org.apache.lucene.codecs.Codec
# contains the union of both Codec collections.
java_binary(
name = "lucene-core-and-backward-codecs-merged",
data = ["//lib:LICENSE-Apache2.0"],
main_class = "NotImportant",
runtime_deps = [
# in case of conflict, we want the implementation of backwards-codecs
# first.
"@backward-codecs//jar",
"@lucene-core//jar",
],
data = ["//lib:LICENSE-Apache2.0"],
)
java_import(
name = "lucene-core-and-backward-codecs",
jars = [
":lucene-core-and-backward-codecs-merged_deploy.jar",
],
)
java_library(

View File

@@ -4,17 +4,9 @@ load(
"default_java_toolchain",
)
load("@rules_java//java:defs.bzl", "java_package_configuration")
load("@rules_python//python:defs.bzl", "py_binary")
exports_files(["nongoogle.bzl"])
py_binary(
name = "merge_jars",
srcs = ["merge_jars.py"],
main = "merge_jars.py",
visibility = ["//visibility:public"],
)
default_java_toolchain(
name = "error_prone_warnings_toolchain",
bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"],

View File

@@ -1,49 +0,0 @@
#!/usr/bin/env python
# Copyright (C) 2015 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
import collections
import sys
import zipfile
if len(sys.argv) < 3:
print('usage: %s <out.zip> <in.zip>...' % sys.argv[0], file=sys.stderr)
exit(1)
outfile = sys.argv[1]
infiles = sys.argv[2:]
seen = set()
SERVICES = 'META-INF/services/'
try:
with zipfile.ZipFile(outfile, 'w') as outzip:
services = collections.defaultdict(lambda: '')
for infile in infiles:
with zipfile.ZipFile(infile) as inzip:
for info in inzip.infolist():
n = info.filename
if n in seen:
continue
elif n.startswith(SERVICES):
# Concatenate all provider configuration files.
services[n] += inzip.read(n).decode("UTF-8")
continue
outzip.writestr(info, inzip.read(n))
seen.add(n)
for n, v in list(services.items()):
outzip.writestr(n, v)
except Exception as err:
exit('Failed to merge jars: %s' % err)