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

Diff of /eclass/java-utils-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.127
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.127 2009/05/19 21:23:32 caster Exp $
10 10
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27
28IUSE="elibc_FreeBSD"
27 29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
33# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
34 36
35# Make sure we use java-config-2 37# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
37 39
38# TODO document 40# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
65# -----------------------------------------------------------------------------
66hasq "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
40 67
41# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
43# 70#
44# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
45# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
46# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
47# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.6 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
49 77
50# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 80# @variable-default yes
53# 81#
100# ----------------------------------------------------------------------------- 128# -----------------------------------------------------------------------------
101 129
102# ----------------------------------------------------------------------------- 130# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 131# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 132# @default /usr/share/java-config-2/compiler
105# 133#
106# Directory where compiler settings are saved, without trailing slash. 134# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 135# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 136# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 137JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 138
120 148
121# ----------------------------------------------------------------------------- 149# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 150# @variable-external JAVA_PKG_FORCE_COMPILER
123# 151#
124# Explicitly set a list of compilers to use. This is normally read from 152# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 153# JAVA_PKG_COMPILERS_CONF.
126# 154#
127# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
131 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
132# TODO document me 174# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
134 176
135# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
136# @section-end variables 178# @section-end variables
143# 185#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 187# libraries, etc.
146# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
147 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
148 230
149# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
151# 233#
152# Installs any number of jars. 234# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 235# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 236# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 237# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 238# Instead, use java-pkg_newjar defined below.
157# 239#
158# @example 240# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 241# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 242#
171 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
173 255
174 local jar 256 local jar
175 # for each jar 257 # for each jar
176 for jar in "$@"; do 258 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
178 260
179 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
180 262
181 # check if it exists 263 # check if it exists
182 if [[ -e "${jar}" ]] ; then 264 if [[ -e "${jar}" ]] ; then
265 # Don't overwrite if jar has already been installed with the same
266 # name
267 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
268 if [[ -e "${dest}" ]]; then
269 ewarn "Overwriting ${dest}"
270 fi
271
183 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
199 done 291 done
200 292
201 java-pkg_do_write_ 293 java-pkg_do_write_
202} 294}
203 295
296# ------------------------------------------------------------------------------
297# @internal-function depend-java-query
298#
299# Wrapper for the depend-java-query binary to enable passing USE in env.
300# Using env variables keeps this eclass working with java-config versions that
301# do not handle use flags.
302# ------------------------------------------------------------------------------
204 303
304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
307 USE="${USE}" /usr/bin/depend-java-query "${@}"
308}
205 309
206# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
208# 312#
209# Records an already installed jar in the package.env 313# Records an already installed jar in the package.env
222# will not work, because: 326# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 327# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 328# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 329# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 330# doesn't exist
227# 331#
228# you have to use it as: 332# you have to use it as:
229# 333#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 334# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 335#
232# @param $@ - jars to record 336# @param $@ - jars to record
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 345
242 java-pkg_init_paths_ 346 java-pkg_init_paths_
243 347
244 local jar jar_dir jar_file 348 local jar jar_dir jar_file
245 for jar in "$@"; do 349 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
248 # nelchael: we should strip ${D} in this case too, here's why: 358 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 359 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
254 elif [[ -e "${D}${jar}" ]]; then
255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
256 else 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
370 debug-print "${jar} or ${D}${jar} not found"
257 die "${jar} does not exist" 371 die "${jar} does not exist"
258 fi 372 fi
259 done 373 done
260 374
261 java-pkg_do_write_ 375 java-pkg_do_write_
262} 376}
263
264 377
265# ------------------------------------------------------------------------------ 378# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 379# @ebuild-function java-pkg_newjar
267# 380#
268# Installs a jar with a new name 381# Installs a jar with a new name
279 local original_jar="${1}" 392 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 393 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 394 local new_jar_dest="${T}/${new_jar}"
282 395
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 396 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 397 [[ ! -f ${original_jar} ]] \
398 && die "${original_jar} does not exist or is not a file!"
285 399
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 400 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 401 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 402 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 403 java-pkg_dojar "${new_jar_dest}"
290} 404}
291 405
292
293# ------------------------------------------------------------------------------ 406# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 407# @ebuild-function java-pkg_addcp
295# 408#
296# Add something to the package's classpath. For jars, you should use dojar, 409# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 410# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 415java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 416 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 417 java-pkg_do_write_
305} 418}
306 419
307
308# ------------------------------------------------------------------------------ 420# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 421# @ebuild-function java-pkg_doso
310# 422#
311# Installs any number of JNI libraries 423# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 424# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 425# can be used change this path
314# 426#
315# Example: 427# Example:
318# @param $@ - JNI libraries to install 430# @param $@ - JNI libraries to install
319# ------------------------------------------------------------------------------ 431# ------------------------------------------------------------------------------
320java-pkg_doso() { 432java-pkg_doso() {
321 debug-print-function ${FUNCNAME} $* 433 debug-print-function ${FUNCNAME} $*
322 434
323 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
324 java-pkg_check-phase install 435 java-pkg_check-phase install
325 436
326 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 437 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
327 438
328 java-pkg_init_paths_ 439 java-pkg_init_paths_
329 440
330 local lib 441 local lib
331 # for each lib 442 # for each lib
334 if [[ -e "${lib}" ]] ; then 445 if [[ -e "${lib}" ]] ; then
335 # install if it isn't a symlink 446 # install if it isn't a symlink
336 if [[ ! -L "${lib}" ]] ; then 447 if [[ ! -L "${lib}" ]] ; then
337 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 448 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
338 INSOPTIONS="${LIBOPTIONS}" \ 449 INSOPTIONS="${LIBOPTIONS}" \
339 doins "${lib}" || "failed to install ${lib}" 450 doins "${lib}" || die "failed to install ${lib}"
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
343 else 454 else
344 # TODO use dosym
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 455 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
346 debug-print "${lib} is a symlink, linking accordanly" 456 debug-print "${lib} is a symlink, linking accordantly"
347 fi 457 fi
348 # otherwise die 458 # otherwise die
349 else 459 else
350 die "${lib} does not exist" 460 die "${lib} does not exist"
351 fi 461 fi
367java-pkg_regso() { 477java-pkg_regso() {
368 debug-print-function ${FUNCNAME} $* 478 debug-print-function ${FUNCNAME} $*
369 479
370 java-pkg_check-phase install 480 java-pkg_check-phase install
371 481
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 482 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
373 483
374 java-pkg_init_paths_ 484 java-pkg_init_paths_
375 485
376 local lib target_dir 486 local lib target_dir
377 for lib in "$@" ; do 487 for lib in "$@" ; do
378 # Check the absolute path of the lib 488 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 489 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 490 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 538# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 539java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 540 debug-print-function ${FUNCNAME} $*
431 541
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 542 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 543
544 # from /usr/lib/portage/bin/dohtml -h
545 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 546 dohtml -f package-list "$@"
547
435 # this probably shouldn't be here but it provides 548 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 549 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 550 # old ebuilds.
438 java-pkg_recordjavadoc 551 java-pkg_recordjavadoc
439} 552}
440 553
441# TODO document 554# ------------------------------------------------------------------------------
555# @ebuild-function java-pkg_dojavadoc
556#
557# Installs javadoc documentation. This should be controlled by the doc use flag.
558#
559# @param $1: optional --symlink creates to symlink like this for html
560# documentation bundles.
561# @param $2: - The javadoc root directory.
562#
563# @example:
564# java-pkg_dojavadoc docs/api
565# java-pkg_dojavadoc --symlink apidocs docs/api
566#
567# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 568java-pkg_dojavadoc() {
569 debug-print-function ${FUNCNAME} $*
570
571 # For html documentation bundles that link to Javadoc
572 local symlink
573 if [[ ${1} = --symlink ]]; then
574 symlink=${2}
575 shift 2
576 fi
577
443 local dir="$1" 578 local dir="$1"
579 local dest=/usr/share/doc/${PF}/html
580
581 # QA checks
444 582
445 java-pkg_check-phase install 583 java-pkg_check-phase install
446 584
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 585 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 586 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
587 if [[ ! -e "${dir}/index.html" ]]; then
588 local msg="No index.html in javadoc directory"
589 ewarn "${msg}"
590 is-java-strict && die "${msg}"
591 fi
592
593 if [[ -e ${D}/${dest}/api ]]; then
594 eerror "${dest} already exists. Will not overwrite."
595 die "${dest}"
596 fi
597
598 # Renaming to match our directory layout
449 599
450 local dir_to_install="${dir}" 600 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 601 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 602 dir_to_install="${T}/api"
453 # TODO use doins 603 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 604 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 605 fi
456 606
607 # Actual installation
608
457 java-pkg_dohtml -r ${dir_to_install} 609 java-pkg_dohtml -r "${dir_to_install}"
610
611 # Let's make a symlink to the directory we have everything else under
612 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
613
614 if [[ ${symlink} ]]; then
615 debug-print "symlinking ${dest}/{api,${symlink}}"
616 dosym ${dest}/{api,${symlink}} || die
617 fi
458} 618}
459 619
460# ------------------------------------------------------------------------------ 620# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 621# @ebuild-function java-pkg_dosrc
462# 622#
463# Installs a zip containing the source for a package, so it can used in 623# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 624# from IDEs like eclipse and netbeans.
465# 625#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 626# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 627#
468# It also should be controlled by USE=source. 628# It also should be controlled by USE=source.
469# 629#
470# @example: 630# @example:
471# java-pkg_dosrc src/* 631# java-pkg_dosrc src/*
472# 632#
473# ------------------------------------------------------------------------------ 633# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 634# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 635# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 636# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 637# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 638# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 639java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 640 debug-print-function ${FUNCNAME} $*
481 641
482 [ ${#} -lt 1 ] && die "At least one argument needed" 642 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi
486 643
487 java-pkg_check-phase install 644 java-pkg_check-phase install
488 645
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 646 [[ ${#} -lt 1 ]] && die "At least one argument needed"
647
648 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
649 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
650 java-pkg_announce-qa-violation ${msg}
651 fi
490 652
491 java-pkg_init_paths_ 653 java-pkg_init_paths_
492 654
493 local zip_name="${PN}-src.zip" 655 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 656 local zip_path="${T}/${zip_name}"
495 local dir 657 local dir
496 for dir in ${@}; do 658 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 659 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 660 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 661 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 662 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 663 local result=$?
518# @ebuild-function java-pkg_dolauncher 680# @ebuild-function java-pkg_dolauncher
519# 681#
520# Make a wrapper script to lauch/start this package 682# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 683# If necessary, the wrapper will switch to the appropriate VM.
522# 684#
685# Can be called without parameters if the package installs only one jar
686# that has the Main-class attribute set. The wrapper will be named ${PN}.
687#
523# @param $1 - filename of launcher to create 688# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 689# @param $2 - options, as follows:
525# --main the.main.class.too.start 690# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 691# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 692# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 693# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 694# --pwd Directory the launcher changes to before executing java
530# -into 695# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 696# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 697# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 698java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 699 debug-print-function ${FUNCNAME} $*
535 700
536 java-pkg_check-phase install 701 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 702 java-pkg_init_paths_
541 703
704 if [[ ${#} = 0 ]]; then
705 local name="${PN}"
706 else
542 local name="${1}" 707 local name="${1}"
708 shift
709 fi
710
543 # TODO rename to launcher 711 # TODO rename to launcher
544 local target="${T}/${name}" 712 local target="${T}/${name}"
713 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 714 local target_dir pre
546 shift
547 715
548 echo "#!/bin/bash" > "${target}" 716 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 717 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 718 local var="${1}" value="${2}"
551 if [[ "${var:0:2}" == "--" ]]; then 719 if [[ "${var:0:2}" == "--" ]]; then
720 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 721 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
722 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 723 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 724 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 725 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 726 pre="${value}"
557 fi 727 fi
558 shift 2 728 shift 2
559 done 729 done
730
731 # Test if no --jar and --main arguments were given and
732 # in that case check if the package only installs one jar
733 # and use that jar.
734 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
735 local cp="${JAVA_PKG_CLASSPATH}"
736 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
737 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
738 else
739 local msg="Not enough information to create a launcher given."
740 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
741 die "${msg}"
742 fi
743 fi
744
745 # Write the actual script
746 echo "#!/bin/bash" > "${target}"
747 if [[ -n "${pre}" ]]; then
748 if [[ -f "${pre}" ]]; then
749 cat "${pre}" >> "${target}"
750 else
751 die "-pre specified file '${pre}' does not exist"
752 fi
753 fi
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 754 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 755 cat "${var_tmp}" >> "${target}"
756 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 757 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 758
564 if [[ -n "${into}" ]]; then 759 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 760 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 761 local ret=$?
567 return ${ret} 762 return ${ret}
568 else 763 else
569 dobin "${target}" 764 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 792 echo "dowar: warning, skipping directory ${war}"
598 continue 793 continue
599 else 794 else
600 warpath="${war}" 795 warpath="${war}"
601 fi 796 fi
602 797
603 # Install those files like you mean it 798 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 799 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 800 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 801 doins ${warpath}
607 done 802 done
642# @ebuild-function java-pkg_jar-from 837# @ebuild-function java-pkg_jar-from
643# 838#
644# Makes a symlink to a jar from a certain package 839# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 840# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 841# You can use this function to replace these bundled dependencies.
842# The dependency is recorded into package.env DEPEND line, unless "--build-only"
843# is passed as the very first argument, for jars that have to be present only
844# at build time and are not needed on runtime (junit testing etc).
647# 845#
648# Example: get all jars from xerces slot 2 846# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 847# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 848# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 849# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 850# Example: get a specific jar from xerces slot 2, and name it diffrently
653# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 851# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
852# Example: get junit.jar which is needed only for building
853# java-pkg_jar-from --build-only junit junit.jar
654# 854#
655# @param $1 - Package to get jars from. 855# @param $opt
856# --build-only - makes the jar(s) not added into package.env DEPEND line.
857# (assumed automatically when called inside src_test)
858# --with-dependencies - get jars also from requested package's dependencies
859# transitively.
860# --virtual - Packages passed to this function are to be handled as virtuals
861# and will not have individual jar dependencies recorded.
862# --into $dir - symlink jar(s) into $dir (must exist) instead of .
863# @param $1 - Package to get jars from, or comma-separated list of packages in
864# case other parameters are not used.
656# @param $2 - jar from package. If not specified, all jars will be used. 865# @param $2 - jar from package. If not specified, all jars will be used.
657# @param $3 - When a single jar is specified, destination filename of the 866# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 867# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 868# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 869# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 870java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 871 debug-print-function ${FUNCNAME} $*
663 872
873 local build_only=""
874 local destdir="."
875 local deep=""
876 local virtual=""
877
878 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
879
880 while [[ "${1}" == --* ]]; do
881 if [[ "${1}" = "--build-only" ]]; then
882 build_only="build"
883 elif [[ "${1}" = "--with-dependencies" ]]; then
884 deep="--with-dependencies"
885 elif [[ "${1}" = "--virtual" ]]; then
886 virtual="true"
887 elif [[ "${1}" = "--into" ]]; then
888 destdir="${2}"
889 shift
890 else
891 die "java-pkg_jar-from called with unknown parameter: ${1}"
892 fi
893 shift
894 done
895
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 896 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 897
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 898 [[ -z ${target_pkg} ]] && die "Must specify a package"
899
900 if [[ "${EAPI}" == "1" ]]; then
901 target_pkg="${target_pkg//:/-}"
902 fi
667 903
668 # default destjar to the target jar 904 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 905 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 906
907 local error_msg="There was a problem getting the classpath for ${target_pkg}."
908 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 909 classpath="$(java-config ${deep} --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 910 [[ $? != 0 ]] && die ${error_msg}
911
912 # When we have commas this functions is called to bring jars from multiple
913 # packages. This affects recording of dependencencies performed later
914 # which expects one package only, so we do it here.
915 if [[ ${target_pkg} = *,* ]]; then
916 for pkg in ${target_pkg//,/ }; do
917 java-pkg_ensure-dep "${build_only}" "${pkg}"
918 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
919 done
920 # setting this disables further record-jar_ calls later
921 build_only="build"
922 else
923 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
924 fi
925
926 # Record the entire virtual as a dependency so that
927 # no jars are missed.
928 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
929 java-pkg_record-jar_ "${target_pkg}"
930 # setting this disables further record-jars_ calls later
931 build_only="build"
932 fi
933
934 pushd ${destdir} > /dev/null \
935 || die "failed to change directory to ${destdir}"
673 936
674 local jar 937 local jar
675 for jar in ${classpath//:/ }; do 938 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 939 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 940 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 944 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 945 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 946 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 947 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 948 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 949 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 950 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 951 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 952 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 953 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 954 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 955 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
956 popd > /dev/null
693 return 0 957 return 0
694 fi 958 fi
695 done 959 done
960 popd > /dev/null
696 # if no target was specified, we're ok 961 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 962 if [[ -z "${target_jar}" ]] ; then
698 return 0 963 return 0
699 # otherwise, die bitterly 964 # otherwise, die bitterly
700 else 965 else
714# ------------------------------------------------------------------------------ 979# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 980# @ebuild-function java-pkg_getjars
716# 981#
717# Get the classpath provided by any number of packages 982# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 983# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
984# The providing packages are recorded as dependencies into package.env DEPEND
985# line, unless "--build-only" is passed as the very first argument, for jars
986# that have to be present only at build time and are not needed on runtime
987# (junit testing etc).
719# 988#
720# Example: Get the classpath for xerces-2, 989# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 990# java-pkg_getjars xerces-2,xalan
722# Example Return: 991# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 992# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 993#
994# @param $opt
995# --build-only - makes the jar(s) not added into package.env DEPEND line.
996# (assumed automatically when called inside src_test)
997# --with-dependencies - get jars also from requested package's dependencies
998# transitively.
725# @param $@ - list of packages to get jars from 999# @param $1 - list of packages to get jars from
1000# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 1001# ------------------------------------------------------------------------------
727java-pkg_getjars() { 1002java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 1003 debug-print-function ${FUNCNAME} $*
729 1004
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1005 local build_only=""
1006 local deep=""
731 1007
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 1008 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
733 local classpath pkg 1009
734 for pkg in ${@//,/ }; do 1010 while [[ "${1}" == --* ]]; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 1011 if [[ "${1}" = "--build-only" ]]; then
736 jars="$(java-config --classpath=${pkg})" 1012 build_only="build"
737 debug-print "${pkg}:${jars}" 1013 elif [[ "${1}" = "--with-dependencies" ]]; then
738 # TODO should we ensure jars exist? 1014 deep="--with-dependencies"
739 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}"
741 else 1015 else
742 classpath="${classpath}:${jars}" 1016 die "java-pkg_jar-from called with unknown parameter: ${1}"
743 fi 1017 fi
744 java-pkg_record-jar_ "${pkg}" 1018 shift
745 done 1019 done
746 echo "${classpath}" 1020
1021 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1022
1023
1024 local pkgs="${1}"
1025
1026 if [[ "${EAPI}" == "1" ]]; then
1027 pkgs="${pkgs//:/-}"
1028 fi
1029
1030 jars="$(java-config ${deep} --classpath=${pkgs})"
1031 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1032 debug-print "${pkgs}:${jars}"
1033
1034 for pkg in ${pkgs//,/ }; do
1035 java-pkg_ensure-dep "${build_only}" "${pkg}"
1036 done
1037
1038 # Only record jars that aren't build-only
1039 if [[ -z "${build_only}" ]]; then
1040 for pkg in ${pkgs//,/ }; do
1041 java-pkg_record-jar_ "${pkg}"
1042 done
1043 fi
1044
1045 echo "${jars}"
747} 1046}
748 1047
749# ------------------------------------------------------------------------------ 1048# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 1049# @ebuild-function java-pkg_getjar
751# 1050#
752# Get the filename of a single jar from a package 1051# Get the filename of a single jar from a package
1052# The providing package is recorded as runtime dependency into package.env
1053# DEPEND line, unless "--build-only" is passed as the very first argument, for
1054# jars that have to be present only at build time and are not needed on runtime
1055# (junit testing etc).
753# 1056#
754# @example 1057# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 1058# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 1059# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 1060# /usr/share/xerces-2/lib/xml-apis.jar
758# 1061#
1062# @param $opt
1063# --build-only - makes the jar not added into package.env DEPEND line.
1064# --virtual - Packages passed to this function are to be handled as virtuals
1065# and will not have individual jar dependencies recorded.
759# @param $1 - package to use 1066# @param $1 - package to use
760# @param $2 - jar to get 1067# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 1068# ------------------------------------------------------------------------------
762java-pkg_getjar() { 1069java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 1070 debug-print-function ${FUNCNAME} $*
764 1071
1072 local build_only=""
1073 local virtual=""
1074
1075 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1076
1077 while [[ "${1}" == --* ]]; do
1078 if [[ "${1}" = "--build-only" ]]; then
1079 build_only="build"
1080 elif [[ "${1}" == "--virtual" ]]; then
1081 virtual="true"
1082 else
1083 die "java-pkg_getjar called with unknown parameter: ${1}"
1084 fi
1085 shift
1086 done
1087
1088 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1089
765 local pkg="${1}" target_jar="${2}" jar 1090 local pkg="${1}" target_jar="${2}" jar
1091
1092 if [[ "${EAPI}" == "1" ]]; then
1093 pkg="${pkg//:/-}"
1094 fi
1095
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1096 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1097 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 1098
769 # TODO check that package is actually installed 1099 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1100 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 1101 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1102 [[ $? != 0 ]] && die ${error_msg}
1103
1104 java-pkg_ensure-dep "${build_only}" "${pkg}"
1105
1106 # Record the package(Virtual) as a dependency and then set build_only
1107 # So that individual jars are not recorded.
1108 if [[ -n "${virtual}" ]]; then
1109 java-pkg_record-jar_ "${pkg}"
1110 build_only="true"
1111 fi
1112
772 for jar in ${classpath//:/ }; do 1113 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 1114 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 1115 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 1116 fi
776 1117
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1118 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 1119 # Only record jars that aren't build-only
1120 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 1121 echo "${jar}"
780 return 0 1122 return 0
781 fi 1123 fi
782 done 1124 done
783 1125
784 die "Could not find ${target_jar} in ${pkg}" 1126 die "Could not find ${target_jar} in ${pkg}"
785 return 1 1127 return 1
1128}
1129
1130# ------------------------------------------------------------------------------
1131# @ebuild-function java-pkg_register-dependency
1132#
1133# Registers runtime dependency on a package, list of packages, or a single jar
1134# from a package, into package.env DEPEND line. Can only be called in
1135# src_install phase.
1136# Intended for binary packages where you don't need to symlink the jars or get
1137# their classpath during build. As such, the dependencies only need to be
1138# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1139#
1140# @param $1 - comma-separated list of packages, or a single package
1141# @param $2 - if param $1 is a single package, optionally specify the jar
1142# to depend on
1143#
1144# Example: Record the dependency on whole xerces-2 and xalan,
1145# java-pkg_register-dependency xerces-2,xalan
1146# Example: Record the dependency on ant.jar from ant-core
1147# java-pkg_register-dependency ant-core ant.jar
1148#
1149# Note: Passing both list of packages as the first parameter AND specifying the
1150# jar as the second is not allowed and will cause the function to die. We assume
1151# that there's more chance one passes such combination as a mistake, than that
1152# there are more packages providing identically named jar without class
1153# collisions.
1154# ------------------------------------------------------------------------------
1155java-pkg_register-dependency() {
1156 debug-print-function ${FUNCNAME} $*
1157
1158 java-pkg_check-phase install
1159
1160 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1161
1162 local pkgs="${1}"
1163 local jar="${2}"
1164
1165 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1166
1167 if [[ "${EAPI}" == "1" ]]; then
1168 pkgs="${pkgs//:/-}"
1169 fi
1170
1171 if [[ -z "${jar}" ]]; then
1172 for pkg in ${pkgs//,/ }; do
1173 java-pkg_ensure-dep runtime "${pkg}"
1174 java-pkg_record-jar_ "${pkg}"
1175 done
1176 else
1177 [[ ${pkgs} == *,* ]] && \
1178 die "${FUNCNAME} called with both package list and jar name"
1179 java-pkg_ensure-dep runtime "${pkgs}"
1180 java-pkg_record-jar_ "${pkgs}" "${jar}"
1181 fi
1182
1183 java-pkg_do_write_
1184}
1185
1186# ------------------------------------------------------------------------------
1187# @ebuild-function java-pkg_register-optional-dependency
1188#
1189# Registers optional runtime dependency on a package, list of packages, or a
1190# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1191# called in src_install phase.
1192# Intended for packages that can use other packages when those are in classpath.
1193# Will be put on classpath by launcher if they are installed. Typical case is
1194# JDBC implementations for various databases. It's better than having USE flag
1195# for each implementation triggering hard dependency.
1196#
1197# @param $1 - comma-separated list of packages, or a single package
1198# @param $2 - if param $1 is a single package, optionally specify the jar
1199# to depend on
1200#
1201# Example: Record the optional dependency on some jdbc providers
1202# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1203#
1204# Note: Passing both list of packages as the first parameter AND specifying the
1205# jar as the second is not allowed and will cause the function to die. We assume
1206# that there's more chance one passes such combination as a mistake, than that
1207# there are more packages providing identically named jar without class
1208# collisions.
1209# ------------------------------------------------------------------------------
1210java-pkg_register-optional-dependency() {
1211 debug-print-function ${FUNCNAME} $*
1212
1213 java-pkg_check-phase install
1214
1215 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1216
1217 local pkgs="${1}"
1218 local jar="${2}"
1219
1220 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1221
1222 if [[ "${EAPI}" == "1" ]]; then
1223 pkgs="${pkgs//:/-}"
1224 fi
1225
1226 if [[ -z "${jar}" ]]; then
1227 for pkg in ${pkgs//,/ }; do
1228 java-pkg_record-jar_ --optional "${pkg}"
1229 done
1230 else
1231 [[ ${pkgs} == *,* ]] && \
1232 die "${FUNCNAME} called with both package list and jar name"
1233 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1234 fi
1235
1236 java-pkg_do_write_
1237}
1238
1239# ------------------------------------------------------------------------------
1240# @ebuild-function java-pkg_register-environment-variable
1241#
1242# Register an arbitrary environment variable into package.env. The gjl launcher
1243# for this package or any package depending on this will export it into
1244# environement before executing java command.
1245# Must only be called in src_install phase.
1246#
1247# @param $1 - variable name
1248# @param $2 - variable value
1249# ------------------------------------------------------------------------------
1250JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1251JAVA_PKG_EXTRA_ENV_VARS=""
1252java-pkg_register-environment-variable() {
1253 debug-print-function ${FUNCNAME} $*
1254
1255 java-pkg_check-phase install
1256
1257 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1258
1259 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1260 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1261
1262 java-pkg_do_write_
786} 1263}
787 1264
788# This function reads stdin, and based on that input, figures out how to 1265# This function reads stdin, and based on that input, figures out how to
789# populate jars from the filesystem. 1266# populate jars from the filesystem.
790# Need to figure out a good way of making use of this, ie be able to use a 1267# Need to figure out a good way of making use of this, ie be able to use a
802# line="${line// /}" 1279# line="${line// /}"
803# 1280#
804# # format: path=jarinfo 1281# # format: path=jarinfo
805# local path=${line%%=*} 1282# local path=${line%%=*}
806# local jarinfo=${line##*=} 1283# local jarinfo=${line##*=}
807# 1284#
808# # format: jar@package 1285# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 1286# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 1287# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 1288# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 1289# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 1302# @section-end query
826# ------------------------------------------------------------------------------ 1303# ------------------------------------------------------------------------------
827 1304
828# ------------------------------------------------------------------------------ 1305# ------------------------------------------------------------------------------
829# @section-begin helper 1306# @section-begin helper
830# @section-summary Helper functions 1307# @section-summary Helper functions
831# 1308#
832# Various other functions to use from an ebuild 1309# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 1310# ------------------------------------------------------------------------------
834 1311
835# ------------------------------------------------------------------------------ 1312# ------------------------------------------------------------------------------
841# jdbc-stdext 1318# jdbc-stdext
842# jaf 1319# jaf
843# jdbc-rowset 1320# jdbc-rowset
844# jms 1321# jms
845# 1322#
846# @param $1 - Optionally indicate that the dependencies are controlled by 1323# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 1324# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 1325# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 1326# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 1327# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 1328# TODO rewrite to parse a line based declaration file instead -- karltk
907# 1384#
908# export DEPEND="${DEPEND} ${depstr}" 1385# export DEPEND="${DEPEND} ${depstr}"
909# export RDEPEND="${RDEPEND} ${depstr}" 1386# export RDEPEND="${RDEPEND} ${depstr}"
910#} 1387#}
911 1388
1389# ------------------------------------------------------------------------------
1390# @ebuild-function java-pkg_find-normal-jars
1391#
1392# Find the files with suffix .jar file in the given directory or $WORKDIR
1393#
1394# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1395# ------------------------------------------------------------------------------
1396java-pkg_find-normal-jars() {
1397 local dir=$1
1398 [[ "${dir}" ]] || dir="${WORKDIR}"
1399 local found
1400 for jar in $(find "${dir}" -name "*.jar" -type f); do
1401 echo "${jar}"
1402 found="true"
1403 done
1404 [[ "${found}" ]]
1405 return $?
1406}
1407
1408# ------------------------------------------------------------------------------
1409# @ebuild-function java-pkg_ensure-no-bundled-jars
1410#
1411# Try to locate bundled jar files in ${WORKDIR} and die if found.
912# This should be used after S has been populated with symlinks to jars 1412# This function should be called after WORKDIR has been populated with symlink
913# TODO document 1413# to system jar files or bundled jars removed.
1414# ------------------------------------------------------------------------------
914java-pkg_ensure-no-bundled-jars() { 1415java-pkg_ensure-no-bundled-jars() {
915 debug-print-function ${FUNCNAME} $* 1416 debug-print-function ${FUNCNAME} $*
916 pushd ${WORKDIR} >/dev/null 2>/dev/null
917 1417
918 local bundled_jars=$(find . -name "*.jar" -type f) 1418 local bundled_jars=$(java-pkg_find-normal-jars)
919 if [[ -n ${bundled_jars} ]]; then 1419 if [[ -n ${bundled_jars} ]]; then
920 echo "Bundled jars found:" 1420 echo "Bundled jars found:"
921 local jar 1421 local jar
922 for jar in ${bundled_jars}; do 1422 for jar in ${bundled_jars}; do
923 echo $(pwd)${jar/./} 1423 echo $(pwd)${jar/./}
924 done 1424 done
925 die "Bundled jars found!" 1425 die "Bundled jars found!"
926
927 fi 1426 fi
928 popd >/dev/null 2>/dev/null
929} 1427}
930 1428
931# ------------------------------------------------------------------------------ 1429# ------------------------------------------------------------------------------
932# @internal-function java-pkg_ensure-vm-version-sufficient 1430# @internal-function java-pkg_ensure-vm-version-sufficient
933# 1431#
945 fi 1443 fi
946} 1444}
947 1445
948# ------------------------------------------------------------------------------ 1446# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1447# @internal-function java-pkg_is-vm-version-sufficient
950# 1448#
951# @return zero - VM is sufficient 1449# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1450# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1451# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1452java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1453 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1473 die "Active Java VM too old"
976 fi 1474 fi
977} 1475}
978 1476
979# ------------------------------------------------------------------------------ 1477# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1478# @internal-function java-pkg_is-vm-version-eq
981# 1479#
982# @param $@ - VM version to compare current VM to 1480# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1481# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1482# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1483# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1484java-pkg_is-vm-version-eq() {
1016# 1514#
1017# @param $@ - VM version to compare current to 1515# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1516# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1517java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1518 debug-print-function ${FUNCNAME} $*
1021 1519
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1520 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1521 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1522 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1523 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1524 die "Active Java VM too old"
1027 fi 1525 fi
1028} 1526}
1029 1527
1030# ------------------------------------------------------------------------------ 1528# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1529# @internal-function java-pkg_is-vm-version-ge
1032# 1530#
1033# @param $@ - VM version to compare current VM to 1531# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1532# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1533# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1534# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1535java-pkg_is-vm-version-ge() {
1051 return 1 1549 return 1
1052 fi 1550 fi
1053 fi 1551 fi
1054} 1552}
1055 1553
1554java-pkg_set-current-vm() {
1555 export GENTOO_VM=${1}
1556}
1557
1558java-pkg_get-current-vm() {
1559 echo ${GENTOO_VM}
1560}
1561
1562java-pkg_current-vm-matches() {
1563 hasq $(java-pkg_get-current-vm) ${@}
1564 return $?
1565}
1566
1056# ------------------------------------------------------------------------------ 1567# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1568# @ebuild-function java-pkg_get-source
1058# 1569#
1059# Determines what source version should be used, for passing to -source. 1570# Determines what source version should be used, for passing to -source.
1060# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1571# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1572#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1573# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1574# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1579# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1580# @ebuild-function java-pkg_get-target
1070# 1581#
1071# Determines what target version should be used, for passing to -target. 1582# Determines what target version should be used, for passing to -target.
1072# If you don't care about lower versions, you can set _WANT_TARGET to the 1583# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1584# version of your JDK.
1074# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm.
1077# 1585#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1586# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1587# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1588java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1084 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1085 echo ${JAVA_PKG_WANT_TARGET}
1086 else
1087 echo ${min}
1088 fi
1089 else
1090 echo ${min}
1091 fi
1092
1093 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1589 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1094} 1590}
1095 1591
1096java-pkg_get-javac() { 1592java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1593 debug-print-function ${FUNCNAME} $*
1098 1594
1099 java-pkg_init-compiler_ 1595
1100 local compiler="${GENTOO_COMPILER}" 1596 local compiler="${GENTOO_COMPILER}"
1101 1597
1102 local compiler_executable 1598 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1599 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1600 # nothing fancy needs to be done for javac
1112 unset JAVAC 1608 unset JAVAC
1113 # try to get value of JAVAC 1609 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1610 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1611 export JAVAC=${old_javac}
1116 1612
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1613 if [[ -z ${compiler_executable} ]]; then
1118 1614 echo "JAVAC is empty or undefined in ${compiler_env}"
1615 return 1
1616 fi
1617
1119 # check that it's executable 1618 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1619 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1620 echo "${compiler_executable} doesn't exist, or isn't executable"
1621 return 1
1123 fi 1622 fi
1124 else 1623 else
1125 eerror "Could not find environment file for ${compiler}" 1624 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1625 return 1
1127 fi 1626 fi
1128 fi 1627 fi
1129 echo ${compiler_executable} 1628 echo ${compiler_executable}
1130} 1629}
1131 1630
1132# ------------------------------------------------------------------------------ 1631# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1632# @ebuild-function java-pkg_javac-args
1134# 1633#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1634# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1635# to know what -source/-target to use.
1137# 1636#
1138# @return string - arguments to pass to javac, complete with -target and -source 1637# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1640 debug-print-function ${FUNCNAME} $*
1142 1641
1143 local want_source="$(java-pkg_get-source)" 1642 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1643 local want_target="$(java-pkg_get-target)"
1145 1644
1146 local source_str="-source ${want_source}" 1645 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1646 local target_str="-target ${want_target}"
1148 1647
1149 debug-print "want source: ${want_source}" 1648 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1649 debug-print "want target: ${want_target}"
1151 1650
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1651 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1652 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1653 echo "Could not find valid -source/-target values for javac"
1654 return 1
1155 else 1655 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1656 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1657 echo "${source_str} ${target_str}"
1158 else 1658 else
1159 echo "${target_str}" 1659 echo "${target_str}"
1163 1663
1164# TODO document 1664# TODO document
1165java-pkg_get-jni-cflags() { 1665java-pkg_get-jni-cflags() {
1166 local flags="-I${JAVA_HOME}/include" 1666 local flags="-I${JAVA_HOME}/include"
1167 1667
1668 local platform="linux"
1669 use elibc_FreeBSD && platform="freebsd"
1670
1168 # TODO do a check that the directories are valid 1671 # TODO do a check that the directories are valid
1169 # TODO figure out how to cope with other things than linux...
1170 flags="${flags} -I${JAVA_HOME}/include/linux" 1672 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1171 1673
1172 echo ${flags} 1674 echo ${flags}
1173} 1675}
1174 1676
1175java-pkg_ensure-gcj() { 1677java-pkg_ensure-gcj() {
1180 ebeep 5 1682 ebeep 5
1181 die "No GCJ support found!" 1683 die "No GCJ support found!"
1182 fi 1684 fi
1183} 1685}
1184 1686
1687java-pkg_ensure-test() {
1688 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1689 && hasq test ${IUSE} && ! use test;
1690 then
1691 eerror "You specified FEATURES=test, but USE=test is needed"
1692 eerror "to pull in the additional dependencies for testing"
1693 die "Need USE=test enabled"
1694 fi
1695}
1696
1697# ------------------------------------------------------------------------------
1698# @ebuild-function java-pkg_register-ant-task
1699#
1700# Register this package as ant task, so that ant will load it when no specific
1701# ANT_TASKS are specified. Note that even without this registering, all packages
1702# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1703# packages, but can be also used by other ebuilds that used to symlink their
1704# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1705# compatibility.
1706#
1707# @param --version x.y Register only for ant version x.y (otherwise for any ant
1708# version). Used by the ant-* packages to prevent loading of mismatched
1709# ant-core ant tasks after core was updated, before the tasks are updated,
1710# without a need for blockers.
1711# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1712# ------------------------------------------------------------------------------
1713java-pkg_register-ant-task() {
1714 local TASKS_DIR="tasks"
1715
1716 # check for --version x.y parameters
1717 while [[ -n "${1}" && -n "${2}" ]]; do
1718 local var="${1#--}"
1719 local val="${2}"
1720 if [[ "${var}" == "version" ]]; then
1721 TASKS_DIR="tasks-${val}"
1722 else
1723 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1724 fi
1725 shift 2
1726 done
1727
1728 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1729
1730 dodir /usr/share/ant/${TASKS_DIR}
1731 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1732}
1733
1734# ------------------------------------------------------------------------------
1735# @internal-function java-pkg_ant-tasks-depend
1736#
1737# Translates the WANT_ANT_TASKS variable into valid dependencies.
1738# ------------------------------------------------------------------------------
1739java-pkg_ant-tasks-depend() {
1740 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1741
1742 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1743 local DEP=""
1744 for i in ${WANT_ANT_TASKS}
1745 do
1746 if [[ ${i} = ant-* ]]; then
1747 DEP="${DEP}dev-java/${i} "
1748 elif [[ ${i} = */*:* ]]; then
1749 DEP="${DEP}${i} "
1750 else
1751 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1752 return 1
1753 fi
1754 done
1755 echo ${DEP}
1756 return 0
1757 else
1758 return 0
1759 fi
1760}
1761
1762# ------------------------------------------------------------------------------
1763# @ebuild-function ejunit
1764#
1765# Junit wrapper function. Makes it easier to run the tests and checks for
1766# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1767#
1768# Examples:
1769# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1770# ejunit org.blinkenlights.jid3.test.AllTests
1771#
1772# @param $1 - -cp or -classpath
1773# @param $2 - classpath; junit and recorded dependencies get appended
1774# @param $@ - the rest of the parameters are passed to java
1775# ------------------------------------------------------------------------------
1776ejunit() {
1777 debug-print-function ${FUNCNAME} $*
1778
1779 local pkgs
1780 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1781 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1782 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1783 done
1784 fi
1785
1786 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1787 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1788 cp="${2}:${cp}"
1789 shift 2
1790 else
1791 cp=".:${cp}"
1792 fi
1793
1794 local runner=junit.textui.TestRunner
1795 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1796 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1797}
1798
1185# ------------------------------------------------------------------------------ 1799# ------------------------------------------------------------------------------
1186# @section-end helper 1800# @section-end helper
1187# ------------------------------------------------------------------------------ 1801# ------------------------------------------------------------------------------
1802
1803# ------------------------------------------------------------------------------
1804# @eclass-src_prepare
1805#
1806# src_prepare Searches for bundled jars
1807# Don't call directly, but via java-pkg-2_src_prepare!
1808# ------------------------------------------------------------------------------
1809
1810java-utils-2_src_prepare() {
1811 [[ ${EBUILD_PHASE} == prepare ]] &&
1812 java-pkg_func-exists java_prepare && java_prepare
1813
1814 # Remember that eant will call this unless called via Portage
1815 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1816 echo "Searching for bundled jars:"
1817 java-pkg_find-normal-jars || echo "None found."
1818 echo "Searching for bundled classes (no output if none found):"
1819 find "${WORKDIR}" -name "*.class"
1820 echo "Search done."
1821 fi
1822 touch "${T}/java-utils-2_src_prepare-run"
1823}
1824
1825# ------------------------------------------------------------------------------
1826# @eclass-pkg_preinst
1827#
1828# pkg_preinst Searches for missing and unneeded dependencies
1829# Don't call directly, but via java-pkg-2_pkg_preinst!
1830# ------------------------------------------------------------------------------
1831
1832java-utils-2_pkg_preinst() {
1833 if is-java-strict; then
1834 if has_version dev-java/java-dep-check; then
1835 [[ -e "${JAVA_PKG_ENV}" ]] || return
1836 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1837 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1838 ewarn "Possibly unneeded dependencies found in package.env:"
1839 for dep in ${output}; do
1840 ewarn "\t${dep}"
1841 done
1842 fi
1843 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1844 ewarn "${output}"
1845 fi
1846 else
1847 eerror "Install dev-java/java-dep-check for dependency checking"
1848 fi
1849 fi
1850}
1188 1851
1189# ------------------------------------------------------------------------------ 1852# ------------------------------------------------------------------------------
1190# @section-begin build 1853# @section-begin build
1191# @section-summary Build functions 1854# @section-summary Build functions
1192# 1855#
1196 1859
1197# ------------------------------------------------------------------------------ 1860# ------------------------------------------------------------------------------
1198# @ebuild-function eant 1861# @ebuild-function eant
1199# 1862#
1200# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1863# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1201# compiler. 1864# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1202# 1865# variables:
1866# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1867# gentoo.classpath property. Be sure to call
1868# java-ant_rewrite-classpath in src_unpack.
1869# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1870# for build-time purposes, the dependency is not recorded to
1871# package.env!
1872# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1873# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1203# ------------------------------------------------------------------------------ 1874# ------------------------------------------------------------------------------
1204eant() { 1875eant() {
1205 debug-print-function ${FUNCNAME} $* 1876 debug-print-function ${FUNCNAME} $*
1206 1877
1207 local antflags 1878 if [[ ${EBUILD_PHASE} = compile ]]; then
1879 java-ant-2_src_configure
1880 java-utils-2_src_prepare
1881 fi
1882
1883 if ! hasq java-ant-2 ${INHERITED}; then
1884 local msg="You should inherit java-ant-2 when using eant"
1885 java-pkg_announce-qa-violation "${msg}"
1886 fi
1887
1888 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1889
1208 java-pkg_init-compiler_ 1890 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1891 local compiler="${GENTOO_COMPILER}"
1210 1892
1211 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1893 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1212
1213 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1894 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1214 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1895 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1215 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1896 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1216 fi 1897 fi
1217 1898
1218 if [[ ${compiler} != "javac" ]]; then 1899 if [[ ${compiler} != "javac" ]]; then
1219 antflags="-Dbuild.compiler=${build_compiler}" 1900 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1220 # Figure out any extra stuff to put on the classpath for compilers aside 1901 # Figure out any extra stuff to put on the classpath for compilers aside
1221 # from javac 1902 # from javac
1222 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1903 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1223 # java-config -p 1904 # java-config -p
1224 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1905 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1225 if [[ -n ${build_compiler_deps} ]]; then 1906 if [[ -n ${build_compiler_deps} ]]; then
1226 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1907 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1227 fi 1908 fi
1228 fi 1909 fi
1229 1910
1911 for arg in "${@}"; do
1912 if [[ ${arg} = -lib ]]; then
1230 if is-java-strict; then 1913 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1914 eerror "You should not use the -lib argument to eant because it will fail"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1915 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1916 eerror "or ant properties to make dependencies available."
1917 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1918 eerror "split ant (>=dev-java/ant-core-1.7)."
1919 die "eant -lib is deprecated/forbidden"
1920 else
1921 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1922 echo "more info."
1923 fi
1233 fi 1924 fi
1234 1925 done
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1926
1236 antflags="${antflags} -debug" 1927 # parse WANT_ANT_TASKS for atoms
1928 local want_ant_tasks
1929 for i in ${WANT_ANT_TASKS}; do
1930 if [[ ${i} = */*:* ]]; then
1931 i=${i#*/}
1932 i=${i%:0}
1933 want_ant_tasks+="${i/:/-} "
1934 else
1935 want_ant_tasks+="${i} "
1237 fi 1936 fi
1238 1937 done
1938 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1939 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1940
1941 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1942 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1943
1944 # if ant-tasks is not set by ebuild or forced, use none
1945 ANT_TASKS="${ANT_TASKS:-none}"
1946
1947 # at this point, ANT_TASKS should be "all", "none" or explicit list
1948 if [[ "${ANT_TASKS}" == "all" ]]; then
1949 einfo "Using all available ANT_TASKS"
1950 elif [[ "${ANT_TASKS}" == "none" ]]; then
1951 einfo "Disabling all optional ANT_TASKS"
1952 else
1953 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1954 fi
1955
1956 export ANT_TASKS
1957
1958 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1959 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1960
1961 local gcp="${EANT_GENTOO_CLASSPATH}"
1962 local getjarsarg=""
1963
1964 if [[ ${EBUILD_PHASE} = "test" ]]; then
1965 antflags="${antflags} -DJunit.present=true"
1966 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1967 getjarsarg="--with-dependencies"
1968 fi
1969
1970 local cp
1971
1972 for atom in ${gcp}; do
1973 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1974 done
1975
1976 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1977
1978 if [[ ${cp} ]]; then
1979 # It seems ant does not like single quotes around ${cp}
1980 cp=${cp#:}
1981 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1982 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1983 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1984 fi
1985
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1986 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1987 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 1988 ant ${antflags} "${@}" || die "eant failed"
1241
1242} 1989}
1243 1990
1244# ------------------------------------------------------------------------------ 1991# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 1992# @ebuild-function ejavac
1246# 1993#
1247# Javac wrapper function. Will use the appropriate compiler, based on 1994# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 1995# /etc/java-config/compilers.conf
1249# 1996#
1250# @param $@ - Arguments to be passed to the compiler 1997# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 1998# ------------------------------------------------------------------------------
1252ejavac() { 1999ejavac() {
1253 debug-print-function ${FUNCNAME} $* 2000 debug-print-function ${FUNCNAME} $*
1254 2001
1255 # FIXME using get-javac ends up printing stuff with einfo 2002 java-pkg_init-compiler_
2003
2004 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 2005 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 2006 if [[ ${?} != 0 ]]; then
2007 eerror "There was a problem determining compiler: ${compiler_executable}"
2008 die "get-javac failed"
2009 fi
1258 2010
2011 local javac_args
2012 javac_args="$(java-pkg_javac-args)"
2013 if [[ ${?} != 0 ]]; then
2014 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
2015 die "java-pkg_javac-args failed"
2016 fi
2017
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 2018 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 2019 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 2020}
1262 2021
1263# ------------------------------------------------------------------------------ 2022# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 2023# @ebuild-function java-pkg_filter-compiler
1265# 2024#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 2025# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 2026# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 2027#
1269# @param $@ - compilers to filter 2028# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 2029# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 2047# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 2048# @ebuild-function use_doc
1290# 2049#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 2050# Helper function for getting ant to build javadocs. If the user has USE=doc,
1292# then 'javadoc' or the argument are returned. Otherwise, there is no return. 2051# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 2052#
1294# The output of this should be passed to ant. 2053# The output of this should be passed to ant.
1295# 2054#
1296# Example: build javadocs by calling 'javadoc' target 2055# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 2056# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 2057# Example: build javadocs by calling 'apidoc' target
1303# ------------------------------------------------------------------------------ 2062# ------------------------------------------------------------------------------
1304use_doc() { 2063use_doc() {
1305 use doc && echo ${@:-javadoc} 2064 use doc && echo ${@:-javadoc}
1306} 2065}
1307 2066
2067
1308# ------------------------------------------------------------------------------ 2068# ------------------------------------------------------------------------------
1309# @section-end build 2069# @section-end build
1310# ------------------------------------------------------------------------------ 2070# ------------------------------------------------------------------------------
1311 2071
1312# ------------------------------------------------------------------------------ 2072# ------------------------------------------------------------------------------
1313# @section-begin internal 2073# @section-begin internal
1314# @section-summary Internal functions 2074# @section-summary Internal functions
1315# 2075#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 2076# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 2077# within the java eclasses.
1318# ------------------------------------------------------------------------------ 2078# ------------------------------------------------------------------------------
1319 2079
1320# ----------------------------------------------------------------------------- 2080# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 2081# @function-internal java-pkg_init
1322# 2082#
1323# The purpose of this function, as the name might imply, is to initialize the 2083# The purpose of this function, as the name might imply, is to initialize the
1324# Java environment. It ensures that that there aren't any environment variables 2084# Java environment. It ensures that that there aren't any environment variables
1325# that'll muss things up. It initializes some variables, which are used 2085# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 2086# internally. And most importantly, it'll switch the VM if necessary.
1327# 2087#
1328# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2088# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1329# call it during each of the phases of the merge process. 2089# call it during each of the phases of the merge process.
1330# 2090#
1331# ----------------------------------------------------------------------------- 2091# -----------------------------------------------------------------------------
1332java-pkg_init() { 2092java-pkg_init() {
2093 debug-print-function ${FUNCNAME} $*
1333 unset JAVAC 2094 unset JAVAC
1334 unset JAVA_HOME 2095 unset JAVA_HOME
2096
2097 java-config --help >/dev/null || {
2098 eerror ""
2099 eerror "Can't run java-config --help"
2100 eerror "Have you upgraded python recently but haven't"
2101 eerror "run python-updater yet?"
2102 die "Can't run java-config --help"
2103 }
2104
2105 # People do all kinds of weird things.
2106 # http://forums.gentoo.org/viewtopic-p-3943166.html
2107 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2108 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2109 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2110 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2111 ewarn "sun-jdk vms and and as such break configure scripts that"
2112 ewarn "use it (for example app-office/openoffice) so we filter it out."
2113 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2114 ewarn "make.conf for example) to silence this warning or"
2115 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2116 fi
2117
2118 if [[ -z ${accept} ]]; then
2119 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2120 # -version output
2121 unset _JAVA_OPTIONS
2122 # phase hooks make this run many times without this
2123 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2124 fi
2125
2126 if java-pkg_func-exists ant_src_unpack; then
2127 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2128 fi
2129
1335 java-pkg_init_paths_ 2130 java-pkg_init_paths_
1336 java-pkg_switch-vm 2131 java-pkg_switch-vm
1337 PATH=${JAVA_HOME}/bin:${PATH} 2132 PATH=${JAVA_HOME}/bin:${PATH}
1338 2133
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 2134 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 2135
1341 # Do some QA checks 2136 # Do some QA checks
1342 java-pkg_check-jikes 2137 java-pkg_check-jikes
1343 2138
2139 # Can't use unset here because Portage does not save the unset
2140 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2141
1344 # When users have crazy classpaths some packages can fail to compile. 2142 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 2143 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 2144 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 2145 # from the CLASSPATH.
1348 unset CLASSPATH 2146 export CLASSPATH=
2147
2148 # Unset external ANT_ stuff
2149 export ANT_TASKS=
2150 export ANT_OPTS=
2151 export ANT_RESPECT_JAVA_HOME=
1349} 2152}
1350 2153
1351# ------------------------------------------------------------------------------ 2154# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 2155# @function-internal java-pkg-init-compiler_
1353# 2156#
1354# This function attempts to figure out what compiler should be used. It does 2157# This function attempts to figure out what compiler should be used. It does
1355# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2158# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 2159# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2160# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 2161#
1359# It will go through the list of compilers, and verify that it supports the 2162# It will go through the list of compilers, and verify that it supports the
1360# target and source that are needed. If it is not suitable, then the next 2163# target and source that are needed. If it is not suitable, then the next
1361# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 2164# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 2165# isn't done.
1363# 2166#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2188 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2189 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 2190 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 2191 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 2192 fi
1390 2193
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2194 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 2195
1393 # Figure out if we should announce what compiler we're using 2196 # Figure out if we should announce what compiler we're using
1394 local compiler 2197 local compiler
1395 for compiler in ${compilers}; do 2198 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 2201 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 2202 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 2203 export GENTOO_COMPILER="javac"
1401 break 2204 break
1402 fi 2205 fi
1403 2206
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2207 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2208 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 2209 einfo "Filtering ${compiler}"
1407 continue 2210 continue
1408 fi 2211 fi
1409 fi 2212 fi
1410 2213
1411 # for non-javac, we need to make sure it supports the right target and 2214 # for non-javac, we need to make sure it supports the right target and
1412 # source 2215 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2216 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 2217 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 2218 local desired_target="$(java-pkg_get-target)"
1444 done 2247 done
1445 2248
1446 # If it hasn't been defined already, default to javac 2249 # If it hasn't been defined already, default to javac
1447 if [[ -z ${GENTOO_COMPILER} ]]; then 2250 if [[ -z ${GENTOO_COMPILER} ]]; then
1448 if [[ -n ${compilers} ]]; then 2251 if [[ -n ${compilers} ]]; then
1449 einfo "No suitable compiler found: defaulting javac for compilation" 2252 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1450 else 2253 else
1451 # probably don't need to notify users about the default. 2254 # probably don't need to notify users about the default.
1452 :;#einfo "Defaulting to javac for compilation" 2255 :;#einfo "Defaulting to javac for compilation"
1453 fi 2256 fi
2257 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2258 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2259 else
1454 export GENTOO_COMPILER=javac 2260 export GENTOO_COMPILER=javac
2261 fi
1455 else 2262 else
1456 einfo "Using ${GENTOO_COMPILER} for compilation" 2263 einfo "Using ${GENTOO_COMPILER} for compilation"
1457 fi 2264 fi
1458 2265
1459} 2266}
1475 fi 2282 fi
1476 2283
1477 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2284 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1478 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2285 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1479 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2286 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2287 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2288 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1480 2289
1481 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2290 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1482 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2291 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1483 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2292 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1484 2293
1497# Writes the package.env out to disk. 2306# Writes the package.env out to disk.
1498# 2307#
1499# ------------------------------------------------------------------------------ 2308# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 2309# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 2310java-pkg_do_write_() {
2311 debug-print-function ${FUNCNAME} $*
2312 java-pkg_init_paths_
1502 # Create directory for package.env 2313 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 2314 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2315 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2316 "${JAVA_PKG_DEPEND_FILE}" || -f \
2317 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1505 # Create package.env 2318 # Create package.env
1506 ( 2319 (
1507 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2320 echo "DESCRIPTION=\"${DESCRIPTION}\""
1508 echo "GENERATION=\"2\"" 2321 echo "GENERATION=\"2\""
2322 echo "SLOT=\"${SLOT}\""
1509 2323
1510 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2324 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2325 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2326 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2327 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2328 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2329 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2330 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2331 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1515 ) > "${JAVA_PKG_ENV}" 2332 ) > "${JAVA_PKG_ENV}"
1516 2333
1517 # register target/source 2334 # register target/source
1518 local target="$(java-pkg_get-target)" 2335 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 2336 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2337 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2338 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1529 2346
1530 2347
1531 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2348 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1532 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2349 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1533 2350
2351 # extra env variables
2352 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2353 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2354 # nested echo to remove leading/trailing spaces
2355 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2356 >> "${JAVA_PKG_ENV}" || die
2357 fi
2358
1534 # Strip unnecessary leading and trailing colons 2359 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 2360 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2361 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2362 else
2363 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2364 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2365 debug-print "write package.env."
1537 fi 2366 fi
1538} 2367}
1539
1540 2368
1541# ------------------------------------------------------------------------------ 2369# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 2370# @internal-function java-pkg_record-jar_
1543# 2371#
1544# Record a dependency to the package.env 2372# Record an (optional) dependency to the package.env
1545# 2373# @param --optional - record dependency as optional
2374# @param $1 - package to record
2375# @param $2 - (optional) jar of package to record
1546# ------------------------------------------------------------------------------ 2376# ------------------------------------------------------------------------------
1547JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2377JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2378JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1548 2379
1549java-pkg_record-jar_() { 2380java-pkg_record-jar_() {
1550 debug-print-function ${FUNCNAME} $* 2381 debug-print-function ${FUNCNAME} $*
2382
2383 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2384 if [[ "${1}" == "--optional" ]]; then
2385 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2386 shift
2387 fi
1551 2388
1552 local pkg=${1} jar=${2} append 2389 local pkg=${1} jar=${2} append
1553 if [[ -z "${jar}" ]]; then 2390 if [[ -z "${jar}" ]]; then
1554 append="${pkg}" 2391 append="${pkg}"
1555 else 2392 else
1556 append="$(basename ${jar})@${pkg}" 2393 append="$(basename ${jar})@${pkg}"
1557 fi 2394 fi
1558 2395
1559 echo ${append} >> ${JAVA_PKG_DEPEND} 2396 echo "${append}" >> "${depend_file}"
1560} 2397}
1561 2398
1562# ------------------------------------------------------------------------------ 2399# ------------------------------------------------------------------------------
1563# @internal-function java-pkg_append_ 2400# @internal-function java-pkg_append_
1564# 2401#
1588 fi 2425 fi
1589} 2426}
1590 2427
1591# ------------------------------------------------------------------------------ 2428# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 2429# @internal-function java-pkg_expand_dir_
1593# 2430#
1594# Gets the full path of the file/directory's parent. 2431# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 2432# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 2433# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 2434# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 2435java-pkg_expand_dir_() {
1608# 2445#
1609# @return 0 - function is declared 2446# @return 0 - function is declared
1610# @return 1 - function is undeclared 2447# @return 1 - function is undeclared
1611# ------------------------------------------------------------------------------ 2448# ------------------------------------------------------------------------------
1612java-pkg_func-exists() { 2449java-pkg_func-exists() {
1613 if [[ -n "$(declare -f ${1})" ]]; then 2450 declare -F ${1} > /dev/null
1614 return 0
1615 else
1616 return 1
1617 fi
1618} 2451}
1619 2452
1620# ------------------------------------------------------------------------------ 2453# ------------------------------------------------------------------------------
1621# @internal-function java-pkg_setup-vm 2454# @internal-function java-pkg_setup-vm
1622# 2455#
1624# 2457#
1625# ------------------------------------------------------------------------------ 2458# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 2459java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 2460 debug-print-function ${FUNCNAME} $*
1628 2461
2462 export LANG="C" LC_ALL="C"
2463
1629 local vendor="$(java-pkg_get-vm-vendor)" 2464 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2465 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 2466 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 2467 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 2468 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 2469 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C"
1636 elif [[ "${vendor}" == "jrockit" ]]; then 2470 elif [[ "${vendor}" == "jrockit" ]]; then
1637 addpredict "/proc/cpuinfo" 2471 addpredict "/proc/cpuinfo"
1638 fi 2472 fi
1639} 2473}
1640 2474
1684# @return - The version of the current VM 2518# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 2519# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 2520java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 2521 debug-print-function ${FUNCNAME} $*
1688 2522
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2523 java-config -g PROVIDES_VERSION
1690} 2524}
1691 2525
1692# ------------------------------------------------------------------------------ 2526# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 2527# @internal-function java-pkg_switch-vm
1694# 2528#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2529# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 2530# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 2531# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 2532# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 2533java-pkg_switch-vm() {
2534 debug-print-function ${FUNCNAME} $*
2535
1700 if java-pkg_needs-vm; then 2536 if java-pkg_needs-vm; then
1701 # Use the VM specified by JAVA_PKG_FORCE_VM 2537 # Use the VM specified by JAVA_PKG_FORCE_VM
1702 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2538 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1703 # If you're forcing the VM, I hope you know what your doing... 2539 # If you're forcing the VM, I hope you know what your doing...
2540 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2541 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 2542 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2543 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1707 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2544 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2545 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1709 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2546 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1710 else 2547 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2548 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2549 fi
2550 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2551 eerror "Unable to determine VM for building from dependencies:"
2552 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2553 echo "VNEED: ${JAVA_PKG_VNEED}"
2554 die "Failed to determine VM for building."
2555 else
2556 export GENTOO_VM
1712 fi 2557 fi
1713 # otherwise just make sure the current VM is sufficient 2558 # otherwise just make sure the current VM is sufficient
1714 else 2559 else
1715 java-pkg_ensure-vm-version-sufficient 2560 java-pkg_ensure-vm-version-sufficient
1716 fi 2561 fi
1717 debug-print "Using: $(java-config -f)" 2562 debug-print "Using: $(java-config -f)"
1718 2563
1719 java-pkg_setup-vm 2564 java-pkg_setup-vm
1720 2565
1721 export JAVA=$(java-config --java) 2566 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 2567 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 2568 JAVACFLAGS="$(java-pkg_javac-args)"
2569 if [[ ${?} != 0 ]]; then
2570 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2571 die "java-pkg_javac-args failed"
2572 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2573 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2574 export JAVACFLAGS
1725 2575
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2576 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 2577 export JDK_HOME=${JAVA_HOME}
1728 2578
1729 #TODO If you know a better solution let us know. 2579 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2580 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 2581
1732 local tann="${T}/announced-vm" 2582 local tann="${T}/announced-vm"
2583 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2584 # if people have for example modified eclasses some where
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2585 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1737 then
1738 einfo "Using: $(java-config -f)" 2586 einfo "Using: $(java-config -f)"
1739 [[ ! -f "${tann}" ]] && touch "${tann}" 2587 [[ ! -f "${tann}" ]] && touch "${tann}"
1740 fi
1741 fi 2588 fi
1742 2589
1743 else 2590 else
1744 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2591 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1745 fi 2592 fi
1775 einfo "Classes" 2622 einfo "Classes"
1776 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2623 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1777 fi 2624 fi
1778} 2625}
1779 2626
1780# TODO document 2627# ------------------------------------------------------------------------------
2628# @internal-function java-pkg_verify-classes
2629#
1781# Verify that the classes were compiled for the right source / target 2630# Verify that the classes were compiled for the right source / target. Dies if
2631# not.
2632# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2633# ------------------------------------------------------------------------------
1782java-pkg_verify-classes() { 2634java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2635 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2636
2637 local version_verify="/usr/bin/class-version-verify.py"
2638
2639 if [[ ! -x "${version_verify}" ]]; then
2640 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2641 fi
2642
2643 if [[ ! -x "${version_verify}" ]]; then
2644 ewarn "Unable to perform class version checks as"
2645 ewarn "class-version-verify.py is unavailable"
2646 ewarn "Please install dev-java/javatoolkit."
2647 return
2648 fi
2649
2650 local target=$(java-pkg_get-target)
2651 local result
2652 local log="${T}/class-version-verify.log"
2653 if [[ -n "${1}" ]]; then
2654 ${version_verify} -v -t ${target} "${1}" > "${log}"
1786 result=$? 2655 result=$?
1787 eend ${result}
1788 if [[ ${result} == 0 ]]; then
1789 einfo "All good"
1790 else 2656 else
1791 ewarn "Possible problem" 2657 ebegin "Verifying java class versions (target: ${target})"
1792 die "Bad class files found" 2658 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2659 result=$?
2660 eend ${result}
2661 fi
2662 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2663 if [[ ${result} != 0 ]]; then
2664 eerror "Incorrect bytecode version found"
2665 [[ -n "${1}" ]] && eerror "in file: ${1}"
2666 eerror "See ${log} for more details."
2667 die "Incorrect bytecode found"
2668 fi
2669}
2670
2671# ----------------------------------------------------------------------------
2672# @internal-function java-pkg_ensure-dep
2673# Check that a package being used in jarfrom, getjars and getjar is contained
2674# within DEPEND or RDEPEND.
2675# @param $1 - empty - check both vars; "runtime" or "build" - check only
2676# RDEPEND, resp. DEPEND
2677# @param $2 - Package name and slot.
2678
2679java-pkg_ensure-dep() {
2680 debug-print-function ${FUNCNAME} $*
2681
2682 local limit_to="${1}"
2683 local target_pkg="${2}"
2684 local dev_error=""
2685
2686 local stripped_pkg=$(echo "${target_pkg}" | sed \
2687 's/-[0-9]*\(\.[0-9]\)*$//')
2688
2689 debug-print "Matching against: ${stripped_pkg}"
2690
2691 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2692 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2693 dev_error="${dev_error} declared in DEPEND."
2694 if is-java-strict; then
2695 eerror "${dev_error}"
2696 die "${dev_error}"
2697 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2698 eerror "${dev_error}"
2699 elog "Because you have this package installed the package will"
2700 elog "build without problems, but please report this to"
2701 elog "http://bugs.gentoo.org"
1793 fi 2702 fi
1794} 2703 fi
1795 2704
2705 if [[ ${limit_to} != build ]]; then
2706 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2707 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2708 dev_error="The ebuild is attempting to use ${target_pkg},"
2709 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2710 dev_error="${dev_error} or PDEPEND."
2711 if is-java-strict; then
2712 eerror "${dev_error}"
2713 die "${dev_error}"
2714 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2715 eerror "${dev_error}"
2716 elog "The package will build without problems, but may fail to run"
2717 elog "if you don't have ${target_pkg} installed, so please report"
2718 elog "this to http://bugs.gentoo.org"
2719 fi
2720 fi
2721 fi
2722 fi
2723}
1796 2724
1797# ------------------------------------------------------------------------------ 2725# ------------------------------------------------------------------------------
1798# @section-end internal 2726# @section-end internal
1799# ------------------------------------------------------------------------------ 2727# ------------------------------------------------------------------------------
1800 2728
1801java-pkg_check-phase() { 2729java-pkg_check-phase() {
1802 local phase=${1} 2730 local phase=${1}
1803 local funcname=${2} 2731 local funcname=${FUNCNAME[1]}
1804 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2732 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1805 java-pkg_announce-qa-violation \
1806 "${funcname} used outside of src_${phase}" 2733 local msg="${funcname} used outside of src_${phase}"
2734 java-pkg_announce-qa-violation "${msg}"
1807 fi 2735 fi
1808} 2736}
1809 2737
1810java-pkg_check-versioned-jar() { 2738java-pkg_check-versioned-jar() {
1811 local jar=${1} 2739 local jar=${1}
1820 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2748 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1821 fi 2749 fi
1822} 2750}
1823 2751
1824java-pkg_announce-qa-violation() { 2752java-pkg_announce-qa-violation() {
1825 if is-java-strict; then 2753 local nodie
2754 if [[ ${1} == "--nodie" ]]; then
2755 nodie="true"
2756 shift
2757 fi
1826 echo "Java QA Notice: $@" >&2 2758 echo "Java QA Notice: $@" >&2
1827 increment-qa-violations 2759 increment-qa-violations
1828 fi 2760 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1829} 2761}
1830 2762
1831increment-qa-violations() { 2763increment-qa-violations() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 2764 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 2765 export JAVA_PKG_QA_VIOLATIONS
1834} 2766}
1835 2767
1836is-java-strict() { 2768is-java-strict() {
1837 hasq java-strict ${FEATURES}; 2769 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 2770 return $?
1839} 2771}
1840 2772
2773
1841# ------------------------------------------------------------------------------ 2774# ------------------------------------------------------------------------------
1842# @eclass-end 2775# @eclass-end
1843# ------------------------------------------------------------------------------ 2776# ------------------------------------------------------------------------------

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.127

  ViewVC Help
Powered by ViewVC 1.1.20