/[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.22 Revision 1.129
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.129 2009/06/07 08:22:42 ali_bush 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
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27 27
28IUSE="elibc_FreeBSD"
29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
32# Summary of variables which control the behavior of building Java packges. 34# Summary of variables which control the behavior of building Java packges.
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#
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.
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
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
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
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#
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 to java' 692# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to 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}"
545 local var_tmp="${T}/launcher_variables_tmp" 713 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 714 local target_dir pre
547 shift
548 715
549 # Process the other the rest of the arguments 716 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 717 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 718 local var="${1}" value="${2}"
552 if [[ "${var:0:2}" == "--" ]]; then 719 if [[ "${var:0:2}" == "--" ]]; then
720 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 721 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
722 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 723 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 724 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 725 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 726 pre="${value}"
558 fi 727 fi
559 shift 2 728 shift 2
560 done 729 done
561 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
562 # Write the actual script 745 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 746 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${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
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 754 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
566 cat "${var_tmp}" >> "${target}" 755 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}" 756 rm -f "${var_tmp}"
568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 757 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
569 758
661# 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
662# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 851# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building 852# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar 853# java-pkg_jar-from --build-only junit junit.jar
665# 854#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into 855# @param $opt
667# package.env DEPEND line. 856# --build-only - makes the jar(s) not added into package.env DEPEND line.
668# @param $1 - Package to get jars from. 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.
669# @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.
670# @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
671# symlink. Defaults to the name of the jar. 867# symlink. Defaults to the name of the jar.
672# ------------------------------------------------------------------------------ 868# ------------------------------------------------------------------------------
673# TODO could probably be cleaned up a little 869# TODO could probably be cleaned up a little
674java-pkg_jar-from() { 870java-pkg_jar-from() {
675 debug-print-function ${FUNCNAME} $* 871 debug-print-function ${FUNCNAME} $*
676 872
677 local build_only="" 873 local build_only=""
874 local destdir="."
875 local deep=""
876 local virtual=""
877 local record_jar=""
678 878
879 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
880
881 while [[ "${1}" == --* ]]; do
679 if [[ "${1}" = "--build-only" ]]; then 882 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true" 883 build_only="build"
884 elif [[ "${1}" = "--with-dependencies" ]]; then
885 deep="--with-dependencies"
886 elif [[ "${1}" = "--virtual" ]]; then
887 virtual="true"
888 elif [[ "${1}" = "--into" ]]; then
889 destdir="${2}"
890 shift
891 else
892 die "java-pkg_jar-from called with unknown parameter: ${1}"
893 fi
681 shift 894 shift
682 fi 895 done
683 896
684 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 897 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
685 898
686 [[ -z ${target_pkg} ]] && die "Must specify a package" 899 [[ -z ${target_pkg} ]] && die "Must specify a package"
900
901 if [[ "${EAPI}" == "1" ]]; then
902 target_pkg="${target_pkg//:/-}"
903 fi
687 904
688 # default destjar to the target jar 905 # default destjar to the target jar
689 [[ -z "${destjar}" ]] && destjar="${target_jar}" 906 [[ -z "${destjar}" ]] && destjar="${target_jar}"
690 907
691 local error_msg="There was a problem getting the classpath for ${target_pkg}." 908 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath 909 local classpath
693 classpath="$(java-config --classpath=${target_pkg})" 910 classpath="$(java-config ${deep} --classpath=${target_pkg})"
694 [[ $? != 0 ]] && die ${error_msg} 911 [[ $? != 0 ]] && die ${error_msg}
912
913 # When we have commas this functions is called to bring jars from multiple
914 # packages. This affects recording of dependencencies performed later
915 # which expects one package only, so we do it here.
916 if [[ ${target_pkg} = *,* ]]; then
917 for pkg in ${target_pkg//,/ }; do
918 java-pkg_ensure-dep "${build_only}" "${pkg}"
919 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
920 done
921 # setting this disables further record-jar_ calls later
922 record_jar="true"
923 else
924 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
925 fi
926
927 # Record the entire virtual as a dependency so that
928 # no jars are missed.
929 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
930 java-pkg_record-jar_ "${target_pkg}"
931 # setting this disables further record-jars_ calls later
932 record_jar="true"
933 fi
934
935 pushd ${destdir} > /dev/null \
936 || die "failed to change directory to ${destdir}"
695 937
696 local jar 938 local jar
697 for jar in ${classpath//:/ }; do 939 for jar in ${classpath//:/ }; do
698 local jar_name=$(basename "${jar}") 940 local jar_name=$(basename "${jar}")
699 if [[ ! -f "${jar}" ]] ; then 941 if [[ ! -f "${jar}" ]] ; then
703 # If no specific target jar was indicated, link it 945 # If no specific target jar was indicated, link it
704 if [[ -z "${target_jar}" ]] ; then 946 if [[ -z "${target_jar}" ]] ; then
705 [[ -f "${target_jar}" ]] && rm "${target_jar}" 947 [[ -f "${target_jar}" ]] && rm "${target_jar}"
706 ln -snf "${jar}" \ 948 ln -snf "${jar}" \
707 || die "Failed to make symlink from ${jar} to ${jar_name}" 949 || die "Failed to make symlink from ${jar} to ${jar_name}"
950 if [[ -z "${record_jar}" ]]; then
951 if [[ -z "${build_only}" ]]; then
708 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 952 java-pkg_record-jar_ "${target_pkg}" "${jar}"
953 else
954 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
955 fi
956 fi
709 # otherwise, if the current jar is the target jar, link it 957 # otherwise, if the current jar is the target jar, link it
710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 958 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
711 [[ -f "${destjar}" ]] && rm "${destjar}" 959 [[ -f "${destjar}" ]] && rm "${destjar}"
712 ln -snf "${jar}" "${destjar}" \ 960 ln -snf "${jar}" "${destjar}" \
713 || die "Failed to make symlink from ${jar} to ${destjar}" 961 || die "Failed to make symlink from ${jar} to ${destjar}"
962 if [[ -z "${record_jar}" ]]; then
963 if [[ -z "${build_only}" ]]; then
714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 964 java-pkg_record-jar_ "${target_pkg}" "${jar}"
965 else
966 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}"
967 fi
968 fi
969 popd > /dev/null
715 return 0 970 return 0
716 fi 971 fi
717 done 972 done
973 popd > /dev/null
718 # if no target was specified, we're ok 974 # if no target was specified, we're ok
719 if [[ -z "${target_jar}" ]] ; then 975 if [[ -z "${target_jar}" ]] ; then
720 return 0 976 return 0
721 # otherwise, die bitterly 977 # otherwise, die bitterly
722 else 978 else
741# The providing packages are recorded as dependencies into package.env DEPEND 997# The providing packages are recorded as dependencies into package.env DEPEND
742# line, unless "--build-only" is passed as the very first argument, for jars 998# line, unless "--build-only" is passed as the very first argument, for jars
743# that have to be present only at build time and are not needed on runtime 999# that have to be present only at build time and are not needed on runtime
744# (junit testing etc). 1000# (junit testing etc).
745# 1001#
746# Example: Get the classpath for xerces-2, 1002# Example: Get the classpath for xerces-2 and xalan,
747# java-pkg_getjars xerces-2 xalan 1003# java-pkg_getjars xerces-2,xalan
748# Example Return: 1004# Example Return:
749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 1005# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
750# 1006#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into 1007# @param $opt
752# package.env DEPEND line. 1008# --build-only - makes the jar(s) not added into package.env DEPEND line.
1009# (assumed automatically when called inside src_test)
1010# --with-dependencies - get jars also from requested package's dependencies
1011# transitively.
753# @param $@ - list of packages to get jars from 1012# @param $1 - list of packages to get jars from
1013# (passed to java-config --classpath)
754# ------------------------------------------------------------------------------ 1014# ------------------------------------------------------------------------------
755java-pkg_getjars() { 1015java-pkg_getjars() {
756 debug-print-function ${FUNCNAME} $* 1016 debug-print-function ${FUNCNAME} $*
757 1017
758 local build_only="" 1018 local build_only=""
1019 local deep=""
759 1020
1021 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1022
1023 while [[ "${1}" == --* ]]; do
760 if [[ "${1}" = "--build-only" ]]; then 1024 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true" 1025 build_only="build"
1026 elif [[ "${1}" = "--with-dependencies" ]]; then
1027 deep="--with-dependencies"
1028 else
1029 die "java-pkg_jar-from called with unknown parameter: ${1}"
1030 fi
762 shift 1031 shift
763 fi 1032 done
764 1033
765 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1034 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
766 1035
767 # NOTE could probably just pass $@ to java-config --classpath. and return it 1036
768 local classpath pkg 1037 local pkgs="${1}"
769 for pkg in ${@//,/ }; do 1038
770 #for pkg in $(echo "$@" | tr ',' ' '); do 1039 if [[ "${EAPI}" == "1" ]]; then
1040 pkgs="${pkgs//:/-}"
1041 fi
1042
771 jars="$(java-config --classpath=${pkg})" 1043 jars="$(java-config ${deep} --classpath=${pkgs})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed" 1044 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
773 debug-print "${pkg}:${jars}" 1045 debug-print "${pkgs}:${jars}"
774 1046
1047 for pkg in ${pkgs//,/ }; do
1048 java-pkg_ensure-dep "${build_only}" "${pkg}"
1049 done
1050
1051 for pkg in ${pkgs//,/ }; do
775 if [[ -z "${classpath}" ]]; then 1052 if [[ -z "${build_only}" ]]; then
776 classpath="${jars}" 1053 java-pkg_record-jar_ "${pkg}"
777 else 1054 else
778 classpath="${classpath}:${jars}" 1055 java-pkg_record-jar_ --build-only "${pkg}"
779 fi 1056 fi
780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
782 done 1057 done
783 echo "${classpath}" 1058
1059 echo "${jars}"
784} 1060}
785 1061
786# ------------------------------------------------------------------------------ 1062# ------------------------------------------------------------------------------
787# @ebuild-function java-pkg_getjar 1063# @ebuild-function java-pkg_getjar
788# 1064#
795# @example 1071# @example
796# java-pkg_getjar xerces-2 xml-apis.jar 1072# java-pkg_getjar xerces-2 xml-apis.jar
797# @example-return 1073# @example-return
798# /usr/share/xerces-2/lib/xml-apis.jar 1074# /usr/share/xerces-2/lib/xml-apis.jar
799# 1075#
800# @param $1 - (optional) "--build-only" makes the jar not added into 1076# @param $opt
801# package.env DEPEND line. 1077# --build-only - makes the jar not added into package.env DEPEND line.
1078# --virtual - Packages passed to this function are to be handled as virtuals
1079# and will not have individual jar dependencies recorded.
802# @param $1 - package to use 1080# @param $1 - package to use
803# @param $2 - jar to get 1081# @param $2 - jar to get
804# ------------------------------------------------------------------------------ 1082# ------------------------------------------------------------------------------
805java-pkg_getjar() { 1083java-pkg_getjar() {
806 debug-print-function ${FUNCNAME} $* 1084 debug-print-function ${FUNCNAME} $*
807 1085
808 local build_only="" 1086 local build_only=""
1087 local virtual=""
1088 local record_jar=""
809 1089
1090 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1091
1092 while [[ "${1}" == --* ]]; do
810 if [[ "${1}" = "--build-only" ]]; then 1093 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true" 1094 build_only="build"
1095 elif [[ "${1}" == "--virtual" ]]; then
1096 virtual="true"
1097 else
1098 die "java-pkg_getjar called with unknown parameter: ${1}"
1099 fi
812 shift 1100 shift
813 fi 1101 done
1102
1103 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
814 1104
815 local pkg="${1}" target_jar="${2}" jar 1105 local pkg="${1}" target_jar="${2}" jar
1106
1107 if [[ "${EAPI}" == "1" ]]; then
1108 pkg="${pkg//:/-}"
1109 fi
1110
816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1111 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
817 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1112 [[ -z ${target_jar} ]] && die "Must specify jar to get"
818 1113
819 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1114 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
820 local classpath 1115 local classpath
821 classpath=$(java-config --classpath=${pkg}) 1116 classpath=$(java-config --classpath=${pkg})
822 [[ $? != 0 ]] && die ${error_msg} 1117 [[ $? != 0 ]] && die ${error_msg}
823 1118
1119 java-pkg_ensure-dep "${build_only}" "${pkg}"
1120
1121 # Record the package(Virtual) as a dependency and then set build_only
1122 # So that individual jars are not recorded.
1123 if [[ -n "${virtual}" ]]; then
1124 if [[ -z "${build_only}" ]]; then
1125 java-pkg_record-jar_ "${pkg}"
1126 else
1127 java-pkg_record-jar_ --build-only "${pkg}"
1128 fi
1129 record_jar="true"
1130 fi
1131
824 for jar in ${classpath//:/ }; do 1132 for jar in ${classpath//:/ }; do
825 if [[ ! -f "${jar}" ]] ; then 1133 if [[ ! -f "${jar}" ]] ; then
826 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1134 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
827 fi 1135 fi
828 1136
829 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1137 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
830 # Only record jars that aren't build-only 1138 # Only record jars that aren't build-only
831 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}" 1139 if [[ -z "${record_jar}" ]]; then
1140 if [[ -z "${build_only}" ]]; then
1141 java-pkg_record-jar_ "${pkg}" "${jar}"
1142 else
1143 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1144 fi
1145 fi
832 echo "${jar}" 1146 echo "${jar}"
833 return 0 1147 return 0
834 fi 1148 fi
835 done 1149 done
836 1150
837 die "Could not find ${target_jar} in ${pkg}" 1151 die "Could not find ${target_jar} in ${pkg}"
838 return 1 1152 return 1
1153}
1154
1155# ------------------------------------------------------------------------------
1156# @ebuild-function java-pkg_register-dependency
1157#
1158# Registers runtime dependency on a package, list of packages, or a single jar
1159# from a package, into package.env DEPEND line. Can only be called in
1160# src_install phase.
1161# Intended for binary packages where you don't need to symlink the jars or get
1162# their classpath during build. As such, the dependencies only need to be
1163# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1164#
1165# @param $1 - comma-separated list of packages, or a single package
1166# @param $2 - if param $1 is a single package, optionally specify the jar
1167# to depend on
1168#
1169# Example: Record the dependency on whole xerces-2 and xalan,
1170# java-pkg_register-dependency xerces-2,xalan
1171# Example: Record the dependency on ant.jar from ant-core
1172# java-pkg_register-dependency ant-core ant.jar
1173#
1174# Note: Passing both list of packages as the first parameter AND specifying the
1175# jar as the second is not allowed and will cause the function to die. We assume
1176# that there's more chance one passes such combination as a mistake, than that
1177# there are more packages providing identically named jar without class
1178# collisions.
1179# ------------------------------------------------------------------------------
1180java-pkg_register-dependency() {
1181 debug-print-function ${FUNCNAME} $*
1182
1183 java-pkg_check-phase install
1184
1185 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1186
1187 local pkgs="${1}"
1188 local jar="${2}"
1189
1190 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1191
1192 if [[ "${EAPI}" == "1" ]]; then
1193 pkgs="${pkgs//:/-}"
1194 fi
1195
1196 if [[ -z "${jar}" ]]; then
1197 for pkg in ${pkgs//,/ }; do
1198 java-pkg_ensure-dep runtime "${pkg}"
1199 java-pkg_record-jar_ "${pkg}"
1200 done
1201 else
1202 [[ ${pkgs} == *,* ]] && \
1203 die "${FUNCNAME} called with both package list and jar name"
1204 java-pkg_ensure-dep runtime "${pkgs}"
1205 java-pkg_record-jar_ "${pkgs}" "${jar}"
1206 fi
1207
1208 java-pkg_do_write_
1209}
1210
1211# ------------------------------------------------------------------------------
1212# @ebuild-function java-pkg_register-optional-dependency
1213#
1214# Registers optional runtime dependency on a package, list of packages, or a
1215# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1216# called in src_install phase.
1217# Intended for packages that can use other packages when those are in classpath.
1218# Will be put on classpath by launcher if they are installed. Typical case is
1219# JDBC implementations for various databases. It's better than having USE flag
1220# for each implementation triggering hard dependency.
1221#
1222# @param $1 - comma-separated list of packages, or a single package
1223# @param $2 - if param $1 is a single package, optionally specify the jar
1224# to depend on
1225#
1226# Example: Record the optional dependency on some jdbc providers
1227# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1228#
1229# Note: Passing both list of packages as the first parameter AND specifying the
1230# jar as the second is not allowed and will cause the function to die. We assume
1231# that there's more chance one passes such combination as a mistake, than that
1232# there are more packages providing identically named jar without class
1233# collisions.
1234# ------------------------------------------------------------------------------
1235java-pkg_register-optional-dependency() {
1236 debug-print-function ${FUNCNAME} $*
1237
1238 java-pkg_check-phase install
1239
1240 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1241
1242 local pkgs="${1}"
1243 local jar="${2}"
1244
1245 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1246
1247 if [[ "${EAPI}" == "1" ]]; then
1248 pkgs="${pkgs//:/-}"
1249 fi
1250
1251 if [[ -z "${jar}" ]]; then
1252 for pkg in ${pkgs//,/ }; do
1253 java-pkg_record-jar_ --optional "${pkg}"
1254 done
1255 else
1256 [[ ${pkgs} == *,* ]] && \
1257 die "${FUNCNAME} called with both package list and jar name"
1258 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1259 fi
1260
1261 java-pkg_do_write_
1262}
1263
1264# ------------------------------------------------------------------------------
1265# @ebuild-function java-pkg_register-environment-variable
1266#
1267# Register an arbitrary environment variable into package.env. The gjl launcher
1268# for this package or any package depending on this will export it into
1269# environement before executing java command.
1270# Must only be called in src_install phase.
1271#
1272# @param $1 - variable name
1273# @param $2 - variable value
1274# ------------------------------------------------------------------------------
1275JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1276JAVA_PKG_EXTRA_ENV_VARS=""
1277java-pkg_register-environment-variable() {
1278 debug-print-function ${FUNCNAME} $*
1279
1280 java-pkg_check-phase install
1281
1282 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1283
1284 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1285 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1286
1287 java-pkg_do_write_
839} 1288}
840 1289
841# This function reads stdin, and based on that input, figures out how to 1290# This function reads stdin, and based on that input, figures out how to
842# populate jars from the filesystem. 1291# populate jars from the filesystem.
843# Need to figure out a good way of making use of this, ie be able to use a 1292# Need to figure out a good way of making use of this, ie be able to use a
884# 1333#
885# Various other functions to use from an ebuild 1334# Various other functions to use from an ebuild
886# ------------------------------------------------------------------------------ 1335# ------------------------------------------------------------------------------
887 1336
888# ------------------------------------------------------------------------------ 1337# ------------------------------------------------------------------------------
889# @ebuild-function java-pkg_need 1338# @ebuild-function java-pkg_find-normal-jars
890# 1339#
891# Adds virtual dependencies, which can optionally be controlled by a USE flag. 1340# Find the files with suffix .jar file in the given directory or $WORKDIR
892# Currently supported virtuals are:
893# javamail
894# jdbc-stdext
895# jaf
896# jdbc-rowset
897# jms
898# 1341#
899# @param $1 - Optionally indicate that the dependencies are controlled by 1342# @param $1 - The directory to search for jar files (default: ${WORKDIR})
900# a use flag by specifying '--use' Requires $2.
901# @param $2 - USE flag which will enable the dependencies.
902# @param $@ - virtual packages to add depenedencies for
903# ------------------------------------------------------------------------------ 1343# ------------------------------------------------------------------------------
904# TODO rewrite to parse a line based declaration file instead -- karltk 1344java-pkg_find-normal-jars() {
905#java-pkg_need() { 1345 local dir=$1
906# debug-print-function ${FUNCNAME} $* 1346 [[ "${dir}" ]] || dir="${WORKDIR}"
907# local useflag 1347 local found
908# if [[ ${1} == "--use" ]]; then 1348 for jar in $(find "${dir}" -name "*.jar" -type f); do
909# useflag="${2}" 1349 echo "${jar}"
910# shift 2 1350 found="true"
911# fi
912#
913# if [[ -z ${1} ]]; then
914# die "Must specify at least one virtual package."
915# fi
916#
917# local depstr newdepstr
918#
919# for virtual in ${@}; do
920# if has ${virtual} ${JAVA_PKG_VNEED}; then
921# debug-print "Already registered virtual ${virtual}"
922# continue
923# fi
924# case ${virtual} in
925# javamail)
926# debug-print "java-pkg_need: adding javamail dependencies"
927# newdepstr="|| ( dev-java/gnu-javamail dev-java/sun-javamail-bin )"
928# ;;
929# jdbc-stdext)
930# debug-print "java-pkg_need: adding jdbc-stdext dependencies"
931# newdepstr="|| ( >=virtual/jdk-1.4 dev-java/jdbc2-stdext )"
932# ;;
933# jaf)
934# debug-print "java-pkg_need: adding jaf dependencies"
935# newdepstr="|| ( dev-java/gnu-jaf dev-java/sun-jaf-bin )"
936# ;;
937# jdbc-rowset)
938# debug-print "java-pkg_need: adding jdbc-rowset dependencies"
939# newdepstr="|| ( >=virtual/jdk-1.5 dev-java/sun-jdbc-rowset )"
940# ;;
941# jms)
942# debug-print "java-pkg_need: adding jms dependencies"
943# newdepstr="|| ( dev-java/sun-jms dev-java/openjms )"
944# ;;
945# *)
946# die "Invalid virtual: ${virtual}"
947# esac
948#
949# export JAVA_PKG_VNEED="${JAVA_PKG_VNEED} ${virtual}"
950#
951# if [[ -n ${useflag} ]]; then
952# depstr="${depstr} ${useflag}? ( ${newdepstr} )"
953# else
954# depstr="${depstr} ${newdepstr}"
955# fi
956# done 1351 done
957# 1352 [[ "${found}" ]]
958# [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}" 1353 return $?
959# [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}" 1354}
960#
961# export DEPEND="${DEPEND} ${depstr}"
962# export RDEPEND="${RDEPEND} ${depstr}"
963#}
964 1355
1356# ------------------------------------------------------------------------------
1357# @ebuild-function java-pkg_ensure-no-bundled-jars
1358#
1359# Try to locate bundled jar files in ${WORKDIR} and die if found.
965# This should be used after S has been populated with symlinks to jars 1360# This function should be called after WORKDIR has been populated with symlink
966# TODO document 1361# to system jar files or bundled jars removed.
1362# ------------------------------------------------------------------------------
967java-pkg_ensure-no-bundled-jars() { 1363java-pkg_ensure-no-bundled-jars() {
968 debug-print-function ${FUNCNAME} $* 1364 debug-print-function ${FUNCNAME} $*
969 pushd ${WORKDIR} >/dev/null 2>/dev/null
970 1365
971 local bundled_jars=$(find . -name "*.jar" -type f) 1366 local bundled_jars=$(java-pkg_find-normal-jars)
972 if [[ -n ${bundled_jars} ]]; then 1367 if [[ -n ${bundled_jars} ]]; then
973 echo "Bundled jars found:" 1368 echo "Bundled jars found:"
974 local jar 1369 local jar
975 for jar in ${bundled_jars}; do 1370 for jar in ${bundled_jars}; do
976 echo $(pwd)${jar/./} 1371 echo $(pwd)${jar/./}
977 done 1372 done
978 die "Bundled jars found!" 1373 die "Bundled jars found!"
979
980 fi 1374 fi
981 popd >/dev/null 2>/dev/null
982} 1375}
983 1376
984# ------------------------------------------------------------------------------ 1377# ------------------------------------------------------------------------------
985# @internal-function java-pkg_ensure-vm-version-sufficient 1378# @internal-function java-pkg_ensure-vm-version-sufficient
986# 1379#
1135# @ebuild-function java-pkg_get-target 1528# @ebuild-function java-pkg_get-target
1136# 1529#
1137# Determines what target version should be used, for passing to -target. 1530# Determines what target version should be used, for passing to -target.
1138# If you don't care about lower versions, you can set _WANT_TARGET to the 1531# If you don't care about lower versions, you can set _WANT_TARGET to the
1139# version of your JDK. 1532# version of your JDK.
1140# Remember doing this will mostly like cause things to break.
1141# Doesn't allow it to be lower then the one in depend.
1142# Doesn't allow it to be higher then the active vm.
1143# 1533#
1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1534# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1145# ------------------------------------------------------------------------------ 1535# ------------------------------------------------------------------------------
1146java-pkg_get-target() { 1536java-pkg_get-target() {
1147 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1148 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1149 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1150 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1151 echo ${JAVA_PKG_WANT_TARGET}
1152 else
1153 echo ${min}
1154 fi
1155 else
1156 echo ${min}
1157 fi
1158
1159 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1537 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1160} 1538}
1161 1539
1162java-pkg_get-javac() { 1540java-pkg_get-javac() {
1163 debug-print-function ${FUNCNAME} $* 1541 debug-print-function ${FUNCNAME} $*
1164 1542
1165 java-pkg_init-compiler_ 1543
1166 local compiler="${GENTOO_COMPILER}" 1544 local compiler="${GENTOO_COMPILER}"
1167 1545
1168 local compiler_executable 1546 local compiler_executable
1169 if [[ "${compiler}" = "javac" ]]; then 1547 if [[ "${compiler}" = "javac" ]]; then
1170 # nothing fancy needs to be done for javac 1548 # nothing fancy needs to be done for javac
1178 unset JAVAC 1556 unset JAVAC
1179 # try to get value of JAVAC 1557 # try to get value of JAVAC
1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1558 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1181 export JAVAC=${old_javac} 1559 export JAVAC=${old_javac}
1182 1560
1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1561 if [[ -z ${compiler_executable} ]]; then
1562 echo "JAVAC is empty or undefined in ${compiler_env}"
1563 return 1
1564 fi
1184 1565
1185 # check that it's executable 1566 # check that it's executable
1186 if [[ ! -x ${compiler_executable} ]]; then 1567 if [[ ! -x ${compiler_executable} ]]; then
1187 eerror "Could not find ${compiler_executable}!"
1188 die "${compiler_executable} doesn't exist, or isn't executable" 1568 echo "${compiler_executable} doesn't exist, or isn't executable"
1569 return 1
1189 fi 1570 fi
1190 else 1571 else
1191 eerror "Could not find environment file for ${compiler}" 1572 echo "Could not find environment file for ${compiler}"
1192 die "Could not find ${compiler_env}" 1573 return 1
1193 fi 1574 fi
1194 fi 1575 fi
1195 echo ${compiler_executable} 1576 echo ${compiler_executable}
1196} 1577}
1197 1578
1214 1595
1215 debug-print "want source: ${want_source}" 1596 debug-print "want source: ${want_source}"
1216 debug-print "want target: ${want_target}" 1597 debug-print "want target: ${want_target}"
1217 1598
1218 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1599 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1219 debug-print "could not find valid -source/-target values" 1600 debug-print "could not find valid -source/-target values for javac"
1220 die "Could not find valid -source/-target values" 1601 echo "Could not find valid -source/-target values for javac"
1602 return 1
1221 else 1603 else
1222 if java-pkg_is-vm-version-ge "1.4"; then 1604 if java-pkg_is-vm-version-ge "1.4"; then
1223 echo "${source_str} ${target_str}" 1605 echo "${source_str} ${target_str}"
1224 else 1606 else
1225 echo "${target_str}" 1607 echo "${target_str}"
1229 1611
1230# TODO document 1612# TODO document
1231java-pkg_get-jni-cflags() { 1613java-pkg_get-jni-cflags() {
1232 local flags="-I${JAVA_HOME}/include" 1614 local flags="-I${JAVA_HOME}/include"
1233 1615
1616 local platform="linux"
1617 use elibc_FreeBSD && platform="freebsd"
1618
1234 # TODO do a check that the directories are valid 1619 # TODO do a check that the directories are valid
1235 # TODO figure out how to cope with other things than linux...
1236 flags="${flags} -I${JAVA_HOME}/include/linux" 1620 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1237 1621
1238 echo ${flags} 1622 echo ${flags}
1239} 1623}
1240 1624
1241java-pkg_ensure-gcj() { 1625java-pkg_ensure-gcj() {
1247 die "No GCJ support found!" 1631 die "No GCJ support found!"
1248 fi 1632 fi
1249} 1633}
1250 1634
1251java-pkg_ensure-test() { 1635java-pkg_ensure-test() {
1252 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1636 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1637 && hasq test ${IUSE} && ! use test;
1638 then
1253 eerror "You specified FEATURES=test, but USE=test is needed" 1639 eerror "You specified FEATURES=test, but USE=test is needed"
1254 eerror "to pull in the additional dependencies for testing" 1640 eerror "to pull in the additional dependencies for testing"
1255 die "Need USE=test enabled" 1641 die "Need USE=test enabled"
1256 fi 1642 fi
1257} 1643}
1258 1644
1259# ------------------------------------------------------------------------------ 1645# ------------------------------------------------------------------------------
1646# @ebuild-function java-pkg_register-ant-task
1647#
1648# Register this package as ant task, so that ant will load it when no specific
1649# ANT_TASKS are specified. Note that even without this registering, all packages
1650# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1651# packages, but can be also used by other ebuilds that used to symlink their
1652# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1653# compatibility.
1654#
1655# @param --version x.y Register only for ant version x.y (otherwise for any ant
1656# version). Used by the ant-* packages to prevent loading of mismatched
1657# ant-core ant tasks after core was updated, before the tasks are updated,
1658# without a need for blockers.
1659# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1660# ------------------------------------------------------------------------------
1661java-pkg_register-ant-task() {
1662 local TASKS_DIR="tasks"
1663
1664 # check for --version x.y parameters
1665 while [[ -n "${1}" && -n "${2}" ]]; do
1666 local var="${1#--}"
1667 local val="${2}"
1668 if [[ "${var}" == "version" ]]; then
1669 TASKS_DIR="tasks-${val}"
1670 else
1671 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1672 fi
1673 shift 2
1674 done
1675
1676 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1677
1678 dodir /usr/share/ant/${TASKS_DIR}
1679 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1680}
1681
1682# ------------------------------------------------------------------------------
1683# @internal-function java-pkg_ant-tasks-depend
1684#
1685# Translates the WANT_ANT_TASKS variable into valid dependencies.
1686# ------------------------------------------------------------------------------
1687java-pkg_ant-tasks-depend() {
1688 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1689
1690 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1691 local DEP=""
1692 for i in ${WANT_ANT_TASKS}
1693 do
1694 if [[ ${i} = ant-* ]]; then
1695 DEP="${DEP}dev-java/${i} "
1696 elif [[ ${i} = */*:* ]]; then
1697 DEP="${DEP}${i} "
1698 else
1699 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1700 return 1
1701 fi
1702 done
1703 echo ${DEP}
1704 return 0
1705 else
1706 return 0
1707 fi
1708}
1709
1710# ------------------------------------------------------------------------------
1711# @ebuild-function ejunit
1712#
1713# Junit wrapper function. Makes it easier to run the tests and checks for
1714# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1715#
1716# Examples:
1717# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1718# ejunit org.blinkenlights.jid3.test.AllTests
1719#
1720# @param $1 - -cp or -classpath
1721# @param $2 - classpath; junit and recorded dependencies get appended
1722# @param $@ - the rest of the parameters are passed to java
1723# ------------------------------------------------------------------------------
1724ejunit() {
1725 debug-print-function ${FUNCNAME} $*
1726
1727 local pkgs
1728 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1729 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1730 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1731 done
1732 fi
1733
1734 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1735 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1736 cp="${2}:${cp}"
1737 shift 2
1738 else
1739 cp=".:${cp}"
1740 fi
1741
1742 local runner=junit.textui.TestRunner
1743 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1744 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1745}
1746
1747# ------------------------------------------------------------------------------
1260# @section-end helper 1748# @section-end helper
1261# ------------------------------------------------------------------------------ 1749# ------------------------------------------------------------------------------
1750
1751# ------------------------------------------------------------------------------
1752# @eclass-src_prepare
1753#
1754# src_prepare Searches for bundled jars
1755# Don't call directly, but via java-pkg-2_src_prepare!
1756# ------------------------------------------------------------------------------
1757
1758java-utils-2_src_prepare() {
1759 [[ ${EBUILD_PHASE} == prepare ]] &&
1760 java-pkg_func-exists java_prepare && java_prepare
1761
1762 # Remember that eant will call this unless called via Portage
1763 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1764 echo "Searching for bundled jars:"
1765 java-pkg_find-normal-jars || echo "None found."
1766 echo "Searching for bundled classes (no output if none found):"
1767 find "${WORKDIR}" -name "*.class"
1768 echo "Search done."
1769 fi
1770 touch "${T}/java-utils-2_src_prepare-run"
1771}
1772
1773# ------------------------------------------------------------------------------
1774# @eclass-pkg_preinst
1775#
1776# pkg_preinst Searches for missing and unneeded dependencies
1777# Don't call directly, but via java-pkg-2_pkg_preinst!
1778# ------------------------------------------------------------------------------
1779
1780java-utils-2_pkg_preinst() {
1781 if is-java-strict; then
1782 if has_version dev-java/java-dep-check; then
1783 [[ -e "${JAVA_PKG_ENV}" ]] || return
1784 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1785 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1786 ewarn "Possibly unneeded dependencies found in package.env:"
1787 for dep in ${output}; do
1788 ewarn "\t${dep}"
1789 done
1790 fi
1791 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1792 ewarn "${output}"
1793 fi
1794 else
1795 eerror "Install dev-java/java-dep-check for dependency checking"
1796 fi
1797 fi
1798}
1262 1799
1263# ------------------------------------------------------------------------------ 1800# ------------------------------------------------------------------------------
1264# @section-begin build 1801# @section-begin build
1265# @section-summary Build functions 1802# @section-summary Build functions
1266# 1803#
1270 1807
1271# ------------------------------------------------------------------------------ 1808# ------------------------------------------------------------------------------
1272# @ebuild-function eant 1809# @ebuild-function eant
1273# 1810#
1274# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1811# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1275# compiler. 1812# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1276# 1813# variables:
1814# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1815# gentoo.classpath property. Be sure to call
1816# java-ant_rewrite-classpath in src_unpack.
1817# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1818# for build-time purposes, the dependency is not recorded to
1819# package.env!
1820# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1821# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1277# ------------------------------------------------------------------------------ 1822# ------------------------------------------------------------------------------
1278eant() { 1823eant() {
1279 debug-print-function ${FUNCNAME} $* 1824 debug-print-function ${FUNCNAME} $*
1280 1825
1281 # FIXME get this working 1826 if [[ ${EBUILD_PHASE} = compile ]]; then
1282# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1827 java-ant-2_src_configure
1828 java-utils-2_src_prepare
1829 fi
1830
1831 if ! hasq java-ant-2 ${INHERITED}; then
1832 local msg="You should inherit java-ant-2 when using eant"
1283# java-pkg_announce-qa-violation \ 1833 java-pkg_announce-qa-violation "${msg}"
1284# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1285# fi 1834 fi
1286 1835
1287 local antflags 1836 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1837
1288 java-pkg_init-compiler_ 1838 java-pkg_init-compiler_
1289 local compiler="${GENTOO_COMPILER}" 1839 local compiler="${GENTOO_COMPILER}"
1290 1840
1291 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1841 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1292
1293 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1842 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1294 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1843 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1295 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1844 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1296 fi 1845 fi
1297 1846
1298 if [[ ${compiler} != "javac" ]]; then 1847 if [[ ${compiler} != "javac" ]]; then
1299 antflags="-Dbuild.compiler=${build_compiler}" 1848 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1300 # Figure out any extra stuff to put on the classpath for compilers aside 1849 # Figure out any extra stuff to put on the classpath for compilers aside
1301 # from javac 1850 # from javac
1302 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1851 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1303 # java-config -p 1852 # java-config -p
1304 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1853 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1305 if [[ -n ${build_compiler_deps} ]]; then 1854 if [[ -n ${build_compiler_deps} ]]; then
1306 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1855 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1307 fi 1856 fi
1308 fi 1857 fi
1309 1858
1859 for arg in "${@}"; do
1860 if [[ ${arg} = -lib ]]; then
1310 if is-java-strict; then 1861 if is-java-strict; then
1311 einfo "Disabling system classpath for ant" 1862 eerror "You should not use the -lib argument to eant because it will fail"
1312 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1863 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1864 eerror "or ant properties to make dependencies available."
1865 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1866 eerror "split ant (>=dev-java/ant-core-1.7)."
1867 die "eant -lib is deprecated/forbidden"
1868 else
1869 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1870 echo "more info."
1871 fi
1313 fi 1872 fi
1873 done
1314 1874
1315 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1875 # parse WANT_ANT_TASKS for atoms
1316 antflags="${antflags} -debug" 1876 local want_ant_tasks
1877 for i in ${WANT_ANT_TASKS}; do
1878 if [[ ${i} = */*:* ]]; then
1879 i=${i#*/}
1880 i=${i%:0}
1881 want_ant_tasks+="${i/:/-} "
1882 else
1883 want_ant_tasks+="${i} "
1884 fi
1885 done
1886 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1887 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1888
1889 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1890 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1891
1892 # if ant-tasks is not set by ebuild or forced, use none
1893 ANT_TASKS="${ANT_TASKS:-none}"
1894
1895 # at this point, ANT_TASKS should be "all", "none" or explicit list
1896 if [[ "${ANT_TASKS}" == "all" ]]; then
1897 einfo "Using all available ANT_TASKS"
1898 elif [[ "${ANT_TASKS}" == "none" ]]; then
1899 einfo "Disabling all optional ANT_TASKS"
1900 else
1901 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1902 fi
1903
1904 export ANT_TASKS
1905
1906 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1907 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1908
1909 local gcp="${EANT_GENTOO_CLASSPATH}"
1910 local getjarsarg=""
1911
1912 if [[ ${EBUILD_PHASE} = "test" ]]; then
1913 antflags="${antflags} -DJunit.present=true"
1914 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1915 getjarsarg="--with-dependencies"
1916 fi
1917
1918 local cp
1919
1920 for atom in ${gcp}; do
1921 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1922 done
1923
1924 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
1925
1926 if [[ ${cp} ]]; then
1927 # It seems ant does not like single quotes around ${cp}
1928 cp=${cp#:}
1929 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1930 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1931 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1317 fi 1932 fi
1318 1933
1319 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1934 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1935 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1320 ant ${antflags} "${@}" || die "eant failed" 1936 ant ${antflags} "${@}" || die "eant failed"
1321
1322} 1937}
1323 1938
1324# ------------------------------------------------------------------------------ 1939# ------------------------------------------------------------------------------
1325# @ebuild-function ejavac 1940# @ebuild-function ejavac
1326# 1941#
1330# @param $@ - Arguments to be passed to the compiler 1945# @param $@ - Arguments to be passed to the compiler
1331# ------------------------------------------------------------------------------ 1946# ------------------------------------------------------------------------------
1332ejavac() { 1947ejavac() {
1333 debug-print-function ${FUNCNAME} $* 1948 debug-print-function ${FUNCNAME} $*
1334 1949
1335 # FIXME using get-javac ends up printing stuff with einfo 1950 java-pkg_init-compiler_
1951
1952 local compiler_executable
1336# local compiler_executable=$(java-pkg_get-javac) 1953 compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac" 1954 if [[ ${?} != 0 ]]; then
1955 eerror "There was a problem determining compiler: ${compiler_executable}"
1956 die "get-javac failed"
1957 fi
1338 1958
1959 local javac_args
1960 javac_args="$(java-pkg_javac-args)"
1961 if [[ ${?} != 0 ]]; then
1962 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1963 die "java-pkg_javac-args failed"
1964 fi
1965
1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1966 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1967 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1341} 1968}
1342 1969
1343# ------------------------------------------------------------------------------ 1970# ------------------------------------------------------------------------------
1344# @ebuild-function java-pkg_filter-compiler 1971# @ebuild-function java-pkg_filter-compiler
1345# 1972#
1383# ------------------------------------------------------------------------------ 2010# ------------------------------------------------------------------------------
1384use_doc() { 2011use_doc() {
1385 use doc && echo ${@:-javadoc} 2012 use doc && echo ${@:-javadoc}
1386} 2013}
1387 2014
2015
1388# ------------------------------------------------------------------------------ 2016# ------------------------------------------------------------------------------
1389# @section-end build 2017# @section-end build
1390# ------------------------------------------------------------------------------ 2018# ------------------------------------------------------------------------------
1391 2019
1392# ------------------------------------------------------------------------------ 2020# ------------------------------------------------------------------------------
1408# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2036# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1409# call it during each of the phases of the merge process. 2037# call it during each of the phases of the merge process.
1410# 2038#
1411# ----------------------------------------------------------------------------- 2039# -----------------------------------------------------------------------------
1412java-pkg_init() { 2040java-pkg_init() {
2041 debug-print-function ${FUNCNAME} $*
1413 unset JAVAC 2042 unset JAVAC
1414 unset JAVA_HOME 2043 unset JAVA_HOME
2044
2045 java-config --help >/dev/null || {
2046 eerror ""
2047 eerror "Can't run java-config --help"
2048 eerror "Have you upgraded python recently but haven't"
2049 eerror "run python-updater yet?"
2050 die "Can't run java-config --help"
2051 }
2052
2053 # People do all kinds of weird things.
2054 # http://forums.gentoo.org/viewtopic-p-3943166.html
2055 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2056 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2057 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2058 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2059 ewarn "sun-jdk vms and and as such break configure scripts that"
2060 ewarn "use it (for example app-office/openoffice) so we filter it out."
2061 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2062 ewarn "make.conf for example) to silence this warning or"
2063 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2064 fi
2065
2066 if [[ -z ${accept} ]]; then
2067 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2068 # -version output
2069 unset _JAVA_OPTIONS
2070 # phase hooks make this run many times without this
2071 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2072 fi
2073
2074 if java-pkg_func-exists ant_src_unpack; then
2075 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2076 fi
2077
1415 java-pkg_init_paths_ 2078 java-pkg_init_paths_
1416 java-pkg_switch-vm 2079 java-pkg_switch-vm
1417 PATH=${JAVA_HOME}/bin:${PATH} 2080 PATH=${JAVA_HOME}/bin:${PATH}
1418 2081
1419 # TODO we will probably want to set JAVAC and JAVACFLAGS 2082 # TODO we will probably want to set JAVAC and JAVACFLAGS
1420 2083
1421 # Do some QA checks 2084 # Do some QA checks
1422 java-pkg_check-jikes 2085 java-pkg_check-jikes
2086
2087 # Can't use unset here because Portage does not save the unset
2088 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1423 2089
1424 # When users have crazy classpaths some packages can fail to compile. 2090 # When users have crazy classpaths some packages can fail to compile.
1425 # and everything should work with empty CLASSPATH. 2091 # and everything should work with empty CLASSPATH.
1426 # This also helps prevent unexpected dependencies on random things 2092 # This also helps prevent unexpected dependencies on random things
1427 # from the CLASSPATH. 2093 # from the CLASSPATH.
1428 unset CLASSPATH 2094 export CLASSPATH=
2095
2096 # Unset external ANT_ stuff
2097 export ANT_TASKS=
2098 export ANT_OPTS=
2099 export ANT_RESPECT_JAVA_HOME=
1429} 2100}
1430 2101
1431# ------------------------------------------------------------------------------ 2102# ------------------------------------------------------------------------------
1432# @function-internal java-pkg-init-compiler_ 2103# @function-internal java-pkg-init-compiler_
1433# 2104#
1524 done 2195 done
1525 2196
1526 # If it hasn't been defined already, default to javac 2197 # If it hasn't been defined already, default to javac
1527 if [[ -z ${GENTOO_COMPILER} ]]; then 2198 if [[ -z ${GENTOO_COMPILER} ]]; then
1528 if [[ -n ${compilers} ]]; then 2199 if [[ -n ${compilers} ]]; then
1529 einfo "No suitable compiler found: defaulting javac for compilation" 2200 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1530 else 2201 else
1531 # probably don't need to notify users about the default. 2202 # probably don't need to notify users about the default.
1532 :;#einfo "Defaulting to javac for compilation" 2203 :;#einfo "Defaulting to javac for compilation"
1533 fi 2204 fi
2205 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2206 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2207 else
1534 export GENTOO_COMPILER=javac 2208 export GENTOO_COMPILER=javac
2209 fi
1535 else 2210 else
1536 einfo "Using ${GENTOO_COMPILER} for compilation" 2211 einfo "Using ${GENTOO_COMPILER} for compilation"
1537 fi 2212 fi
1538 2213
1539} 2214}
1555 fi 2230 fi
1556 2231
1557 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2232 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1558 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2233 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1559 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2234 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2235 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2236 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1560 2237
1561 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2238 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1562 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2239 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1563 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2240 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1564 2241
1577# Writes the package.env out to disk. 2254# Writes the package.env out to disk.
1578# 2255#
1579# ------------------------------------------------------------------------------ 2256# ------------------------------------------------------------------------------
1580# TODO change to do-write, to match everything else 2257# TODO change to do-write, to match everything else
1581java-pkg_do_write_() { 2258java-pkg_do_write_() {
2259 debug-print-function ${FUNCNAME} $*
2260 java-pkg_init_paths_
1582 # Create directory for package.env 2261 # Create directory for package.env
1583 dodir "${JAVA_PKG_SHAREPATH}" 2262 dodir "${JAVA_PKG_SHAREPATH}"
1584 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2263 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2264 "${JAVA_PKG_DEPEND_FILE}" || -f \
2265 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1585 # Create package.env 2266 # Create package.env
1586 ( 2267 (
1587 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2268 echo "DESCRIPTION=\"${DESCRIPTION}\""
1588 echo "GENERATION=\"2\"" 2269 echo "GENERATION=\"2\""
2270 echo "SLOT=\"${SLOT}\""
2271 echo "CATEGORY=\"${CATEGORY}\""
2272 echo "PVR=\"${PVR}\""
1589 2273
1590 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2274 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1591 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2275 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1592 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2276 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1593 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2277 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2278 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2279 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2280 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1594 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2281 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2282 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2283 && echo "BUILD_DEPEND=\"$(cat "${JAVA_PKG_BUILD_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1595 ) > "${JAVA_PKG_ENV}" 2284 ) > "${JAVA_PKG_ENV}"
1596 2285
1597 # register target/source 2286 # register target/source
1598 local target="$(java-pkg_get-target)" 2287 local target="$(java-pkg_get-target)"
1599 local source="$(java-pkg_get-source)" 2288 local source="$(java-pkg_get-source)"
1609 2298
1610 2299
1611 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2300 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1612 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2301 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1613 2302
2303 # extra env variables
2304 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2305 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2306 # nested echo to remove leading/trailing spaces
2307 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2308 >> "${JAVA_PKG_ENV}" || die
2309 fi
2310
1614 # Strip unnecessary leading and trailing colons 2311 # Strip unnecessary leading and trailing colons
1615 # TODO try to cleanup if possible 2312 # TODO try to cleanup if possible
1616 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2313 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2314 else
2315 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2316 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2317 debug-print "write package.env."
1617 fi 2318 fi
1618} 2319}
1619
1620 2320
1621# ------------------------------------------------------------------------------ 2321# ------------------------------------------------------------------------------
1622# @internal-function java-pkg_record-jar_ 2322# @internal-function java-pkg_record-jar_
1623# 2323#
1624# Record a dependency to the package.env 2324# Record an (optional) dependency to the package.env
1625# 2325# @param --optional - record dependency as optional
2326# @param --build - record dependency as build_only
2327# @param $1 - package to record
2328# @param $2 - (optional) jar of package to record
1626# ------------------------------------------------------------------------------ 2329# ------------------------------------------------------------------------------
1627JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2330JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2331JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2332JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
1628 2333
1629java-pkg_record-jar_() { 2334java-pkg_record-jar_() {
1630 debug-print-function ${FUNCNAME} $* 2335 debug-print-function ${FUNCNAME} $*
2336
2337 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2338 case "${1}" in
2339 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2340 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2341 esac
1631 2342
1632 local pkg=${1} jar=${2} append 2343 local pkg=${1} jar=${2} append
1633 if [[ -z "${jar}" ]]; then 2344 if [[ -z "${jar}" ]]; then
1634 append="${pkg}" 2345 append="${pkg}"
1635 else 2346 else
1636 append="$(basename ${jar})@${pkg}" 2347 append="$(basename ${jar})@${pkg}"
1637 fi 2348 fi
1638 2349
1639 echo ${append} >> ${JAVA_PKG_DEPEND} 2350 echo "${append}" >> "${depend_file}"
1640} 2351}
1641 2352
1642# ------------------------------------------------------------------------------ 2353# ------------------------------------------------------------------------------
1643# @internal-function java-pkg_append_ 2354# @internal-function java-pkg_append_
1644# 2355#
1688# 2399#
1689# @return 0 - function is declared 2400# @return 0 - function is declared
1690# @return 1 - function is undeclared 2401# @return 1 - function is undeclared
1691# ------------------------------------------------------------------------------ 2402# ------------------------------------------------------------------------------
1692java-pkg_func-exists() { 2403java-pkg_func-exists() {
1693 if [[ -n "$(declare -f ${1})" ]]; then 2404 declare -F ${1} > /dev/null
1694 return 0
1695 else
1696 return 1
1697 fi
1698} 2405}
1699 2406
1700# ------------------------------------------------------------------------------ 2407# ------------------------------------------------------------------------------
1701# @internal-function java-pkg_setup-vm 2408# @internal-function java-pkg_setup-vm
1702# 2409#
1704# 2411#
1705# ------------------------------------------------------------------------------ 2412# ------------------------------------------------------------------------------
1706java-pkg_setup-vm() { 2413java-pkg_setup-vm() {
1707 debug-print-function ${FUNCNAME} $* 2414 debug-print-function ${FUNCNAME} $*
1708 2415
2416 export LANG="C" LC_ALL="C"
2417
1709 local vendor="$(java-pkg_get-vm-vendor)" 2418 local vendor="$(java-pkg_get-vm-vendor)"
1710 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2419 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1711 addpredict "/dev/random" 2420 addpredict "/dev/random"
1712 elif [[ "${vendor}" == "ibm" ]]; then 2421 elif [[ "${vendor}" == "ibm" ]]; then
1713 addpredict "/proc/self/maps" 2422 addpredict "/proc/self/maps"
1714 addpredict "/proc/cpuinfo" 2423 addpredict "/proc/cpuinfo"
1715 export LANG="C" LC_ALL="C"
1716 elif [[ "${vendor}" == "jrockit" ]]; then 2424 elif [[ "${vendor}" == "jrockit" ]]; then
1717 addpredict "/proc/cpuinfo" 2425 addpredict "/proc/cpuinfo"
1718 fi 2426 fi
1719} 2427}
1720 2428
1775# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2483# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1776# verify that the current VM is sufficient. 2484# verify that the current VM is sufficient.
1777# Setup the environment for the VM being used. 2485# Setup the environment for the VM being used.
1778# ------------------------------------------------------------------------------ 2486# ------------------------------------------------------------------------------
1779java-pkg_switch-vm() { 2487java-pkg_switch-vm() {
2488 debug-print-function ${FUNCNAME} $*
2489
1780 if java-pkg_needs-vm; then 2490 if java-pkg_needs-vm; then
1781 # Use the VM specified by JAVA_PKG_FORCE_VM 2491 # Use the VM specified by JAVA_PKG_FORCE_VM
1782 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2492 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1783 # If you're forcing the VM, I hope you know what your doing... 2493 # If you're forcing the VM, I hope you know what your doing...
2494 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1784 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2495 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1785 # if we're allowed to switch the vm... 2496 # if we're allowed to switch the vm...
1786 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2497 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1787 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2498 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1788 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1789 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2499 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2500 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2501 eerror "Unable to determine VM for building from dependencies:"
2502 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2503 die "Failed to determine VM for building."
1790 else 2504 else
1791 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2505 export GENTOO_VM
1792 fi 2506 fi
1793 # otherwise just make sure the current VM is sufficient 2507 # otherwise just make sure the current VM is sufficient
1794 else 2508 else
1795 java-pkg_ensure-vm-version-sufficient 2509 java-pkg_ensure-vm-version-sufficient
1796 fi 2510 fi
1798 2512
1799 java-pkg_setup-vm 2513 java-pkg_setup-vm
1800 2514
1801 export JAVA=$(java-config --java) 2515 export JAVA=$(java-config --java)
1802 export JAVAC=$(java-config --javac) 2516 export JAVAC=$(java-config --javac)
1803 export JAVACFLAGS="$(java-pkg_javac-args)" 2517 JAVACFLAGS="$(java-pkg_javac-args)"
2518 if [[ ${?} != 0 ]]; then
2519 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2520 die "java-pkg_javac-args failed"
2521 fi
1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2522 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2523 export JAVACFLAGS
1805 2524
1806 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2525 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1807 export JDK_HOME=${JAVA_HOME} 2526 export JDK_HOME=${JAVA_HOME}
1808 2527
1809 #TODO If you know a better solution let us know. 2528 #TODO If you know a better solution let us know.
1810 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2529 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1811 2530
1812 local tann="${T}/announced-vm" 2531 local tann="${T}/announced-vm"
2532 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2533 # if people have for example modified eclasses some where
1813 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2534 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1814 # Add a check for setup/preinst phase... to avoid duplicate outputs
1815 # for when FEATURES=buildpkg
1816 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1817 then
1818 einfo "Using: $(java-config -f)" 2535 einfo "Using: $(java-config -f)"
1819 [[ ! -f "${tann}" ]] && touch "${tann}" 2536 [[ ! -f "${tann}" ]] && touch "${tann}"
1820 fi
1821 fi 2537 fi
1822 2538
1823 else 2539 else
1824 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2540 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1825 fi 2541 fi
1855 einfo "Classes" 2571 einfo "Classes"
1856 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2572 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1857 fi 2573 fi
1858} 2574}
1859 2575
1860# TODO document 2576# ------------------------------------------------------------------------------
2577# @internal-function java-pkg_verify-classes
2578#
1861# Verify that the classes were compiled for the right source / target 2579# Verify that the classes were compiled for the right source / target. Dies if
2580# not.
2581# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2582# ------------------------------------------------------------------------------
1862java-pkg_verify-classes() { 2583java-pkg_verify-classes() {
1863 ebegin "Verifying java class versions"
1864 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2584 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1865 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2585
2586 local version_verify="/usr/bin/class-version-verify.py"
2587
2588 if [[ ! -x "${version_verify}" ]]; then
2589 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2590 fi
2591
2592 if [[ ! -x "${version_verify}" ]]; then
2593 ewarn "Unable to perform class version checks as"
2594 ewarn "class-version-verify.py is unavailable"
2595 ewarn "Please install dev-java/javatoolkit."
2596 return
2597 fi
2598
2599 local target=$(java-pkg_get-target)
2600 local result
2601 local log="${T}/class-version-verify.log"
2602 if [[ -n "${1}" ]]; then
2603 ${version_verify} -v -t ${target} "${1}" > "${log}"
1866 result=$? 2604 result=$?
1867 eend ${result}
1868 if [[ ${result} == 0 ]]; then
1869 einfo "All good"
1870 else 2605 else
1871 ewarn "Possible problem" 2606 ebegin "Verifying java class versions (target: ${target})"
1872 die "Bad class files found" 2607 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2608 result=$?
2609 eend ${result}
2610 fi
2611 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2612 if [[ ${result} != 0 ]]; then
2613 eerror "Incorrect bytecode version found"
2614 [[ -n "${1}" ]] && eerror "in file: ${1}"
2615 eerror "See ${log} for more details."
2616 die "Incorrect bytecode found"
2617 fi
2618}
2619
2620# ----------------------------------------------------------------------------
2621# @internal-function java-pkg_ensure-dep
2622# Check that a package being used in jarfrom, getjars and getjar is contained
2623# within DEPEND or RDEPEND.
2624# @param $1 - empty - check both vars; "runtime" or "build" - check only
2625# RDEPEND, resp. DEPEND
2626# @param $2 - Package name and slot.
2627
2628java-pkg_ensure-dep() {
2629 debug-print-function ${FUNCNAME} $*
2630
2631 local limit_to="${1}"
2632 local target_pkg="${2}"
2633 local dev_error=""
2634
2635 local stripped_pkg=$(echo "${target_pkg}" | sed \
2636 's/-[0-9]*\(\.[0-9]\)*$//')
2637
2638 debug-print "Matching against: ${stripped_pkg}"
2639
2640 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2641 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2642 dev_error="${dev_error} declared in DEPEND."
2643 if is-java-strict; then
2644 eerror "${dev_error}"
2645 die "${dev_error}"
2646 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2647 eerror "${dev_error}"
2648 elog "Because you have this package installed the package will"
2649 elog "build without problems, but please report this to"
2650 elog "http://bugs.gentoo.org"
1873 fi 2651 fi
1874} 2652 fi
1875 2653
2654 if [[ ${limit_to} != build ]]; then
2655 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2656 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2657 dev_error="The ebuild is attempting to use ${target_pkg},"
2658 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2659 dev_error="${dev_error} or PDEPEND."
2660 if is-java-strict; then
2661 eerror "${dev_error}"
2662 die "${dev_error}"
2663 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2664 eerror "${dev_error}"
2665 elog "The package will build without problems, but may fail to run"
2666 elog "if you don't have ${target_pkg} installed, so please report"
2667 elog "this to http://bugs.gentoo.org"
2668 fi
2669 fi
2670 fi
2671 fi
2672}
1876 2673
1877# ------------------------------------------------------------------------------ 2674# ------------------------------------------------------------------------------
1878# @section-end internal 2675# @section-end internal
1879# ------------------------------------------------------------------------------ 2676# ------------------------------------------------------------------------------
1880 2677
1881java-pkg_check-phase() { 2678java-pkg_check-phase() {
1882 local phase=${1} 2679 local phase=${1}
1883 local funcname=${2} 2680 local funcname=${FUNCNAME[1]}
1884 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2681 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1885 java-pkg_announce-qa-violation \
1886 "${funcname} used outside of src_${phase}" 2682 local msg="${funcname} used outside of src_${phase}"
2683 java-pkg_announce-qa-violation "${msg}"
1887 fi 2684 fi
1888} 2685}
1889 2686
1890java-pkg_check-versioned-jar() { 2687java-pkg_check-versioned-jar() {
1891 local jar=${1} 2688 local jar=${1}
1900 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2697 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1901 fi 2698 fi
1902} 2699}
1903 2700
1904java-pkg_announce-qa-violation() { 2701java-pkg_announce-qa-violation() {
1905 if is-java-strict; then 2702 local nodie
2703 if [[ ${1} == "--nodie" ]]; then
2704 nodie="true"
2705 shift
2706 fi
1906 echo "Java QA Notice: $@" >&2 2707 echo "Java QA Notice: $@" >&2
1907 increment-qa-violations 2708 increment-qa-violations
1908 fi 2709 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1909} 2710}
1910 2711
1911increment-qa-violations() { 2712increment-qa-violations() {
1912 let "JAVA_PKG_QA_VIOLATIONS+=1" 2713 let "JAVA_PKG_QA_VIOLATIONS+=1"
1913 export JAVA_PKG_QA_VIOLATIONS 2714 export JAVA_PKG_QA_VIOLATIONS
1916is-java-strict() { 2717is-java-strict() {
1917 [[ -n ${JAVA_PKG_STRICT} ]] 2718 [[ -n ${JAVA_PKG_STRICT} ]]
1918 return $? 2719 return $?
1919} 2720}
1920 2721
2722
1921# ------------------------------------------------------------------------------ 2723# ------------------------------------------------------------------------------
1922# @eclass-end 2724# @eclass-end
1923# ------------------------------------------------------------------------------ 2725# ------------------------------------------------------------------------------

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.129

  ViewVC Help
Powered by ViewVC 1.1.20