Skip to content

Commit

Permalink
Merge pull request #191 from Aditya-2001/aditya/add-exports+opens
Browse files Browse the repository at this point in the history
Add support for add-opens and add-exports
  • Loading branch information
plaird authored Mar 18, 2024
2 parents 758565c + 8b04107 commit 55bdaae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion springboot/default_bazelrun_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ echo ""
echo "Using JAVA_OPTS from the environment: ${JAVA_OPTS}"
echo "Using bazelrun_jvm_flags from the BUILD file: ${JVM_FLAGS}"

if [ -f "${ADD_EXPORTS}" ]; then
echo "Using ADD_EXPORTS from the environment: ${ADD_EXPORTS}"
fi

if [ -f "${ADD_OPENS}" ]; then
echo "Using ADD_OPENS from the environment: ${ADD_OPENS}"
fi

# main args
main_args="$@"

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

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

echo "Running ${cmd}"
echo "In directory $(pwd)"
Expand Down
4 changes: 4 additions & 0 deletions springboot/springboot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ def springboot(
tags = [],
testonly = False,
visibility = None,
bazelrun_addopens = [],
bazelrun_addexports = [],
exclude = [], # deprecated
classpath_index = "@rules_spring//springboot:empty.txt", # deprecated
use_build_dependency_order = True, # deprecated
Expand Down Expand Up @@ -585,6 +587,8 @@ def springboot(
name = genbazelrunenv_rule,
cmd = "$(location @rules_spring//springboot:write_bazelrun_env.sh) " + name + " " + _get_springboot_jar_file_name(name)
+ " " + _get_relative_package_path() + " $@ " + _convert_starlarkbool_to_bashbool(bazelrun_background)
+ " " + " ".join(["--add-exports=" + element for element in bazelrun_addexports])
+ " " + " ".join(["--add-opens=" + element for element in bazelrun_addopens])
+ " " + bazelrun_jvm_flags,
# message = "SpringBoot rule is writing the bazel run launcher env...",
tools = ["@rules_spring//springboot:write_bazelrun_env.sh"],
Expand Down
6 changes: 5 additions & 1 deletion springboot/write_bazelrun_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ SPRINGBOOTJAR_FILENAME=${2}
LABEL_PATH=${3}
OUTPUTFILE_PATH=${4}
DO_BACKGROUND=${5}
FIRST_JVMFLAG_ARG=6
ADD_EXPORTS=${6}
ADD_OPENS=${7}
FIRST_JVMFLAG_ARG=8

if [ "$LABEL_PATH" == "root" ]; then
# token that indicates that the target is in the root path, which for the
Expand All @@ -43,4 +45,6 @@ echo "export RULE_NAME=$RULE_NAME" > $OUTPUTFILE_PATH
echo "export LABEL_PATH=$LABEL_PATH" >> $OUTPUTFILE_PATH
echo "export SPRINGBOOTJAR_FILENAME=$SPRINGBOOTJAR_FILENAME" >> $OUTPUTFILE_PATH
echo "export DO_BACKGROUND=$DO_BACKGROUND" >> $OUTPUTFILE_PATH
echo "export ADD_EXPORTS=$ADD_EXPORTS" >> $OUTPUTFILE_PATH
echo "export ADD_OPENS=$ADD_OPENS" >> $OUTPUTFILE_PATH
echo "export JVM_FLAGS=\"$JVM_FLAGS\"" >> $OUTPUTFILE_PATH

0 comments on commit 55bdaae

Please sign in to comment.