summaryrefslogtreecommitdiff
blob: 0754bb2ae05863bd6cd2fab377173768ee3e19fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/java.eclass,v 1.32 2006/10/14 20:27:21 swegener Exp $
#
# Author: Karl Trygve Kalleberg <karltk@gentoo.org>

inherit eutils

DESCRIPTION="Based on the $ECLASS eclass"
JAVA_CONFIG_DEP="|| ( =dev-java/java-config-1.3* =dev-java/java-config-1.2* )"
DEPEND="${JAVA_CONFIG_DEP}
	sys-apps/findutils"
RDEPEND="${JAVA_CONFIG_DEP}"

export WANT_JAVA_CONFIG="1"

VMHANDLE=${PN}-${PV}

EXPORT_FUNCTIONS pkg_postinst pkg_prerm

java_pkg_postinst() {
	local jdk=${PN#*-}
	if [ ${jdk:0:3} == "jdk" ]; then
		java_set_default_vm_
	else
		# Only install the JRE as the system default if there's no JDK
		# installed. Installing a JRE over an existing JDK will result
		# in major breakage, see #9289.
		if [ ! -f "${JAVAC}" ]; then
			ewarn "Found no JDK, setting ${VMHANDLE} as default system VM"
			java_set_default_vm_
	fi
	fi
	java_mozilla_clean_
}

java_pkg_prerm() {
	if java-config -J | grep -q ${P} ; then
		ewarn "It appears you are removing your default system VM!"
		ewarn "Please run java-config -L then java-config -S to set a new system VM!"
	fi
}

java_set_default_vm_() {
	java-config --set-system-vm=${VMHANDLE}
	/usr/sbin/env-update
	source /etc/profile

	echo
	einfo " After installing ${P} this"
	einfo " was set as the default JVM to run."
	einfo " When finished please run the following so your"
	einfo " enviroment gets updated."
	eerror "	/usr/sbin/env-update && source /etc/profile"
	einfo " Or use java-config program to set your preferred VM"
}

system_arch() {
	local sarch
	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/`
	if [ -z "$sarch" ] ; then
		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/`
	fi
	echo $sarch
}

set_java_env() {
	dodir /etc/env.d/java
	platform=`system_arch`

	sed \
		-e "s/@P@/${P}/g" \
		-e "s/@PN@/${PN}/g" \
		-e "s/@PV@/${PV}/g" \
		-e "s/@PF@/${PF}/g" \
		-e "s/@PLATFORM@/${platform}/g" \
		-e "/^ADDLDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \
		< $1 \
		> ${D}/etc/env.d/java/20`basename $1` || die
}


java_get_plugin_dir_() {
	echo /usr/$(get_libdir)/nsbrowser/plugins
}

install_mozilla_plugin() {
	if [ ! -f ${D}/$1 ] ; then
		die "Cannot find mozilla plugin at ${D}/${1}"
	fi

	local plugin_dir=$(java_get_plugin_dir_)
	dodir ${plugin_dir}
	dosym ${1} ${plugin_dir}/javaplugin.so
}

java_mozilla_clean_() {
	#Because previously some ebuilds installed symlinks outside of pkg_install
	#and are left behind, which forces you to manualy remove them to select the
	#jdk/jre you want to use for java
	local plugin_dir=$(java_get_plugin_dir_)
	for file in ${plugin_dir}/javaplugin_*; do
		rm -f ${file}
	done
	for file in ${plugin_dir}/libjavaplugin*; do
		rm -f ${file}
	done
}

# Use this to remove libjsoundalsa.so from ${D}.
# You generally would want to use this like:
# use !alsa && java_remove-libjoundalsa /opt/${P}
java_remove-libjsoundalsa() {
	[[ ${#} -ne 1 ]] && die "Expected one argument"
	local search_path="$@"
	local libs=$(find ${D}/${search_path} -name libjsoundalsa.so)
	if [[ -n ${libs} ]]; then
		rm ${libs} || die "Failed to delete ${libs}"
	fi
}

# Symlinks i386 to i?86. Updates env file to then use i?86
# for LD_LIBRARY_PATH. See bug #23579.
#
# Takes an argument, which is a directory living in ${D}
# which has a directory named i386, that should be i686, i486, etc.
# This argument defaults to /opt/${P}/jre/lib
fix-i386-dir() {
	[[ ${#} != 1 ]] && die "Expected one argument"
	local libdir=${1}
	if use x86; then
		local host=${CTARGET:-${CHOST}}
		host=${host%%-*}

		if [[ ${host} != i386 ]]; then
			local orig_dir="${libdir}/i386"
			local new_dir="${libdir}/${host}"
			dosym i386 ${new_dir} || die "Failed to dosym"


			sed -i -e "s/i386/${host}/g" \
				${D}/etc/env.d/java/20${VMHANDLE} || die "Failed to sed"
		fi
	fi
}