From 2cff75b9e29dc0f3c8966c19b7f2d3f999a8b2f5 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Wed, 5 Jul 2023 09:35:04 +0100 Subject: [PATCH 1/2] debugging --- springboot/springboot.bzl | 17 ++++++++++------- springboot/springboot_pkg.sh | 33 +++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/springboot/springboot.bzl b/springboot/springboot.bzl index 0fc690a..035ebd1 100644 --- a/springboot/springboot.bzl +++ b/springboot/springboot.bzl @@ -249,6 +249,7 @@ def springboot( deps_use_starlark_order = None, dupeclassescheck_enable = None, dupeclassescheck_ignorelist = None, + include_git_properties_file=True, bazelrun_script = None, bazelrun_jvm_flags = None, bazelrun_data = None, @@ -295,6 +296,7 @@ def springboot( once, but with a different hash. This indicates that your dependency tree has conflicting libraries. dupeclassescheck_ignorelist: Optional. When using the duplicate class check, this attribute provides a file that contains a list of libraries excluded from the analysis. Ex: *dupeclass_libs.txt* + include_git_properties_file: If *True*, will include a git.properties file in the resulting jar. bazelrun_script: Optional. When launching the application using 'bazel run', a default launcher script is used. This attribute can be used to provide a customized launcher script. Ex: *my_custom_script.sh* bazelrun_jvm_flags: Optional. When launching the application using 'bazel run', an optional set of JVM flags @@ -406,12 +408,13 @@ def springboot( # 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: executable jar output filename to write to - # param7: compiled application jar - # param8: manifest file - # param9: git.properties file - # param10: classpath_index file - # param11-N: upstream transitive dependency jar(s) + # 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) native.genrule( name = genjar_rule, srcs = [ @@ -425,7 +428,7 @@ def springboot( ], cmd = "$(location @rules_spring//springboot:springboot_pkg.sh) " + "$(location @bazel_tools//tools/jdk:singlejar) " + boot_app_class + - " $(JAVABASE) " + name + " " + str(deps_use_starlark_order) + " $@ $(SRCS)", + " $(JAVABASE) " + name + " " + str(deps_use_starlark_order) + " " + str(include_git_properties_file) + " $@ $(SRCS)", tools = [ "@rules_spring//springboot:springboot_pkg.sh", "@bazel_tools//tools/jdk:singlejar", diff --git a/springboot/springboot_pkg.sh b/springboot/springboot_pkg.sh index 606146f..4e6b86f 100755 --- a/springboot/springboot_pkg.sh +++ b/springboot/springboot_pkg.sh @@ -24,19 +24,27 @@ mainclass=$2 javabase=$3 appjar_name=$4 deps_starlark_order=$5 -outputjar=$6 -appjar=$7 -manifest=$8 -gitpropsfile=$9 -deps_index_file=${10} -first_addin_arg=11 - +include_git_properties_file=$6 +outputjar=$7 +appjar=$8 +manifest=$9 +gitpropsfile=$10 +deps_index_file=${11} +first_addin_arg=12 + +# converting starlark booleans to bash booleans if [ $deps_starlark_order = "True" ]; then deps_starlark_order=true else deps_starlark_order=false fi +if [ $include_git_properties_file = "True" ]; then + include_git_properties_file=true +else + include_git_properties_file=false +fi + # package name (not guaranteed to be globally unique) packagename=$(basename $appjar_name) @@ -225,9 +233,14 @@ echo "DEBUG: finished copying transitives into BOOT-INF/lib, elapsed time (secon # Inject the Git properties into a properties file in the jar # (the -f is needed when remote caching is used, as cached files come down as r-x and # if you rerun the build it needs to overwrite) -echo "DEBUG: adding git.properties" >> $debugfile -cat $ruledir/$gitpropsfile >> $debugfile -cp -f $ruledir/$gitpropsfile $working_dir/BOOT-INF/classes +echo $include_git_properties_file +if [[ $include_git_properties_file = true ]]; then + echo "DEBUG: adding git.properties" >> $debugfile + cat $ruledir/$gitpropsfile >> $debugfile + echo "DEBUG: kaaa" >> $debugfile + cp -f $ruledir/$gitpropsfile $working_dir/BOOT-INF/classes + echo "DEBUG: baaa" >> $debugfile +fi # Inject the classpath index (unless it is the default empty.txt file). Requires Spring Boot version 2.3+ # https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-executable-jar-format.html#executable-jar-war-index-files-classpath From bf6adf291aea08764df4adc312d2f3668c299856 Mon Sep 17 00:00:00 2001 From: Kris Foster Date: Wed, 5 Jul 2023 09:51:37 +0100 Subject: [PATCH 2/2] generate docs --- springboot/springboot_doc.md | 24 ++++++++++++++---------- springboot/springboot_pkg.sh | 8 +++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/springboot/springboot_doc.md b/springboot/springboot_doc.md index 97d6e48..5d3ed92 100755 --- a/springboot/springboot_doc.md +++ b/springboot/springboot_doc.md @@ -5,9 +5,10 @@ ## springboot
-springboot(name, java_library, boot_app_class, deps, deps_exclude, deps_index_file,
-           deps_use_starlark_order, dupeclassescheck_enable, dupeclassescheck_ignorelist,
-           bazelrun_script, bazelrun_jvm_flags, bazelrun_data, bazelrun_background, tags, testonly, visibility,
+springboot(name, java_library, boot_app_class, deps, deps_exclude, deps_exclude_paths,
+           deps_index_file, deps_use_starlark_order, dupeclassescheck_enable,
+           dupeclassescheck_ignorelist, include_git_properties_file, bazelrun_script,
+           bazelrun_jvm_flags, bazelrun_data, bazelrun_background, addins, tags, testonly, visibility,
            exclude, classpath_index, use_build_dependency_order, fail_on_duplicate_classes,
            duplicate_class_allowlist, jvm_flags, data)
 
@@ -26,19 +27,20 @@ Note that the rule README has more detailed usage instructions for each attribut | java_library | **Required**. The built jar, identified by the name of the java_library rule, that contains the Spring Boot application. | none | | boot_app_class | **Required**. The fully qualified name of the class annotated with @SpringBootApplication. Ex: *com.sample.SampleMain* | none | | deps | Optional. An additional set of Java dependencies to add to the executable. Normally all dependencies are set on the *java_library*. | None | -| deps_exclude | Optional. A list of jar labels that will be omitted from the final packaging step. This is a manual option for eliminating a problematic dependency that cannot be eliminated upstream. Ex: *["@maven//:commons_cli_commons_cli"]*. | None | -| deps_exclude_paths | Optional. This attribute provides a list of partial paths that will be omitted from the final packaging step if the string is contained within the dep filename. This is a more raw method than deps_exclude for eliminating a problematic dependency/file that cannot be eliminated upstream. Ex: [*jackson-databind-*]. | None | +| deps_exclude | Optional. This attribute provides a list of partial paths that will be omitted from the final packaging step if the string is contained within the dep filename. This is a more raw method than deps_exclude for eliminating a problematic dependency/file that cannot be eliminated upstream. Ex: [*jackson-databind-*]. | None | +| deps_exclude_paths |

-

| None | | deps_index_file | Optional. Uses Spring Boot's [classpath index feature](https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-executable-jar-format.html#executable-jar-war-index-files-classpath) to define classpath order. This feature is not commonly used, as the application must be extracted from the jar file for it to work. Ex: *my_classpath_index.idx* | None | -| deps_use_starlark_order | When running the Spring Boot application from the executable jar file, setting this attribute to *True* will use the classpath order as expressed by the order of deps in the BUILD file. Otherwise it is random order. | True | -| dupeclassescheck_enable | If *True*, will analyze the list of dependencies looking for any class that appears more than once, but with a different hash. This indicates that your dependency tree has conflicting libraries. | False | -| dupeclassescheck_ignorelist | Optional. When using the duplicate class check, this attribute can provide a file that contains a list of libraries excluded from the analysis. Ex: *dupeclass_libs.txt* | None | +| deps_use_starlark_order | When running the Spring Boot application from the executable jar file, setting this attribute to *True* will use the classpath order as expressed by the order of deps in the BUILD file. Otherwise it is random order. | None | +| dupeclassescheck_enable | If *True*, will analyze the list of dependencies looking for any class that appears more than once, but with a different hash. This indicates that your dependency tree has conflicting libraries. | None | +| dupeclassescheck_ignorelist | Optional. When using the duplicate class check, this attribute provides a file that contains a list of libraries excluded from the analysis. Ex: *dupeclass_libs.txt* | None | +| include_git_properties_file | If *True*, will include a git.properties file in the resulting jar. | True | | bazelrun_script | Optional. When launching the application using 'bazel run', a default launcher script is used. This attribute can be used to provide a customized launcher script. Ex: *my_custom_script.sh* | None | | 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* | None | | bazelrun_data | Uncommon option to add data files to runfiles. Behaves like the *data* attribute defined for *java_binary*. | None | | bazelrun_background | Optional. If True, the *bazel run* launcher will not block. The run command will return and process will remain running. | False | -| 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. | None | +| 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. | False | +| testonly | Optional. Bazel standard attribute. Defaults to False. | False | | visibility | Optional. Bazel standard attribute. | None | | exclude | Deprecated synonym of *deps_exclude* | [] | | classpath_index | Deprecated synonym of *deps_index_file* | "@rules_spring//springboot:empty.txt" | @@ -47,3 +49,5 @@ Note that the rule README has more detailed usage instructions for each attribut | duplicate_class_allowlist | Deprecated synonym of *dupeclassescheck_ignorelist* | None | | jvm_flags | Deprecated synonym of *bazelrun_jvm_flags* | "" | | data | Deprecated synonym of *bazelrun_data* | [] | + + diff --git a/springboot/springboot_pkg.sh b/springboot/springboot_pkg.sh index 4e6b86f..c76fcf9 100755 --- a/springboot/springboot_pkg.sh +++ b/springboot/springboot_pkg.sh @@ -28,7 +28,7 @@ include_git_properties_file=$6 outputjar=$7 appjar=$8 manifest=$9 -gitpropsfile=$10 +gitpropsfile=${10} deps_index_file=${11} first_addin_arg=12 @@ -94,6 +94,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 " gitpropsfile $gitpropsfile (the location of the generated git.properties file)" >> $debugfile echo "*************************************************************************************" >> $debugfile # compute path to jar utility @@ -233,13 +234,10 @@ echo "DEBUG: finished copying transitives into BOOT-INF/lib, elapsed time (secon # Inject the Git properties into a properties file in the jar # (the -f is needed when remote caching is used, as cached files come down as r-x and # if you rerun the build it needs to overwrite) -echo $include_git_properties_file -if [[ $include_git_properties_file = true ]]; then +if [[ "$include_git_properties_file" == true ]]; then echo "DEBUG: adding git.properties" >> $debugfile cat $ruledir/$gitpropsfile >> $debugfile - echo "DEBUG: kaaa" >> $debugfile cp -f $ruledir/$gitpropsfile $working_dir/BOOT-INF/classes - echo "DEBUG: baaa" >> $debugfile fi # Inject the classpath index (unless it is the default empty.txt file). Requires Spring Boot version 2.3+