From 86657a6d32b6dbdcfd83ec075eabe60bb82113e5 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 11 Aug 2022 21:54:33 +0200 Subject: [PATCH] Feature: Manual and auto classpath option - Adding option to put additional class paths to the builder - Adding option to get automatically the class path for jar files (tested with Spring-Boot) --- .gitignore | 1 + README.md | 4 ++++ warp4j | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 98c43f0..4c3a4d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ fatjar/ warped/ TODO.md +/.project diff --git a/README.md b/README.md index 541a05a..6d114c9 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Options: override JDK/JRE version examples: "11", "11.0", "11.0.2", "11.0.2+9" (default: 11) + -cp, --class-path + adds additional classpaths to the jdeps call -o, --output override output directory; this is relative to current PWD @@ -81,6 +83,8 @@ Options: --pull check if more recent JDK/JRE distro is available; by default latest cached version that matches "--java-version" is used + --spring-boot extract from (Spring-Boot) jar the dependencies' + to get the classpath for jdeps call' --linux create binary for Linux --macos create binary for macOS --windows create binary for Windows diff --git a/warp4j b/warp4j index bac0480..41b092f 100755 --- a/warp4j +++ b/warp4j @@ -11,6 +11,8 @@ function print_help { echo ' override JDK/JRE version' echo ' examples: "11", "11.0", "11.0.2", "11.0.2+9"' echo ' (default: 11)' + echo ' -cp, --class-path ' + echo ' adds additional classpaths to the jdeps call' echo ' -o, --output ' echo ' override output directory;' echo ' this is relative to current PWD' @@ -27,6 +29,8 @@ function print_help { echo ' --pull check if more recent JDK/JRE distro is available;' echo ' by default latest cached version that matches' echo ' "--java-version" is used' + echo ' --spring-boot extract from (Spring-Boot) jar the dependencies' + echo ' to get the classpath for jdeps call' echo ' --linux create binary for Linux' echo ' --macos create binary for macOS' echo ' --windows create binary for Windows' @@ -104,6 +108,10 @@ while [[ $# -gt 0 ]]; do print_help exit ;; + -cp|--class-path) + CLASS_PATH="$2" + shift 2 + ;; -j|--java-version) JAVA_VERSION="$2" JAVA_VERSION_OVERRIDEN=true @@ -145,6 +153,10 @@ while [[ $# -gt 0 ]]; do JVM_OPTIONS="$2" shift 2 ;; + --spring-boot) + SPRING_BOOT=true + shift + ;; -*|--*) # unsupported options fail_with "Unsupported option $1" ;; @@ -369,6 +381,11 @@ fi JAVA_DOWNLOAD_PATH=$CACHE_PATH/$JAVA_DISTRO_TYPE/$JVM_IMPL BUNDLES_PATH=$CACHE_PATH/bundle # prepare bundles here +# path for extracted jar (Spring-Boot) files +EXTRACTED_JAR_PATH=$CACHE_PATH/app-jar # prepare bundles here +mkdir -p ${EXTRACTED_JAR_PATH} +trap 'rm -rf ${EXTRACTED_JAR_PATH}' EXIT + DIR="$(pwd -P)" # execution directory path # final binaries created in WARPED_TEMP_PATH and then moved to WARPED_PATH @@ -407,10 +424,10 @@ SETLOCAL SET "JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"'" SET "JAR='"$JAR_NAME"'.jar" -SET "JAVA=%~dp0\%JAVA_DIST%\bin\java.exe" +SET "JAVA=%~dp0\%JAVA_DIST%\bin\javaw.exe" SET "JAR_PATH=%~dp0\%JAR%" -CALL %JAVA% '"$JVM_OPTIONS"' -jar %JAR_PATH% %* +START %JAVA% '"$JVM_OPTIONS"' -jar %JAR_PATH% %* EXIT /B %ERRORLEVEL% ' } @@ -620,7 +637,21 @@ JDEPS=$JDK_PATH/bin/jdeps if [[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]]; then echo "Analyzing dependencies..." # TODO check for errors - MODULES=$("$JDEPS" --print-module-deps "$JAR" | grep -v Warning) + # TODO If JAVA_VERSION is not an INT it will throw an error + if [ -n "$CLASS_PATH" ] + then + echo "Using given classpaths: $CLASS_PATH" + MODULES=$("$JDEPS" -cp $CLASS_PATH --print-module-deps --ignore-missing-deps --multi-release $JAVA_VERSION_BASE "$JAR" | grep -v Warning) + elif [ "$SPRING_BOOT" ] + then + echo "Extracting jar file to get classpath" + unzip -q "${JAR}" -d "${EXTRACTED_JAR_PATH}" + echo "Fetching modules" + MODULES=$("$JDEPS" -classpath \'${EXTRACTED_JAR_PATH}/BOOT-INF/lib/*:${EXTRACTED_JAR_PATH}/BOOT-INF/classes:${EXTRACTED_JAR_PATH}\' --print-module-deps --ignore-missing-deps --module-path ${EXTRACTED_JAR_PATH}/BOOT-INF/lib/javax.activation-api-1.2.0.jar --recursive --multi-release ${JAVA_VERSION_BASE} -quiet ${EXTRACTED_JAR_PATH}/org ${EXTRACTED_JAR_PATH}/BOOT-INF/classes ${EXTRACTED_JAR_PATH}/BOOT-INF/lib/*.jar | grep -v Warning) + else + echo "Fetch modules with default behavior" + MODULES=$("$JDEPS" --print-module-deps --ignore-missing-deps --multi-release $JAVA_VERSION_BASE "$JAR" | grep -v Warning) + fi fi # creates minimized runtime for the platform @@ -734,4 +765,4 @@ function warp_targets() { } # actually create binaries and archives for all targets -warp_targets +warp_targets \ No newline at end of file