2013-08-27 15:14:44 +04:00
|
|
|
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
## Gestion de la sélection d'une version de Java
|
|
|
|
##@cooked nocomments
|
|
|
|
##@require base
|
|
|
|
##@require sysinfos
|
|
|
|
uprovide java
|
|
|
|
urequire base sysinfos
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# versions installées sur le système
|
|
|
|
JAVA_VMS13=(); JAVA_HOMES13=()
|
|
|
|
JAVA_VMS14=(); JAVA_HOMES14=()
|
|
|
|
JAVA_VMS5=(); JAVA_HOMES5=()
|
|
|
|
JAVA_VMS6=(); JAVA_HOMES6=()
|
|
|
|
JAVA_VMS7=(); JAVA_HOMES7=()
|
2014-11-11 16:25:53 +04:00
|
|
|
JAVA_VMS8=(); JAVA_HOMES8=()
|
2013-08-27 15:14:44 +04:00
|
|
|
# versions locales 32 bits
|
|
|
|
JAVA32_VMS13=(); JAVA32_HOMES13=()
|
|
|
|
JAVA32_VMS14=(); JAVA32_HOMES14=()
|
|
|
|
JAVA32_VMS5=(); JAVA32_HOMES5=()
|
|
|
|
JAVA32_VMS6=(); JAVA32_HOMES6=()
|
|
|
|
JAVA32_VMS7=(); JAVA32_HOMES7=()
|
2014-11-11 16:25:53 +04:00
|
|
|
JAVA32_VMS8=(); JAVA32_HOMES8=()
|
2013-08-27 15:14:44 +04:00
|
|
|
# versions locales 64 bits
|
|
|
|
JAVA64_VMS5=(); JAVA64_HOMES5=()
|
|
|
|
JAVA64_VMS6=(); JAVA64_HOMES6=()
|
|
|
|
JAVA64_VMS7=(); JAVA64_HOMES7=()
|
2014-11-11 16:25:53 +04:00
|
|
|
JAVA64_VMS8=(); JAVA64_HOMES8=()
|
2013-08-27 15:14:44 +04:00
|
|
|
# version sélectionnée
|
|
|
|
SELECTED_JAVA_VM=; SELECTED_JAVA_HOME=
|
|
|
|
SELECTED_JAVA=; SELECTED_JAVAC=
|
|
|
|
|
|
|
|
function __java_add() {
|
|
|
|
# Ajouter la valeur $2 à la liste JAVA$3_$1
|
|
|
|
array_add "JAVA${3}_${1}" "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
function __java_compute_vms() {
|
|
|
|
# calculer la liste de VMs disponibles et initialiser les tableaux
|
2014-11-11 16:25:53 +04:00
|
|
|
# JAVA{,32,64}_{VMS,HOMES}{13,14,5,6,7,8}
|
2013-08-27 15:14:44 +04:00
|
|
|
[ -z "$__COMPUTED_JAVA_VMS" ] || return
|
|
|
|
|
|
|
|
local vms vm v
|
|
|
|
if check_sysinfos -s linux; then
|
|
|
|
# D'abord chercher dans les JVMs installées manuellement dans
|
|
|
|
# ~/opt/jvm{32,64}
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "sun-jdk-*")"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm#sun-jdk-}"
|
|
|
|
if [ "$v" == 1.4 ]; then
|
|
|
|
__java_add VMS14 "$vm" 32
|
|
|
|
__java_add HOMES14 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
elif [ "$v" == 1.5 ]; then
|
|
|
|
__java_add VMS5 "$vm" 32
|
|
|
|
__java_add HOMES5 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
elif [ "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm" 32
|
|
|
|
__java_add HOMES6 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
elif [ "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm" 32
|
|
|
|
__java_add HOMES7 "$HOME/opt/jvm32/$vm" 32
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm" 32
|
|
|
|
__java_add HOMES8 "$HOME/opt/jvm32/$vm" 32
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "j2sdk1.4.2*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS14 "$vm" 32
|
|
|
|
__java_add HOMES14 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "jdk1.5.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS5 "$vm" 32
|
|
|
|
__java_add HOMES5 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "jdk1.6.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS6 "$vm" 32
|
|
|
|
__java_add HOMES6 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "jdk1.7.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS7 "$vm" 32
|
|
|
|
__java_add HOMES7 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
done
|
2014-11-11 16:25:53 +04:00
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm32" "jdk1.8.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS8 "$vm" 32
|
|
|
|
__java_add HOMES8 "$HOME/opt/jvm32/$vm" 32
|
|
|
|
done
|
2013-08-27 15:14:44 +04:00
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm64" "sun-jdk-*")"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm#sun-jdk-}"
|
|
|
|
if [ "$v" == 1.5 ]; then
|
|
|
|
__java_add VMS5 "$vm" 64
|
|
|
|
__java_add HOMES5 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
elif [ "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm" 64
|
|
|
|
__java_add HOMES6 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
elif [ "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm" 64
|
|
|
|
__java_add HOMES7 "$HOME/opt/jvm64/$vm" 64
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm" 64
|
|
|
|
__java_add HOMES8 "$HOME/opt/jvm64/$vm" 64
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm64" "jdk1.5.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS5 "$vm" 64
|
|
|
|
__java_add HOMES5 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm64" "jdk1.6.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS6 "$vm" 64
|
|
|
|
__java_add HOMES6 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm64" "jdk1.7.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS7 "$vm" 64
|
|
|
|
__java_add HOMES7 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
done
|
2014-11-11 16:25:53 +04:00
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt/jvm64" "jdk1.8.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS8 "$vm" 64
|
|
|
|
__java_add HOMES8 "$HOME/opt/jvm64/$vm" 64
|
|
|
|
done
|
2013-08-27 15:14:44 +04:00
|
|
|
# Puis chercher dans les JVMs installées manuellement dans ~/opt
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "sun-jdk-*")"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm#sun-jdk-}"
|
|
|
|
if [ "$v" == 1.4 ]; then
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "$HOME/opt/$vm"
|
|
|
|
elif [ "$v" == 1.5 ]; then
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "$HOME/opt/$vm"
|
|
|
|
elif [ "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "$HOME/opt/$vm"
|
|
|
|
elif [ "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "$HOME/opt/$vm"
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "$HOME/opt/$vm"
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "j2sdk1.4.2*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "$HOME/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "jdk1.5.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "$HOME/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "jdk1.6.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "$HOME/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "jdk1.7.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "$HOME/opt/$vm"
|
|
|
|
done
|
2014-11-11 16:25:53 +04:00
|
|
|
array_from_lines vms "$(list_dirs "$HOME/opt" "jdk1.8.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "$HOME/opt/$vm"
|
|
|
|
done
|
2013-08-27 15:14:44 +04:00
|
|
|
# Puis chercher dans les JVMs installées manuellement dans /opt
|
|
|
|
array_from_lines vms "$(list_dirs "/opt" "sun-jdk-*")"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm#sun-jdk-}"
|
|
|
|
if [ "$v" == 1.4 ]; then
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "/opt/$vm"
|
|
|
|
elif [ "$v" == 1.5 ]; then
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "/opt/$vm"
|
|
|
|
elif [ "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "/opt/$vm"
|
|
|
|
elif [ "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "/opt/$vm"
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "/opt/$vm"
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "/opt" "j2sdk1.4.2*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "/opt" "jdk1.5.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "/opt" "jdk1.6.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "/opt/$vm"
|
|
|
|
done
|
|
|
|
array_from_lines vms "$(list_dirs "/opt" "jdk1.7.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "/opt/$vm"
|
|
|
|
done
|
2014-11-11 16:25:53 +04:00
|
|
|
array_from_lines vms "$(list_dirs "/opt" "jdk1.8.*" | LANG=C sort -r)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "/opt/$vm"
|
|
|
|
done
|
2013-08-27 15:14:44 +04:00
|
|
|
# Puis chercher dans les JVMs installées par le système dans
|
|
|
|
# /usr/lib/jvm
|
|
|
|
if check_sysinfos -d gentoo; then
|
|
|
|
# sur gentoo
|
|
|
|
array_from_lines vms "$(list_dirs /usr/lib/jvm)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm#sun-jdk-}"
|
|
|
|
if [ "$v" == 1.4 ]; then
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 1.5 ]; then
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "/usr/lib/jvm/$vm"
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "/usr/lib/jvm/$vm"
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
elif check_sysinfos -d debianlike; then
|
|
|
|
# sur debian
|
|
|
|
array_from_lines vms "$(list_dirs /usr/lib/jvm)"
|
|
|
|
for vm in "${vms[@]}"; do
|
|
|
|
v="${vm%-sun}"
|
|
|
|
v="${v#java-}"
|
|
|
|
v="${v#j2sdk}"
|
|
|
|
if [ "$v" == 1.4 ]; then
|
|
|
|
__java_add VMS14 "$vm"
|
|
|
|
__java_add HOMES14 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 1.5 -o "$v" == 1.5.0 ]; then
|
|
|
|
__java_add VMS5 "$vm"
|
|
|
|
__java_add HOMES5 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 6 -o "$v" == 1.6 ]; then
|
|
|
|
__java_add VMS6 "$vm"
|
|
|
|
__java_add HOMES6 "/usr/lib/jvm/$vm"
|
|
|
|
elif [ "$v" == 7 -o "$v" == 1.7 ]; then
|
|
|
|
__java_add VMS7 "$vm"
|
|
|
|
__java_add HOMES7 "/usr/lib/jvm/$vm"
|
2014-11-11 16:25:53 +04:00
|
|
|
elif [ "$v" == 8 -o "$v" == 1.8 ]; then
|
|
|
|
__java_add VMS8 "$vm"
|
|
|
|
__java_add HOMES8 "/usr/lib/jvm/$vm"
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -d /usr/lib/j2sdk1.4-sun ]; then
|
|
|
|
__java_add VMS14 j2sdk1.4-sun
|
|
|
|
__java_add HOMES14 /usr/lib/j2sdk1.4-sun
|
|
|
|
fi
|
|
|
|
elif check_sysinfos -d redhatlike; then
|
|
|
|
# XXX sur redhat
|
|
|
|
:
|
|
|
|
fi
|
|
|
|
elif check_sysinfos -s macosx; then
|
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.3" ]; then
|
|
|
|
__java_add VMS13 "1.3"
|
|
|
|
__java_add HOMES13 "/System/Library/Frameworks/JavaVM.framework/Versions/1.3/Home"
|
|
|
|
fi
|
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.4" ]; then
|
|
|
|
__java_add VMS14 "1.4"
|
|
|
|
__java_add HOMES14 "/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Home"
|
|
|
|
fi
|
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.5" ]; then
|
|
|
|
__java_add VMS5 "1.5"
|
|
|
|
__java_add HOMES5 "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home"
|
|
|
|
fi
|
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.6" ]; then
|
|
|
|
__java_add VMS6 "1.6"
|
|
|
|
__java_add HOMES6 "/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"
|
|
|
|
fi
|
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.7" ]; then
|
|
|
|
__java_add VMS7 "1.7"
|
|
|
|
__java_add HOMES7 "/System/Library/Frameworks/JavaVM.framework/Versions/1.7/Home"
|
|
|
|
fi
|
2014-11-11 16:25:53 +04:00
|
|
|
if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.8" ]; then
|
|
|
|
__java_add VMS8 "1.8"
|
|
|
|
__java_add HOMES8 "/System/Library/Frameworks/JavaVM.framework/Versions/1.8/Home"
|
|
|
|
fi
|
2013-08-27 15:14:44 +04:00
|
|
|
fi
|
|
|
|
__COMPUTED_JAVA_VMS=1
|
|
|
|
}
|
|
|
|
|
|
|
|
function __java_dump_vms() {
|
|
|
|
local v b i vms homes
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 13 14 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
for b in "" 32 64; do
|
|
|
|
vms="JAVA${b}_VMS${v}[@]"; vms=("${!vms}")
|
|
|
|
homes="JAVA${b}_HOMES${v}[@]"; homes=("${!homes}")
|
|
|
|
i=0
|
|
|
|
while [ $i -lt "${#vms[*]}" ]; do
|
|
|
|
echo "$v${b:+-$b}:${vms[$i]}:${homes[$i]}"
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function __java_select_vms() {
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
array_copy vms "JAVA_VMS$1"
|
|
|
|
if [ -n "${vms[*]}" ]; then
|
|
|
|
array_copy homes "JAVA_HOMES$1"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
array_copy vms "JAVA${2}_VMS$1"
|
|
|
|
array_copy homes "JAVA${2}_HOMES$1"
|
|
|
|
custom=1
|
|
|
|
[ -n "${vms[*]}" ] && return 0 || return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function __java_select() {
|
2014-11-11 16:25:53 +04:00
|
|
|
# Sélectionner la version de java $1 (qui peut être 13, 14, 5, 6, 7 ou 8)
|
2013-08-27 15:14:44 +04:00
|
|
|
# Si $2 est défini, il peut s'agit de 32 ou 64 selon que l'on requière la
|
|
|
|
# version 32bits ou 64 bits. Sinon, la version sélectionnée peut être 32bits
|
|
|
|
# ou 64bits selon ce qui est disponible.
|
|
|
|
__java_compute_vms
|
|
|
|
|
|
|
|
local vms homes custom
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
__java_select_vms "$1" "$MYBITS" ||
|
|
|
|
__java_select_vms "$1" ||
|
|
|
|
__java_select_vms "$1" 32 ||
|
|
|
|
__java_select_vms "$1" 64
|
|
|
|
elif [ "$MYBITS" == "$2" ]; then
|
|
|
|
__java_select_vms "$1" "$2" ||
|
|
|
|
__java_select_vms "$1"
|
|
|
|
else
|
|
|
|
__java_select_vms "$1" "$2"
|
|
|
|
fi
|
|
|
|
if [ -n "${vms[*]}" ]; then
|
|
|
|
SELECTED_JAVA_VM="${vms[0]}"
|
|
|
|
SELECTED_JAVA_HOME="${homes[0]}"
|
|
|
|
SELECTED_JAVA="$SELECTED_JAVA_HOME/bin/java"
|
|
|
|
SELECTED_JAVAC="$SELECTED_JAVA_HOME/bin/javac"
|
|
|
|
if [ -z "$custom" -a "$LINUX_FLAVOUR" == "gentoo" ]; then
|
|
|
|
export GENTOO_VM="$SELECTED_JAVA_VM"
|
|
|
|
export JAVA=java
|
|
|
|
export JAVAC=javac
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
[ "$LINUX_FLAVOUR" == "gentoo" ] && unset GENTOO_VM
|
|
|
|
export JAVA_HOME="$SELECTED_JAVA_HOME"
|
|
|
|
export JAVA="$SELECTED_JAVA"
|
|
|
|
export JAVAC="$SELECTED_JAVAC"
|
2013-11-06 09:45:34 +04:00
|
|
|
udelpath "$JAVA_HOME/bin"
|
|
|
|
uinspath "$JAVA_HOME/bin"
|
|
|
|
export PATH
|
2013-08-27 15:14:44 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function __java_select_default() {
|
|
|
|
# Sélectionner la version de java par défaut. Si JAVA_HOME est défini,
|
2014-11-11 16:25:53 +04:00
|
|
|
# prendre cette valeur. Sinon, essayer dans l'ordre 5, 6, 7, 8, puis 14
|
2013-08-27 15:14:44 +04:00
|
|
|
# la version 13 n'est jamais sélectionnée automatiquement
|
|
|
|
if [ -n "$JAVA_HOME" ]; then
|
2013-11-06 09:45:34 +04:00
|
|
|
export JAVA_HOME # s'assurer que cette variable est exportée
|
2013-08-27 15:14:44 +04:00
|
|
|
export JAVA="$JAVA_HOME/bin/java"
|
|
|
|
export JAVAC="$JAVA_HOME/bin/java"
|
2013-11-06 09:45:34 +04:00
|
|
|
udelpath "$JAVA_HOME/bin"
|
|
|
|
uinspath "$JAVA_HOME/bin"
|
|
|
|
export PATH
|
2013-08-27 15:14:44 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
local vm
|
2014-11-11 16:25:53 +04:00
|
|
|
for vm in 5 6 7 8 14; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$vm" && return 0
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_java() {
|
|
|
|
# sélectionner la version *minimum* de java correspondant à $1
|
2014-11-11 16:25:53 +04:00
|
|
|
# $1== 1.3|1.3+|1.4|1.4+|1.5|1.5+|1.6|1.6+|1.7|1.7+|1.8|1.8+
|
2013-08-27 15:14:44 +04:00
|
|
|
# Si $2 est défini, il peut s'agit de 32 ou 64 selon que l'on requière la
|
|
|
|
# version 32bits ou 64 bits
|
|
|
|
local v vms homes
|
|
|
|
|
|
|
|
case "$1" in
|
2013-11-06 09:45:34 +04:00
|
|
|
1.3|1.3+|13|13+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 13 14 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.4|1.4+|14|14+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 14 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.5|1.5+|5|5+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.6|1.6+|6|6+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.7|1.7+|7|7+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 7 8; do
|
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
1.8|1.8+|8|8+)
|
|
|
|
for v in 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_java_exact() {
|
2013-11-06 09:45:34 +04:00
|
|
|
# sélectionner la version *exacte* de java correspondant à $1
|
2014-11-11 16:25:53 +04:00
|
|
|
# $1== 1.3|1.4|1.5|1.6|1.7|1.8 pour une correspondance exacte
|
|
|
|
# $1== 1.3+|1.4+|1.5+|1.6+|1.7+|1.8+ pour une version minimum
|
2013-08-27 15:14:44 +04:00
|
|
|
# Si $2 est défini, il peut s'agit de 32 ou 64 selon que l'on requière la
|
|
|
|
# version 32bits ou 64 bits
|
|
|
|
local v vms homes
|
|
|
|
|
|
|
|
case "$1" in
|
2013-11-06 09:45:34 +04:00
|
|
|
1.3|13)
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select 13 && return 0
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.3+|13+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 13 14 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.4|14)
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select 14 && return 0
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.4+|14+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 14 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.5|5)
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select 5 "$2" && return 0
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.5+|5+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 5 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.6|6)
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select 6 "$2" && return 0
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.6+|6+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 6 7 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.7|7)
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select 7 "$2" && return 0
|
|
|
|
;;
|
2013-11-06 09:45:34 +04:00
|
|
|
1.7+|7+)
|
2014-11-11 16:25:53 +04:00
|
|
|
for v in 7 8; do
|
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
1.8|8)
|
|
|
|
__java_select 8 "$2" && return 0
|
|
|
|
;;
|
|
|
|
1.8+|8+)
|
|
|
|
for v in 8; do
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_select "$v" "$2" && return 0
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-11-06 09:45:34 +04:00
|
|
|
function select_java_any() {
|
|
|
|
# Sélectionner la version exacte de java correspondant aux arguments, dans
|
|
|
|
# l'ordre, jusqu'à ce qu'un argument corresponde. DEFAULT correspond à la
|
|
|
|
# valeur actuelle de JAVA_HOME, si elle est définie.
|
2014-11-11 16:25:53 +04:00
|
|
|
# Si aucun argument n'est défini, on assume "DEFAULT 5 6 7 8 1.4"
|
2013-11-06 09:45:34 +04:00
|
|
|
local v
|
2014-11-11 16:25:53 +04:00
|
|
|
[ -n "$*" ] || set -- DEFAULT 5 6 7 8 1.4
|
2013-11-06 09:45:34 +04:00
|
|
|
for v in "$@"; do
|
|
|
|
if [ "$v" == DEFAULT ]; then
|
|
|
|
if [ -n "$JAVA_HOME" ]; then
|
|
|
|
__java_select_default && return 0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
select_java_exact "$v" && return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:14:44 +04:00
|
|
|
################################################################################
|
|
|
|
# Gestion des préfixes
|
|
|
|
|
|
|
|
function get_default_javahome_prefix() {
|
|
|
|
local GENTOO_VM JAVA_HOME JAVA JAVAC PATH="$PATH"
|
|
|
|
__java_select_default
|
|
|
|
[ -n "$JAVA_HOME" ] && echo "$JAVA_HOME"
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_javaextensions_prefix() {
|
|
|
|
local javaextensions
|
|
|
|
if check_sysinfos -s linux; then
|
|
|
|
if [ -n "$JAVA_HOME" ]; then
|
|
|
|
javaextensions="$JAVA_HOME/jre/lib/ext"
|
|
|
|
[ -d "$javaextensions" ] || javaextensions="$JAVA_HOME/lib/ext"
|
|
|
|
fi
|
|
|
|
elif check_sysinfos -s darwin; then
|
|
|
|
javaextensions=/Library/Java/Extensions
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$javaextensions" -a -d "$javaextensions" ] && echo "$javaextensions"
|
|
|
|
}
|
|
|
|
|
|
|
|
__java_prefixes=
|
|
|
|
function __compute_java_prefixes() {
|
|
|
|
[ -n "$__java_prefixes" ] && return
|
|
|
|
[ -n "$JAVA_HOME" ] || JAVA_HOME="$(get_default_javahome_prefix)"
|
|
|
|
JAVAEXTENSIONS="${JAVAEXTENSIONS:-$(get_javaextensions_prefix)}"
|
|
|
|
__java_prefixes=1
|
|
|
|
}
|
|
|
|
|
2015-08-23 22:56:23 +04:00
|
|
|
JAVA_PREFIXES=(JAVA_HOME JAVAEXTENSIONS)
|
|
|
|
UTOOLS_PREFIXES=("${UTOOLS_PREFIXES[@]}" "${JAVA_PREFIXES[@]}")
|
2013-08-27 15:14:44 +04:00
|
|
|
|
|
|
|
function compute_java_prefixes() {
|
|
|
|
__compute_java_prefixes
|
|
|
|
}
|
|
|
|
|
|
|
|
function recompute_java_prefixes() {
|
2015-08-23 22:56:23 +04:00
|
|
|
local v
|
|
|
|
for v in "${JAVA_PREFIXES[@]}"; do
|
|
|
|
eval "$v="
|
|
|
|
done
|
2013-08-27 15:14:44 +04:00
|
|
|
__java_prefixes=
|
|
|
|
__compute_java_prefixes
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_JAVA_HOME_prefix() {
|
|
|
|
__compute_java_prefixes
|
|
|
|
echo "$JAVA_HOME"
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_JAVAEXTENSIONS_prefix() {
|
|
|
|
__compute_java_prefixes
|
|
|
|
echo "$JAVAEXTENSIONS"
|
|
|
|
}
|