Skip to content

Commit 62f5f5e

Browse files
authored
Merge pull request #161 from salesforce/plaird/addins
Implement addins feature
2 parents ec5ca65 + 564bc4e commit 62f5f5e

File tree

8 files changed

+45
-11
lines changed

8 files changed

+45
-11
lines changed

examples/demoapp/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ springboot(
8585

8686
# if you have conflicting classes in dependency jar files, you can define the order in which the jars are loaded
8787
# https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-executable-jar-format.html#executable-jar-war-index-files-classpath
88-
deps_index_file = "demoapp_classpath.idx",
88+
deps_index_file = ":demoapp_classpath.idx",
89+
90+
# sometimes packagers want to put certain files into the root of the springboot app jar
91+
# these addins will be copied into the root of the generated springboot jar
92+
addins = [":info.txt", ":author.txt"],
8993
)
9094

9195
springboottest_deps = [

examples/demoapp/author.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Salesforce

examples/demoapp/info.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This springboot jar was built by Bazel rules_spring.
2+
3+
It is copied into the toplevel directory of the springboot jar as an 'addin'.

springboot/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports_files([
2020
"default_bazelrun_script.sh",
2121
"dupe_class_jar_allowlist.txt",
2222
"empty.txt",
23+
"addin_end.txt",
2324
])
2425

2526
py_binary(

springboot/addin_end.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marker file that indicates the end of the addin list.

springboot/springboot.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def springboot(
253253
bazelrun_jvm_flags = None,
254254
bazelrun_data = None,
255255
bazelrun_background = False,
256+
addins = [],
256257
tags = [],
257258
testonly = False,
258259
visibility = None,
@@ -300,6 +301,7 @@ def springboot(
300301
to pass to the JVM at startup. Ex: *-Dcustomprop=gold -DcustomProp2=silver*
301302
bazelrun_data: Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*.
302303
bazelrun_background: Optional. If True, the *bazel run* launcher will not block. The run command will return and process will remain running.
304+
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.
303305
tags: Optional. Bazel standard attribute.
304306
testonly: Optional. Bazel standard attribute. Defaults to False.
305307
visibility: Optional. Bazel standard attribute.
@@ -417,6 +419,8 @@ def springboot(
417419
":" + genmanifest_rule,
418420
":" + gengitinfo_rule,
419421
deps_index_file,
422+
] + addins + [
423+
"@rules_spring//springboot:addin_end.txt",
420424
":" + dep_aggregator_rule,
421425
],
422426
cmd = "$(location @rules_spring//springboot:springboot_pkg.sh) " +

springboot/springboot_doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Note that the rule README has more detailed usage instructions for each attribut
3636
| 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> |
3737
| bazelrun_data | Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*. | <code>None</code> |
3838
| 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> |
39+
| 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> |
3940
| tags | Optional. Bazel standard attribute. | <code>[]</code> |
4041
| testonly | Optional. Bazel standard attribute. | <code>False</code> |
4142
| visibility | Optional. Bazel standard attribute. | <code>None</code> |

springboot/springboot_pkg.sh

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ appjar=$7
2929
manifest=$8
3030
gitpropsfile=$9
3131
deps_index_file=${10}
32-
first_jar_arg=11
32+
first_addin_arg=11
3333

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

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

98-
# log the list of dep jars we were given
99-
i=$first_jar_arg
100-
while [ "$i" -le "$#" ]; do
101-
eval "lib=\${$i}"
102-
echo " DEPLIB: $lib" >> $debugfile
103-
i=$((i + 1))
104-
done
105-
echo "" >> $debugfile
106-
10799
echo $shasum_install_msg >> $debugfile
108100
echo "Unique identifier for this build: [$packagesha] computed from [$packagesha_raw]" >> $debugfile
109101

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

114+
# Addins is the feature to add files to the root of the springboot jar
115+
# The addins are listed in order as args, until the addin_end.txt file marks the end
116+
i=$first_addin_arg
117+
while [ "$i" -le "$#" ]; do
118+
eval "addin=\${$i}"
119+
echo " ADDINt: $addin" >> $debugfile
120+
if [[ $addin == *addin_end.txt ]]; then
121+
i=$((i + 1))
122+
echo " ADDIN end found: $addin" >> $debugfile
123+
break
124+
fi
125+
echo " ADDIN: $addin" >> $debugfile
126+
cp $addin $working_dir
127+
i=$((i + 1))
128+
done
129+
first_jar_arg=$i
130+
echo "" >> $debugfile
131+
132+
# log the list of dep jars we were given
133+
i=$first_jar_arg
134+
while [ "$i" -le "$#" ]; do
135+
eval "lib=\${$i}"
136+
echo " DEPLIB: $lib" >> $debugfile
137+
i=$((i + 1))
138+
done
139+
echo "" >> $debugfile
140+
122141
# Extract the compiled Boot application classes into BOOT-INF/classes
123142
# this must include the application's main class (annotated with @SpringBootApplication)
124143
cd $working_dir/BOOT-INF/classes

0 commit comments

Comments
 (0)