diff options
author | Ralph Sennhauser <sera@gentoo.org> | 2012-06-10 12:33:10 +0000 |
---|---|---|
committer | Ralph Sennhauser <sera@gentoo.org> | 2012-06-10 12:33:10 +0000 |
commit | eef9d142998cb22d7960b54292b3ae7aa5fe865d (patch) | |
tree | 54a6b121405c39a6858c2dd3cca86fbc98b39d85 /src/modules/java-vm.eselect.in | |
download | eselect-java-eef9d142998cb22d7960b54292b3ae7aa5fe865d.tar.gz eselect-java-eef9d142998cb22d7960b54292b3ae7aa5fe865d.tar.bz2 eselect-java-eef9d142998cb22d7960b54292b3ae7aa5fe865d.zip |
New project eselect-java, new home of all java releated eselect modules.
Write build system and auxilary files.
Import eselect modules "java-vm" and "java-nsplugin" from java-config-2.1.12.
Import eselect module "maven" from eselect-maven-0.2
import eselect module "ecj" from eselect-ecj-0.7
svn path=/projects/eselect-java/trunk/; revision=9067
Diffstat (limited to 'src/modules/java-vm.eselect.in')
-rw-r--r-- | src/modules/java-vm.eselect.in | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/modules/java-vm.eselect.in b/src/modules/java-vm.eselect.in new file mode 100644 index 0000000..063b7c2 --- /dev/null +++ b/src/modules/java-vm.eselect.in @@ -0,0 +1,163 @@ +# Copyright 1999-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: $ + +# Based on kernel.eselect + +DESCRIPTION="Manage the Java system and user VM" +MAINTAINER="java@gentoo.org" +SVN_DATE='$Date: $' +VERSION=$(svn_date_to_version "${SVN_DATE}" ) + +VM_BASE=/usr/lib/jvm +VM_SYSTEM="/etc/java-config-2/current-system-vm" +VM_USER="${HOME}/.gentoo/java-config-2/current-user-vm" +VM_CONFIG="/usr/share/java-config-2/vm" + +find_targets() { + local f + for f in ${VM_BASE}/* ; do + [[ -L ${f} ]] && echo $(basename ${f}) + done +} + +sym_to_vm() { + basename $(readlink "${1}") +} + +### show action ### + +describe_show() { + echo "Show the current vm" +} + +do_show() { + if [[ ${1} == "system" ]]; then + my_show ${VM_SYSTEM} 'system-vm' + elif [[ ${1} == "user" ]]; then + my_show ${VM_USER} 'user-vm' + else + my_show ${VM_SYSTEM} 'system-vm' + my_show ${VM_USER} 'user-vm' + fi +} + +my_show() { + local symlink=${1} vm_type=${2} + write_list_start "Current ${vm_type}" + if [[ -L "${symlink}" ]] ; then + write_kv_list_entry "$(sym_to_vm ${symlink})" "" + else + write_kv_list_entry "(unset)" "" + fi +} + +### list action ### + +describe_list() { + echo "List Available Virtual Machines" +} + +do_list() { + targets=( $(find_targets) ) + write_list_start "Available Java Virtual Machines:" + local found_build_only + if [[ -n ${targets[@]} ]] ; then + local i system_name user_name + + [[ -L ${VM_SYSTEM} ]] && system_name=$(sym_to_vm ${VM_SYSTEM}) + [[ -L ${VM_USER} ]] && user_name=$(sym_to_vm ${VM_USER}) + + for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do + local build_only=$(grep 'BUILD_ONLY' ${VM_CONFIG}/${targets[${i}]} | cut -c 13-16 ) + local mark="" + + if [[ "${build_only}" == "TRUE" || "{build_only}" == "true" ]]; then + mark="$(highlight_warning 'Build Only')" + found_build_only="TRUE" + fi + + if [[ ${targets[${i}]} == ${system_name} ]]; then + mark="${mark} $(highlight 'system-vm')" + fi + if [[ ${targets[${i}]} == ${user_name} ]]; then + mark="${mark} $(highlight 'user-vm' )" + fi + targets[${i}]="${targets[${i}]} ${mark}" + done + write_numbered_list "${targets[@]}" + else + write_kv_list_entry "(none found)" "" + fi + echo + if [[ "${found_build_only}" == "TRUE" ]]; then + write_warning_msg "VMs marked as Build Only may contain Security Vulnerabilities and/or be EOL." + write_warning_msg "Gentoo recommends not setting these VMs as either your System or User VM." + write_warning_msg "Please see http://www.gentoo.org/doc/en/java.xml#build-only for more information." + fi +} + +### set action ### + +describe_set() { + echo "Set a new system or user vm" +} + +do_set() { + local usage="Usage [user|system] [vm]" + if [[ ${#} != 2 ]]; then + die -q ${usage} + + elif [[ ${1} == "system" ]]; then + if [[ -w $(dirname ${VM_SYSTEM}) ]]; then + my_set ${VM_SYSTEM} ${2} + else + die -q "Sorry, you don't have enough premission to set system" + fi + elif [[ ${1} == "user" ]]; then + if [[ ${UID} != 0 ]]; then + my_set ${VM_USER} ${2} + else + die -q "Sorry, you cannot set a user vm as root. Set the system vm instead" + fi + else + die -q ${usage} + fi +} + +my_set() { + local target=${2} symlink=${1} + if [[ -z ${target} ]] ; then + die -q "You didn't tell me what to set the symlink to" + + elif [[ -L "${symlink}" ]] ; then + set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink" + + elif [[ -e "${symlink}" ]] ; then + die -q "Target file already exists and is not a symlink: ${symlink}" + + else + set_symlink "${target}" "${symlink}" || die -q "Couldn't set a new symlink" + fi +} + +set_symlink() { + local target=${1} symlink=${2} + if is_number "${target}" ; then + targets=( $(find_targets) ) + target=${targets[$(( ${target} - 1 ))]} + fi + if [[ -z ${target} ]] ; then + die -q "Target \"${1}\" doesn't appear to be valid!" + elif [[ -d "${VM_BASE}/${target}" ]] ; then + local sym_dir=$(dirname ${symlink}) + if [[ ! -d ${sym_dir} ]]; then + mkdir -p ${sym_dir} || die -q "Could not create ${my_dir}" + fi + ln -snf "${VM_BASE}/${target}" "${symlink}" + else + die -q "Target \"${1}\" doesn't appear to be valid!" + fi +} + +# vim: set ft=eselect : |