| 1 |
# Copyright 1999-2004 Gentoo Foundation |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
# $Header: /var/cvsroot/gentoo-x86/eclass/java-vm-2.eclass,v 1.2 2006/06/25 16:28:09 nichoj Exp $ |
| 4 |
# |
| 5 |
# Author: Karl Trygve Kalleberg <karltk@gentoo.org> |
| 6 |
|
| 7 |
inherit eutils |
| 8 |
|
| 9 |
DEPEND=" |
| 10 |
=dev-java/java-config-2.0* |
| 11 |
=dev-java/java-config-1.3*" |
| 12 |
RDEPEND=" |
| 13 |
=dev-java/java-config-2.0* |
| 14 |
=dev-java/java-config-1.3*" |
| 15 |
|
| 16 |
export WANT_JAVA_CONFIG=2 |
| 17 |
|
| 18 |
if [[ "${SLOT}" != "0" ]]; then |
| 19 |
VMHANDLE=${PN}-${SLOT} |
| 20 |
else |
| 21 |
VMHANDLE=${PN} |
| 22 |
fi |
| 23 |
|
| 24 |
JAVA_VM_CONFIG_DIR="/usr/share/java-config-2/vm" |
| 25 |
JAVA_VM_DIR="/usr/lib/jvm" |
| 26 |
|
| 27 |
EXPORT_FUNCTIONS pkg_postinst pkg_prerm |
| 28 |
|
| 29 |
java-vm-2_pkg_postinst() { |
| 30 |
# Set the generation-2 system VM, if it isn't set |
| 31 |
if [[ -z "$(java-config-2 -f)" ]]; then |
| 32 |
java_set_default_vm_ |
| 33 |
fi |
| 34 |
|
| 35 |
if [[ ${JAVA_VM_NO_GENERATION1} != "true" ]]; then |
| 36 |
local systemvm1="$(java-config-1 -f)" |
| 37 |
# no generation-1 system-vm was yet set |
| 38 |
if [[ -z "${systemvm1}" ]]; then |
| 39 |
einfo "No valid generation-1 system-vm set, setting to ${P}" |
| 40 |
java-config-1 --set-system-vm=${P} |
| 41 |
# dirty check to see if we are upgrading current generation-1 system vm |
| 42 |
elif [[ ${systemvm1} =~ "^${VMHANDLE}" ]]; then |
| 43 |
einfo "Upgrading generation-1 system-vm... updating its env file" |
| 44 |
java-config-1 --set-system-vm=${P} |
| 45 |
fi |
| 46 |
# else... some other VM is being updated, so we don't have to worry |
| 47 |
fi |
| 48 |
|
| 49 |
if has nsplugin ${IUSE} && use nsplugin; then |
| 50 |
if [[ ! -f /usr/lib/nsbrowser/plugins/javaplugin.so ]]; then |
| 51 |
eselect java-nsplugin set ${VMHANDLE} |
| 52 |
fi |
| 53 |
fi |
| 54 |
|
| 55 |
java_mozilla_clean_ |
| 56 |
} |
| 57 |
|
| 58 |
java-vm-2_pkg_prerm() { |
| 59 |
if [[ "$(java-config -f)" == "${VMHANDLE}" ]]; then |
| 60 |
ewarn "It appears you are removing your default system VM!" |
| 61 |
ewarn "Please run java-config -L then java-config -S to set a new system VM!" |
| 62 |
fi |
| 63 |
} |
| 64 |
|
| 65 |
java_set_default_vm_() { |
| 66 |
java-config-2 --set-system-vm="${VMHANDLE}" |
| 67 |
|
| 68 |
einfo " After installing ${P} this" |
| 69 |
einfo " was set as the default JVM to run." |
| 70 |
} |
| 71 |
|
| 72 |
get_system_arch() { |
| 73 |
local sarch |
| 74 |
sarch=$(echo ${ARCH} | sed -e s/[i]*.86/i386/ -e s/x86_64/amd64/ -e s/sun4u/sparc/ -e s/sparc64/sparc/ -e s/arm.*/arm/ -e s/sa110/arm/) |
| 75 |
if [ -z "${sarch}" ]; then |
| 76 |
sarch=$(uname -m | sed -e s/[i]*.86/i386/ -e s/x86_64/amd64/ -e s/sun4u/sparc/ -e s/sparc64/sparc/ -e s/arm.*/arm/ -e s/sa110/arm/) |
| 77 |
fi |
| 78 |
echo ${sarch} |
| 79 |
} |
| 80 |
|
| 81 |
# TODO rename to something more evident, like install_env_file |
| 82 |
set_java_env() { |
| 83 |
local platform="$(get_system_arch)" |
| 84 |
local env_file="${D}${JAVA_VM_CONFIG_DIR}/${VMHANDLE}" |
| 85 |
local old_env_file="${D}/etc/env.d/java/20${P}" |
| 86 |
local source_env_file="${FILESDIR}/${VMHANDLE}.env" |
| 87 |
|
| 88 |
if [[ ! -f ${source_env_file} ]]; then |
| 89 |
die "Unable to find the env file: ${source_env_file}" |
| 90 |
fi |
| 91 |
|
| 92 |
dodir ${JAVA_VM_CONFIG_DIR} |
| 93 |
dodir /etc/env.d/java # generation-1 compatibility |
| 94 |
sed \ |
| 95 |
-e "s/@P@/${P}/g" \ |
| 96 |
-e "s/@PN@/${PN}/g" \ |
| 97 |
-e "s/@PV@/${PV}/g" \ |
| 98 |
-e "s/@PF@/${PF}/g" \ |
| 99 |
-e "s/@PLATFORM@/${platform}/g" \ |
| 100 |
-e "/^LDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \ |
| 101 |
< ${source_env_file} \ |
| 102 |
> ${env_file} || die "sed failed" |
| 103 |
|
| 104 |
echo "VMHANDLE=\"${VMHANDLE}\"" >> ${env_file} |
| 105 |
|
| 106 |
# generation-1 compatibility |
| 107 |
if [[ ${JAVA_VM_NO_GENERATION1} != true ]]; then |
| 108 |
# We need to strip some things out of the new style env, |
| 109 |
# because these end up going in the env |
| 110 |
sed -e 's/.*CLASSPATH.*//' \ |
| 111 |
-e 's/.*PROVIDES.*//' \ |
| 112 |
${env_file} \ |
| 113 |
> ${old_env_file} || die "failed to create old-style env file" |
| 114 |
fi |
| 115 |
|
| 116 |
[[ -n ${JAVA_PROVIDE} ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" >> ${env_file} |
| 117 |
|
| 118 |
local java_home=$(source ${env_file}; echo ${JAVA_HOME}) |
| 119 |
[[ -z ${java_home} ]] && die "No JAVA_HOME defined in ${env_file}" |
| 120 |
|
| 121 |
# Make the symlink |
| 122 |
dosym ${java_home} ${JAVA_VM_DIR}/${VMHANDLE} \ |
| 123 |
|| die "Failed to make VM symlink at ${JAVA_VM_DIR}/${VMHANDE}" |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
java_get_plugin_dir_() { |
| 128 |
echo /usr/$(get_libdir)/nsbrowser/plugins |
| 129 |
} |
| 130 |
|
| 131 |
install_mozilla_plugin() { |
| 132 |
local plugin=${1} |
| 133 |
|
| 134 |
if [ ! -f "${D}/${plugin}" ] ; then |
| 135 |
die "Cannot find mozilla plugin at ${D}/${plugin}" |
| 136 |
fi |
| 137 |
|
| 138 |
local plugin_dir=/usr/share/java-config-2/nsplugin |
| 139 |
dodir ${plugin_dir} |
| 140 |
dosym ${plugin} ${plugin_dir}/${VMHANDLE}-javaplugin.so |
| 141 |
} |
| 142 |
|
| 143 |
java_mozilla_clean_() { |
| 144 |
# Because previously some ebuilds installed symlinks outside of pkg_install |
| 145 |
# and are left behind, which forces you to manualy remove them to select the |
| 146 |
# jdk/jre you want to use for java |
| 147 |
local plugin_dir=$(java_get_plugin_dir_) |
| 148 |
for file in ${plugin_dir}/javaplugin_*; do |
| 149 |
rm -f ${file} |
| 150 |
done |
| 151 |
for file in ${plugin_dir}/libjavaplugin*; do |
| 152 |
rm -f ${file} |
| 153 |
done |
| 154 |
} |