[arch-commits] Commit in java-meta/trunk (bin_archlinux-java bin_archlinux-java_tests)

Guillaume Alaux guillaume at archlinux.org
Tue Jul 22 20:05:49 UTC 2014


    Date: Tuesday, July 22, 2014 @ 22:05:49
  Author: guillaume
Revision: 217738

Add warning when setting JRE in place of JDK and improve 'fix'

Modified:
  java-meta/trunk/bin_archlinux-java
  java-meta/trunk/bin_archlinux-java_tests

--------------------------+
 bin_archlinux-java       |   17 ++++++++++++++++-
 bin_archlinux-java_tests |   23 +++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

Modified: bin_archlinux-java
===================================================================
--- bin_archlinux-java	2014-07-22 19:45:28 UTC (rev 217737)
+++ bin_archlinux-java	2014-07-22 20:05:49 UTC (rev 217738)
@@ -1,5 +1,10 @@
 #! /bin/bash
 
+# TODO
+# Add info about license here
+# add message when setting JRE whereas JDK exists
+# ensure links do not output errors (???)
+
 # Arch Linux helper script to set/unset/check the enabled Java environment
 # See '-h' or '--help' for usage
 
@@ -64,6 +69,11 @@
     | while read bpath; do
       ln -sf ${WRAPPER_PATH} ${BIN_PATH}/$(basename ${bpath})
     done
+  parent_dir=$(dirname $1)
+  if is_java_valid ${parent_dir}; then
+    echo "Warning: '${parent_dir}' looks like a valid JDK whereas you are only setting '$1' as default"
+    echo "Fix this with 'archlinux-java --force-set ${parent_dir}'"
+  fi
 }
 
 unset_default() {
@@ -141,7 +151,12 @@
 fix_default() {
   default=$(get_default_java)
   if is_java_valid ${default}; then
-    echo "Current default Java environment is valid: '${default}'"
+    if is_java_valid $(dirname ${default}); then
+      unset_default
+      set_default_to $(dirname ${default})
+    else
+      echo "Current default Java environment is valid: '${default}'"
+    fi
   else
     if [ "x${default}" != "x" ]; then
       unset_default

Modified: bin_archlinux-java_tests
===================================================================
--- bin_archlinux-java_tests	2014-07-22 19:45:28 UTC (rev 217737)
+++ bin_archlinux-java_tests	2014-07-22 20:05:49 UTC (rev 217738)
@@ -125,6 +125,18 @@
   assertDefaultSetTo "${JAVA_NAME}/jre"
 }
 
+test_set_default_to_jre_but_jdk() {
+  create_valid_jdk_env "${JAVA_NAME}"
+  output=$(set_default_to "${JAVA_NAME}/jre")
+  mess="Setting Java environment '${JAVA_NAME}/jre' as default"
+  mess+="\nWarning: '${JAVA_NAME}' looks like a valid JDK"
+  mess+=" whereas you are only setting '${JAVA_NAME}/jre' as default"
+  mess+="\nFix this with 'archlinux-java --force-set ${JAVA_NAME}'"
+  expected=$(echo -e ${mess})
+  assertEquals 'Wrong message' "${expected}" "${output}"
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
 tests_unset_default() {
   create_valid_jre_env "${JAVA_NAME}/jre"
   set_default_for_test "${JAVA_NAME}/jre"
@@ -291,6 +303,17 @@
   assertDefaultNotSet
 }
 
+test_fix_default_jre_but_jdk_exists() {
+  create_valid_jdk_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  output=$(fix_default)
+  mess="Unsetting ${JAVA_NAME}/jre as default"
+  mess+="\nSetting Java environment '${JAVA_NAME}' as default"
+  expected=$(echo -e ${mess})
+  assertEquals 'Wrong message' "${expected}" "${output}"
+  assertDefaultSetTo "${JAVA_NAME}"
+}
 
+
 # load shunit2
 . shunit2-2.1.6/src/shunit2




More information about the arch-commits mailing list