commit:     4aa75266725556940aa1b7dfcfd64989012dc603
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 24 07:02:14 2022 +0000
Commit:     Florian Schmaus <flow <AT> gentoo <DOT> org>
CommitDate: Fri Jun 24 07:39:59 2022 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-java.git/commit/?id=4aa75266

Add "eselect java-vm update"

Bug: https://bugs.gentoo.org/853928
Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>

 src/modules/java-vm.eselect.in | 55 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

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}"
+}

Reply via email to