Feature: Manual and auto classpath option

- Renaming option --spring-boot to --auto-class-path
- Adding option -s and --silent to use javaw for windows programs
This commit is contained in:
david 2022-08-12 17:25:22 +02:00
parent caccbe74e4
commit ff575c0d83

27
warp4j
View File

@ -13,6 +13,8 @@ function print_help {
echo ' (default: 17)' echo ' (default: 17)'
echo ' -cp, --class-path <classpath>' echo ' -cp, --class-path <classpath>'
echo ' adds additional classpaths to the jdeps call' echo ' adds additional classpaths to the jdeps call'
echo ' --auto-class-path extract and get class-path values from jar file'
echo ' ignored when -cp, --class-path is set'
echo ' -o, --output <directory>' echo ' -o, --output <directory>'
echo ' override output directory;' echo ' override output directory;'
echo ' this is relative to current PWD' echo ' this is relative to current PWD'
@ -29,7 +31,6 @@ function print_help {
echo ' --pull check if more recent JDK/JRE distro is available;' echo ' --pull check if more recent JDK/JRE distro is available;'
echo ' by default latest cached version that matches' echo ' by default latest cached version that matches'
echo ' "--java-version" is used' echo ' "--java-version" is used'
echo ' --spring-boot extract from (Spring-Boot) jar the dependencies'
echo ' to get the classpath for jdeps call' echo ' to get the classpath for jdeps call'
echo ' --linux create binary for Linux' echo ' --linux create binary for Linux'
echo ' --macos create binary for macOS' echo ' --macos create binary for macOS'
@ -43,6 +44,7 @@ function print_help {
echo ' "java <options> -jar <jar file>";' echo ' "java <options> -jar <jar file>";'
echo ' use quotes when passing multiple options' echo ' use quotes when passing multiple options'
echo " example: '-Xms512m -Xmx1024m'" echo " example: '-Xms512m -Xmx1024m'"
echo ' -s, --silent using javaw instead of java for windows'
echo ' -h, --help show this message' echo ' -h, --help show this message'
exit exit
} }
@ -153,8 +155,12 @@ while [[ $# -gt 0 ]]; do
JVM_OPTIONS="$2" JVM_OPTIONS="$2"
shift 2 shift 2
;; ;;
--spring-boot) --auto-class-path)
SPRING_BOOT=true AUTO_CLASS_PATH=true
shift
;;
-s|--silent)
SILENT=true
shift shift
;; ;;
-*|--*) # unsupported options -*|--*) # unsupported options
@ -381,7 +387,7 @@ fi
JAVA_DOWNLOAD_PATH=$CACHE_PATH/$JAVA_DISTRO_TYPE/$JVM_IMPL JAVA_DOWNLOAD_PATH=$CACHE_PATH/$JAVA_DISTRO_TYPE/$JVM_IMPL
BUNDLES_PATH=$CACHE_PATH/bundle # prepare bundles here BUNDLES_PATH=$CACHE_PATH/bundle # prepare bundles here
# path for extracted jar (Spring-Boot) files # path for extracted jar files
EXTRACTED_JAR_PATH=$CACHE_PATH/app-jar # prepare bundles here EXTRACTED_JAR_PATH=$CACHE_PATH/app-jar # prepare bundles here
mkdir -p ${EXTRACTED_JAR_PATH} mkdir -p ${EXTRACTED_JAR_PATH}
trap 'rm -rf ${EXTRACTED_JAR_PATH}' EXIT trap 'rm -rf ${EXTRACTED_JAR_PATH}' EXIT
@ -407,7 +413,7 @@ JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"'
JAR='"$JAR_NAME"'.jar JAR='"$JAR_NAME"'.jar
DIR="$(cd "$(dirname "$0")" ; pwd -P)" DIR="$(cd "$(dirname "$0")" ; pwd -P)"
JAVA=$DIR/$JAVA_DIST/bin/java JAVA=$DIR/$JAVA_DIST/bin/'"$JAVA_EXEC"'
JAR_PATH=$DIR/$JAR JAR_PATH=$DIR/$JAR
exec "$JAVA" '"$JVM_OPTIONS"' -jar "$JAR_PATH" "$@" exec "$JAVA" '"$JVM_OPTIONS"' -jar "$JAR_PATH" "$@"
@ -424,7 +430,7 @@ SETLOCAL
SET "JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"'" SET "JAVA_DIST='"$BUNDLED_DISTRO_SUBDIR"'"
SET "JAR='"$JAR_NAME"'.jar" SET "JAR='"$JAR_NAME"'.jar"
SET "JAVA=%~dp0\%JAVA_DIST%\bin\java.exe" SET "JAVA=%~dp0\%JAVA_DIST%\bin\'"$JAVA_EXEC"'
SET "JAR_PATH=%~dp0\%JAR%" SET "JAR_PATH=%~dp0\%JAR%"
START %JAVA% '"$JVM_OPTIONS"' -jar %JAR_PATH% %* START %JAVA% '"$JVM_OPTIONS"' -jar %JAR_PATH% %*
@ -642,7 +648,7 @@ if [[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]]; then
then then
echo "Using given classpaths: $CLASS_PATH" echo "Using given classpaths: $CLASS_PATH"
MODULES=$($JDEPS --class-path=$CLASS_PATH --print-module-deps --ignore-missing-deps --multi-release $JAVA_VERSION_BASE $JAR | grep -v Warning) MODULES=$($JDEPS --class-path=$CLASS_PATH --print-module-deps --ignore-missing-deps --multi-release $JAVA_VERSION_BASE $JAR | grep -v Warning)
elif [ "$SPRING_BOOT" ] elif [ "$AUTO_CLASS_PATH" ]
then then
echo "Extracting jar file to get classpath" echo "Extracting jar file to get classpath"
unzip -q "${JAR}" -d "${EXTRACTED_JAR_PATH}" unzip -q "${JAR}" -d "${EXTRACTED_JAR_PATH}"
@ -672,6 +678,13 @@ function create_optimized_runtime() {
# creates warp bundle for the platform # creates warp bundle for the platform
function create_bundle() { function create_bundle() {
local platform=$1 local platform=$1
if [[ $SILENT ]] && [[ $platform == $WIN ]]; then
JAVA_EXEC=javaw
else
JAVA_EXEC=java
fi
case $JAVA_DISTRO_TYPE in case $JAVA_DISTRO_TYPE in
$DISTRO_TYPE_JDK) $DISTRO_TYPE_JDK)
create_optimized_runtime $platform create_optimized_runtime $platform