aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/java-vm.eselect.in')
-rw-r--r--src/modules/java-vm.eselect.in55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in
index e332c5a..c7d5a82 100644
--- a/src/modules/java-vm.eselect.in
+++ b/src/modules/java-vm.eselect.in
@@ -177,3 +177,58 @@ set_symlink() {
die -q "Target \"${1}\" doesn't appear to be valid!"
fi
}
+
+describe_update() {
+ echo "Automatically update the Java system VM"
+}
+
+do_update() {
+ local targets
+ targets=( $(find_targets) )
+
+ if [[ ${#targets[@]} -eq 0 ]]; then
+ echo "No installed Java VMs found, can not update"
+ return
+ fi
+
+ if [[ -e "${VM_SYSTEM}" ]]; then
+ local current_system_vm_name=$(sym_to_vm "${VM_SYSTEM}")
+ echo "Current Java system VM ${current_system_vm_name} is valid, no need to update"
+ return
+ fi
+
+ local new_target old_system_vm_name
+ if [[ -L "${VM_SYSTEM}" ]]; then
+ # There exists a Java system VM symlink that has become stale,
+ # try to find another available VM with the same slot.
+ old_system_vm_name=$(sym_to_vm "${VM_SYSTEM}")
+
+ local old_system_vm_slot="${old_system_vm_name##*-}"
+
+ local target
+ for target in "${targets[@]}"; do
+ local target_slot="${target##*-}"
+ if [[ ${target_slot} -eq ${old_system_vm_slot} ]]; then
+ new_target="${target}"
+ break
+ fi
+ done
+ fi
+
+ if [[ -z "${new_target}" ]]; then
+ # There is no Java system VM symlink or we could not find a
+ # slot-matching replacement. But there are potential targets,
+ # simply choose the first.
+ # TODO: We could get more sophisticated here to select the "best"
+ # target, but that is far from trivial.
+ new_target="${targets[0]}"
+ fi
+
+ local from_vm_text=""
+ if [[ -n "${old_system_vm_name}" ]]; then
+ from_vm_text="from ${old_system_vm_name} "
+ fi
+
+ echo "Updating Java system VM ${from_vm_text}to ${new_target}"
+ set_symlink "${new_target}" "${VM_SYSTEM}"
+}