feature/manual_and_auto_classpath_option #1

Merged
David merged 10 commits from feature/manual_and_auto_classpath_option into master 2022-08-12 18:40:10 +02:00
3 changed files with 40 additions and 4 deletions
Showing only changes of commit 86657a6d32 - Show all commits

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
fatjar/
warped/
TODO.md
/.project

View File

@ -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 <classpath>
adds additional classpaths to the jdeps call
-o, --output <directory>
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

37
warp4j
View File

@ -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 <classpath>'
echo ' adds additional classpaths to the jdeps call'
echo ' -o, --output <directory>'
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