Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing new Spring Boot JarLauncher class #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions springboot/springboot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def springboot(
name,
java_library,
boot_app_class,
boot_launcher_class = "org.springframework.boot.loader.JarLauncher",
deps = None,
deps_banned = None,
deps_exclude = None,
Expand Down Expand Up @@ -525,7 +526,7 @@ def springboot(
native.genrule(
name = genmanifest_rule,
srcs = [":" + dep_aggregator_rule],
cmd = "$(location @rules_spring//springboot:write_manifest.sh) " + boot_app_class + " $@ $(JAVABASE) $(SRCS)",
cmd = "$(location @rules_spring//springboot:write_manifest.sh) " + boot_app_class + " " + boot_launcher_class + " $@ $(JAVABASE) $(SRCS)",
# message = "SpringBoot rule is writing the MANIFEST.MF...",
tools = ["@rules_spring//springboot:write_manifest.sh"],
outs = [genmanifest_out],
Expand Down Expand Up @@ -562,16 +563,17 @@ def springboot(
# param0: directory containing the springboot rule
# param1: location of the jar utility (singlejar)
# param2: boot application main classname (the @SpringBootApplication class)
# param3: jdk path for running java tools e.g. jar; $(JAVABASE)
# param4: compiled application jar name
# param5: use build file deps order [True|False]
# param6: include git.properties file in resulting jar
# param7: executable jar output filename to write to
# param8: compiled application jar
# param9: manifest file
# param10: git.properties file
# param11: classpath_index file
# param12-N: upstream transitive dependency jar(s)
# param3: spring boot launcher class
# param4: jdk path for running java tools e.g. jar; $(JAVABASE)
# param5: compiled application jar name
# param6: use build file deps order [True|False]
# param7: include git.properties file in resulting jar
# param8: executable jar output filename to write to
# param9: compiled application jar
# param10: manifest file
# param11: git.properties file
# param12: classpath_index file
# param13-N: upstream transitive dependency jar(s)
native.genrule(
name = genjar_rule,
srcs = [
Expand All @@ -584,7 +586,7 @@ def springboot(
":" + dep_aggregator_rule,
],
cmd = "$(location @rules_spring//springboot:springboot_pkg.sh) " +
"$(location @bazel_tools//tools/jdk:singlejar) " + boot_app_class +
"$(location @bazel_tools//tools/jdk:singlejar) " + boot_app_class + " " + boot_launcher_class +
" $(JAVABASE) " + name + " " + str(deps_use_starlark_order) + " " + str(include_git_properties_file) + " $@ $(SRCS)",
tools = [
"@rules_spring//springboot:springboot_pkg.sh",
Expand Down
24 changes: 13 additions & 11 deletions springboot/springboot_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ set -e
ruledir=$(pwd)
singlejar_cmd=$(pwd)/$1
mainclass=$2
javabase=$3
appjar_name=$4
deps_starlark_order=$5
include_git_properties_file=$6
outputjar=$7
appjar=$8
manifest=$9
gitpropsfile=${10}
deps_index_file=${11}
first_addin_arg=12
spring_boot_launcher_class=${3}
javabase=$4
appjar_name=$5
deps_starlark_order=$6
include_git_properties_file=$7
outputjar=$8
appjar=$9
manifest=${10}
gitpropsfile=${11}
deps_index_file=${12}
first_addin_arg=13

# converting starlark booleans to bash booleans
if [ $deps_starlark_order = "True" ]; then
Expand Down Expand Up @@ -87,6 +88,7 @@ echo "SPRING BOOT PACKAGER FOR BAZEL" >> $debugfile
echo " ruledir $ruledir (build working directory)" >> $debugfile
echo " singlejar $singlejar_cmd (path to the singlejar utility)" >> $debugfile
echo " mainclass $mainclass (classname of the @SpringBootApplication class for the manifest.MF file entry)" >> $debugfile
echo " bootloader $spring_boot_launcher_class (classname of the Spring Boot Loader to use)" >> $debugfile
echo " outputjar $outputjar (the executable JAR that will be built from this rule)" >> $debugfile
echo " javabase $javabase (the path to the JDK2)" >> $debugfile
echo " appjar $appjar (contains the .class files for the Spring Boot application)" >> $debugfile
Expand Down Expand Up @@ -307,7 +309,7 @@ cd $working_dir
# so we have to respecify the manifest data
# TODO we should rewrite write_manfiest.sh to produce inputs compatible for singlejar (Issue #27)
singlejar_options="--normalize --dont_change_compression" # add in --verbose for more details from command
singlejar_mainclass="--main_class org.springframework.boot.loader.JarLauncher"
singlejar_mainclass="--main_class $spring_boot_launcher_class"
$singlejar_cmd $singlejar_options $singlejar_mainclass \
--deploy_manifest_lines "Start-Class: $mainclass" \
--sources $raw_output_jar \
Expand Down
7 changes: 4 additions & 3 deletions springboot/write_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
set -e

mainclass=$1
manifestfile=$2
javabase=$3
springbootlauncherclass=$2
manifestfile=$3
javabase=$4
found_spring_jar=0
# Looking for the springboot jar injected by springboot.bzl and extracting the version
for var in "$@"
Expand Down Expand Up @@ -48,7 +49,7 @@ java_version=$(echo "$java_string" | head -n1 | cut -d ' ' -f 3 | rev | cut -c2-
echo "Manifest-Version: 1.0" > $manifestfile
echo "Created-By: Bazel" >> $manifestfile
echo "Built-By: Bazel" >> $manifestfile
echo "Main-Class: org.springframework.boot.loader.JarLauncher" >> $manifestfile
echo "Main-Class: $springbootlauncherclass" >> $manifestfile
echo "Spring-Boot-Classes: BOOT-INF/classes/" >> $manifestfile
echo "Spring-Boot-Lib: BOOT-INF/lib/" >> $manifestfile
echo "Spring-Boot-Version: $spring_version" >> $manifestfile
Expand Down