/[gentoo-x86]/eclass/java-vm-2.eclass
Gentoo

Contents of /eclass/java-vm-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (show annotations) (download)
Thu Sep 1 14:15:57 2011 UTC (2 years, 10 months ago) by caster
Branch: MAIN
Changes since 1.32: +26 -10 lines
Prefix support, thanks to sera and darkside.

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.32 2011/07/08 11:35:01 ssuominen Exp $
4
5 # -----------------------------------------------------------------------------
6 # @eclass-begin
7 # @eclass-shortdesc Java Virtual Machine eclass
8 # @eclass-maintainer java@gentoo.org
9 #
10 # This eclass provides functionality which assists with installing
11 # virtual machines, and ensures that they are recognized by java-config.
12 #
13 # -----------------------------------------------------------------------------
14
15 inherit eutils fdo-mime multilib prefix
16
17 DEPEND="=dev-java/java-config-2*"
18 has "${EAPI}" 0 1 && DEPEND="${DEPEND} >=sys-apps/portage-2.1"
19
20 RDEPEND="
21 =dev-java/java-config-2*"
22
23 export WANT_JAVA_CONFIG=2
24
25 JAVA_VM_CONFIG_DIR="/usr/share/java-config-2/vm"
26 JAVA_VM_DIR="/usr/lib/jvm"
27 JAVA_VM_BUILD_ONLY="${JAVA_VM_BUILD_ONLY:-FALSE}"
28
29 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_prerm pkg_postrm
30
31 java-vm-2_pkg_setup() {
32 if [[ "${SLOT}" != "0" ]]; then
33 VMHANDLE=${PN}-${SLOT}
34 else
35 VMHANDLE=${PN}
36 fi
37 }
38
39 java-vm-2_pkg_postinst() {
40 # Set the generation-2 system VM, if it isn't set
41 if [[ -z "$(java-config-2 -f)" ]]; then
42 java_set_default_vm_
43 fi
44
45 java-vm_check-nsplugin
46 java_mozilla_clean_
47 fdo-mime_desktop_database_update
48 }
49
50 java-vm_check-nsplugin() {
51 local libdir
52 if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
53 libdir=lib32
54 else
55 libdir=lib
56 fi
57
58 has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
59
60 # Install a default nsplugin if we don't already have one
61 if has nsplugin ${IUSE} && use nsplugin; then
62 if [[ ! -f "${EPREFIX}"/usr/${libdir}/nsbrowser/plugins/javaplugin.so ]]; then
63 einfo "No system nsplugin currently set."
64 java-vm_set-nsplugin
65 else
66 einfo "System nsplugin is already set, not changing it."
67 fi
68 einfo "You can change nsplugin with eselect java-nsplugin."
69 fi
70 }
71
72 java-vm_set-nsplugin() {
73 local extra_args
74 if use amd64; then
75 if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
76 extra_args="32bit"
77 else
78 extra_args="64bit"
79 fi
80 einfo "Setting ${extra_args} nsplugin to ${VMHANDLE}"
81 else
82 einfo "Setting nsplugin to ${VMHANDLE}..."
83 fi
84 eselect java-nsplugin set ${extra_args} ${VMHANDLE}
85 }
86
87 java-vm-2_pkg_prerm() {
88 if [[ "$(java-config -f 2>/dev/null)" == "${VMHANDLE}" ]]; then
89 ewarn "It appears you are removing your system-vm!"
90 ewarn "Please run java-config -L to list available VMs,"
91 ewarn "then use java-config -S to set a new system-vm!"
92 fi
93 }
94
95 java-vm-2_pkg_postrm() {
96 fdo-mime_desktop_database_update
97 }
98
99 java_set_default_vm_() {
100 java-config-2 --set-system-vm="${VMHANDLE}"
101
102 einfo " ${P} set as the default system-vm."
103 }
104
105 get_system_arch() {
106 local sarch
107 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/)
108 if [ -z "${sarch}" ]; then
109 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/)
110 fi
111 echo ${sarch}
112 }
113
114 # TODO rename to something more evident, like install_env_file
115 set_java_env() {
116 debug-print-function ${FUNCNAME} $*
117
118 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
119
120 local platform="$(get_system_arch)"
121 local env_file="${ED}${JAVA_VM_CONFIG_DIR}/${VMHANDLE}"
122 local old_env_file="${ED}/etc/env.d/java/20${P}"
123 if [[ ${1} ]]; then
124 local source_env_file="${1}"
125 else
126 local source_env_file="${FILESDIR}/${VMHANDLE}.env"
127 fi
128
129 if [[ ! -f ${source_env_file} ]]; then
130 die "Unable to find the env file: ${source_env_file}"
131 fi
132
133 dodir ${JAVA_VM_CONFIG_DIR}
134 sed \
135 -e "s/@P@/${P}/g" \
136 -e "s/@PN@/${PN}/g" \
137 -e "s/@PV@/${PV}/g" \
138 -e "s/@PF@/${PF}/g" \
139 -e "s/@PLATFORM@/${platform}/g" \
140 -e "s/@LIBDIR@/$(get_libdir)/g" \
141 -e "/^LDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \
142 < "${source_env_file}" \
143 > "${env_file}" || die "sed failed"
144
145 (
146 echo "VMHANDLE=\"${VMHANDLE}\""
147 echo "BUILD_ONLY=\"${JAVA_VM_BUILD_ONLY}\""
148 ) >> "${env_file}"
149
150 eprefixify ${env_file}
151
152 [[ -n ${JAVA_PROVIDE} ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" >> ${env_file}
153
154 local java_home=$(source "${env_file}"; echo ${JAVA_HOME})
155 [[ -z ${java_home} ]] && die "No JAVA_HOME defined in ${env_file}"
156
157 # Make the symlink
158 dodir "${JAVA_VM_DIR}"
159 dosym ${java_home} ${JAVA_VM_DIR}/${VMHANDLE} \
160 || die "Failed to make VM symlink at ${JAVA_VM_DIR}/${VMHANDLE}"
161 }
162
163 # -----------------------------------------------------------------------------
164 # @ebuild-function java-vm_revdep-mask
165 #
166 # Installs a revdep-rebuild control file which SEARCH_DIR_MASK set to the path
167 # where the VM is installed. Prevents pointless rebuilds - see bug #177925.
168 # Also gives a notice to the user.
169 #
170 # @example
171 # java-vm_revdep-mask
172 # java-vm_revdep-mask /path/to/jdk/
173 #
174 # @param $1 - Path of the VM (defaults to /opt/${P} if not set)
175 # ------------------------------------------------------------------------------
176 java-vm_revdep-mask() {
177 if has ${EAPI:-0} 0 1 2 && ! use prefix; then
178 ED="${D}"
179 EPREFIX=
180 fi
181
182 local VMROOT="${1-"${EPREFIX}"/opt/${P}}"
183
184 dodir /etc/revdep-rebuild/
185 echo "SEARCH_DIRS_MASK=\"${VMROOT}\""> "${ED}/etc/revdep-rebuild/61-${VMHANDLE}"
186
187 elog "A revdep-rebuild control file was installed to prevent reinstalls due to"
188 elog "missing dependencies (see bug #177925 for more info). Note that some parts"
189 elog "of the JVM may require dependencies that are pulled only through respective"
190 elog "USE flags (typically X, alsa, odbc) and some Java code may fail without them."
191 }
192
193 java_get_plugin_dir_() {
194 has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
195 echo "${EPREFIX}"/usr/$(get_libdir)/nsbrowser/plugins
196 }
197
198 install_mozilla_plugin() {
199 local plugin="${1}"
200 local variant="${2}"
201
202 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
203 if [[ ! -f "${ED}/${plugin}" ]]; then
204 die "Cannot find mozilla plugin at ${ED}/${plugin}"
205 fi
206
207 if [[ -n "${variant}" ]]; then
208 variant="-${variant}"
209 fi
210
211 local plugin_dir="/usr/share/java-config-2/nsplugin"
212 dodir "${plugin_dir}"
213 dosym "${plugin}" "${plugin_dir}/${VMHANDLE}${variant}-javaplugin.so"
214 }
215
216 java_mozilla_clean_() {
217 # Because previously some ebuilds installed symlinks outside of pkg_install
218 # and are left behind, which forces you to manualy remove them to select the
219 # jdk/jre you want to use for java
220 local plugin_dir=$(java_get_plugin_dir_)
221 for file in ${plugin_dir}/javaplugin_*; do
222 rm -f ${file}
223 done
224 for file in ${plugin_dir}/libjavaplugin*; do
225 rm -f ${file}
226 done
227 }
228
229 # ------------------------------------------------------------------------------
230 # @eclass-end
231 # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20