feat: Remake to use AdoptOpenJDK project
This commit is contained in:
parent
e014026c5d
commit
84c60bf198
547
warp4j
547
warp4j
@ -7,13 +7,28 @@ function print_help {
|
|||||||
echo 'Turn Java application into self-contained executable'
|
echo 'Turn Java application into self-contained executable'
|
||||||
echo
|
echo
|
||||||
echo 'Options:'
|
echo 'Options:'
|
||||||
echo ' --jdk-version <version>'
|
echo ' --java-version <version>'
|
||||||
echo ' override JDK version'
|
echo ' override JDK/JRE version'
|
||||||
echo ' examples: "11.0.2", TODO more'
|
echo ' examples: "11", "11.0", "11.0.2", "11.0.2+9"'
|
||||||
|
echo ' default: 11'
|
||||||
|
echo ' --no-optimize use JRE instead of optimized JDK'
|
||||||
|
echo ' by default jdeps and jlink are used to create'
|
||||||
|
echo ' optimized JDK for the partiular jar,'
|
||||||
|
echo ' JRE is always used for java 8'
|
||||||
|
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 ' --target-linux create binary for Linux'
|
||||||
|
echo ' --target-macos create binary for macOS'
|
||||||
|
echo ' --target-windows create binary for Windows'
|
||||||
|
echo ' if no targets specified then create for all'
|
||||||
|
echo ' --jvm-impl jvm implementation: hotspot or openj9'
|
||||||
|
echo ' default: hotspot'
|
||||||
echo ' --jvm-options <options>'
|
echo ' --jvm-options <options>'
|
||||||
echo ' passed to java before "-jar"'
|
echo ' passed to java like this:'
|
||||||
|
echo ' "java <options> -jar <jar file>"'
|
||||||
echo ' --launcher-shell <path to shell script>'
|
echo ' --launcher-shell <path to shell script>'
|
||||||
echo ' custom launcher for Linux and MacOS'
|
echo ' custom launcher for Linux and macOS'
|
||||||
echo ' (not implemented)'
|
echo ' (not implemented)'
|
||||||
echo ' --launcher-cmd <path to cmd script>'
|
echo ' --launcher-cmd <path to cmd script>'
|
||||||
echo ' custom launcher for Windows'
|
echo ' custom launcher for Windows'
|
||||||
@ -21,11 +36,31 @@ function print_help {
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# default options
|
trap "exit 1" TERM
|
||||||
JDK_VERSION=11.0.2
|
export TOP_PID=$$
|
||||||
LAUNCHER_SHELL=""
|
function fail() {
|
||||||
LAUNCHER_CMD=""
|
kill -s TERM $TOP_PID
|
||||||
JVM_OPTIONS=""
|
}
|
||||||
|
|
||||||
|
# target IDs
|
||||||
|
LIN=linux
|
||||||
|
MAC=macos
|
||||||
|
WIN=windows
|
||||||
|
|
||||||
|
function get_this_platform() {
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Linux*) echo $LIN ;;
|
||||||
|
Darwin*) echo $MAC ;;
|
||||||
|
CYGWIN*) echo $WIN ;;
|
||||||
|
MINGW*) echo $WIN ;;
|
||||||
|
*)
|
||||||
|
echo "Error: Unsupported platform" >&2
|
||||||
|
fail
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
THIS_PLATFORM=$(get_this_platform)
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
print_help
|
print_help
|
||||||
@ -41,8 +76,37 @@ while [[ $# -gt 0 ]]; do
|
|||||||
print_help
|
print_help
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
--jdk-version)
|
--java-version)
|
||||||
JDK_VERSION="$2"
|
JAVA_VERSION="$2"
|
||||||
|
JAVA_VERSION_OVERRIDEN=true
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--no-optimize)
|
||||||
|
NO_OPTIMIZE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--pull)
|
||||||
|
PULL=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--target-linux)
|
||||||
|
TARGETS+=$LIN
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--target-macos)
|
||||||
|
TARGETS+=$MAC
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--target-windows)
|
||||||
|
TARGETS+=$WIN
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--jvm-impl)
|
||||||
|
JVM_IMPL="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--jvm-options)
|
||||||
|
JVM_OPTIONS="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--launcher-shell)
|
--launcher-shell)
|
||||||
@ -53,12 +117,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
LAUNCHER_CMD="$2"
|
LAUNCHER_CMD="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--jvm-options)
|
-*|--*) # unsupported options
|
||||||
JVM_OPTIONS="$2"
|
echo "Error: Unsupported option $1" >&2
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-*|--*) # unsupported flags
|
|
||||||
echo "Error: Unsupported flag $1" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -77,6 +137,41 @@ else
|
|||||||
JAR=$1
|
JAR=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check if java version specified correctly
|
||||||
|
function java_version_is_correct() {
|
||||||
|
local pattern="^[0-9]+(\.[0-9]+(\.[0-9]+(\+[0-9]+)?)?)?$"
|
||||||
|
local version=$1
|
||||||
|
if [[ $version =~ $pattern ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# validate java version
|
||||||
|
if [[ $JAVA_VERSION ]] && ! java_version_is_correct $JAVA_VERSION ; then
|
||||||
|
echo "Error: JDK version \"$JAVA_VERSION\" is not correct" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JVM_IMPL_HOTSPOT=hotspot
|
||||||
|
JVM_IMPL_OPENJ9=openj9
|
||||||
|
|
||||||
|
# validate jvm implementation
|
||||||
|
if [[ $JVM_IMPL ]] &&
|
||||||
|
[[ $JVM_IMPL != $JVM_IMPL_HOTSPOT ]] &&
|
||||||
|
[[ $JVM_IMPL != $JVM_IMPL_OPENJ9 ]]; then
|
||||||
|
echo "Error: jvm implementation \"$JVM_IMPL\" is not correct" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
LATEST_LTS=11
|
||||||
|
|
||||||
|
# default options
|
||||||
|
test -z $JAVA_VERSION && JAVA_VERSION=$LATEST_LTS
|
||||||
|
test -z $TARGETS && TARGETS=($LIN $MAC $WIN)
|
||||||
|
test -z $JVM_IMPL && JVM_IMPL=$JVM_IMPL_HOTSPOT
|
||||||
|
|
||||||
JAR_FILE_BASE_NAME=$(basename -- "$JAR")
|
JAR_FILE_BASE_NAME=$(basename -- "$JAR")
|
||||||
JAR_EXTENSION="${JAR_FILE_BASE_NAME##*.}"
|
JAR_EXTENSION="${JAR_FILE_BASE_NAME##*.}"
|
||||||
JAR_EXTENSION_LOWERCASE=$(printf "%s" "$JAR_EXTENSION" | tr '[:upper:]' '[:lower:]')
|
JAR_EXTENSION_LOWERCASE=$(printf "%s" "$JAR_EXTENSION" | tr '[:upper:]' '[:lower:]')
|
||||||
@ -95,33 +190,43 @@ if [[ $(file $JAR) != *"Zip"* ]] ||
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function get_base_version() {
|
||||||
|
local version=$1
|
||||||
|
echo `echo $version | cut -d"." -f1`
|
||||||
|
}
|
||||||
|
|
||||||
|
JAVA_VERSION_BASE=$(get_base_version $JAVA_VERSION)
|
||||||
|
|
||||||
|
DISTRO_TYPE_JRE=jre
|
||||||
|
DISTRO_TYPE_JDK=jdk
|
||||||
|
|
||||||
|
function choose_distro_type() {
|
||||||
|
if [[ $JAVA_VERSION_BASE == 8 ]] ||
|
||||||
|
[[ $NO_OPTIMIZE ]]; then
|
||||||
|
echo $DISTRO_TYPE_JRE
|
||||||
|
else
|
||||||
|
echo $DISTRO_TYPE_JDK
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
JAVA_DISTRO_TYPE=$(choose_distro_type)
|
||||||
|
|
||||||
APP_NAME=$JAR_NAME
|
APP_NAME=$JAR_NAME
|
||||||
LAUNCHER_NAME=$JAR_NAME
|
LAUNCHER_NAME=$JAR_NAME
|
||||||
|
|
||||||
JDK_URL_BASE=https://download.java.net/java/GA/jdk11/9/GPL
|
|
||||||
|
|
||||||
TARGETS=(linux osx windows)
|
|
||||||
|
|
||||||
JDK_DISTRO_FILES=(\
|
|
||||||
openjdk-"$JDK_VERSION"_${TARGETS[0]}-x64_bin.tar.gz \
|
|
||||||
openjdk-"$JDK_VERSION"_${TARGETS[1]}-x64_bin.tar.gz \
|
|
||||||
openjdk-"$JDK_VERSION"_${TARGETS[2]}-x64_bin.zip
|
|
||||||
)
|
|
||||||
|
|
||||||
DIR="$(pwd -P)"
|
DIR="$(pwd -P)"
|
||||||
CACHE_PATH=$HOME/.local/share/warp4j
|
CACHE_PATH=$HOME/.local/share/warp4j
|
||||||
JDK_DOWNLOAD_PATH=$CACHE_PATH/jdk
|
JAVA_DOWNLOAD_PATH=$CACHE_PATH/$JAVA_DISTRO_TYPE/$JVM_IMPL
|
||||||
BUNDLES_PATH=$CACHE_PATH/bundle
|
BUNDLES_PATH=$CACHE_PATH/bundle
|
||||||
WARPED_PATH=$DIR/warped
|
WARPED_PATH=$DIR/warped
|
||||||
|
|
||||||
JAVA_HOME="$JDK_DOWNLOAD_PATH/linux"
|
BUNDLED_DISTRO_SUBDIR="java"
|
||||||
JLINK="$JAVA_HOME/bin/jlink"
|
|
||||||
|
|
||||||
function print_launcher_bash() {
|
function print_launcher_bash() {
|
||||||
printf "%s" \
|
printf "%s" \
|
||||||
'#!/usr/bin/env bash
|
'#!/usr/bin/env bash
|
||||||
|
|
||||||
JAVA_DIST=jdk
|
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)"
|
||||||
@ -138,7 +243,7 @@ printf "%s" \
|
|||||||
|
|
||||||
SETLOCAL
|
SETLOCAL
|
||||||
|
|
||||||
SET "JAVA_DIST=jdk"
|
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.exe"
|
||||||
@ -149,116 +254,302 @@ EXIT /B %ERRORLEVEL%
|
|||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_jdks() {
|
function api_url() {
|
||||||
if [ ! -d $JDK_DOWNLOAD_PATH ]; then
|
local request=$1 # info/binary
|
||||||
mkdir -p $JDK_DOWNLOAD_PATH
|
local platform=$2 # windows/linux/macos
|
||||||
echo "Downloading JDKs..."
|
# adoptopenjdk uses "mac" instead of "macos"
|
||||||
for file_name in ${JDK_DISTRO_FILES[@]}; do
|
if [[ $platform == "macos" ]]; then
|
||||||
echo "$file_name..."
|
platform="mac"
|
||||||
curl --progress-bar \
|
fi
|
||||||
$JDK_URL_BASE/$file_name \
|
echo -n "https://api.adoptopenjdk.net/v2/\
|
||||||
--output $JDK_DOWNLOAD_PATH/$file_name
|
$request/releases/openjdk$JAVA_VERSION_BASE?\
|
||||||
done
|
openjdk_impl=$JVM_IMPL&\
|
||||||
|
os=$platform&\
|
||||||
|
arch=x64&\
|
||||||
|
type=$JAVA_DISTRO_TYPE"
|
||||||
|
}
|
||||||
|
|
||||||
echo "Uncompressing JDKs..."
|
MARKER_DOWNLOADED="downloaded"
|
||||||
(cd $JDK_DOWNLOAD_PATH
|
MARKER_UNPACKED="unpacked"
|
||||||
echo "${TARGETS[0]}..."
|
|
||||||
rm -rf $JDK_DOWNLOAD_PATH/${TARGETS[0]}
|
|
||||||
mkdir -p $JDK_DOWNLOAD_PATH/${TARGETS[0]}
|
|
||||||
tar --strip-components=1 -C ${TARGETS[0]} -xzf ${JDK_DISTRO_FILES[0]}
|
|
||||||
|
|
||||||
echo "${TARGETS[1]}..."
|
# find latest cached version that matches version specifies by user
|
||||||
rm -rf $JDK_DOWNLOAD_PATH/${TARGETS[1]}
|
function find_latest_cached() {
|
||||||
mkdir -p $JDK_DOWNLOAD_PATH/${TARGETS[1]}
|
local platform=$1 # in terms of adoptopenjdk.net: windows, linux, mac
|
||||||
tar --strip-components=4 -C ${TARGETS[1]} -xzf ${JDK_DISTRO_FILES[1]} \
|
local user_version=$2
|
||||||
./jdk-$JDK_VERSION.jdk/Contents/Home
|
local platform_dir=$JAVA_DOWNLOAD_PATH/$platform/
|
||||||
|
# turning something like "11.0.1+13" into regexp like "^11\.0\.1\+13"
|
||||||
echo "${TARGETS[2]}..."
|
local pattern="^"$(echo $user_version | sed -e 's/\./\\\./g' -e 's/\+/\\\+/g')
|
||||||
rm -rf $JDK_DOWNLOAD_PATH/${TARGETS[2]}
|
local versions=$(ls -1 $platform_dir 2> /dev/null | sort -r)
|
||||||
unzip -oq ${JDK_DISTRO_FILES[2]}
|
local version
|
||||||
mv jdk-$JDK_VERSION ${TARGETS[2]}
|
for v in ${versions[@]}; do
|
||||||
)
|
if [[ -e $platform_dir/$v/$MARKER_DOWNLOADED ]] &&
|
||||||
|
[[ $v =~ $pattern ]]; then
|
||||||
# check if downloaded successfully
|
version=$v
|
||||||
if [ ! -f $JDK_DOWNLOAD_PATH/${TARGETS[0]}/bin/java ] || \
|
break
|
||||||
[ ! -f $JDK_DOWNLOAD_PATH/${TARGETS[1]}/bin/java ] || \
|
|
||||||
[ ! -f $JDK_DOWNLOAD_PATH/${TARGETS[2]}/bin/java.exe ]; then
|
|
||||||
echo "Error: Failed to download JDKs" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
if [[ $version ]]; then
|
||||||
|
echo $version
|
||||||
else
|
else
|
||||||
echo "JDKs already present, skip download"
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_optimized_jdks() {
|
function fetch_distro_info() {
|
||||||
echo "Creating minimal JDKs..."
|
local platform=$1 # in terms of adoptopenjdk.net: windows, linux, mac
|
||||||
for target in ${TARGETS[@]}; do
|
local branch=$2 # 8/9/10/11...
|
||||||
echo "${target}..."
|
echo "Fetching $JVM_IMPL-$JAVA_DISTRO_TYPE-$branch-$platform info ..." >&2 # TODO remove
|
||||||
$JLINK \
|
curl -s $(api_url info $platform)
|
||||||
--no-header-files \
|
if [[ $? != 0 ]]; then
|
||||||
--no-man-pages \
|
echo "Error: Failed to fetch JDK $branch info for $platform" >&2
|
||||||
--module-path $JDK_DOWNLOAD_PATH/${target}/jmods \
|
fail
|
||||||
--add-modules $(jdeps --print-module-deps $JAR | grep -v Warning) \
|
fi
|
||||||
--output $BUNDLES_PATH/${target}/jdk
|
}
|
||||||
|
|
||||||
|
# searches for latest concrete distro version that matches
|
||||||
|
# version supplied by user
|
||||||
|
function find_latest_version() {
|
||||||
|
local info=$1 # info fetched from AdoptOpenJDK
|
||||||
|
local user_version=$2 # version supplied by user is a template
|
||||||
|
local matched_version # latest version that matches the template
|
||||||
|
local versions # all versions
|
||||||
|
versions=$(echo "$info" \
|
||||||
|
| grep '"semver"' \
|
||||||
|
| sort -r \
|
||||||
|
| awk '{print $2}' \
|
||||||
|
| sed -e 's/"//g' -e 's/,//')
|
||||||
|
# turning something like "11.0.1+13" into regexp like "^11\.0\.1\+13"
|
||||||
|
local pattern="^"$(echo $user_version | sed -e 's/\./\\\./g' -e 's/\+/\\\+/g')
|
||||||
|
for v in ${versions[@]}; do
|
||||||
|
if [[ $v =~ $pattern ]]; then
|
||||||
|
matched_version=$v
|
||||||
|
break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
if [[ -z $matched_version ]]; then
|
||||||
|
echo "Error: Can't find distro that matches $user_version" >&2
|
||||||
|
fail
|
||||||
|
fi
|
||||||
|
echo $matched_version
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_bundles() {
|
function find_distro_link() {
|
||||||
rm -rf $BUNDLES_PATH
|
local info=$1 # info fetched from AdoptOpenJDK
|
||||||
|
local version=$2 # concrete distro version like "11.0.2+9"
|
||||||
create_optimized_jdks
|
local link=$(echo "$info" \
|
||||||
|
| grep -B11 "\"semver\": \"$version\"" \
|
||||||
echo "Adding launchers..."
|
| grep "binary_link" \
|
||||||
print_launcher_bash > $BUNDLES_PATH/${TARGETS[0]}/$LAUNCHER_NAME.sh
|
| awk '{print $2}' \
|
||||||
print_launcher_bash > $BUNDLES_PATH/${TARGETS[1]}/$LAUNCHER_NAME.sh
|
| sed -e 's/"//g' -e 's/,//')
|
||||||
print_launcher_cmd > $BUNDLES_PATH/${TARGETS[2]}/$LAUNCHER_NAME.cmd
|
if [[ -z $link ]]; then
|
||||||
|
echo "Error: Can't find download link for $version" >&2
|
||||||
echo "Adding jars..."
|
fail
|
||||||
cp $JAR $BUNDLES_PATH/${TARGETS[0]}/
|
fi
|
||||||
cp $JAR $BUNDLES_PATH/${TARGETS[1]}/
|
echo "$link"
|
||||||
cp $JAR $BUNDLES_PATH/${TARGETS[2]}/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function download_distro() {
|
||||||
|
local platform=$1
|
||||||
|
local version=$2
|
||||||
|
local link=$3
|
||||||
|
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$version
|
||||||
|
echo "Downloading $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform..."
|
||||||
|
rm -rf $download_dir
|
||||||
|
mkdir -p $download_dir
|
||||||
|
(cd $download_dir
|
||||||
|
curl --progress-bar --location --remote-name $link
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
touch $MARKER_DOWNLOADED
|
||||||
|
else
|
||||||
|
echo "Error: Failed to download $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform" >&2
|
||||||
|
fail
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
# ensure if required distro is in cache
|
||||||
|
function ensure_distro_cached() {
|
||||||
|
local platform=$1
|
||||||
|
local distro_info
|
||||||
|
local distro_link
|
||||||
|
if [[ -z $PULL ]]; then
|
||||||
|
if [[ -z $JAVA_VERSION_OVERRIDEN ]]; then
|
||||||
|
if [[ ! $(find_latest_cached $platform $LATEST_LTS) ]]; then
|
||||||
|
distro_info=$(fetch_distro_info $platform $LATEST_LTS)
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_version $distro_info $LATEST_LTS)
|
||||||
|
distro_link=$(find_distro_link $distro_info $CONCRETE_JAVA_VERSION)
|
||||||
|
download_distro $platform $CONCRETE_JAVA_VERSION $distro_link
|
||||||
|
else
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $LATEST_LTS)
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ ! $(find_latest_cached $platform $JAVA_VERSION) ]]; then
|
||||||
|
distro_info=$(fetch_distro_info $platform $JAVA_VERSION_BASE)
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $JAVA_VERSION)
|
||||||
|
distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION)
|
||||||
|
download_distro $platform $CONCRETE_JAVA_VERSION $distro_link
|
||||||
|
else
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $JAVA_VERSION)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ -z $JAVA_VERSION ]]; then
|
||||||
|
distro_info=$(fetch_distro_info $platform $LATEST_LTS)
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $LATEST_LTS)
|
||||||
|
else
|
||||||
|
distro_info=$(fetch_distro_info $platform $JAVA_VERSION_BASE)
|
||||||
|
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $JAVA_VERSION)
|
||||||
|
fi
|
||||||
|
if [[ ! $(find_latest_cached $platform $CONCRETE_JAVA_VERSION) ]]; then
|
||||||
|
distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION)
|
||||||
|
download_distro $platform $CONCRETE_JAVA_VERSION $distro_link
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for target in ${TARGETS[@]}; do
|
||||||
|
ensure_distro_cached $target
|
||||||
|
done
|
||||||
|
|
||||||
|
UNPACKED_SUBDIR="distro"
|
||||||
|
|
||||||
|
function ensure_distro_unpacked() {
|
||||||
|
local platform=$1
|
||||||
|
local version=$2
|
||||||
|
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$version
|
||||||
|
local unpacked_dir=$download_dir/$UNPACKED_SUBDIR
|
||||||
|
if [[ ! -e $download_dir/$MARKER_UNPACKED ]]; then
|
||||||
|
echo "Uncompressing $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform"
|
||||||
|
# removing all leftover directories
|
||||||
|
for d in $download_dir/* ; do
|
||||||
|
if [[ -d $d ]]; then
|
||||||
|
rm -rf $d
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
case $platform in
|
||||||
|
$LIN)
|
||||||
|
mkdir -p $unpacked_dir
|
||||||
|
tar --strip-components=1 -C $unpacked_dir -xzf $download_dir/*.tar.gz
|
||||||
|
;;
|
||||||
|
$MAC)
|
||||||
|
mkdir -p $unpacked_dir
|
||||||
|
tar --wildcards --strip-components=3 -C $unpacked_dir -xzf $download_dir/*.tar.gz \
|
||||||
|
"jdk*/Contents/Home"
|
||||||
|
;;
|
||||||
|
$WIN)
|
||||||
|
(cd $download_dir
|
||||||
|
unzip -oq *.zip && mv jdk* $UNPACKED_SUBDIR
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if [[ $? == 0 ]]; then
|
||||||
|
touch $download_dir/$MARKER_UNPACKED
|
||||||
|
else
|
||||||
|
echo "Error: Failed to unpack $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform" >&2
|
||||||
|
fail
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for target in ${TARGETS[@]}; do
|
||||||
|
ensure_distro_unpacked $target $CONCRETE_JAVA_VERSION
|
||||||
|
done
|
||||||
|
|
||||||
|
JLINK=$JAVA_DOWNLOAD_PATH/$THIS_PLATFORM/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/bin/jlink
|
||||||
|
JDEPS=$JAVA_DOWNLOAD_PATH/$THIS_PLATFORM/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/bin/jdeps
|
||||||
|
|
||||||
|
if [[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]]; then
|
||||||
|
echo "Analyzing dependencies..."
|
||||||
|
MODULES=$($JDEPS --print-module-deps $JAR | grep -v Warning)
|
||||||
|
fi
|
||||||
|
|
||||||
|
function create_optimized_runtime() {
|
||||||
|
local platform=$1
|
||||||
|
local jmods=$JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/jmods
|
||||||
|
echo "Creating minimal runtime for $platform..."
|
||||||
|
$JLINK \
|
||||||
|
--no-header-files \
|
||||||
|
--no-man-pages \
|
||||||
|
--module-path $jmods \
|
||||||
|
--add-modules $MODULES \
|
||||||
|
--output $BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo "Error: Failed to optimize runtime" >&2
|
||||||
|
fail
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_bundle() {
|
||||||
|
local platform=$1
|
||||||
|
case $JAVA_DISTRO_TYPE in
|
||||||
|
$DISTRO_TYPE_JDK)
|
||||||
|
create_optimized_runtime $platform
|
||||||
|
;;
|
||||||
|
$DISTRO_TYPE_JRE)
|
||||||
|
mkdir -p $BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR
|
||||||
|
cp -r $JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/* \
|
||||||
|
$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
case $platform in
|
||||||
|
$WIN) print_launcher_cmd > $BUNDLES_PATH/$platform/$LAUNCHER_NAME.cmd ;;
|
||||||
|
*) print_launcher_bash > $BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh
|
||||||
|
chmod +x $BUNDLES_PATH/$platform/$LAUNCHER_NAME.sh
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
cp $JAR $BUNDLES_PATH/$platform/
|
||||||
|
}
|
||||||
|
|
||||||
|
rm -rf $BUNDLES_PATH
|
||||||
|
for target in ${TARGETS[@]}; do
|
||||||
|
create_bundle $target
|
||||||
|
done
|
||||||
|
|
||||||
function warp_targets() {
|
function warp_targets() {
|
||||||
rm -rf $WARPED_PATH
|
if [[ ${TARGETS[*]} == *"$LIN"* ]]; then
|
||||||
|
echo "Warping for $LIN..."
|
||||||
|
mkdir -p $WARPED_PATH/$LIN
|
||||||
|
warp-packer \
|
||||||
|
--arch linux-x64 \
|
||||||
|
--input_dir $BUNDLES_PATH/$LIN \
|
||||||
|
--exec $LAUNCHER_NAME.sh \
|
||||||
|
--output $WARPED_PATH/$LIN/$APP_NAME \
|
||||||
|
&> /dev/null
|
||||||
|
tar -C $WARPED_PATH/$LIN -czf $WARPED_PATH/$APP_NAME-$LIN-x64.tar.gz $APP_NAME
|
||||||
|
mv $WARPED_PATH/$LIN/$APP_NAME $WARPED_PATH/$APP_NAME-$LIN
|
||||||
|
rmdir $WARPED_PATH/$LIN
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Warping linux target..."
|
if [[ ${TARGETS[*]} == *"$MAC"* ]]; then
|
||||||
mkdir -p $WARPED_PATH/${TARGETS[0]}
|
echo "Warping for $MAC..."
|
||||||
warp-packer \
|
mkdir -p $WARPED_PATH/$MAC
|
||||||
--arch linux-x64 \
|
warp-packer \
|
||||||
--input_dir $BUNDLES_PATH/${TARGETS[0]} \
|
--arch macos-x64 \
|
||||||
--exec $LAUNCHER_NAME.sh \
|
--input_dir $BUNDLES_PATH/$MAC \
|
||||||
--output $WARPED_PATH/${TARGETS[0]}/$APP_NAME
|
--exec $LAUNCHER_NAME.sh \
|
||||||
tar -C $WARPED_PATH/${TARGETS[0]} -czf $WARPED_PATH/$APP_NAME.${TARGETS[0]}-x64.tar.gz $APP_NAME
|
--output $WARPED_PATH/$MAC/$APP_NAME \
|
||||||
mv $WARPED_PATH/${TARGETS[0]}/$APP_NAME $WARPED_PATH/$APP_NAME-${TARGETS[0]}
|
&> /dev/null
|
||||||
rmdir $WARPED_PATH/${TARGETS[0]}
|
tar -C $WARPED_PATH/$MAC -czf $WARPED_PATH/$APP_NAME-$MAC-x64.tar.gz $APP_NAME
|
||||||
|
mv $WARPED_PATH/$MAC/$APP_NAME $WARPED_PATH/$APP_NAME-$MAC
|
||||||
|
rmdir $WARPED_PATH/$MAC
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Warping osx target..."
|
if [[ ${TARGETS[*]} == *"$WIN"* ]]; then
|
||||||
mkdir -p $WARPED_PATH/${TARGETS[1]}
|
echo "Warping for $WIN..."
|
||||||
warp-packer \
|
mkdir -p $WARPED_PATH/$WIN
|
||||||
--arch macos-x64 \
|
warp-packer \
|
||||||
--input_dir $BUNDLES_PATH/${TARGETS[1]} \
|
--arch windows-x64 \
|
||||||
--exec $LAUNCHER_NAME.sh \
|
--input_dir $BUNDLES_PATH/$WIN \
|
||||||
--output $WARPED_PATH/${TARGETS[1]}/$APP_NAME
|
--exec $LAUNCHER_NAME.cmd \
|
||||||
tar -C $WARPED_PATH/${TARGETS[1]} -czf $WARPED_PATH/$APP_NAME.${TARGETS[1]}-x64.tar.gz $APP_NAME
|
--output $WARPED_PATH/$WIN/$APP_NAME.exe \
|
||||||
mv $WARPED_PATH/${TARGETS[1]}/$APP_NAME $WARPED_PATH/$APP_NAME-${TARGETS[1]}
|
&> /dev/null
|
||||||
rmdir $WARPED_PATH/${TARGETS[1]}
|
(cd $WARPED_PATH/$WIN
|
||||||
|
zip -r $WARPED_PATH/$APP_NAME-$WIN-x64.zip $APP_NAME.exe &> /dev/null
|
||||||
echo "Warping windows target..."
|
)
|
||||||
mkdir -p $WARPED_PATH/${TARGETS[2]}
|
mv $WARPED_PATH/$WIN/$APP_NAME.exe $WARPED_PATH/$APP_NAME-windows.exe
|
||||||
warp-packer \
|
rmdir $WARPED_PATH/$WIN
|
||||||
--arch windows-x64 \
|
fi
|
||||||
--input_dir $BUNDLES_PATH/${TARGETS[2]} \
|
|
||||||
--exec $LAUNCHER_NAME.cmd \
|
|
||||||
--output $WARPED_PATH/${TARGETS[2]}/$APP_NAME.exe
|
|
||||||
(cd $WARPED_PATH/${TARGETS[2]}
|
|
||||||
zip -r $WARPED_PATH/$APP_NAME.${TARGETS[2]}-x64.zip $APP_NAME.exe
|
|
||||||
)
|
|
||||||
mv $WARPED_PATH/${TARGETS[2]}/$APP_NAME.exe $WARPED_PATH/$APP_NAME-windows.exe
|
|
||||||
rmdir $WARPED_PATH/${TARGETS[2]}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
download_jdks
|
rm -rf $WARPED_PATH
|
||||||
create_bundles
|
|
||||||
warp_targets
|
warp_targets
|
||||||
|
Loading…
Reference in New Issue
Block a user