Skip to content

Commit

Permalink
Merge pull request #1 from chrismgrayftsinc/spring-components
Browse files Browse the repository at this point in the history
Add support for spring.components files
  • Loading branch information
chrismgrayftsinc authored Dec 2, 2022
2 parents 077e65e + ea44a0d commit 3d8cf78
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion spring_image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,20 @@ def tar_jars(ctx, files, out):
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
jar_path = "%s/bin/jar" % java_runtime.java_home
paths = [f.path for f in files]
spring_components_file_path = "spring.components"
spring_components_file = ctx.actions.declare_file(spring_components_file_path)
ctx.actions.run_shell(
inputs = ctx.files._jdk + files,
outputs = [spring_components_file],
command = "touch {file}; for i in {all_paths}; do {jar} xf $i && if [ -s META-INF/spring.components ]; then cat META-INF/spring.components >> {file}; fi; done".format(file = spring_components_file.path, jar = jar_path, all_paths = " ".join(paths)),
)

ctx.actions.run_shell(
inputs = ctx.files._jdk + files + [spring_components_file],
outputs = [out],
command = 'tar cf %s -T /dev/null && for i in %s; do %s xf ${i} && %s tf ${i} | tar rf %s --transform "s,^,BOOT-INF/classes/," -T -; done' % (out.path, " ".join(paths), jar_path, jar_path, out.path),
# Create an empty tarball, then extract all the jars and append the contents into it.
# TODO: get rid of the hardcoded bazel-out path in the first transform.
command = 'tar cf {out} -T /dev/null && if [ -s {scf} ]; then tar rhf {out} --transform "s,bazel-out/k8-fastbuild/bin/,BOOT-INF/classes/META-INF/," {scf}; fi && for i in {all_paths}; do {jar} xf $i && {jar} tf $i | tar rf {out} --transform "s,^,BOOT-INF/classes/," -T -; done'.format(out = out.path, all_paths = " ".join(paths), jar = jar_path, scf = spring_components_file.path),
)

def _application_copier_rule_impl(ctx):
Expand Down

0 comments on commit 3d8cf78

Please sign in to comment.