[arch-commits] Commit in java-common/repos (7 files)

Felix Yan felixonmars at archlinux.org
Sat May 16 09:31:15 UTC 2020


    Date: Saturday, May 16, 2020 @ 09:31:15
  Author: felixonmars
Revision: 383878

archrelease: copy trunk to staging-any

Added:
  java-common/repos/staging-any/
  java-common/repos/staging-any/PKGBUILD
    (from rev 383876, java-common/trunk/PKGBUILD)
  java-common/repos/staging-any/bin_archlinux-java
    (from rev 383876, java-common/trunk/bin_archlinux-java)
  java-common/repos/staging-any/install_java-runtime-common.sh
    (from rev 383876, java-common/trunk/install_java-runtime-common.sh)
  java-common/repos/staging-any/profile_jre.csh
    (from rev 383876, java-common/trunk/profile_jre.csh)
  java-common/repos/staging-any/profile_jre.sh
    (from rev 383877, java-common/trunk/profile_jre.sh)
  java-common/repos/staging-any/test_archlinux-java
    (from rev 383877, java-common/trunk/test_archlinux-java)

--------------------------------+
 PKGBUILD                       |   71 +++++
 bin_archlinux-java             |  184 +++++++++++++++
 install_java-runtime-common.sh |   16 +
 profile_jre.csh                |    3 
 profile_jre.sh                 |    3 
 test_archlinux-java            |  465 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 742 insertions(+)

Copied: java-common/repos/staging-any/PKGBUILD (from rev 383876, java-common/trunk/PKGBUILD)
===================================================================
--- staging-any/PKGBUILD	                        (rev 0)
+++ staging-any/PKGBUILD	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,71 @@
+# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
+# Contributor: Guillaume ALAUX <guillaume at archlinux.org>
+
+pkgbase=java-common
+pkgname=('java-runtime-common' 'java-environment-common')
+pkgver=3
+pkgrel=3
+pkgdesc='Common files for Java Runtime Environments'
+url='https://www.archlinux.org/packages/extra/any/java-common/'
+arch=('any')
+license=('GPL')
+makedepends=('bash' 'findutils' 'coreutils')
+checkdepends=('wget')
+_shunitver=2.1.7
+source=(profile_jre.csh
+        profile_jre.sh
+        bin_archlinux-java
+        test_archlinux-java
+        https://github.com/kward/shunit2/archive/v${_shunitver}/shunit2-${_shunitver}.tar.gz)
+sha256sums=('9d25638cafc2fabd1ba6f2f26aa01233eccf3d31db003d956b571f0ab655dd23'
+            '519e9881a2a9f4fc3d581ea0ef0da594eedbfdfcf734f9fdc0bb595e8ac77e4c'
+            '5101f9d3d42cd545843a537826451c1b2e0bf2b16aba4e36ac797d9ace16dc63'
+            'f4c3fc55568fbbd298c1bf617bdd7f45db600b47c9991b072e409876e8cdd341'
+            '41a103aa984bfdeea3fec426edb0b3dda19153a5ce448d4b4bbe52a85c4d7fee')
+
+check() {
+  ln -s shunit2-${_shunitver} shunit2
+  ./test_archlinux-java
+}
+
+package_java-runtime-common() {
+  pkgdesc='Common files for Java Runtime Environments'
+  backup=(etc/profile.d/jre.sh
+          etc/profile.d/jre.csh)
+  depends=('bash' 'findutils' 'coreutils')
+  install=install_java-runtime-common.sh
+
+  install -d -m 755 "${pkgdir}/usr/lib/jvm/"
+  ln -s /dev/null "${pkgdir}/usr/lib/jvm/default"
+  ln -s /dev/null "${pkgdir}/usr/lib/jvm/default-runtime"
+
+  install -D -m 644 profile_jre.sh  "${pkgdir}/etc/profile.d/jre.sh"
+  install -D -m 644 profile_jre.csh "${pkgdir}/etc/profile.d/jre.csh"
+  install -D -m 755 bin_archlinux-java "${pkgdir}/usr/bin/archlinux-java"
+
+  install -d -m 755 "${pkgdir}/usr/bin/"
+  # Official list of binaries that Java headless runtime packages MUST provide
+  # This list is based on Arch Linux' default Java implementation: "OpenJDK 7 Icedtea"
+  for b in \
+    java keytool orbd pack200 rmid rmiregistry servertool tnameserv unpack200;
+  do
+    ln -s /usr/lib/jvm/default-runtime/bin/${b} "${pkgdir}/usr/bin/${b}"
+  done
+}
+
+package_java-environment-common() {
+  pkgdesc='Common files for Java Development Kits'
+
+  install -d "${pkgdir}/usr/bin"
+  # Official list of supplementary binaries that Java environment packages MUST provide
+  # This list is based on Arch Linux' default Java implementation: "OpenJDK 7 Icedtea"
+  for b in \
+    jar jarsigner javac javadoc javah javap jcmd \
+    jconsole jdb jinfo jmap jps jstack jstat \
+    jstatd rmic schemagen serialver wsgen wsimport xjc;
+  do
+    ln -s /usr/lib/jvm/default/bin/${b} "${pkgdir}/usr/bin/${b}"
+  done
+}
+
+# vim: ts=2 sw=2 et:

Copied: java-common/repos/staging-any/bin_archlinux-java (from rev 383876, java-common/trunk/bin_archlinux-java)
===================================================================
--- staging-any/bin_archlinux-java	                        (rev 0)
+++ staging-any/bin_archlinux-java	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,184 @@
+#! /bin/bash
+
+# Arch Linux helper script to set/unset/check/fix the enabled Java environment
+# This program may be freely redistributed under the terms of the GNU General Public License
+#
+# Author: Guillaume ALAUX <guillaume at archlinux.org>
+
+JVM_DIR=/usr/lib/jvm
+DEFAULT_NAME=default
+DEFAULT_PATH=${JVM_DIR}/${DEFAULT_NAME}
+DEFAULT_NAME_JRE=default-runtime
+DEFAULT_PATH_JRE=${JVM_DIR}/${DEFAULT_NAME_JRE}
+
+
+# Utility functions
+
+check_root() {
+  if [ $(id -u) -ne 0 ]; then
+    echo 'This script must be run as root'
+    exit 1
+  fi
+}
+
+# $1: parameter count given to this script for this option
+# $2: expected parameter count for this option
+check_param_count() {
+  if [ $1 -ne $2 ]; then
+    echo 'Wrong parameter count'
+    exit 2
+  fi
+}
+
+# Second level functions
+
+get_default_java() {
+  path=$(readlink -e ${DEFAULT_PATH})
+  if [ "x${path}" != "x/dev/null" ]; then
+    echo ${path/${JVM_DIR}\/}
+  else
+    echo ""
+  fi
+}
+
+get_installed_javas() {
+  if [ -d ${JVM_DIR} ]; then
+    for dir in $(find ${JVM_DIR} -mindepth 1 -maxdepth 1 -type d | sort); do
+      if [ -x ${dir}/bin/java ]; then
+        javas+=(${dir/${JVM_DIR}\/})
+      else
+        if [ -x ${dir}/jre/bin/java ]; then
+        javas+=(${dir/${JVM_DIR}\/}/jre)
+        fi
+      fi
+    done
+  fi
+  echo ${javas[@]}
+}
+
+# $1: Java environment name to test
+is_java_valid() {
+  test "x$1" != "x${DEFAULT_NAME}" && test -x ${JVM_DIR}/$1/bin/java
+}
+
+# $1: Java environment name to set as default
+set_default_link_to() {
+  new_default=$1
+  unlink ${DEFAULT_PATH} 2>/dev/null
+  ln -sf ${new_default} ${DEFAULT_PATH}
+
+  unlink ${DEFAULT_PATH_JRE} 2>/dev/null
+  if [[ -d ${new_default}/jre ]]; then
+    ln -sf ${new_default}/jre ${DEFAULT_PATH_JRE}
+  else
+    ln -sf ${new_default} ${DEFAULT_PATH_JRE}
+  fi
+}
+
+unset_default_link() {
+  unlink ${DEFAULT_PATH} 2>/dev/null
+  unlink ${DEFAULT_PATH_JRE} 2>/dev/null
+}
+
+# First level functions
+
+do_status() {
+  installed_java=($(get_installed_javas))
+  if [ ${#installed_java[@]} -eq 0 ]; then
+    echo 'No compatible Java environment installed'
+  else
+    default_java=$(get_default_java)
+    echo 'Available Java environments:'
+    for java in ${installed_java[@]}; do
+      # We discoverd this Java env but its JRE is actually set as default
+      if [ "${java}/jre" = "${default_java}" ]; then
+        echo -e "  ${java} (${java}/jre default)"
+      elif [ ${java} = "${default_java}" ]; then
+        echo -e "  ${java} (default)"
+      else
+        echo "  ${java}"
+      fi
+    done
+    if [ -z ${default_java} ]; then
+      echo "No Java environment set as default"
+    fi
+  fi
+}
+
+do_get() {
+  get_default_java
+}
+
+# $1: Java environment name to set as default
+do_set() {
+  if ! is_java_valid $1; then
+    echo "'${JVM_DIR}/$1' is not a valid Java environment path"
+    exit 1
+  fi
+  default=$(get_default_java)
+  if [ "x$1" != "x${default}" ] || ! is_java_valid ${default}; then
+    unset_default_link
+    set_default_link_to $1
+  fi
+
+  #parent_dir=$(dirname $1)
+  #if is_java_valid ${parent_dir}; then
+  #  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
+}
+
+# $1: Java environment name to unset
+do_unset() {
+  unset_default_link
+}
+
+do_fix() {
+  default=$(get_default_java)
+  if is_java_valid ${default}; then
+    # If its parent is also a valid Java environment
+    if is_java_valid $(dirname ${default}); then
+      unset_default_link
+      set_default_link_to $(dirname ${default})
+    fi
+  else
+    prev=$(readlink ${DEFAULT_PATH})
+    unset_default_link
+    potential_fixes=("${prev/\/jre}" "${prev}/jre")
+    openjdk8=('java-8-openjdk' 'java-8-openjdk/jre')
+    # List of environments to check by order of preference:
+    # - first potential fixes of user choices,
+    # - then OpenJDK8 as it is considered a default in Arch Linux
+    # - finally, any installed environment
+    to_check=(${potential_fixes[@]} ${openjdk8[@]} $(get_installed_javas))
+    for java in ${to_check[@]}; do
+      if ! is_java_valid $(get_default_java) && is_java_valid ${java}; then
+        set_default_link_to ${java}
+      fi
+    done
+  fi
+  if ! is_java_valid $(get_default_java); then
+    echo 'No valid Java environment found'
+  fi
+}
+
+usage() {
+  echo "$(basename $0) <COMMAND>"
+  echo -e "\nCOMMAND:"
+  echo -e '\tstatus\t\tList installed Java environments and enabled one'
+  echo -e '\tget\t\tReturn the short name of the Java environment set as default'
+  echo -e '\tset <JAVA_ENV>\tForce <JAVA_ENV> as default'
+  echo -e '\tunset\t\tUnset current default Java environment'
+  echo -e '\tfix\t\tFix an invalid/broken default Java environment configuration'
+}
+
+## Main
+case $1 in
+  '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

Copied: java-common/repos/staging-any/install_java-runtime-common.sh (from rev 383876, java-common/trunk/install_java-runtime-common.sh)
===================================================================
--- staging-any/install_java-runtime-common.sh	                        (rev 0)
+++ staging-any/install_java-runtime-common.sh	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,16 @@
+pre_upgrade() {
+  if grep -q '^export _JAVA_AWT_WM_NONREPARENTING=1' /etc/profile.d/jre.sh > /dev/null 2>&1; then
+    echo "Variable '_JAVA_AWT_WM_NONREPARENTING' should not be set in /etc/profile.d/jre.sh any more"
+    echo "Please declare it in ~/.xinitrc or such"
+  fi
+}
+
+post_install() {
+  echo 'For the complete set of Java binaries to be available in your PATH,'
+  echo 'you need to re-login or source /etc/profile.d/jre.sh'
+  echo 'Please note that this package does not support forcing JAVA_HOME as former package 'java-common' did'
+}
+
+post_upgrade() {
+  archlinux-java fix
+}

Copied: java-common/repos/staging-any/profile_jre.csh (from rev 383876, java-common/trunk/profile_jre.csh)
===================================================================
--- staging-any/profile_jre.csh	                        (rev 0)
+++ staging-any/profile_jre.csh	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,3 @@
+# Do not change this unless you want to completely by-pass Arch Linux' way
+# of handling Java versions and vendors. Instead, please use script `archlinux-java`
+setenv PATH "${PATH}:/usr/lib/jvm/default/bin"

Copied: java-common/repos/staging-any/profile_jre.sh (from rev 383877, java-common/trunk/profile_jre.sh)
===================================================================
--- staging-any/profile_jre.sh	                        (rev 0)
+++ staging-any/profile_jre.sh	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,3 @@
+# Do not change this unless you want to completely by-pass Arch Linux' way
+# of handling Java versions and vendors. Instead, please use script `archlinux-java`
+export PATH=${PATH}:/usr/lib/jvm/default/bin

Copied: java-common/repos/staging-any/test_archlinux-java (from rev 383877, java-common/trunk/test_archlinux-java)
===================================================================
--- staging-any/test_archlinux-java	                        (rev 0)
+++ staging-any/test_archlinux-java	2020-05-16 09:31:15 UTC (rev 383878)
@@ -0,0 +1,465 @@
+#! /bin/sh
+#
+# To run this script, ensure shunit2 (https://github.com/kward/shunit2)
+# is available on the local directory, then just run sh bin_archlinux-java_tests
+#
+# inotifywait -r -m -e MODIFY . | while read l; do sh bin_archlinux-java_tests; done
+
+declare test_dir
+
+. ./bin_archlinux-java > /dev/null
+
+INIT_JVM_DIR=${JVM_DIR}
+INIT_DEFAULT_PATH=${DEFAULT_PATH}
+INIT_DEFAULT_PATH_JRE=${DEFAULT_PATH_JRE}
+
+# Redefining this so that tested script can be invoked without root privileges
+check_root() {
+  true
+}
+
+
+get_rand_str() {
+  echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
+}
+
+setUp() {
+  test_dir=$(mktemp -d)
+  JVM_DIR=${test_dir}${INIT_JVM_DIR}
+  DEFAULT_PATH=${test_dir}${INIT_DEFAULT_PATH}
+  DEFAULT_PATH_JRE=${test_dir}${INIT_DEFAULT_PATH_JRE}
+  JAVA_NAME=$(get_rand_str)
+  mkdir -p ${JVM_DIR}
+}
+
+tearDown() {
+  rm -rf ${test_dir}
+}
+
+# $1: path of Java environment to create
+create_raw_java_env() {
+  java_env_name=$1
+  bin_name=$2
+  mkdir -p ${JVM_DIR}/${java_env_name}/bin
+  touch    ${JVM_DIR}/${java_env_name}/bin/$bin_name
+  chmod +x ${JVM_DIR}/${java_env_name}/bin/$bin_name
+}
+
+create_valid_jre8_env() {
+  create_raw_java_env "$1/jre" "java"
+}
+
+# $1: path of Java environment to create
+create_valid_jre8_jdk8_env() {
+  create_raw_java_env "$1" "java"
+  create_raw_java_env "$1" "javac"
+  create_valid_jre8_env "$1"
+}
+
+create_valid_jre9_env() {
+  create_raw_java_env "$1" "java"
+}
+
+create_valid_jre9_jdk9_env() {
+  create_raw_java_env "$1" "java"
+  create_raw_java_env "$1" "javac"
+}
+
+set_default_for_test() {
+  ln -s $1 ${DEFAULT_PATH}
+  if [ -d ${DEFAULT_PATH}/jre ]; then
+    ln -s $1/jre ${DEFAULT_PATH_JRE}
+  else
+    ln -s $1 ${DEFAULT_PATH_JRE}
+  fi
+}
+
+assertDefaultNotSet() {
+  assertNull 'Default is set' "$(readlink ${DEFAULT_PATH})"
+  assertNull 'Default runtime is set' "$(readlink ${DEFAULT_PATH_JRE})"
+}
+
+assertDefaultSetTo() {
+  new_java=$1
+  assertEquals "Default points at wrong Java env" "${new_java}" "$(readlink ${DEFAULT_PATH})"
+  if [ ${new_java} == */jre ]; then
+    assertEquals "Default runtime points at wrong Java env" "${new_java}/jre" "$(readlink ${DEFAULT_PATH_JRE})"
+  fi
+}
+
+# do_status
+
+test_do_status_with_jre8_default() {
+  JAVA_NAME_1="a$(get_rand_str)"
+  JAVA_NAME_2="b$(get_rand_str)"
+  JAVA_NAME_3="c$(get_rand_str)"
+  create_valid_jre8_env "${JAVA_NAME_1}"
+  set_default_for_test "${JAVA_NAME_1}/jre"
+  create_valid_jre8_jdk8_env "${JAVA_NAME_2}"
+  create_valid_jre9_env "${JAVA_NAME_3}"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME_1}/jre (default)"
+  mess+="\n  ${JAVA_NAME_2}"
+  mess+="\n  ${JAVA_NAME_3}"
+  expected=$(echo -e "${mess}")
+  assertEquals 'Wrong status output' "${expected}" "$(do_status)"
+}
+
+test_do_status_with_jre9_default() {
+  JAVA_NAME_1="a$(get_rand_str)"
+  JAVA_NAME_2="b$(get_rand_str)"
+  JAVA_NAME_3="c$(get_rand_str)"
+  create_valid_jre8_env "${JAVA_NAME_1}"
+  create_valid_jre8_jdk8_env "${JAVA_NAME_2}"
+  create_valid_jre9_env "${JAVA_NAME_3}"
+  set_default_for_test "${JAVA_NAME_3}"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME_1}/jre"
+  mess+="\n  ${JAVA_NAME_2}"
+  mess+="\n  ${JAVA_NAME_3} (default)"
+  expected=$(echo -e "${mess}")
+  assertEquals 'Wrong status output' "${expected}" "$(do_status)"
+}
+
+test_do_status_with_jdk9_default() {
+  JAVA_NAME_1="a$(get_rand_str)"
+  JAVA_NAME_2="b$(get_rand_str)"
+  JAVA_NAME_3="c$(get_rand_str)"
+  create_valid_jre8_env "${JAVA_NAME_1}"
+  create_valid_jre8_jdk8_env "${JAVA_NAME_2}"
+  create_valid_jre9_jdk9_env "${JAVA_NAME_3}"
+  set_default_for_test "${JAVA_NAME_3}"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME_1}/jre"
+  mess+="\n  ${JAVA_NAME_2}"
+  mess+="\n  ${JAVA_NAME_3} (default)"
+  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)"
+  JAVA_NAME_3="c$(get_rand_str)"
+  JAVA_NAME_4="d$(get_rand_str)"
+  create_valid_jre8_env "${JAVA_NAME_1}"
+  create_valid_jre8_jdk8_env "${JAVA_NAME_2}"
+  create_valid_jre9_env "${JAVA_NAME_3}"
+  create_valid_jre9_jdk9_env "${JAVA_NAME_4}"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME_1}/jre"
+  mess+="\n  ${JAVA_NAME_2}"
+  mess+="\n  ${JAVA_NAME_3}"
+  mess+="\n  ${JAVA_NAME_4}"
+  mess+="\nNo Java environment set as default"
+  expected=$(echo -e "${mess}")
+  assertEquals 'Wrong status output' "${expected}" "$(do_status)"
+}
+
+test_do_status_no_duplicate_entry_jre9_jdk9() {
+  JAVA_NAME_1="a$(get_rand_str)"
+  create_valid_jre9_jdk9_env "${JAVA_NAME_1}"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME_1}"
+  mess+="\nNo Java environment set as default"
+  expected=$(echo -e "${mess}")
+  assertEquals 'Wrong status output' "${expected}" "$(do_status)"
+}
+
+test_do_status_no_javas() {
+  assertEquals 'Wrong status output' 'No compatible Java environment installed' "$(do_status)"
+}
+
+test_do_status_jre_but_jdk_exists() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  mess="Available Java environments:"
+  mess+="\n  ${JAVA_NAME} (${JAVA_NAME}/jre default)"
+  expected=$(echo -e "${mess}")
+  assertEquals 'Wrong status output' "${expected}" "$(do_status)"
+}
+
+# do_get
+
+test_do_get_with_jdk8_default() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  assertEquals 'Wrong result' "${JAVA_NAME}" "$(do_get)"
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_get_without_default() {
+  create_valid_jre8_jdk8_env "$(get_rand_str)"
+  create_valid_jre9_jdk9_env "$(get_rand_str)"
+  assertNull 'Wrong result' "$(do_get)"
+}
+
+test_do_get_with_initial_null() {
+  set_default_for_test "/dev/null"
+  assertNull 'Wrong result' "$(do_get)"
+}
+
+test_do_get_with_jdk9_default() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  assertEquals 'Wrong result' "${JAVA_NAME}" "$(do_get)"
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+# do_set
+
+test_do_set_new_invalid() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  output=$(do_set "INVALID")
+  assertEquals 'Wrong status returned' 1 $?
+  assertEquals 'Wrong message' "'${JVM_DIR}/INVALID' is not a valid Java environment path" "${output}"
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_set_current_invalid() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "INVALID"
+  $(do_set "${JAVA_NAME}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_set_jre8_with_default_already_set_to_jre8() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  JAVA_NAME_2="$(get_rand_str)"
+  create_valid_jre8_env "${JAVA_NAME_2}"
+  $(do_set "${JAVA_NAME_2}/jre")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME_2}/jre"
+}
+
+test_do_set_jre9_with_default_already_set_to_jre8() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  JAVA_NAME_2="$(get_rand_str)"
+  create_valid_jre9_env "${JAVA_NAME_2}"
+  $(do_set "${JAVA_NAME_2}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME_2}"
+}
+
+test_do_set_jdk9_with_default_already_set_to_jdk8() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  JAVA_NAME_2="$(get_rand_str)"
+  create_valid_jre9_jdk9_env "${JAVA_NAME_2}"
+  $(do_set "${JAVA_NAME_2}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME_2}"
+}
+
+test_do_set_jre8_no_previous_default() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  $(do_set "${JAVA_NAME}/jre")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_set_jre9_no_previous_default() {
+  create_valid_jre9_env "${JAVA_NAME}"
+  $(do_set "${JAVA_NAME}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_set_jdk9_no_previous_default() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  $(do_set "${JAVA_NAME}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_set_jre8_while_jdk8_also_exists() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  output=$(do_set "${JAVA_NAME}/jre")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+  #mess="Warning: '${JAVA_NAME}' looks like a valid JDK whereas you only set '${JAVA_NAME}/jre' as default"
+  #mess+="\nFix this with 'archlinux-java set ${JAVA_NAME}'"
+  #expected=$(echo -e "${mess}")
+  #assertEquals 'Wrong message' "${expected}" "${output}"
+}
+
+test_do_set_jdk8_cleanup_old_jre8_default() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  output=$(do_set "${JAVA_NAME}/jre")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_set_jdk9_cleanup_old_jdk8_default() {
+  JAVA8_NAME=$(get_rand_str)
+  create_valid_jre8_jdk8_env "${JAVA8_NAME}"
+  set_default_for_test "${JAVA8_NAME}"
+  JAVA9_NAME=$(get_rand_str)
+  create_valid_jre9_jdk9_env "${JAVA9_NAME}"
+  output=$(do_set "${JAVA9_NAME}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA9_NAME}"
+}
+
+test_do_set_jdk8_devnull() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "/dev/null"
+  output=$(do_set "${JAVA_NAME}/jre")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_set_jdk9_devnull() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  set_default_for_test "/dev/null"
+  output=$(do_set "${JAVA_NAME}")
+  assertEquals 'Wrong status returned' 0 $?
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+# do_unset
+
+test_do_unset_jre8() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  do_unset
+  assertDefaultNotSet
+}
+
+test_do_unset_no_default_link() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  unlink ${DEFAULT_PATH}
+  do_unset
+  assertDefaultNotSet
+}
+
+test_do_unset_devnull() {
+  set_default_for_test "/dev/null"
+  do_unset
+  assertDefaultNotSet
+}
+
+test_do_unset_jre9() {
+  create_valid_jre9_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  do_unset
+  assertDefaultNotSet
+}
+
+test_do_unset_jdk9() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  do_unset
+  assertDefaultNotSet
+}
+
+# do_fix
+
+test_do_fix_default_valid_jre8() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_default_valid_jre9() {
+  create_valid_jre9_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_default_valid_jdk9() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_no_default_jre8() {
+  create_valid_jre8_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_no_default_jre9() {
+  create_valid_jre9_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_no_default_jdk9() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_default_invalid_openjdk7_jdk_installed() {
+  create_valid_jre8_jdk8_env "java-8-openjdk"
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "java-8-openjdk"
+}
+
+test_do_fix_jdk8_not_default_but_openjdk7_jre_installed() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  create_valid_jre8_env "java-8-openjdk"
+  do_fix
+  assertDefaultSetTo "java-8-openjdk/jre"
+}
+
+test_do_fix_jdk9_not_default_but_openjdk7_jre_installed() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  create_valid_jre8_env "java-8-openjdk"
+  do_fix
+  assertDefaultSetTo "java-8-openjdk/jre"
+}
+
+test_do_fix_default_invalid_random_java8_installed() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_default_invalid_random_java9_installed() {
+  create_valid_jre9_jdk9_env "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_default_invalid_no_java_installed() {
+  assertEquals 'Wrong message' "No valid Java environment found" "$(do_fix)"
+  assertDefaultNotSet
+}
+
+test_do_fix_jre8_but_jdk8_exists() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "${JAVA_NAME}/jre"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_jdk_but_jre_exists() {
+  create_valid_jre8_jdk8_env "java-7-openjdk"
+  create_valid_jre8_env "${JAVA_NAME}"
+  # Only JRE is installed but setting JDK as default
+  set_default_for_test "${JAVA_NAME}"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_devnull() {
+  create_valid_jre8_jdk8_env "${JAVA_NAME}"
+  set_default_for_test "/dev/null"
+  do_fix
+  assertDefaultSetTo "${JAVA_NAME}"
+}
+
+# load shunit2
+. shunit2/shunit2


More information about the arch-commits mailing list