Skip to content

Commit afd4c9f

Browse files
authored
Merge pull request #234 from salesforce/plaird/bazelrun_vars
fix bazelrun jvmflags, add list attribute
2 parents 4f2a26f + 5b0a4a0 commit afd4c9f

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

springboot/default_bazelrun_script.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ echo ""
5555
echo "Using JAVA_OPTS from the environment: ${JAVA_OPTS}"
5656
echo "Using bazelrun_jvm_flags from the BUILD file: ${JVM_FLAGS}"
5757

58-
if [ -f "${ADD_EXPORTS}" ]; then
59-
echo "Using ADD_EXPORTS from the environment: ${ADD_EXPORTS}"
60-
fi
61-
62-
if [ -f "${ADD_OPENS}" ]; then
63-
echo "Using ADD_OPENS from the environment: ${ADD_OPENS}"
64-
fi
65-
6658
# main args
6759
main_args="$@"
6860

@@ -72,7 +64,7 @@ jar=${SPRINGBOOTJAR_FILENAME}
7264

7365
# assemble the command
7466
# use exec so that we can pass signals to the underlying process (https://github.com/salesforce/rules_spring/issues/91)
75-
cmd="exec ${java_cmd} ${JVM_FLAGS} ${JAVA_OPTS} ${ADD_EXPORTS} ${ADD_OPENS} -jar ${path}${jar} ${main_args}"
67+
cmd="exec ${java_cmd} ${JVM_FLAGS} ${JAVA_OPTS} -jar ${path}${jar} ${main_args}"
7668

7769
echo "Running ${cmd}"
7870
echo "In directory $(pwd)"

springboot/springboot.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ def springboot(
380380
bazelrun_java_toolchain = None,
381381
bazelrun_script = None,
382382
bazelrun_jvm_flags = None,
383+
bazelrun_jvm_flag_list = None,
383384
bazelrun_data = None,
384385
bazelrun_background = False,
385386
addins = [],
@@ -441,8 +442,9 @@ def springboot(
441442
bazelrun_java_toolchain: Optional. Label to the Java toolchain to use when launching the application using 'bazel run'
442443
bazelrun_script: Optional. When launching the application using 'bazel run', a default launcher script is used.
443444
This attribute can be used to provide a customized launcher script. Ex: *my_custom_script.sh*
444-
bazelrun_jvm_flags: Optional. When launching the application using 'bazel run', an optional set of JVM flags
445-
to pass to the JVM at startup. Ex: *-Dcustomprop=gold -DcustomProp2=silver*
445+
bazelrun_jvm_flags: Optional. Deprecated form of bazelrun_jvm_flag_list. Ex: *-Dcustomprop=gold -DcustomProp2=silver*
446+
bazelrun_jvm_flag_list: Optional. When launching the application using 'bazel run', an optional set of JVM flags
447+
to pass to the JVM at startup. Ex: *['-Dcustomprop=gold', '-DcustomProp2=silver']*
446448
bazelrun_data: Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*.
447449
bazelrun_background: Optional. If True, the *bazel run* launcher will not block. The run command will return and process will remain running.
448450
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.
@@ -488,6 +490,10 @@ def springboot(
488490
dupeclassescheck_ignorelist = duplicate_class_allowlist
489491
if bazelrun_jvm_flags == None:
490492
bazelrun_jvm_flags = jvm_flags
493+
if bazelrun_jvm_flags == None:
494+
bazelrun_jvm_flags = ""
495+
if bazelrun_jvm_flag_list != None:
496+
bazelrun_jvm_flags = bazelrun_jvm_flags + " ".join(bazelrun_jvm_flag_list)
491497
if bazelrun_data == None:
492498
bazelrun_data = data
493499

springboot/write_bazelrun_env.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@ SPRINGBOOTJAR_FILENAME=${2}
1717
LABEL_PATH=${3}
1818
OUTPUTFILE_PATH=${4}
1919
DO_BACKGROUND=${5}
20-
ADD_EXPORTS=${6}
21-
ADD_OPENS=${7}
22-
FIRST_JVMFLAG_ARG=8
20+
FIRST_JVMFLAG_ARG=6
2321

2422
if [ "$LABEL_PATH" == "root" ]; then
2523
# token that indicates that the target is in the root path, which for the
2624
# purposes of the label path, is empty string
2725
LABEL_PATH=""
2826
fi
2927

30-
#echo "Generating 'bazel run' env."
31-
#echo "SPRINGBOOTJAR_FILENAME=$SPRINGBOOTJAR_FILENAME"
32-
#echo "LABEL_PATH=$LABEL_PATH"
33-
#echo "OUTPUTFILE_PATH=$OUTPUTFILE_PATH"
34-
#echo "DO_BACKGROUND=$DO_BACKGROUND"
35-
3628
JVM_FLAGS=""
3729
i=$FIRST_JVMFLAG_ARG
3830
while [ "$i" -le "$#" ]; do
@@ -45,6 +37,14 @@ echo "export RULE_NAME=$RULE_NAME" > $OUTPUTFILE_PATH
4537
echo "export LABEL_PATH=$LABEL_PATH" >> $OUTPUTFILE_PATH
4638
echo "export SPRINGBOOTJAR_FILENAME=$SPRINGBOOTJAR_FILENAME" >> $OUTPUTFILE_PATH
4739
echo "export DO_BACKGROUND=$DO_BACKGROUND" >> $OUTPUTFILE_PATH
48-
echo "export ADD_EXPORTS=$ADD_EXPORTS" >> $OUTPUTFILE_PATH
49-
echo "export ADD_OPENS=$ADD_OPENS" >> $OUTPUTFILE_PATH
5040
echo "export JVM_FLAGS=\"$JVM_FLAGS\"" >> $OUTPUTFILE_PATH
41+
42+
43+
# DEBUG output
44+
#echo "Generating 'bazel run' env."
45+
#echo "SPRINGBOOTJAR_FILENAME=$SPRINGBOOTJAR_FILENAME"
46+
#echo "LABEL_PATH=$LABEL_PATH"
47+
#echo "OUTPUTFILE_PATH=$OUTPUTFILE_PATH"
48+
#echo "DO_BACKGROUND=$DO_BACKGROUND"
49+
#echo "JVM_FLAGS=$JVM_FLAGS"
50+

0 commit comments

Comments
 (0)