summaryrefslogtreecommitdiffstats
path: root/abs
diff options
context:
space:
mode:
Diffstat (limited to 'abs')
-rw-r--r--abs/extra/java-common/PKGBUILD70
-rwxr-xr-xabs/extra/java-common/bin_archlinux-java178
-rwxr-xr-xabs/extra/java-common/bin_java-common-wrapper2
-rw-r--r--abs/extra/java-common/install_java-runtime-common.sh16
-rw-r--r--abs/extra/java-common/profile_jre.csh3
-rw-r--r--abs/extra/java-common/profile_jre.sh3
-rwxr-xr-xabs/extra/java-common/test_archlinux-java286
7 files changed, 558 insertions, 0 deletions
diff --git a/abs/extra/java-common/PKGBUILD b/abs/extra/java-common/PKGBUILD
new file mode 100644
index 0000000..502622e
--- /dev/null
+++ b/abs/extra/java-common/PKGBUILD
@@ -0,0 +1,70 @@
+# Maintainer: Guillaume ALAUX <guillaume@archlinux.org>
+pkgname=('java-runtime-common' 'java-environment-common')
+pkgbase=java-common
+pkgver=2
+pkgrel=2
+arch=('any')
+url='www.archlinux.org'
+license=('GPL')
+checkdepends=('wget')
+source=(profile_jre.csh
+ profile_jre.sh
+ bin_archlinux-java
+ test_archlinux-java
+ https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz)
+
+sha256sums=('9d25638cafc2fabd1ba6f2f26aa01233eccf3d31db003d956b571f0ab655dd23'
+ '519e9881a2a9f4fc3d581ea0ef0da594eedbfdfcf734f9fdc0bb595e8ac77e4c'
+ '272296ec7ca673b4f9f59fb70565328b6daef682c29cd964c988c018090c3fc2'
+ 'c2c413a6b2f8b88ed170a5b19f7cb620518e09686f0d286b4b27d30f571e5050'
+ '65a313a76fd5cc1c58c9e19fbc80fc0e418a4cbfbd46d54b35ed5b6e0025d4ee')
+
+check() {
+ cd "${srcdir}"
+ ./test_archlinux-java
+}
+
+package_java-runtime-common() {
+ pkgdesc='Common files for Java Runtime Environments'
+ conflicts=('java-common')
+ replaces=('java-common')
+ backup=(etc/profile.d/jre.sh
+ etc/profile.d/jre.csh)
+ install=install_java-runtime-common.sh
+
+ cd "${srcdir}"
+
+ 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 policytool 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'
+
+ cd "${srcdir}"
+
+ install -d -m 755 "${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 \
+ appletviewer extcheck idlj jar jarsigner javac javadoc javah javap jcmd \
+ jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat \
+ jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc;
+ do
+ ln -s /usr/lib/jvm/default/bin/${b} "${pkgdir}/usr/bin/${b}"
+ done
+}
diff --git a/abs/extra/java-common/bin_archlinux-java b/abs/extra/java-common/bin_archlinux-java
new file mode 100755
index 0000000..453b0a4
--- /dev/null
+++ b/abs/extra/java-common/bin_archlinux-java
@@ -0,0 +1,178 @@
+#! /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@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/javac ]; 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 [[ ${new_default} == */jre ]]; then
+ ln -sf ${new_default} ${DEFAULT_PATH_JRE}
+ else
+ ln -sf ${new_default}/jre ${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
+ 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 is_java_valid $(dirname ${default}); then
+ unset_default_link
+ set_default_link_to $(dirname ${default})
+ fi
+ else
+ prev=$(readlink ${DEFAULT_PATH})
+ unset_default_link
+ prev_fix=("${prev/\/jre}" "${prev}/jre")
+ openjdk7=('java-7-openjdk' 'java-7-openjdk/jre')
+ to_check=(${prev_fix[@]} ${openjdk7[@]} $(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
diff --git a/abs/extra/java-common/bin_java-common-wrapper b/abs/extra/java-common/bin_java-common-wrapper
new file mode 100755
index 0000000..19d9eda
--- /dev/null
+++ b/abs/extra/java-common/bin_java-common-wrapper
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec "${JAVA_HOME:-/usr/lib/jvm/default}/bin/${0##*/}" "$@"
diff --git a/abs/extra/java-common/install_java-runtime-common.sh b/abs/extra/java-common/install_java-runtime-common.sh
new file mode 100644
index 0000000..f61d177
--- /dev/null
+++ b/abs/extra/java-common/install_java-runtime-common.sh
@@ -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
+}
diff --git a/abs/extra/java-common/profile_jre.csh b/abs/extra/java-common/profile_jre.csh
new file mode 100644
index 0000000..a224d89
--- /dev/null
+++ b/abs/extra/java-common/profile_jre.csh
@@ -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"
diff --git a/abs/extra/java-common/profile_jre.sh b/abs/extra/java-common/profile_jre.sh
new file mode 100644
index 0000000..f5b2585
--- /dev/null
+++ b/abs/extra/java-common/profile_jre.sh
@@ -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
diff --git a/abs/extra/java-common/test_archlinux-java b/abs/extra/java-common/test_archlinux-java
new file mode 100755
index 0000000..867745d
--- /dev/null
+++ b/abs/extra/java-common/test_archlinux-java
@@ -0,0 +1,286 @@
+#! /bin/sh
+#
+# To run this script, ensure shunit2 (https://code.google.com/p/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_valid_jre_env() {
+ mkdir -p ${JVM_DIR}/$1/bin
+ for binary in java keytool orbd; do
+ touch ${JVM_DIR}/$1/bin/${binary}
+ chmod +x ${JVM_DIR}/$1/bin/${binary}
+ done
+}
+
+# $1: path of Java environment to create
+create_valid_jdk_env() {
+ create_valid_jre_env "$1"
+ for binary in javac javah jhat; do
+ touch ${JVM_DIR}/$1/bin/${binary}
+ chmod +x ${JVM_DIR}/$1/bin/${binary}
+ done
+ create_valid_jre_env "$1/jre"
+}
+
+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() {
+ 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}"
+ expected=$(echo -e "Available Java environments:\n ${JAVA_NAME_1}/jre (default)\n ${JAVA_NAME_2}")
+ 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)"
+ create_valid_jre_env "${JAVA_NAME_1}/jre"
+ create_valid_jdk_env "${JAVA_NAME_2}"
+ mess="Available Java environments:"
+ mess+="\n ${JAVA_NAME_1}/jre"
+ mess+="\n ${JAVA_NAME_2}"
+ 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_jdk_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_default() {
+ create_valid_jdk_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_jdk_env "${JAVA_NAME}"
+ assertNull 'Wrong result' "$(do_get)"
+}
+
+test_do_get_without_default() {
+ set_default_for_test "/dev/null"
+ assertNull 'Wrong result' "$(do_get)"
+}
+
+# do_set
+
+test_do_set_new_invalid() {
+ create_valid_jdk_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_jdk_env "${JAVA_NAME}"
+ set_default_for_test "INVALID"
+ $(do_set "${JAVA_NAME}")
+ assertEquals 'Wrong status returned' 0 $?
+ assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_set_with_default_already_set() {
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ set_default_for_test "${JAVA_NAME}/jre"
+ JAVA_NAME_2="$(get_rand_str)"
+ create_valid_jre_env "${JAVA_NAME_2}/jre"
+ $(do_set "${JAVA_NAME_2}/jre")
+ assertEquals 'Wrong status returned' 0 $?
+ assertDefaultSetTo "${JAVA_NAME_2}/jre"
+}
+
+test_do_set_no_default() {
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ $(do_set "${JAVA_NAME}/jre")
+ assertEquals 'Wrong status returned' 0 $?
+ assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_set_exists_jdk() {
+ create_valid_jdk_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_cleanup_old_java_default() {
+ create_valid_jdk_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_devnull() {
+ create_valid_jdk_env "${JAVA_NAME}"
+ set_default_for_test "/dev/null"
+ output=$(do_set "${JAVA_NAME}/jre")
+ assertEquals 'Wrong status returned' 0 $?
+ assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+# do_unset
+
+test_do_unset_default_not_target() {
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ set_default_for_test "${JAVA_NAME}/jre"
+ do_unset
+ assertDefaultNotSet
+}
+
+test_do_unset_no_default_link() {
+ create_valid_jdk_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
+}
+
+# do_fix
+
+test_do_fix_default_valid() {
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ set_default_for_test "${JAVA_NAME}/jre"
+ do_fix
+ assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_no_default() {
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ do_fix
+ assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_default_invalid_openjdk7_jdk_installed() {
+ create_valid_jdk_env "java-7-openjdk"
+ create_valid_jdk_env "${JAVA_NAME}"
+ do_fix
+ assertDefaultSetTo "java-7-openjdk"
+}
+
+test_do_fix_default_invalid_openjdk7_jre_installed() {
+ create_valid_jdk_env "${JAVA_NAME}"
+ create_valid_jre_env "java-7-openjdk/jre"
+ do_fix
+ assertDefaultSetTo "java-7-openjdk/jre"
+}
+
+test_do_fix_default_invalid_random_java_installed() {
+ create_valid_jdk_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_jre_but_jdk_exists() {
+ create_valid_jdk_env "${JAVA_NAME}"
+ set_default_for_test "${JAVA_NAME}/jre"
+ do_fix
+ assertDefaultSetTo "${JAVA_NAME}"
+}
+
+test_do_fix_jdk_but_jre_exists() {
+ create_valid_jdk_env "java-7-openjdk"
+ create_valid_jre_env "${JAVA_NAME}/jre"
+ set_default_for_test "${JAVA_NAME}"
+ do_fix
+ assertDefaultSetTo "${JAVA_NAME}/jre"
+}
+
+test_do_fix_devnull() {
+ create_valid_jdk_env "${JAVA_NAME}"
+ set_default_for_test "/dev/null"
+ do_fix
+ assertDefaultSetTo "${JAVA_NAME}"
+}
+
+# load shunit2
+. shunit2-2.1.6/src/shunit2