/[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.47 - (hide annotations) (download)
Tue Jul 22 06:38:56 2014 UTC (2 months, 4 weeks ago) by haubi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.46: +6 -5 lines
java-vm-2.eclass: Respect EPREFIX in pkg_postinst, bug#517236.

1 haubi 1.47 # Copyright 1999-2014 Gentoo Foundation
2 nichoj 1.1 # Distributed under the terms of the GNU General Public License v2
3 haubi 1.47 # $Header: /var/cvsroot/gentoo-x86/eclass/java-vm-2.eclass,v 1.46 2012/07/23 19:06:20 sera Exp $
4 nichoj 1.9
5 sera 1.44 # @ECLASS: java-vm-2.eclass
6     # @MAINTAINER:
7     # java@gentoo.org
8     # @BLURB: Java Virtual Machine eclass
9     # @DESCRIPTION:
10 nichoj 1.9 # This eclass provides functionality which assists with installing
11     # virtual machines, and ensures that they are recognized by java-config.
12 nichoj 1.1
13 sera 1.39 inherit eutils fdo-mime multilib pax-utils prefix
14 nichoj 1.1
15 sera 1.44 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_prerm pkg_postrm
16    
17 sera 1.43 RDEPEND="
18     =dev-java/java-config-2*
19     || ( app-admin/eselect-java <dev-java/java-config-2.2 )"
20     DEPEND="${RDEPEND}"
21 ssuominen 1.32 has "${EAPI}" 0 1 && DEPEND="${DEPEND} >=sys-apps/portage-2.1"
22 betelgeuse 1.26
23 nichoj 1.1 export WANT_JAVA_CONFIG=2
24    
25 sera 1.44
26     # @ECLASS-VARIABLE: JAVA_VM_CONFIG_DIR
27     # @INTERNAL
28     # @DESCRIPTION:
29     # Where to place the vm env file.
30 nichoj 1.1 JAVA_VM_CONFIG_DIR="/usr/share/java-config-2/vm"
31 sera 1.44
32     # @ECLASS-VARIABLE: JAVA_VM_DIR
33     # @INTERNAL
34     # @DESCRIPTION:
35     # Base directory for vm links.
36 nichoj 1.1 JAVA_VM_DIR="/usr/lib/jvm"
37 sera 1.44
38     # @ECLASS-VARIABLE: JAVA_VM_SYSTEM
39     # @INTERNAL
40     # @DESCRIPTION:
41     # Link for system-vm
42 caster 1.35 JAVA_VM_SYSTEM="/etc/java-config-2/current-system-vm"
43 sera 1.44
44     # @ECLASS-VARIABLE: JAVA_VM_BUILD_ONLY
45     # @DESCRIPTION:
46     # Set to YES to mark a vm as build-only.
47 ali_bush 1.28 JAVA_VM_BUILD_ONLY="${JAVA_VM_BUILD_ONLY:-FALSE}"
48 nichoj 1.1
49 sera 1.44
50     # @FUNCTION: java-vm-2_pkg_setup
51     # @DESCRIPTION:
52     # default pkg_setup
53     #
54     # Initialize vm handle.
55 betelgeuse 1.17
56     java-vm-2_pkg_setup() {
57     if [[ "${SLOT}" != "0" ]]; then
58     VMHANDLE=${PN}-${SLOT}
59     else
60     VMHANDLE=${PN}
61     fi
62     }
63 nichoj 1.1
64 sera 1.44
65     # @FUNCTION: java-vm-2_pkg_postinst
66     # @DESCRIPTION:
67     # default pkg_postinst
68     #
69     # Set the generation-2 system VM and Java plugin, if it isn't set or the
70     # setting is invalid. Also update mime database.
71    
72 nichoj 1.1 java-vm-2_pkg_postinst() {
73 haubi 1.47 has ${EAPI:-0} 0 1 2 && ! use prefix && EROOT=${ROOT}
74 caster 1.35 # Note that we cannot rely on java-config here, as it will silently recognize
75     # e.g. icedtea6-bin as valid system VM if icedtea6 is set but invalid (e.g. due
76     # to the migration to icedtea-6)
77 haubi 1.47 if [[ ! -L "${EROOT}${JAVA_VM_SYSTEM}" ]]; then
78 nichoj 1.1 java_set_default_vm_
79 caster 1.35 else
80 haubi 1.47 local current_vm_path=$(readlink "${EROOT}${JAVA_VM_SYSTEM}")
81 sera 1.45 local current_vm=$(basename "${ROOT}${current_vm_path}")
82 haubi 1.47 if [[ ! -L "${EROOT}${JAVA_VM_DIR}/${current_vm}" ]]; then
83 caster 1.35 java_set_default_vm_
84     fi
85 nichoj 1.1 fi
86    
87 nichoj 1.15 java-vm_check-nsplugin
88     java_mozilla_clean_
89 betelgeuse 1.16 fdo-mime_desktop_database_update
90 nichoj 1.15 }
91    
92 sera 1.44
93     # @FUNCTION: java-vm_check-nsplugin
94     # @INTERNAL
95     # @DESCRIPTION:
96     # Check if the nsplugin needs updating
97    
98 nichoj 1.15 java-vm_check-nsplugin() {
99     local libdir
100     if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
101     libdir=lib32
102     else
103     libdir=lib
104     fi
105 caster 1.33
106     has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
107    
108 nichoj 1.9 # Install a default nsplugin if we don't already have one
109 sera 1.40 if in_iuse nsplugin && use nsplugin; then
110 sera 1.45 if [[ ! -f "${ROOT}${EPREFIX}"/usr/${libdir}/nsbrowser/plugins/javaplugin.so ]]; then
111 nichoj 1.15 einfo "No system nsplugin currently set."
112     java-vm_set-nsplugin
113 caster 1.12 else
114     einfo "System nsplugin is already set, not changing it."
115 nichoj 1.3 fi
116 caster 1.12 einfo "You can change nsplugin with eselect java-nsplugin."
117 nichoj 1.3 fi
118 nichoj 1.15 }
119 nichoj 1.3
120 sera 1.44
121     # @FUNCTION: java-vm_set-nsplugin
122     # @INTERNAL
123     # @DESCRIPTION:
124     # Set the nsplugin implemetation.
125    
126 nichoj 1.15 java-vm_set-nsplugin() {
127     local extra_args
128     if use amd64; then
129     if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
130     extra_args="32bit"
131     else
132     extra_args="64bit"
133     fi
134     einfo "Setting ${extra_args} nsplugin to ${VMHANDLE}"
135     else
136     einfo "Setting nsplugin to ${VMHANDLE}..."
137     fi
138     eselect java-nsplugin set ${extra_args} ${VMHANDLE}
139 nichoj 1.1 }
140    
141 sera 1.44
142     # @FUNCTION: java-vm-2_pkg_prerm
143     # @DESCRIPTION:
144     # default pkg_prerm
145     #
146     # Warn user if removing system-vm.
147    
148 nichoj 1.1 java-vm-2_pkg_prerm() {
149 caster 1.35 # Although REPLACED_BY_VERSION is EAPI=4, we shouldn't need to check EAPI for this use case
150 caster 1.36 if [[ "$(GENTOO_VM="" java-config -f 2>/dev/null)" == "${VMHANDLE}" && -z "${REPLACED_BY_VERSION}" ]]; then
151 betelgeuse 1.22 ewarn "It appears you are removing your system-vm!"
152     ewarn "Please run java-config -L to list available VMs,"
153     ewarn "then use java-config -S to set a new system-vm!"
154     fi
155 nichoj 1.1 }
156    
157 sera 1.44
158     # @FUNCTION: java-vm-2_pkg_postrm
159     # @DESCRIPTION:
160     # default pkg_postrm
161     #
162     # Update mime database.
163    
164 betelgeuse 1.16 java-vm-2_pkg_postrm() {
165     fdo-mime_desktop_database_update
166     }
167    
168 sera 1.44
169     # @FUNCTION: java_set_default_vm_
170     # @INTERNAL
171     # @DESCRIPTION:
172     # Set system-vm.
173    
174 nichoj 1.1 java_set_default_vm_() {
175     java-config-2 --set-system-vm="${VMHANDLE}"
176    
177 nichoj 1.9 einfo " ${P} set as the default system-vm."
178 nichoj 1.1 }
179    
180 sera 1.44
181     # @FUNCTION: get_system_arch
182     # @DESCRIPTION:
183     # Get Java specific arch name.
184    
185 nichoj 1.1 get_system_arch() {
186     local sarch
187     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/)
188     if [ -z "${sarch}" ]; then
189     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/)
190     fi
191     echo ${sarch}
192     }
193    
194 sera 1.44
195     # @FUNCTION: set_java_env
196     # @DESCRIPTION:
197     # Installs a vm env file.
198    
199 nichoj 1.1 # TODO rename to something more evident, like install_env_file
200     set_java_env() {
201 betelgeuse 1.20 debug-print-function ${FUNCNAME} $*
202 caster 1.33
203 grobian 1.34 if has ${EAPI:-0} 0 1 2 && ! use prefix ; then
204     ED="${D}"
205     EPREFIX=""
206     fi
207 caster 1.33
208 nichoj 1.1 local platform="$(get_system_arch)"
209 caster 1.33 local env_file="${ED}${JAVA_VM_CONFIG_DIR}/${VMHANDLE}"
210     local old_env_file="${ED}/etc/env.d/java/20${P}"
211 betelgeuse 1.20 if [[ ${1} ]]; then
212     local source_env_file="${1}"
213     else
214     local source_env_file="${FILESDIR}/${VMHANDLE}.env"
215     fi
216 nichoj 1.1
217     if [[ ! -f ${source_env_file} ]]; then
218     die "Unable to find the env file: ${source_env_file}"
219     fi
220    
221     dodir ${JAVA_VM_CONFIG_DIR}
222     sed \
223     -e "s/@P@/${P}/g" \
224     -e "s/@PN@/${PN}/g" \
225     -e "s/@PV@/${PV}/g" \
226     -e "s/@PF@/${PF}/g" \
227 sera 1.40 -e "s/@SLOT@/${SLOT}/g" \
228 nichoj 1.1 -e "s/@PLATFORM@/${platform}/g" \
229 caster 1.30 -e "s/@LIBDIR@/$(get_libdir)/g" \
230 nichoj 1.1 -e "/^LDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \
231 betelgeuse 1.31 < "${source_env_file}" \
232     > "${env_file}" || die "sed failed"
233 nichoj 1.1
234 ali_bush 1.28 (
235     echo "VMHANDLE=\"${VMHANDLE}\""
236 maekke 1.29 echo "BUILD_ONLY=\"${JAVA_VM_BUILD_ONLY}\""
237 betelgeuse 1.31 ) >> "${env_file}"
238 swegener 1.13
239 caster 1.33 eprefixify ${env_file}
240    
241 nichoj 1.1 [[ -n ${JAVA_PROVIDE} ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" >> ${env_file}
242    
243 betelgeuse 1.31 local java_home=$(source "${env_file}"; echo ${JAVA_HOME})
244 nichoj 1.1 [[ -z ${java_home} ]] && die "No JAVA_HOME defined in ${env_file}"
245    
246     # Make the symlink
247 caster 1.33 dodir "${JAVA_VM_DIR}"
248 grobian 1.34 dosym ${java_home#${EPREFIX}} ${JAVA_VM_DIR}/${VMHANDLE} \
249 nichoj 1.10 || die "Failed to make VM symlink at ${JAVA_VM_DIR}/${VMHANDLE}"
250 nichoj 1.1 }
251    
252 sera 1.44
253     # @FUNCTION: java-vm_set-pax-markings
254     # @DESCRIPTION:
255 sera 1.39 # Set PaX markings on all JDK/JRE executables to allow code-generation on
256     # the heap by the JIT compiler.
257     #
258     # The markings need to be set prior to the first invocation of the the freshly
259     # built / installed VM. Be it before creating the Class Data Sharing archive or
260     # generating cacerts. Otherwise a PaX enabled kernel will kill the VM.
261     # Bug #215225 #389751
262     #
263 sera 1.44 # @CODE
264     # Parameters:
265     # $1 - JDK/JRE base directory.
266 sera 1.39 #
267 sera 1.44 # Examples:
268     # java-vm_set-pax-markings "${S}"
269     # java-vm_set-pax-markings "${ED}"/opt/${P}
270     # @CODE
271    
272 sera 1.39 java-vm_set-pax-markings() {
273     debug-print-function ${FUNCNAME} "$*"
274     [[ $# -ne 1 ]] && die "${FUNCNAME}: takes exactly one argument"
275     [[ ! -f "${1}"/bin/java ]] \
276     && die "${FUNCNAME}: argument needs to be JDK/JRE base directory"
277    
278     local executables=( "${1}"/bin/* )
279     [[ -d "${1}"/jre ]] && executables+=( "${1}"/jre/bin/* )
280    
281 sera 1.46 # Ensure a PaX header is created.
282     local pax_markings="C"
283     # Usally disabeling MPROTECT is sufficent.
284     local pax_markings+="m"
285 sera 1.39 # On x86 for heap sizes over 700MB disable SEGMEXEC and PAGEEXEC as well.
286 sera 1.46 use x86 && pax_markings+="sp"
287 sera 1.39
288     pax-mark ${pax_markings} $(list-paxables "${executables[@]}")
289     }
290    
291 sera 1.44
292     # @FUNCTION: java-vm_revdep-mask
293     # @DESCRIPTION:
294 caster 1.19 # Installs a revdep-rebuild control file which SEARCH_DIR_MASK set to the path
295     # where the VM is installed. Prevents pointless rebuilds - see bug #177925.
296     # Also gives a notice to the user.
297     #
298 sera 1.44 # @CODE
299     # Parameters:
300     # $1 - Path of the VM (defaults to /opt/${P} if not set)
301     #
302     # Examples:
303     # java-vm_revdep-mask
304     # java-vm_revdep-mask /path/to/jdk/
305 caster 1.19 #
306 sera 1.44 # @CODE
307    
308 caster 1.19 java-vm_revdep-mask() {
309 caster 1.33 if has ${EAPI:-0} 0 1 2 && ! use prefix; then
310     ED="${D}"
311     EPREFIX=
312     fi
313    
314     local VMROOT="${1-"${EPREFIX}"/opt/${P}}"
315 caster 1.19
316     dodir /etc/revdep-rebuild/
317 caster 1.33 echo "SEARCH_DIRS_MASK=\"${VMROOT}\""> "${ED}/etc/revdep-rebuild/61-${VMHANDLE}"
318 caster 1.19 }
319 nichoj 1.1
320 sera 1.44
321     # @FUNCTION: java-vm_sandbox-predict
322     # @DESCRIPTION:
323 sera 1.37 # Install a sandbox control file. Specified paths won't cause a sandbox
324     # violation if opened read write but no write takes place. See bug 388937#c1
325     #
326 sera 1.44 # @CODE
327     # Examples:
328     # java-vm_sandbox-predict /dev/random /proc/self/coredump_filter
329     # @CODE
330    
331 sera 1.37 java-vm_sandbox-predict() {
332     debug-print-function ${FUNCNAME} "$*"
333     [[ -z "${1}" ]] && die "${FUNCNAME} takes at least one argument"
334    
335     has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
336    
337     local path path_arr=("$@")
338 ferringb 1.41 # subshell this to prevent IFS bleeding out dependant on bash version.
339     # could use local, which *should* work, but that requires a lot of testing.
340 floppym 1.42 path=$(IFS=":"; echo "${path_arr[*]}")
341 sera 1.37 dodir /etc/sandbox.d
342     echo "SANDBOX_PREDICT=\"${path}\"" > "${ED}/etc/sandbox.d/20${VMHANDLE}" \
343     || die "Failed to write sandbox control file"
344     }
345    
346 sera 1.44
347     # @FUNCTION: java_get_plugin_dir_
348     # @INTERNAL
349     # @DESCRIPTION:
350     # Get the java plugin dir.
351    
352 nichoj 1.1 java_get_plugin_dir_() {
353 caster 1.33 has ${EAPI:-0} 0 1 2 && ! use prefix && EPREFIX=
354     echo "${EPREFIX}"/usr/$(get_libdir)/nsbrowser/plugins
355 nichoj 1.1 }
356    
357 sera 1.44
358     # @FUNCTION: install_mozilla_plugin
359     # @DESCRIPTION:
360     # Register a netscape java-plugin.
361    
362 nichoj 1.1 install_mozilla_plugin() {
363 caster 1.23 local plugin="${1}"
364     local variant="${2}"
365 nichoj 1.1
366 caster 1.33 has ${EAPI:-0} 0 1 2 && ! use prefix && ED="${D}"
367     if [[ ! -f "${ED}/${plugin}" ]]; then
368     die "Cannot find mozilla plugin at ${ED}/${plugin}"
369 nichoj 1.1 fi
370    
371 caster 1.23 if [[ -n "${variant}" ]]; then
372     variant="-${variant}"
373     fi
374    
375     local plugin_dir="/usr/share/java-config-2/nsplugin"
376     dodir "${plugin_dir}"
377     dosym "${plugin}" "${plugin_dir}/${VMHANDLE}${variant}-javaplugin.so"
378 nichoj 1.1 }
379    
380 sera 1.44
381     # @FUNCTION: java_mozilla_clean_
382     # @INTERNAL
383     # @DESCRIPTION:
384     # Because previously some ebuilds installed symlinks outside of pkg_install
385     # and are left behind, which forces you to manualy remove them to select the
386     # jdk/jre you want to use for java
387    
388 nichoj 1.1 java_mozilla_clean_() {
389     local plugin_dir=$(java_get_plugin_dir_)
390     for file in ${plugin_dir}/javaplugin_*; do
391     rm -f ${file}
392     done
393     for file in ${plugin_dir}/libjavaplugin*; do
394     rm -f ${file}
395     done
396     }

  ViewVC Help
Powered by ViewVC 1.1.20