Skip to content

Commit

Permalink
Implement addins feature
Browse files Browse the repository at this point in the history
  • Loading branch information
plaird committed Jan 28, 2023
1 parent ec5ca65 commit 564bc4e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 11 deletions.
6 changes: 5 additions & 1 deletion examples/demoapp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ springboot(

# if you have conflicting classes in dependency jar files, you can define the order in which the jars are loaded
# https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-executable-jar-format.html#executable-jar-war-index-files-classpath
deps_index_file = "demoapp_classpath.idx",
deps_index_file = ":demoapp_classpath.idx",

# sometimes packagers want to put certain files into the root of the springboot app jar
# these addins will be copied into the root of the generated springboot jar
addins = [":info.txt", ":author.txt"],
)

springboottest_deps = [
Expand Down
1 change: 1 addition & 0 deletions examples/demoapp/author.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Salesforce
3 changes: 3 additions & 0 deletions examples/demoapp/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This springboot jar was built by Bazel rules_spring.

It is copied into the toplevel directory of the springboot jar as an 'addin'.
1 change: 1 addition & 0 deletions springboot/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports_files([
"default_bazelrun_script.sh",
"dupe_class_jar_allowlist.txt",
"empty.txt",
"addin_end.txt",
])

py_binary(
Expand Down
1 change: 1 addition & 0 deletions springboot/addin_end.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Marker file that indicates the end of the addin list.
4 changes: 4 additions & 0 deletions springboot/springboot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def springboot(
bazelrun_jvm_flags = None,
bazelrun_data = None,
bazelrun_background = False,
addins = [],
tags = [],
testonly = False,
visibility = None,
Expand Down Expand Up @@ -300,6 +301,7 @@ def springboot(
to pass to the JVM at startup. Ex: *-Dcustomprop=gold -DcustomProp2=silver*
bazelrun_data: Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*.
bazelrun_background: Optional. If True, the *bazel run* launcher will not block. The run command will return and process will remain running.
addins: Uncommon option to add additional files to the root of the springboot jar. For example a license file. Pass an array of files from the package.
tags: Optional. Bazel standard attribute.
testonly: Optional. Bazel standard attribute. Defaults to False.
visibility: Optional. Bazel standard attribute.
Expand Down Expand Up @@ -417,6 +419,8 @@ def springboot(
":" + genmanifest_rule,
":" + gengitinfo_rule,
deps_index_file,
] + addins + [
"@rules_spring//springboot:addin_end.txt",
":" + dep_aggregator_rule,
],
cmd = "$(location @rules_spring//springboot:springboot_pkg.sh) " +
Expand Down
1 change: 1 addition & 0 deletions springboot/springboot_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Note that the rule README has more detailed usage instructions for each attribut
| bazelrun_jvm_flags | Optional. When launching the application using 'bazel run', an optional set of JVM flags to pass to the JVM at startup. Ex: *-Dcustomprop=gold -DcustomProp2=silver* | <code>None</code> |
| bazelrun_data | Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*. | <code>None</code> |
| bazelrun_background | Optional. If True, the *bazel run* launcher will not block. The run command will return and process will remain running. | <code>False</code> |
| addins | Uncommon option to add additional files to the root of the springboot jar. For example a license file. Pass an array of files from the package. | <code>None</code> |
| tags | Optional. Bazel standard attribute. | <code>[]</code> |
| testonly | Optional. Bazel standard attribute. | <code>False</code> |
| visibility | Optional. Bazel standard attribute. | <code>None</code> |
Expand Down
39 changes: 29 additions & 10 deletions springboot/springboot_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ appjar=$7
manifest=$8
gitpropsfile=$9
deps_index_file=${10}
first_jar_arg=11
first_addin_arg=11

if [ $deps_starlark_order = "True" ]; then
deps_starlark_order=true
Expand Down Expand Up @@ -86,6 +86,7 @@ echo " appjar_name $appjar_name (unused, is the appjar filename without the
echo " manifest $manifest (the location of the generated manifest.MF file)" >> $debugfile
echo " deps_index_file $deps_index_file (the location of the classpath index file - optional)" >> $debugfile
echo " deplibs (list of upstream transitive dependencies, these will be incorporated into the jar file in BOOT-INF/lib )" >> $debugfile
echo "*************************************************************************************" >> $debugfile

# compute path to jar utility
pushd . > /dev/null
Expand All @@ -95,15 +96,6 @@ popd > /dev/null
echo "Jar command:" >> $debugfile
echo $jar_command >> $debugfile

# log the list of dep jars we were given
i=$first_jar_arg
while [ "$i" -le "$#" ]; do
eval "lib=\${$i}"
echo " DEPLIB: $lib" >> $debugfile
i=$((i + 1))
done
echo "" >> $debugfile

echo $shasum_install_msg >> $debugfile
echo "Unique identifier for this build: [$packagesha] computed from [$packagesha_raw]" >> $debugfile

Expand All @@ -119,6 +111,33 @@ mkdir -p $working_dir/BOOT-INF/classes
TMP_working_dir=$base_working_dir/tmp
mkdir -p $TMP_working_dir

# Addins is the feature to add files to the root of the springboot jar
# The addins are listed in order as args, until the addin_end.txt file marks the end
i=$first_addin_arg
while [ "$i" -le "$#" ]; do
eval "addin=\${$i}"
echo " ADDINt: $addin" >> $debugfile
if [[ $addin == *addin_end.txt ]]; then
i=$((i + 1))
echo " ADDIN end found: $addin" >> $debugfile
break
fi
echo " ADDIN: $addin" >> $debugfile
cp $addin $working_dir
i=$((i + 1))
done
first_jar_arg=$i
echo "" >> $debugfile

# log the list of dep jars we were given
i=$first_jar_arg
while [ "$i" -le "$#" ]; do
eval "lib=\${$i}"
echo " DEPLIB: $lib" >> $debugfile
i=$((i + 1))
done
echo "" >> $debugfile

# Extract the compiled Boot application classes into BOOT-INF/classes
# this must include the application's main class (annotated with @SpringBootApplication)
cd $working_dir/BOOT-INF/classes
Expand Down

0 comments on commit 564bc4e

Please sign in to comment.