/[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.31 - (show annotations) (download)
Sat Apr 17 08:30:36 2010 UTC (4 years, 3 months ago) by betelgeuse
Branch: MAIN
Changes since 1.30: +5 -5 lines
Add quotes around variables that could contain spaces in paths. Fixes bug #315961. Thanks to Michał Górny <gentoo@mgorny.alt.pl>.

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.30 2010/03/27 22:23:57 caster 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
16
17 DEPEND="=dev-java/java-config-2*"
18 hasq "${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 # Install a default nsplugin if we don't already have one
58 if has nsplugin ${IUSE} && use nsplugin; then
59 if [[ ! -f /usr/${libdir}/nsbrowser/plugins/javaplugin.so ]]; then
60 einfo "No system nsplugin currently set."
61 java-vm_set-nsplugin
62 else
63 einfo "System nsplugin is already set, not changing it."
64 fi
65 einfo "You can change nsplugin with eselect java-nsplugin."
66 fi
67 }
68
69 java-vm_set-nsplugin() {
70 local extra_args
71 if use amd64; then
72 if [[ ${VMHANDLE} =~ emul-linux-x86 ]]; then
73 extra_args="32bit"
74 else
75 extra_args="64bit"
76 fi
77 einfo "Setting ${extra_args} nsplugin to ${VMHANDLE}"
78 else
79 einfo "Setting nsplugin to ${VMHANDLE}..."
80 fi
81 eselect java-nsplugin set ${extra_args} ${VMHANDLE}
82 }
83
84 java-vm-2_pkg_prerm() {
85 if [[ "$(java-config -f 2>/dev/null)" == "${VMHANDLE}" ]]; then
86 ewarn "It appears you are removing your system-vm!"
87 ewarn "Please run java-config -L to list available VMs,"
88 ewarn "then use java-config -S to set a new system-vm!"
89 fi
90 }
91
92 java-vm-2_pkg_postrm() {
93 fdo-mime_desktop_database_update
94 }
95
96 java_set_default_vm_() {
97 java-config-2 --set-system-vm="${VMHANDLE}"
98
99 einfo " ${P} set as the default system-vm."
100 }
101
102 get_system_arch() {
103 local sarch
104 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/)
105 if [ -z "${sarch}" ]; then
106 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/)
107 fi
108 echo ${sarch}
109 }
110
111 # TODO rename to something more evident, like install_env_file
112 set_java_env() {
113 debug-print-function ${FUNCNAME} $*
114 local platform="$(get_system_arch)"
115 local env_file="${D}${JAVA_VM_CONFIG_DIR}/${VMHANDLE}"
116 local old_env_file="${D}/etc/env.d/java/20${P}"
117 if [[ ${1} ]]; then
118 local source_env_file="${1}"
119 else
120 local source_env_file="${FILESDIR}/${VMHANDLE}.env"
121 fi
122
123 if [[ ! -f ${source_env_file} ]]; then
124 die "Unable to find the env file: ${source_env_file}"
125 fi
126
127 dodir ${JAVA_VM_CONFIG_DIR}
128 sed \
129 -e "s/@P@/${P}/g" \
130 -e "s/@PN@/${PN}/g" \
131 -e "s/@PV@/${PV}/g" \
132 -e "s/@PF@/${PF}/g" \
133 -e "s/@PLATFORM@/${platform}/g" \
134 -e "s/@LIBDIR@/$(get_libdir)/g" \
135 -e "/^LDPATH=.*lib\\/\\\"/s|\"\\(.*\\)\"|\"\\1${platform}/:\\1${platform}/server/\"|" \
136 < "${source_env_file}" \
137 > "${env_file}" || die "sed failed"
138
139 (
140 echo "VMHANDLE=\"${VMHANDLE}\""
141 echo "BUILD_ONLY=\"${JAVA_VM_BUILD_ONLY}\""
142 ) >> "${env_file}"
143
144 [[ -n ${JAVA_PROVIDE} ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" >> ${env_file}
145
146 local java_home=$(source "${env_file}"; echo ${JAVA_HOME})
147 [[ -z ${java_home} ]] && die "No JAVA_HOME defined in ${env_file}"
148
149 # Make the symlink
150 dosym ${java_home} ${JAVA_VM_DIR}/${VMHANDLE} \
151 || die "Failed to make VM symlink at ${JAVA_VM_DIR}/${VMHANDLE}"
152 }
153
154 # -----------------------------------------------------------------------------
155 # @ebuild-function java-vm_revdep-mask
156 #
157 # Installs a revdep-rebuild control file which SEARCH_DIR_MASK set to the path
158 # where the VM is installed. Prevents pointless rebuilds - see bug #177925.
159 # Also gives a notice to the user.
160 #
161 # @example
162 # java-vm_revdep-mask
163 # java-vm_revdep-mask /path/to/jdk/
164 #
165 # @param $1 - Path of the VM (defaults to /opt/${P} if not set)
166 # ------------------------------------------------------------------------------
167 java-vm_revdep-mask() {
168 local VMROOT="${1-/opt/${P}}"
169
170 dodir /etc/revdep-rebuild/
171 echo "SEARCH_DIRS_MASK=\"${VMROOT}\""> "${D}/etc/revdep-rebuild/61-${VMHANDLE}"
172
173 elog "A revdep-rebuild control file was installed to prevent reinstalls due to"
174 elog "missing dependencies (see bug #177925 for more info). Note that some parts"
175 elog "of the JVM may require dependencies that are pulled only through respective"
176 elog "USE flags (typically X, alsa, odbc) and some Java code may fail without them."
177 }
178
179 java_get_plugin_dir_() {
180 echo /usr/$(get_libdir)/nsbrowser/plugins
181 }
182
183 install_mozilla_plugin() {
184 local plugin="${1}"
185 local variant="${2}"
186
187 if [[ ! -f "${D}/${plugin}" ]]; then
188 die "Cannot find mozilla plugin at ${D}/${plugin}"
189 fi
190
191 if [[ -n "${variant}" ]]; then
192 variant="-${variant}"
193 fi
194
195 local plugin_dir="/usr/share/java-config-2/nsplugin"
196 dodir "${plugin_dir}"
197 dosym "${plugin}" "${plugin_dir}/${VMHANDLE}${variant}-javaplugin.so"
198 }
199
200 java_mozilla_clean_() {
201 # Because previously some ebuilds installed symlinks outside of pkg_install
202 # and are left behind, which forces you to manualy remove them to select the
203 # jdk/jre you want to use for java
204 local plugin_dir=$(java_get_plugin_dir_)
205 for file in ${plugin_dir}/javaplugin_*; do
206 rm -f ${file}
207 done
208 for file in ${plugin_dir}/libjavaplugin*; do
209 rm -f ${file}
210 done
211 }
212
213 # ------------------------------------------------------------------------------
214 # @eclass-end
215 # ------------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20