| author | Guillaume Alaux
<guillaume@archlinux.org> 2014-08-03 19:46:52 UTC |
| committer | Guillaume Alaux
<guillaume@archlinux.org> 2014-08-03 19:46:52 UTC |
| parent | c656c4baddea3c1d1bc03903fbfb207ce5096c42 |
| PKGBUILD | +2 | -2 |
| bin_archlinux-java | +18 | -17 |
| test_archlinux-java | +20 | -0 |
diff --git a/PKGBUILD b/PKGBUILD index 45ec282..9f42f91 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -21,8 +21,8 @@ source=(profile_jre.csh sha256sums=('d5d583325751bf5cb43cca448f0d5c0a868958d19baf2db3694c9948b9d8974e' '523c88cfe78667960a7c04ef1a0983371690f42153c54174711281337b556378' - '8ca7eea69eeaa62a5603d66c10a4f25ce57911b89220b46876355f604701c047' - '0dd93c9779c617af061b25f5e3d23cacb741d8d757f533312c3af976661e8cbc' + 'a6779034d99b84f5954764bb4f86c89f3dcd172dc343265291d6b0929b350932' + 'f2a4ef37600c4ee12090881c881b085c3b209bb97ce0df10920d8df3e0b1e700' '622927af9ec374140a878993936f7fdd4206fe069dddfcefc6d4e15fa6d67f39' '65a313a76fd5cc1c58c9e19fbc80fc0e418a4cbfbd46d54b35ed5b6e0025d4ee') diff --git a/bin_archlinux-java b/bin_archlinux-java index eb859c0..2ca44e7 100755 --- a/bin_archlinux-java +++ b/bin_archlinux-java @@ -21,17 +21,6 @@ check_root() { fi } -check_java_home() { - if [ "x${JAVA_HOME}" != "x${DEFAULT_PATH}" ]; then - echo "JAVA_HOME is not set to '${DEFAULT_PATH}'," - echo 'which means this script may not provide the expected result.' - echo 'To fix this, please ensure '/etc/profile.d/jre.sh' sets JAVA_HOME' - echo 'accordingly and that no other profile script interfer.' - echo 'You may also need to relogin in order for this variable to be set.' - exit 1 - fi -} - # $1: parameter count given to this script for this option # $2: expected parameter count for this option check_param_count() { @@ -94,6 +83,17 @@ unset_default_link() { # First level functions +check_java_home() { + if [ "x${JAVA_HOME}" != "x${DEFAULT_PATH}" ]; then + echo -e "\nJAVA_HOME is not set to '${DEFAULT_PATH}'," + echo 'which means Java environments may not provide the expected result.' + echo "To fix this, please ensure '/etc/profile.d/jre.sh' sets JAVA_HOME" + echo 'accordingly and that no other profile script interferes.' + echo 'You may also need to relogin in order for this variable to be set.' + exit 1 + fi +} + do_status() { installed_java=($(get_installed_javas)) if [ ${#installed_java[@]} -eq 0 ]; then @@ -111,6 +111,7 @@ do_status() { if [ -z ${default_java} ]; then echo "No Java environment set as default" fi + check_java_home fi } @@ -134,7 +135,7 @@ do_set() { #parent_dir=$(dirname $1) #if is_java_valid ${parent_dir}; then - # echo "Warning: '${parent_dir}' looks like a valid JDK whereas you only set '$1' as default" + # echo "Warning: '${parent_dir}' looks like a valid JDK whereas '$1' is set as default" # echo "Fix this with 'archlinux-java set ${parent_dir}'" #fi } @@ -185,11 +186,11 @@ usage() { ## Main case $1 in - 'status') check_java_home; do_status;; - 'get') check_java_home; do_get;; - 'set') check_java_home; check_root; check_param_count $# 2; do_set $2;; - 'unset') check_java_home; check_root; do_unset;; - 'fix') check_java_home; check_root; do_fix;; + 'status') do_status;; + 'get') do_get;; + 'set') check_root; check_param_count $# 2; do_set $2;; + 'unset') check_root; do_unset;; + 'fix') check_root; do_fix;; 'help' | '--help' | '-h' | '') usage;; *) echo "$(basename $0): unknown option '$@'"; exit 1;; esac diff --git a/test_archlinux-java b/test_archlinux-java index d3640d2..3873a40 100755 --- a/test_archlinux-java +++ b/test_archlinux-java @@ -28,6 +28,7 @@ setUp() { test_dir=$(mktemp -d) JVM_DIR=${test_dir}${INIT_JVM_DIR} DEFAULT_PATH=${test_dir}${INIT_DEFAULT_PATH} + JAVA_HOME=${DEFAULT_PATH} JAVA_NAME=$(get_rand_str) BIN_PATH=${test_dir}${INIT_BIN_PATH} mkdir -p ${BIN_PATH} @@ -106,6 +107,25 @@ test_do_status() { assertEquals 'Wrong status output' "${expected}" "$(do_status)" } +test_do_status_no_javahome() { + JAVA_NAME_1="a$(get_rand_str)" + JAVA_NAME_2="b$(get_rand_str)" + create_valid_jre_env "${JAVA_NAME_1}/jre" + set_default_for_test "${JAVA_NAME_1}/jre" + create_valid_jdk_env "${JAVA_NAME_2}" + unset JAVA_HOME + mess+="Available Java environments:\n" + mess+=" ${JAVA_NAME_1}/jre (default)\n" + mess+=" ${JAVA_NAME_2}\n" + mess+="\nJAVA_HOME is not set to '${DEFAULT_PATH}',\n" + mess+="which means Java environments may not provide the expected result.\n" + mess+="To fix this, please ensure '/etc/profile.d/jre.sh' sets JAVA_HOME\n" + mess+="accordingly and that no other profile script interferes.\n" + mess+="You may also need to relogin in order for this variable to be set." + expected=$(echo -e "${mess}") + assertEquals 'Wrong status output' "${expected}" "$(do_status)" +} + test_do_status_no_default() { JAVA_NAME_1="a$(get_rand_str)" JAVA_NAME_2="b$(get_rand_str)"