/[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.148
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.148 2011/12/13 14:42:39 sera 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# -----------------------------------------------------------------------------
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# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66has "${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.9-r1 ${JAVA_PKG_PORTAGE_DEP}"
76has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
77
78# -----------------------------------------------------------------------------
79# @variable-preinherit JAVA_PKG_WANT_BOOTCLASSPATH
80#
81# The version of bootclasspath the package needs to work. Translates to a proper
82# dependency. The bootclasspath has to be obtained by java-ant_rewrite-bootclasspath
83# -----------------------------------------------------------------------------
84
85if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
86 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
87 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
88 else
89 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
90 # since die in global scope doesn't work, this will make repoman fail
91 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
92 fi
93fi
49 94
50# ----------------------------------------------------------------------------- 95# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 96# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 97# @variable-default yes
53# 98#
127# @note This should only be used internally or for testing. 172# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 173# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 174# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
131 176
177# -----------------------------------------------------------------------------
178# @variable-external JAVA_PKG_FORCE_ANT_TASKS
179#
180# An $IFS separated list of ant tasks. Can be set in environment before calling
181# emerge/ebuild to override variables set in ebuild, mainly for testing before
182# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
183# eant() call, not the dependencies specified in WANT_ANT_TASKS.
184#
185# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
186# ebuild foo.ebuild compile
187#
188# @seealso WANT_ANT_TASKS
189# -----------------------------------------------------------------------------
190
132# TODO document me 191# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 192JAVA_PKG_QA_VIOLATIONS=0
134 193
135# ----------------------------------------------------------------------------- 194# -----------------------------------------------------------------------------
136# @section-end variables 195# @section-end variables
143# 202#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 203# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 204# libraries, etc.
146# ----------------------------------------------------------------------------- 205# -----------------------------------------------------------------------------
147 206
207# -----------------------------------------------------------------------------
208# @ebuild-function java-pkg_doexamples
209#
210# Installs given arguments to /usr/share/doc/${PF}/examples
211# If you give it only one parameter and it is a directory it will install
212# everything in that directory to the examples directory.
213#
214# @example
215# java-pkg_doexamples demo
216# java-pkg_doexamples demo/* examples/*
217#
218# @param --subdir - If the examples need a certain directory structure
219# @param $* - list of files to install
220# ------------------------------------------------------------------------------
221java-pkg_doexamples() {
222 debug-print-function ${FUNCNAME} $*
223
224 [[ ${#} -lt 1 ]] && die "At least one argument needed"
225
226 java-pkg_check-phase install
227
228 local dest=/usr/share/doc/${PF}/examples
229 if [[ ${1} == --subdir ]]; then
230 local dest=${dest}/${2}
231 dodir ${dest}
232 shift 2
233 fi
234
235 if [[ ${#} = 1 && -d ${1} ]]; then
236 ( # dont want to pollute calling env
237 insinto "${dest}"
238 doins -r ${1}/*
239 ) || die "Installing examples failed"
240 else
241 ( # dont want to pollute calling env
242 insinto "${dest}"
243 doins -r "$@"
244 ) || die "Installing examples failed"
245 fi
246
247 # Let's make a symlink to the directory we have everything else under
248 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
249}
148 250
149# ----------------------------------------------------------------------------- 251# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 252# @ebuild-function java-pkg_dojar
151# 253#
152# Installs any number of jars. 254# Installs any number of jars.
171 # Create JARDEST if it doesn't exist 273 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 274 dodir ${JAVA_PKG_JARDEST}
173 275
174 local jar 276 local jar
175 # for each jar 277 # for each jar
176 for jar in "$@"; do 278 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 279 local jar_basename=$(basename "${jar}")
178 280
179 java-pkg_check-versioned-jar ${jar_basename} 281 java-pkg_check-versioned-jar ${jar_basename}
180 282
181 # check if it exists 283 # check if it exists
182 if [[ -e "${jar}" ]] ; then 284 if [[ -e "${jar}" ]] ; then
285 # Don't overwrite if jar has already been installed with the same
286 # name
287 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
288 if [[ -e "${dest}" ]]; then
289 ewarn "Overwriting ${dest}"
290 fi
291
183 # install it into JARDEST if it's a non-symlink 292 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 293 if [[ ! -L "${jar}" ]] ; then
294 #but first check class version when in strict mode.
295 is-java-strict && java-pkg_verify-classes "${jar}"
296
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 297 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 298 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 299 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 300 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 301 # make a symlink to the original jar if it's symlink
199 done 311 done
200 312
201 java-pkg_do_write_ 313 java-pkg_do_write_
202} 314}
203 315
316# ------------------------------------------------------------------------------
317# @internal-function depend-java-query
318#
319# Wrapper for the depend-java-query binary to enable passing USE in env.
320# Using env variables keeps this eclass working with java-config versions that
321# do not handle use flags.
322# ------------------------------------------------------------------------------
204 323
324depend-java-query() {
325 # Used to have a which call here but it caused endless loops for some people
326 # that had some weird bashrc voodoo for which.
327 USE="${USE}" /usr/bin/depend-java-query "${@}"
328}
205 329
206# ------------------------------------------------------------------------------ 330# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 331# @ebuild-function java-pkg_regjar
208# 332#
209# Records an already installed jar in the package.env 333# Records an already installed jar in the package.env
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 364 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 365
242 java-pkg_init_paths_ 366 java-pkg_init_paths_
243 367
244 local jar jar_dir jar_file 368 local jar jar_dir jar_file
245 for jar in "$@"; do 369 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 370 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 371 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
372 [[ -d "${jar}" || -d "${D}${jar}" ]] \
373 && die "Called ${FUNCNAME} on a directory $*"
374
375 #check that class version correct when in strict mode
376 is-java-strict && java-pkg_verify-classes "${jar}"
377
248 # nelchael: we should strip ${D} in this case too, here's why: 378 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 379 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 380 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 381 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 382 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 383 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 384 else
385 if [[ ${jar} = *\** ]]; then
386 eerror "The argument ${jar} to ${FUNCNAME}"
387 eerror "has * in it. If you want it to glob in"
388 eerror '${D} add ${D} to the argument.'
389 fi
390 debug-print "${jar} or ${D}${jar} not found"
257 die "${jar} does not exist" 391 die "${jar} does not exist"
258 fi 392 fi
259 done 393 done
260 394
261 java-pkg_do_write_ 395 java-pkg_do_write_
262} 396}
263
264 397
265# ------------------------------------------------------------------------------ 398# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 399# @ebuild-function java-pkg_newjar
267# 400#
268# Installs a jar with a new name 401# Installs a jar with a new name
279 local original_jar="${1}" 412 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 413 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 414 local new_jar_dest="${T}/${new_jar}"
282 415
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 416 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 417 [[ ! -f ${original_jar} ]] \
418 && die "${original_jar} does not exist or is not a file!"
285 419
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 420 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 421 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 422 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 423 java-pkg_dojar "${new_jar_dest}"
290} 424}
291 425
292
293# ------------------------------------------------------------------------------ 426# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 427# @ebuild-function java-pkg_addcp
295# 428#
296# Add something to the package's classpath. For jars, you should use dojar, 429# 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. 430# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 435java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 436 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 437 java-pkg_do_write_
305} 438}
306 439
307
308# ------------------------------------------------------------------------------ 440# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 441# @ebuild-function java-pkg_doso
310# 442#
311# Installs any number of JNI libraries 443# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 444# They will be installed into /usr/lib by default, but java-pkg_sointo
318# @param $@ - JNI libraries to install 450# @param $@ - JNI libraries to install
319# ------------------------------------------------------------------------------ 451# ------------------------------------------------------------------------------
320java-pkg_doso() { 452java-pkg_doso() {
321 debug-print-function ${FUNCNAME} $* 453 debug-print-function ${FUNCNAME} $*
322 454
323 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
324 java-pkg_check-phase install 455 java-pkg_check-phase install
325 456
326 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 457 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
327 458
328 java-pkg_init_paths_ 459 java-pkg_init_paths_
329 460
330 local lib 461 local lib
331 # for each lib 462 # for each lib
334 if [[ -e "${lib}" ]] ; then 465 if [[ -e "${lib}" ]] ; then
335 # install if it isn't a symlink 466 # install if it isn't a symlink
336 if [[ ! -L "${lib}" ]] ; then 467 if [[ ! -L "${lib}" ]] ; then
337 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 468 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
338 INSOPTIONS="${LIBOPTIONS}" \ 469 INSOPTIONS="${LIBOPTIONS}" \
339 doins "${lib}" || "failed to install ${lib}" 470 doins "${lib}" || die "failed to install ${lib}"
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 471 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 472 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 473 # otherwise make a symlink to the symlink's origin
343 else 474 else
344 # TODO use dosym
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 475 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
346 debug-print "${lib} is a symlink, linking accordanly" 476 debug-print "${lib} is a symlink, linking accordantly"
347 fi 477 fi
348 # otherwise die 478 # otherwise die
349 else 479 else
350 die "${lib} does not exist" 480 die "${lib} does not exist"
351 fi 481 fi
367java-pkg_regso() { 497java-pkg_regso() {
368 debug-print-function ${FUNCNAME} $* 498 debug-print-function ${FUNCNAME} $*
369 499
370 java-pkg_check-phase install 500 java-pkg_check-phase install
371 501
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 502 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
373 503
374 java-pkg_init_paths_ 504 java-pkg_init_paths_
375 505
376 local lib target_dir 506 local lib target_dir
377 for lib in "$@" ; do 507 for lib in "$@" ; do
428# ------------------------------------------------------------------------------ 558# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 559java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 560 debug-print-function ${FUNCNAME} $*
431 561
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 562 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 563
564 # from /usr/lib/portage/bin/dohtml -h
565 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 566 dohtml -f package-list "$@"
567
435 # this probably shouldn't be here but it provides 568 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 569 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 570 # old ebuilds.
438 java-pkg_recordjavadoc 571 java-pkg_recordjavadoc
439} 572}
440 573
441# TODO document 574# ------------------------------------------------------------------------------
575# @ebuild-function java-pkg_dojavadoc
576#
577# Installs javadoc documentation. This should be controlled by the doc use flag.
578#
579# @param $1: optional --symlink creates to symlink like this for html
580# documentation bundles.
581# @param $2: - The javadoc root directory.
582#
583# @example:
584# java-pkg_dojavadoc docs/api
585# java-pkg_dojavadoc --symlink apidocs docs/api
586#
587# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 588java-pkg_dojavadoc() {
589 debug-print-function ${FUNCNAME} $*
590
591 # For html documentation bundles that link to Javadoc
592 local symlink
593 if [[ ${1} = --symlink ]]; then
594 symlink=${2}
595 shift 2
596 fi
597
443 local dir="$1" 598 local dir="$1"
599 local dest=/usr/share/doc/${PF}/html
600
601 # QA checks
444 602
445 java-pkg_check-phase install 603 java-pkg_check-phase install
446 604
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 605 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 606 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
607 if [[ ! -e "${dir}/index.html" ]]; then
608 local msg="No index.html in javadoc directory"
609 ewarn "${msg}"
610 is-java-strict && die "${msg}"
611 fi
612
613 if [[ -e ${D}/${dest}/api ]]; then
614 eerror "${dest} already exists. Will not overwrite."
615 die "${dest}"
616 fi
617
618 # Renaming to match our directory layout
449 619
450 local dir_to_install="${dir}" 620 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 621 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 622 dir_to_install="${T}/api"
453 # TODO use doins 623 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 624 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 625 fi
456 626
627 # Actual installation
628
457 java-pkg_dohtml -r ${dir_to_install} 629 java-pkg_dohtml -r "${dir_to_install}"
630
631 # Let's make a symlink to the directory we have everything else under
632 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
633
634 if [[ ${symlink} ]]; then
635 debug-print "symlinking ${dest}/{api,${symlink}}"
636 dosym ${dest}/{api,${symlink}} || die
637 fi
458} 638}
459 639
460# ------------------------------------------------------------------------------ 640# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 641# @ebuild-function java-pkg_dosrc
462# 642#
478# FIXME apparently this fails if you give it an empty directories 658# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 659java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 660 debug-print-function ${FUNCNAME} $*
481 661
482 [ ${#} -lt 1 ] && die "At least one argument needed" 662 [ ${#} -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 663
487 java-pkg_check-phase install 664 java-pkg_check-phase install
488 665
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 666 [[ ${#} -lt 1 ]] && die "At least one argument needed"
667
668 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
669 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
670 java-pkg_announce-qa-violation ${msg}
671 fi
490 672
491 java-pkg_init_paths_ 673 java-pkg_init_paths_
492 674
493 local zip_name="${PN}-src.zip" 675 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 676 local zip_path="${T}/${zip_name}"
495 local dir 677 local dir
496 for dir in ${@}; do 678 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 679 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 680 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 681 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 682 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 683 local result=$?
518# @ebuild-function java-pkg_dolauncher 700# @ebuild-function java-pkg_dolauncher
519# 701#
520# Make a wrapper script to lauch/start this package 702# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 703# If necessary, the wrapper will switch to the appropriate VM.
522# 704#
705# Can be called without parameters if the package installs only one jar
706# that has the Main-class attribute set. The wrapper will be named ${PN}.
707#
523# @param $1 - filename of launcher to create 708# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 709# @param $2 - options, as follows:
525# --main the.main.class.too.start 710# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 711# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass to java' 712# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to the package' 713# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 714# --pwd Directory the launcher changes to before executing java
530# -into 715# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 716# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 717# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 718java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 719 debug-print-function ${FUNCNAME} $*
535 720
536 java-pkg_check-phase install 721 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 722 java-pkg_init_paths_
541 723
724 if [[ ${#} = 0 ]]; then
725 local name="${PN}"
726 else
542 local name="${1}" 727 local name="${1}"
728 shift
729 fi
730
543 # TODO rename to launcher 731 # TODO rename to launcher
544 local target="${T}/${name}" 732 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp" 733 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 734 local target_dir pre
547 shift
548 735
549 # Process the other the rest of the arguments 736 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 737 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 738 local var="${1}" value="${2}"
552 if [[ "${var:0:2}" == "--" ]]; then 739 if [[ "${var:0:2}" == "--" ]]; then
740 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 741 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
742 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 743 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 744 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 745 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 746 pre="${value}"
558 fi 747 fi
559 shift 2 748 shift 2
560 done 749 done
561 750
751 # Test if no --jar and --main arguments were given and
752 # in that case check if the package only installs one jar
753 # and use that jar.
754 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
755 local cp="${JAVA_PKG_CLASSPATH}"
756 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
757 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
758 else
759 local msg="Not enough information to create a launcher given."
760 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
761 die "${msg}"
762 fi
763 fi
764
562 # Write the actual script 765 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 766 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 767 if [[ -n "${pre}" ]]; then
768 if [[ -f "${pre}" ]]; then
769 cat "${pre}" >> "${target}"
770 else
771 die "-pre specified file '${pre}' does not exist"
772 fi
773 fi
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 774 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
566 cat "${var_tmp}" >> "${target}" 775 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}" 776 rm -f "${var_tmp}"
568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 777 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
569 778
661# Example: get a specific jar from xerces slot 2, and name it diffrently 870# 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 871# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building 872# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar 873# java-pkg_jar-from --build-only junit junit.jar
665# 874#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into 875# @param $opt
667# package.env DEPEND line. 876# --build-only - makes the jar(s) not added into package.env DEPEND line.
668# @param $1 - Package to get jars from. 877# (assumed automatically when called inside src_test)
878# --with-dependencies - get jars also from requested package's dependencies
879# transitively.
880# --virtual - Packages passed to this function are to be handled as virtuals
881# and will not have individual jar dependencies recorded.
882# --into $dir - symlink jar(s) into $dir (must exist) instead of .
883# @param $1 - Package to get jars from, or comma-separated list of packages in
884# case other parameters are not used.
669# @param $2 - jar from package. If not specified, all jars will be used. 885# @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 886# @param $3 - When a single jar is specified, destination filename of the
671# symlink. Defaults to the name of the jar. 887# symlink. Defaults to the name of the jar.
672# ------------------------------------------------------------------------------ 888# ------------------------------------------------------------------------------
673# TODO could probably be cleaned up a little 889# TODO could probably be cleaned up a little
674java-pkg_jar-from() { 890java-pkg_jar-from() {
675 debug-print-function ${FUNCNAME} $* 891 debug-print-function ${FUNCNAME} $*
676 892
677 local build_only="" 893 local build_only=""
894 local destdir="."
895 local deep=""
896 local virtual=""
897 local record_jar=""
678 898
899 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
900
901 while [[ "${1}" == --* ]]; do
679 if [[ "${1}" = "--build-only" ]]; then 902 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true" 903 build_only="build"
904 elif [[ "${1}" = "--with-dependencies" ]]; then
905 deep="--with-dependencies"
906 elif [[ "${1}" = "--virtual" ]]; then
907 virtual="true"
908 elif [[ "${1}" = "--into" ]]; then
909 destdir="${2}"
910 shift
911 else
912 die "java-pkg_jar-from called with unknown parameter: ${1}"
913 fi
681 shift 914 shift
682 fi 915 done
683 916
684 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 917 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
685 918
686 [[ -z ${target_pkg} ]] && die "Must specify a package" 919 [[ -z ${target_pkg} ]] && die "Must specify a package"
920
921 if [[ "${EAPI}" == "1" ]]; then
922 target_pkg="${target_pkg//:/-}"
923 fi
687 924
688 # default destjar to the target jar 925 # default destjar to the target jar
689 [[ -z "${destjar}" ]] && destjar="${target_jar}" 926 [[ -z "${destjar}" ]] && destjar="${target_jar}"
690 927
691 local error_msg="There was a problem getting the classpath for ${target_pkg}." 928 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath 929 local classpath
693 classpath="$(java-config --classpath=${target_pkg})" 930 classpath="$(java-config ${deep} --classpath=${target_pkg})"
694 [[ $? != 0 ]] && die ${error_msg} 931 [[ $? != 0 ]] && die ${error_msg}
932
933 # When we have commas this functions is called to bring jars from multiple
934 # packages. This affects recording of dependencencies performed later
935 # which expects one package only, so we do it here.
936 if [[ ${target_pkg} = *,* ]]; then
937 for pkg in ${target_pkg//,/ }; do
938 java-pkg_ensure-dep "${build_only}" "${pkg}"
939 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
940 done
941 # setting this disables further record-jar_ calls later
942 record_jar="true"
943 else
944 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
945 fi
946
947 # Record the entire virtual as a dependency so that
948 # no jars are missed.
949 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
950 java-pkg_record-jar_ "${target_pkg}"
951 # setting this disables further record-jars_ calls later
952 record_jar="true"
953 fi
954
955 pushd ${destdir} > /dev/null \
956 || die "failed to change directory to ${destdir}"
695 957
696 local jar 958 local jar
697 for jar in ${classpath//:/ }; do 959 for jar in ${classpath//:/ }; do
698 local jar_name=$(basename "${jar}") 960 local jar_name=$(basename "${jar}")
699 if [[ ! -f "${jar}" ]] ; then 961 if [[ ! -f "${jar}" ]] ; then
703 # If no specific target jar was indicated, link it 965 # If no specific target jar was indicated, link it
704 if [[ -z "${target_jar}" ]] ; then 966 if [[ -z "${target_jar}" ]] ; then
705 [[ -f "${target_jar}" ]] && rm "${target_jar}" 967 [[ -f "${target_jar}" ]] && rm "${target_jar}"
706 ln -snf "${jar}" \ 968 ln -snf "${jar}" \
707 || die "Failed to make symlink from ${jar} to ${jar_name}" 969 || die "Failed to make symlink from ${jar} to ${jar_name}"
970 if [[ -z "${record_jar}" ]]; then
971 if [[ -z "${build_only}" ]]; then
708 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 972 java-pkg_record-jar_ "${target_pkg}" "${jar}"
973 else
974 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
975 fi
976 fi
709 # otherwise, if the current jar is the target jar, link it 977 # otherwise, if the current jar is the target jar, link it
710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 978 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
711 [[ -f "${destjar}" ]] && rm "${destjar}" 979 [[ -f "${destjar}" ]] && rm "${destjar}"
712 ln -snf "${jar}" "${destjar}" \ 980 ln -snf "${jar}" "${destjar}" \
713 || die "Failed to make symlink from ${jar} to ${destjar}" 981 || die "Failed to make symlink from ${jar} to ${destjar}"
982 if [[ -z "${record_jar}" ]]; then
983 if [[ -z "${build_only}" ]]; then
714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 984 java-pkg_record-jar_ "${target_pkg}" "${jar}"
985 else
986 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}"
987 fi
988 fi
989 popd > /dev/null
715 return 0 990 return 0
716 fi 991 fi
717 done 992 done
993 popd > /dev/null
718 # if no target was specified, we're ok 994 # if no target was specified, we're ok
719 if [[ -z "${target_jar}" ]] ; then 995 if [[ -z "${target_jar}" ]] ; then
720 return 0 996 return 0
721 # otherwise, die bitterly 997 # otherwise, die bitterly
722 else 998 else
741# The providing packages are recorded as dependencies into package.env DEPEND 1017# 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 1018# 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 1019# that have to be present only at build time and are not needed on runtime
744# (junit testing etc). 1020# (junit testing etc).
745# 1021#
746# Example: Get the classpath for xerces-2, 1022# Example: Get the classpath for xerces-2 and xalan,
747# java-pkg_getjars xerces-2 xalan 1023# java-pkg_getjars xerces-2,xalan
748# Example Return: 1024# Example Return:
749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 1025# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
750# 1026#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into 1027# @param $opt
752# package.env DEPEND line. 1028# --build-only - makes the jar(s) not added into package.env DEPEND line.
1029# (assumed automatically when called inside src_test)
1030# --with-dependencies - get jars also from requested package's dependencies
1031# transitively.
753# @param $@ - list of packages to get jars from 1032# @param $1 - list of packages to get jars from
1033# (passed to java-config --classpath)
754# ------------------------------------------------------------------------------ 1034# ------------------------------------------------------------------------------
755java-pkg_getjars() { 1035java-pkg_getjars() {
756 debug-print-function ${FUNCNAME} $* 1036 debug-print-function ${FUNCNAME} $*
757 1037
758 local build_only="" 1038 local build_only=""
1039 local deep=""
759 1040
1041 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1042
1043 while [[ "${1}" == --* ]]; do
760 if [[ "${1}" = "--build-only" ]]; then 1044 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true" 1045 build_only="build"
1046 elif [[ "${1}" = "--with-dependencies" ]]; then
1047 deep="--with-dependencies"
1048 else
1049 die "java-pkg_jar-from called with unknown parameter: ${1}"
1050 fi
762 shift 1051 shift
763 fi 1052 done
764 1053
765 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1054 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
766 1055
767 # NOTE could probably just pass $@ to java-config --classpath. and return it 1056
768 local classpath pkg 1057 local pkgs="${1}"
769 for pkg in ${@//,/ }; do 1058
770 #for pkg in $(echo "$@" | tr ',' ' '); do 1059 if [[ "${EAPI}" == "1" ]]; then
1060 pkgs="${pkgs//:/-}"
1061 fi
1062
771 jars="$(java-config --classpath=${pkg})" 1063 jars="$(java-config ${deep} --classpath=${pkgs})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed" 1064 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
773 debug-print "${pkg}:${jars}" 1065 debug-print "${pkgs}:${jars}"
774 1066
1067 for pkg in ${pkgs//,/ }; do
1068 java-pkg_ensure-dep "${build_only}" "${pkg}"
1069 done
1070
1071 for pkg in ${pkgs//,/ }; do
775 if [[ -z "${classpath}" ]]; then 1072 if [[ -z "${build_only}" ]]; then
776 classpath="${jars}" 1073 java-pkg_record-jar_ "${pkg}"
777 else 1074 else
778 classpath="${classpath}:${jars}" 1075 java-pkg_record-jar_ --build-only "${pkg}"
779 fi 1076 fi
780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
782 done 1077 done
783 echo "${classpath}" 1078
1079 echo "${jars}"
784} 1080}
785 1081
786# ------------------------------------------------------------------------------ 1082# ------------------------------------------------------------------------------
787# @ebuild-function java-pkg_getjar 1083# @ebuild-function java-pkg_getjar
788# 1084#
795# @example 1091# @example
796# java-pkg_getjar xerces-2 xml-apis.jar 1092# java-pkg_getjar xerces-2 xml-apis.jar
797# @example-return 1093# @example-return
798# /usr/share/xerces-2/lib/xml-apis.jar 1094# /usr/share/xerces-2/lib/xml-apis.jar
799# 1095#
800# @param $1 - (optional) "--build-only" makes the jar not added into 1096# @param $opt
801# package.env DEPEND line. 1097# --build-only - makes the jar not added into package.env DEPEND line.
1098# --virtual - Packages passed to this function are to be handled as virtuals
1099# and will not have individual jar dependencies recorded.
802# @param $1 - package to use 1100# @param $1 - package to use
803# @param $2 - jar to get 1101# @param $2 - jar to get
804# ------------------------------------------------------------------------------ 1102# ------------------------------------------------------------------------------
805java-pkg_getjar() { 1103java-pkg_getjar() {
806 debug-print-function ${FUNCNAME} $* 1104 debug-print-function ${FUNCNAME} $*
807 1105
808 local build_only="" 1106 local build_only=""
1107 local virtual=""
1108 local record_jar=""
809 1109
1110 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1111
1112 while [[ "${1}" == --* ]]; do
810 if [[ "${1}" = "--build-only" ]]; then 1113 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true" 1114 build_only="build"
1115 elif [[ "${1}" == "--virtual" ]]; then
1116 virtual="true"
1117 else
1118 die "java-pkg_getjar called with unknown parameter: ${1}"
1119 fi
812 shift 1120 shift
813 fi 1121 done
1122
1123 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
814 1124
815 local pkg="${1}" target_jar="${2}" jar 1125 local pkg="${1}" target_jar="${2}" jar
1126
1127 if [[ "${EAPI}" == "1" ]]; then
1128 pkg="${pkg//:/-}"
1129 fi
1130
816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1131 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
817 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1132 [[ -z ${target_jar} ]] && die "Must specify jar to get"
818 1133
819 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1134 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
820 local classpath 1135 local classpath
821 classpath=$(java-config --classpath=${pkg}) 1136 classpath=$(java-config --classpath=${pkg})
822 [[ $? != 0 ]] && die ${error_msg} 1137 [[ $? != 0 ]] && die ${error_msg}
823 1138
1139 java-pkg_ensure-dep "${build_only}" "${pkg}"
1140
1141 # Record the package(Virtual) as a dependency and then set build_only
1142 # So that individual jars are not recorded.
1143 if [[ -n "${virtual}" ]]; then
1144 if [[ -z "${build_only}" ]]; then
1145 java-pkg_record-jar_ "${pkg}"
1146 else
1147 java-pkg_record-jar_ --build-only "${pkg}"
1148 fi
1149 record_jar="true"
1150 fi
1151
824 for jar in ${classpath//:/ }; do 1152 for jar in ${classpath//:/ }; do
825 if [[ ! -f "${jar}" ]] ; then 1153 if [[ ! -f "${jar}" ]] ; then
826 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1154 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
827 fi 1155 fi
828 1156
829 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1157 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
830 # Only record jars that aren't build-only 1158 # Only record jars that aren't build-only
831 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}" 1159 if [[ -z "${record_jar}" ]]; then
1160 if [[ -z "${build_only}" ]]; then
1161 java-pkg_record-jar_ "${pkg}" "${jar}"
1162 else
1163 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1164 fi
1165 fi
832 echo "${jar}" 1166 echo "${jar}"
833 return 0 1167 return 0
834 fi 1168 fi
835 done 1169 done
836 1170
837 die "Could not find ${target_jar} in ${pkg}" 1171 die "Could not find ${target_jar} in ${pkg}"
838 return 1 1172 return 1
839} 1173}
1174
1175# ------------------------------------------------------------------------------
1176# @ebuild-function java-pkg_register-dependency
1177#
1178# Registers runtime dependency on a package, list of packages, or a single jar
1179# from a package, into package.env DEPEND line. Can only be called in
1180# src_install phase.
1181# Intended for binary packages where you don't need to symlink the jars or get
1182# their classpath during build. As such, the dependencies only need to be
1183# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1184#
1185# @param $1 - comma-separated list of packages, or a single package
1186# @param $2 - if param $1 is a single package, optionally specify the jar
1187# to depend on
1188#
1189# Example: Record the dependency on whole xerces-2 and xalan,
1190# java-pkg_register-dependency xerces-2,xalan
1191# Example: Record the dependency on ant.jar from ant-core
1192# java-pkg_register-dependency ant-core ant.jar
1193#
1194# Note: Passing both list of packages as the first parameter AND specifying the
1195# jar as the second is not allowed and will cause the function to die. We assume
1196# that there's more chance one passes such combination as a mistake, than that
1197# there are more packages providing identically named jar without class
1198# collisions.
1199# ------------------------------------------------------------------------------
1200java-pkg_register-dependency() {
1201 debug-print-function ${FUNCNAME} $*
1202
1203 java-pkg_check-phase install
1204
1205 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1206
1207 local pkgs="${1}"
1208 local jar="${2}"
1209
1210 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1211
1212 if [[ "${EAPI}" == "1" ]]; then
1213 pkgs="${pkgs//:/-}"
1214 fi
1215
1216 if [[ -z "${jar}" ]]; then
1217 for pkg in ${pkgs//,/ }; do
1218 java-pkg_ensure-dep runtime "${pkg}"
1219 java-pkg_record-jar_ "${pkg}"
1220 done
1221 else
1222 [[ ${pkgs} == *,* ]] && \
1223 die "${FUNCNAME} called with both package list and jar name"
1224 java-pkg_ensure-dep runtime "${pkgs}"
1225 java-pkg_record-jar_ "${pkgs}" "${jar}"
1226 fi
1227
1228 java-pkg_do_write_
1229}
1230
1231# ------------------------------------------------------------------------------
1232# @ebuild-function java-pkg_register-optional-dependency
1233#
1234# Registers optional runtime dependency on a package, list of packages, or a
1235# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1236# called in src_install phase.
1237# Intended for packages that can use other packages when those are in classpath.
1238# Will be put on classpath by launcher if they are installed. Typical case is
1239# JDBC implementations for various databases. It's better than having USE flag
1240# for each implementation triggering hard dependency.
1241#
1242# @param $1 - comma-separated list of packages, or a single package
1243# @param $2 - if param $1 is a single package, optionally specify the jar
1244# to depend on
1245#
1246# Example: Record the optional dependency on some jdbc providers
1247# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1248#
1249# Note: Passing both list of packages as the first parameter AND specifying the
1250# jar as the second is not allowed and will cause the function to die. We assume
1251# that there's more chance one passes such combination as a mistake, than that
1252# there are more packages providing identically named jar without class
1253# collisions.
1254# ------------------------------------------------------------------------------
1255java-pkg_register-optional-dependency() {
1256 debug-print-function ${FUNCNAME} $*
1257
1258 java-pkg_check-phase install
1259
1260 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1261
1262 local pkgs="${1}"
1263 local jar="${2}"
1264
1265 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1266
1267 if [[ "${EAPI}" == "1" ]]; then
1268 pkgs="${pkgs//:/-}"
1269 fi
1270
1271 if [[ -z "${jar}" ]]; then
1272 for pkg in ${pkgs//,/ }; do
1273 java-pkg_record-jar_ --optional "${pkg}"
1274 done
1275 else
1276 [[ ${pkgs} == *,* ]] && \
1277 die "${FUNCNAME} called with both package list and jar name"
1278 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1279 fi
1280
1281 java-pkg_do_write_
1282}
1283
1284# ------------------------------------------------------------------------------
1285# @ebuild-function java-pkg_register-environment-variable
1286#
1287# Register an arbitrary environment variable into package.env. The gjl launcher
1288# for this package or any package depending on this will export it into
1289# environement before executing java command.
1290# Must only be called in src_install phase.
1291#
1292# @param $1 - variable name
1293# @param $2 - variable value
1294# ------------------------------------------------------------------------------
1295JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1296JAVA_PKG_EXTRA_ENV_VARS=""
1297java-pkg_register-environment-variable() {
1298 debug-print-function ${FUNCNAME} $*
1299
1300 java-pkg_check-phase install
1301
1302 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1303
1304 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1305 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1306
1307 java-pkg_do_write_
1308}
1309
1310# ------------------------------------------------------------------------------
1311# @ebuild-function java-pkg_get-bootclasspath
1312#
1313# Returns classpath of a given bootclasspath-providing package version.
1314#
1315# @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1316# of the current JDK
1317# ------------------------------------------------------------------------------
1318
1319java-pkg_get-bootclasspath() {
1320 local version="${1}"
1321
1322 local bcp
1323 case "${version}" in
1324 auto)
1325 bcp="$(java-config -g BOOTCLASSPATH)"
1326 ;;
1327 1.5)
1328 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1329 ;;
1330 *)
1331 eerror "unknown parameter of java-pkg_get-bootclasspath"
1332 die "unknown parameter of java-pkg_get-bootclasspath"
1333 ;;
1334 esac
1335
1336 echo "${bcp}"
1337}
1338
840 1339
841# This function reads stdin, and based on that input, figures out how to 1340# This function reads stdin, and based on that input, figures out how to
842# populate jars from the filesystem. 1341# populate jars from the filesystem.
843# Need to figure out a good way of making use of this, ie be able to use a 1342# Need to figure out a good way of making use of this, ie be able to use a
844# string that was built instead of stdin 1343# string that was built instead of stdin
884# 1383#
885# Various other functions to use from an ebuild 1384# Various other functions to use from an ebuild
886# ------------------------------------------------------------------------------ 1385# ------------------------------------------------------------------------------
887 1386
888# ------------------------------------------------------------------------------ 1387# ------------------------------------------------------------------------------
889# @ebuild-function java-pkg_need 1388# @ebuild-function java-pkg_find-normal-jars
890# 1389#
891# Adds virtual dependencies, which can optionally be controlled by a USE flag. 1390# 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# 1391#
899# @param $1 - Optionally indicate that the dependencies are controlled by 1392# @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# ------------------------------------------------------------------------------ 1393# ------------------------------------------------------------------------------
904# TODO rewrite to parse a line based declaration file instead -- karltk 1394java-pkg_find-normal-jars() {
905#java-pkg_need() { 1395 local dir=$1
906# debug-print-function ${FUNCNAME} $* 1396 [[ "${dir}" ]] || dir="${WORKDIR}"
907# local useflag 1397 local found
908# if [[ ${1} == "--use" ]]; then 1398 for jar in $(find "${dir}" -name "*.jar" -type f); do
909# useflag="${2}" 1399 echo "${jar}"
910# shift 2 1400 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 1401 done
957# 1402 [[ "${found}" ]]
958# [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}" 1403 return $?
959# [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}" 1404}
960#
961# export DEPEND="${DEPEND} ${depstr}"
962# export RDEPEND="${RDEPEND} ${depstr}"
963#}
964 1405
1406# ------------------------------------------------------------------------------
1407# @ebuild-function java-pkg_ensure-no-bundled-jars
1408#
1409# 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 1410# This function should be called after WORKDIR has been populated with symlink
966# TODO document 1411# to system jar files or bundled jars removed.
1412# ------------------------------------------------------------------------------
967java-pkg_ensure-no-bundled-jars() { 1413java-pkg_ensure-no-bundled-jars() {
968 debug-print-function ${FUNCNAME} $* 1414 debug-print-function ${FUNCNAME} $*
969 pushd ${WORKDIR} >/dev/null 2>/dev/null
970 1415
971 local bundled_jars=$(find . -name "*.jar" -type f) 1416 local bundled_jars=$(java-pkg_find-normal-jars)
972 if [[ -n ${bundled_jars} ]]; then 1417 if [[ -n ${bundled_jars} ]]; then
973 echo "Bundled jars found:" 1418 echo "Bundled jars found:"
974 local jar 1419 local jar
975 for jar in ${bundled_jars}; do 1420 for jar in ${bundled_jars}; do
976 echo $(pwd)${jar/./} 1421 echo $(pwd)${jar/./}
977 done 1422 done
978 die "Bundled jars found!" 1423 die "Bundled jars found!"
979
980 fi 1424 fi
981 popd >/dev/null 2>/dev/null
982} 1425}
983 1426
984# ------------------------------------------------------------------------------ 1427# ------------------------------------------------------------------------------
985# @internal-function java-pkg_ensure-vm-version-sufficient 1428# @internal-function java-pkg_ensure-vm-version-sufficient
986# 1429#
1113java-pkg_get-current-vm() { 1556java-pkg_get-current-vm() {
1114 echo ${GENTOO_VM} 1557 echo ${GENTOO_VM}
1115} 1558}
1116 1559
1117java-pkg_current-vm-matches() { 1560java-pkg_current-vm-matches() {
1118 hasq $(java-pkg_get-current-vm) ${@} 1561 has $(java-pkg_get-current-vm) ${@}
1119 return $? 1562 return $?
1120} 1563}
1121 1564
1122# ------------------------------------------------------------------------------ 1565# ------------------------------------------------------------------------------
1123# @ebuild-function java-pkg_get-source 1566# @ebuild-function java-pkg_get-source
1135# @ebuild-function java-pkg_get-target 1578# @ebuild-function java-pkg_get-target
1136# 1579#
1137# Determines what target version should be used, for passing to -target. 1580# 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 1581# If you don't care about lower versions, you can set _WANT_TARGET to the
1139# version of your JDK. 1582# 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# 1583#
1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1584# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1145# ------------------------------------------------------------------------------ 1585# ------------------------------------------------------------------------------
1146java-pkg_get-target() { 1586java-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}")} 1587 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1160} 1588}
1161 1589
1162java-pkg_get-javac() { 1590java-pkg_get-javac() {
1163 debug-print-function ${FUNCNAME} $* 1591 debug-print-function ${FUNCNAME} $*
1164 1592
1165 java-pkg_init-compiler_ 1593
1166 local compiler="${GENTOO_COMPILER}" 1594 local compiler="${GENTOO_COMPILER}"
1167 1595
1168 local compiler_executable 1596 local compiler_executable
1169 if [[ "${compiler}" = "javac" ]]; then 1597 if [[ "${compiler}" = "javac" ]]; then
1170 # nothing fancy needs to be done for javac 1598 # nothing fancy needs to be done for javac
1178 unset JAVAC 1606 unset JAVAC
1179 # try to get value of JAVAC 1607 # try to get value of JAVAC
1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1608 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1181 export JAVAC=${old_javac} 1609 export JAVAC=${old_javac}
1182 1610
1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1611 if [[ -z ${compiler_executable} ]]; then
1612 echo "JAVAC is empty or undefined in ${compiler_env}"
1613 return 1
1614 fi
1184 1615
1185 # check that it's executable 1616 # check that it's executable
1186 if [[ ! -x ${compiler_executable} ]]; then 1617 if [[ ! -x ${compiler_executable} ]]; then
1187 eerror "Could not find ${compiler_executable}!"
1188 die "${compiler_executable} doesn't exist, or isn't executable" 1618 echo "${compiler_executable} doesn't exist, or isn't executable"
1619 return 1
1189 fi 1620 fi
1190 else 1621 else
1191 eerror "Could not find environment file for ${compiler}" 1622 echo "Could not find environment file for ${compiler}"
1192 die "Could not find ${compiler_env}" 1623 return 1
1193 fi 1624 fi
1194 fi 1625 fi
1195 echo ${compiler_executable} 1626 echo ${compiler_executable}
1196} 1627}
1197 1628
1214 1645
1215 debug-print "want source: ${want_source}" 1646 debug-print "want source: ${want_source}"
1216 debug-print "want target: ${want_target}" 1647 debug-print "want target: ${want_target}"
1217 1648
1218 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1649 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1219 debug-print "could not find valid -source/-target values" 1650 debug-print "could not find valid -source/-target values for javac"
1220 die "Could not find valid -source/-target values" 1651 echo "Could not find valid -source/-target values for javac"
1652 return 1
1221 else 1653 else
1222 if java-pkg_is-vm-version-ge "1.4"; then 1654 if java-pkg_is-vm-version-ge "1.4"; then
1223 echo "${source_str} ${target_str}" 1655 echo "${source_str} ${target_str}"
1224 else 1656 else
1225 echo "${target_str}" 1657 echo "${target_str}"
1229 1661
1230# TODO document 1662# TODO document
1231java-pkg_get-jni-cflags() { 1663java-pkg_get-jni-cflags() {
1232 local flags="-I${JAVA_HOME}/include" 1664 local flags="-I${JAVA_HOME}/include"
1233 1665
1666 local platform="linux"
1667 use elibc_FreeBSD && platform="freebsd"
1668
1234 # TODO do a check that the directories are valid 1669 # 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" 1670 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1237 1671
1238 echo ${flags} 1672 echo ${flags}
1239} 1673}
1240 1674
1241java-pkg_ensure-gcj() { 1675java-pkg_ensure-gcj() {
1247 die "No GCJ support found!" 1681 die "No GCJ support found!"
1248 fi 1682 fi
1249} 1683}
1250 1684
1251java-pkg_ensure-test() { 1685java-pkg_ensure-test() {
1252 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1686 if has test ${FEATURES} && ! has -test ${FEATURES} \
1687 && has test ${IUSE} && ! use test;
1688 then
1253 eerror "You specified FEATURES=test, but USE=test is needed" 1689 eerror "You specified FEATURES=test, but USE=test is needed"
1254 eerror "to pull in the additional dependencies for testing" 1690 eerror "to pull in the additional dependencies for testing"
1255 die "Need USE=test enabled" 1691 die "Need USE=test enabled"
1256 fi 1692 fi
1257} 1693}
1258 1694
1259# ------------------------------------------------------------------------------ 1695# ------------------------------------------------------------------------------
1696# @ebuild-function java-pkg_register-ant-task
1697#
1698# Register this package as ant task, so that ant will load it when no specific
1699# ANT_TASKS are specified. Note that even without this registering, all packages
1700# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1701# packages, but can be also used by other ebuilds that used to symlink their
1702# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1703# compatibility.
1704#
1705# @param --version x.y Register only for ant version x.y (otherwise for any ant
1706# version). Used by the ant-* packages to prevent loading of mismatched
1707# ant-core ant tasks after core was updated, before the tasks are updated,
1708# without a need for blockers.
1709# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1710# ------------------------------------------------------------------------------
1711java-pkg_register-ant-task() {
1712 local TASKS_DIR="tasks"
1713
1714 # check for --version x.y parameters
1715 while [[ -n "${1}" && -n "${2}" ]]; do
1716 local var="${1#--}"
1717 local val="${2}"
1718 if [[ "${var}" == "version" ]]; then
1719 TASKS_DIR="tasks-${val}"
1720 else
1721 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1722 fi
1723 shift 2
1724 done
1725
1726 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1727
1728 dodir /usr/share/ant/${TASKS_DIR}
1729 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1730}
1731
1732# ------------------------------------------------------------------------------
1733# @internal-function java-pkg_ant-tasks-depend
1734#
1735# Translates the WANT_ANT_TASKS variable into valid dependencies.
1736# ------------------------------------------------------------------------------
1737java-pkg_ant-tasks-depend() {
1738 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1739
1740 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1741 local DEP=""
1742 for i in ${WANT_ANT_TASKS}
1743 do
1744 if [[ ${i} = ant-* ]]; then
1745 DEP="${DEP}dev-java/${i} "
1746 elif [[ ${i} = */*:* ]]; then
1747 DEP="${DEP}${i} "
1748 else
1749 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1750 return 1
1751 fi
1752 done
1753 echo ${DEP}
1754 return 0
1755 else
1756 return 0
1757 fi
1758}
1759
1760
1761# ------------------------------------------------------------------------------
1762# @internal-function ejunit_
1763#
1764# Internal Junit wrapper function. Makes it easier to run the tests and checks for
1765# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1766#
1767# @param $1 - junit package (junit or junit-4)
1768# @param $2 - -cp or -classpath
1769# @param $3 - classpath; junit and recorded dependencies get appended
1770# @param $@ - the rest of the parameters are passed to java
1771ejunit_() {
1772 debug-print-function ${FUNCNAME} $*
1773
1774 local pkgs
1775 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1776 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1777 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1778 done
1779 fi
1780
1781 local junit=${1}
1782 shift 1
1783
1784 local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1785 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1786 cp="${2}:${cp}"
1787 shift 2
1788 else
1789 cp=".:${cp}"
1790 fi
1791
1792 local runner=junit.textui.TestRunner
1793 if [[ "${junit}" == "junit-4" ]] ; then
1794 runner=org.junit.runner.JUnitCore
1795 fi
1796 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1797 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1798}
1799
1800# ------------------------------------------------------------------------------
1801# @ebuild-function ejunit
1802#
1803# Junit wrapper function. Makes it easier to run the tests and checks for
1804# dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1805#
1806# Examples:
1807# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1808# ejunit org.blinkenlights.jid3.test.AllTests
1809# ejunit org.blinkenlights.jid3.test.FirstTest \
1810# org.blinkenlights.jid3.test.SecondTest
1811#
1812# @param $1 - -cp or -classpath
1813# @param $2 - classpath; junit and recorded dependencies get appended
1814# @param $@ - the rest of the parameters are passed to java
1815# ------------------------------------------------------------------------------
1816ejunit() {
1817 debug-print-function ${FUNCNAME} $*
1818
1819 ejunit_ "junit" "${@}"
1820}
1821
1822# ------------------------------------------------------------------------------
1823# @ebuild-function ejunit4
1824#
1825# Junit4 wrapper function. Makes it easier to run the tests and checks for
1826# dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1827#
1828# Examples:
1829# ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1830# ejunit4 org.blinkenlights.jid3.test.AllTests
1831# ejunit4 org.blinkenlights.jid3.test.FirstTest \
1832# org.blinkenlights.jid3.test.SecondTest
1833#
1834# @param $1 - -cp or -classpath
1835# @param $2 - classpath; junit and recorded dependencies get appended
1836# @param $@ - the rest of the parameters are passed to java
1837# ------------------------------------------------------------------------------
1838ejunit4() {
1839 debug-print-function ${FUNCNAME} $*
1840
1841 ejunit_ "junit-4" "${@}"
1842}
1843
1844# ------------------------------------------------------------------------------
1260# @section-end helper 1845# @section-end helper
1261# ------------------------------------------------------------------------------ 1846# ------------------------------------------------------------------------------
1847
1848# ------------------------------------------------------------------------------
1849# @eclass-src_prepare
1850#
1851# src_prepare Searches for bundled jars
1852# Don't call directly, but via java-pkg-2_src_prepare!
1853# ------------------------------------------------------------------------------
1854
1855java-utils-2_src_prepare() {
1856 [[ ${EBUILD_PHASE} == prepare ]] &&
1857 java-pkg_func-exists java_prepare && java_prepare
1858
1859 # Remember that eant will call this unless called via Portage
1860 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1861 echo "Searching for bundled jars:"
1862 java-pkg_find-normal-jars || echo "None found."
1863 echo "Searching for bundled classes (no output if none found):"
1864 find "${WORKDIR}" -name "*.class"
1865 echo "Search done."
1866 fi
1867 touch "${T}/java-utils-2_src_prepare-run"
1868}
1869
1870# ------------------------------------------------------------------------------
1871# @eclass-pkg_preinst
1872#
1873# pkg_preinst Searches for missing and unneeded dependencies
1874# Don't call directly, but via java-pkg-2_pkg_preinst!
1875# ------------------------------------------------------------------------------
1876
1877java-utils-2_pkg_preinst() {
1878 if is-java-strict; then
1879 if has_version dev-java/java-dep-check; then
1880 [[ -e "${JAVA_PKG_ENV}" ]] || return
1881 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1882 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1883 ewarn "Possibly unneeded dependencies found in package.env:"
1884 for dep in ${output}; do
1885 ewarn "\t${dep}"
1886 done
1887 fi
1888 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1889 ewarn "${output}"
1890 fi
1891 else
1892 eerror "Install dev-java/java-dep-check for dependency checking"
1893 fi
1894 fi
1895}
1262 1896
1263# ------------------------------------------------------------------------------ 1897# ------------------------------------------------------------------------------
1264# @section-begin build 1898# @section-begin build
1265# @section-summary Build functions 1899# @section-summary Build functions
1266# 1900#
1270 1904
1271# ------------------------------------------------------------------------------ 1905# ------------------------------------------------------------------------------
1272# @ebuild-function eant 1906# @ebuild-function eant
1273# 1907#
1274# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1908# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1275# compiler. 1909# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1276# 1910# variables:
1911# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1912# gentoo.classpath property. Be sure to call
1913# java-ant_rewrite-classpath in src_unpack.
1914# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1915# for build-time purposes, the dependency is not recorded to
1916# package.env!
1917# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1277# ------------------------------------------------------------------------------ 1918# ------------------------------------------------------------------------------
1278eant() { 1919eant() {
1279 debug-print-function ${FUNCNAME} $* 1920 debug-print-function ${FUNCNAME} $*
1280 1921
1281 # FIXME get this working 1922 if [[ ${EBUILD_PHASE} = compile ]]; then
1282# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1923 java-ant-2_src_configure
1924 java-utils-2_src_prepare
1925 fi
1926
1927 if ! has java-ant-2 ${INHERITED}; then
1928 local msg="You should inherit java-ant-2 when using eant"
1283# java-pkg_announce-qa-violation \ 1929 java-pkg_announce-qa-violation "${msg}"
1284# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1285# fi 1930 fi
1286 1931
1287 local antflags 1932 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1933
1288 java-pkg_init-compiler_ 1934 java-pkg_init-compiler_
1289 local compiler="${GENTOO_COMPILER}" 1935 local compiler="${GENTOO_COMPILER}"
1290 1936
1291 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1937 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})" 1938 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1294 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1939 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1295 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1940 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1296 fi 1941 fi
1297 1942
1298 if [[ ${compiler} != "javac" ]]; then 1943 if [[ ${compiler} != "javac" ]]; then
1299 antflags="-Dbuild.compiler=${build_compiler}" 1944 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1300 # Figure out any extra stuff to put on the classpath for compilers aside 1945 # Figure out any extra stuff to put on the classpath for compilers aside
1301 # from javac 1946 # from javac
1302 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1947 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1303 # java-config -p 1948 # java-config -p
1304 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1949 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 1950 if [[ -n ${build_compiler_deps} ]]; then
1306 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1951 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1307 fi 1952 fi
1308 fi 1953 fi
1309 1954
1955 for arg in "${@}"; do
1956 if [[ ${arg} = -lib ]]; then
1310 if is-java-strict; then 1957 if is-java-strict; then
1311 einfo "Disabling system classpath for ant" 1958 eerror "You should not use the -lib argument to eant because it will fail"
1312 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1959 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1960 eerror "or ant properties to make dependencies available."
1961 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1962 eerror "split ant (>=dev-java/ant-core-1.7)."
1963 die "eant -lib is deprecated/forbidden"
1964 else
1965 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1966 echo "more info."
1967 fi
1313 fi 1968 fi
1969 done
1314 1970
1315 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1971 # parse WANT_ANT_TASKS for atoms
1316 antflags="${antflags} -debug" 1972 local want_ant_tasks
1973 for i in ${WANT_ANT_TASKS}; do
1974 if [[ ${i} = */*:* ]]; then
1975 i=${i#*/}
1976 i=${i%:0}
1977 want_ant_tasks+="${i/:/-} "
1978 else
1979 want_ant_tasks+="${i} "
1980 fi
1981 done
1982 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1983 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1984
1985 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1986 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1987
1988 # if ant-tasks is not set by ebuild or forced, use none
1989 ANT_TASKS="${ANT_TASKS:-none}"
1990
1991 # at this point, ANT_TASKS should be "all", "none" or explicit list
1992 if [[ "${ANT_TASKS}" == "all" ]]; then
1993 einfo "Using all available ANT_TASKS"
1994 elif [[ "${ANT_TASKS}" == "none" ]]; then
1995 einfo "Disabling all optional ANT_TASKS"
1996 else
1997 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1998 fi
1999
2000 export ANT_TASKS
2001
2002 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
2003 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
2004
2005 local gcp="${EANT_GENTOO_CLASSPATH}"
2006 local getjarsarg=""
2007
2008 if [[ ${EBUILD_PHASE} = "test" ]]; then
2009 antflags="${antflags} -DJunit.present=true"
2010 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
2011 getjarsarg="--with-dependencies"
2012 else
2013 antflags="${antflags} -Dmaven.test.skip=true"
2014 fi
2015
2016 local cp
2017
2018 for atom in ${gcp}; do
2019 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
2020 done
2021
2022 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
2023
2024 if [[ ${cp} ]]; then
2025 # It seems ant does not like single quotes around ${cp}
2026 cp=${cp#:}
2027 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
2028 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
2029 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1317 fi 2030 fi
1318 2031
1319 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 2032 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
2033 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1320 ant ${antflags} "${@}" || die "eant failed" 2034 ant ${antflags} "${@}" || die "eant failed"
1321
1322} 2035}
1323 2036
1324# ------------------------------------------------------------------------------ 2037# ------------------------------------------------------------------------------
1325# @ebuild-function ejavac 2038# @ebuild-function ejavac
1326# 2039#
1330# @param $@ - Arguments to be passed to the compiler 2043# @param $@ - Arguments to be passed to the compiler
1331# ------------------------------------------------------------------------------ 2044# ------------------------------------------------------------------------------
1332ejavac() { 2045ejavac() {
1333 debug-print-function ${FUNCNAME} $* 2046 debug-print-function ${FUNCNAME} $*
1334 2047
1335 # FIXME using get-javac ends up printing stuff with einfo 2048 java-pkg_init-compiler_
2049
2050 local compiler_executable
1336# local compiler_executable=$(java-pkg_get-javac) 2051 compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac" 2052 if [[ ${?} != 0 ]]; then
2053 eerror "There was a problem determining compiler: ${compiler_executable}"
2054 die "get-javac failed"
2055 fi
1338 2056
2057 local javac_args
2058 javac_args="$(java-pkg_javac-args)"
2059 if [[ ${?} != 0 ]]; then
2060 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
2061 die "java-pkg_javac-args failed"
2062 fi
2063
1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 2064 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 2065 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1341} 2066}
1342 2067
1343# ------------------------------------------------------------------------------ 2068# ------------------------------------------------------------------------------
1344# @ebuild-function java-pkg_filter-compiler 2069# @ebuild-function java-pkg_filter-compiler
1345# 2070#
1383# ------------------------------------------------------------------------------ 2108# ------------------------------------------------------------------------------
1384use_doc() { 2109use_doc() {
1385 use doc && echo ${@:-javadoc} 2110 use doc && echo ${@:-javadoc}
1386} 2111}
1387 2112
2113
1388# ------------------------------------------------------------------------------ 2114# ------------------------------------------------------------------------------
1389# @section-end build 2115# @section-end build
1390# ------------------------------------------------------------------------------ 2116# ------------------------------------------------------------------------------
1391 2117
1392# ------------------------------------------------------------------------------ 2118# ------------------------------------------------------------------------------
1408# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2134# 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. 2135# call it during each of the phases of the merge process.
1410# 2136#
1411# ----------------------------------------------------------------------------- 2137# -----------------------------------------------------------------------------
1412java-pkg_init() { 2138java-pkg_init() {
2139 debug-print-function ${FUNCNAME} $*
2140
2141 # Don't set up build environment if installing from binary. #206024 #258423
2142 [[ "${MERGE_TYPE}" == "binary" ]] && return
2143 # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
2144 # work nothing is lost.
2145 has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
2146
1413 unset JAVAC 2147 unset JAVAC
1414 unset JAVA_HOME 2148 unset JAVA_HOME
2149
2150 java-config --help >/dev/null || {
2151 eerror ""
2152 eerror "Can't run java-config --help"
2153 eerror "Have you upgraded python recently but haven't"
2154 eerror "run python-updater yet?"
2155 die "Can't run java-config --help"
2156 }
2157
2158 # People do all kinds of weird things.
2159 # http://forums.gentoo.org/viewtopic-p-3943166.html
2160 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2161 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2162 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2163 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2164 ewarn "sun-jdk vms and and as such break configure scripts that"
2165 ewarn "use it (for example app-office/openoffice) so we filter it out."
2166 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2167 ewarn "make.conf for example) to silence this warning or"
2168 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2169 fi
2170
2171 if [[ -z ${accept} ]]; then
2172 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2173 # -version output
2174 unset _JAVA_OPTIONS
2175 # phase hooks make this run many times without this
2176 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2177 fi
2178
2179 if java-pkg_func-exists ant_src_unpack; then
2180 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2181 fi
2182
1415 java-pkg_init_paths_ 2183 java-pkg_init_paths_
1416 java-pkg_switch-vm 2184 java-pkg_switch-vm
1417 PATH=${JAVA_HOME}/bin:${PATH} 2185 PATH=${JAVA_HOME}/bin:${PATH}
1418 2186
1419 # TODO we will probably want to set JAVAC and JAVACFLAGS 2187 # TODO we will probably want to set JAVAC and JAVACFLAGS
1420 2188
1421 # Do some QA checks 2189 # Do some QA checks
1422 java-pkg_check-jikes 2190 java-pkg_check-jikes
2191
2192 # Can't use unset here because Portage does not save the unset
2193 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1423 2194
1424 # When users have crazy classpaths some packages can fail to compile. 2195 # When users have crazy classpaths some packages can fail to compile.
1425 # and everything should work with empty CLASSPATH. 2196 # and everything should work with empty CLASSPATH.
1426 # This also helps prevent unexpected dependencies on random things 2197 # This also helps prevent unexpected dependencies on random things
1427 # from the CLASSPATH. 2198 # from the CLASSPATH.
1428 unset CLASSPATH 2199 export CLASSPATH=
2200
2201 # Unset external ANT_ stuff
2202 export ANT_TASKS=
2203 export ANT_OPTS=
2204 export ANT_RESPECT_JAVA_HOME=
1429} 2205}
1430 2206
1431# ------------------------------------------------------------------------------ 2207# ------------------------------------------------------------------------------
1432# @function-internal java-pkg-init-compiler_ 2208# @function-internal java-pkg-init-compiler_
1433# 2209#
1524 done 2300 done
1525 2301
1526 # If it hasn't been defined already, default to javac 2302 # If it hasn't been defined already, default to javac
1527 if [[ -z ${GENTOO_COMPILER} ]]; then 2303 if [[ -z ${GENTOO_COMPILER} ]]; then
1528 if [[ -n ${compilers} ]]; then 2304 if [[ -n ${compilers} ]]; then
1529 einfo "No suitable compiler found: defaulting javac for compilation" 2305 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1530 else 2306 else
1531 # probably don't need to notify users about the default. 2307 # probably don't need to notify users about the default.
1532 :;#einfo "Defaulting to javac for compilation" 2308 :;#einfo "Defaulting to javac for compilation"
1533 fi 2309 fi
2310 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2311 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2312 else
1534 export GENTOO_COMPILER=javac 2313 export GENTOO_COMPILER=javac
2314 fi
1535 else 2315 else
1536 einfo "Using ${GENTOO_COMPILER} for compilation" 2316 einfo "Using ${GENTOO_COMPILER} for compilation"
1537 fi 2317 fi
1538 2318
1539} 2319}
1555 fi 2335 fi
1556 2336
1557 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2337 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1558 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2338 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1559 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2339 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2340 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2341 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1560 2342
1561 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2343 [[ -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}" 2344 [[ -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" 2345 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1564 2346
1577# Writes the package.env out to disk. 2359# Writes the package.env out to disk.
1578# 2360#
1579# ------------------------------------------------------------------------------ 2361# ------------------------------------------------------------------------------
1580# TODO change to do-write, to match everything else 2362# TODO change to do-write, to match everything else
1581java-pkg_do_write_() { 2363java-pkg_do_write_() {
2364 debug-print-function ${FUNCNAME} $*
2365 java-pkg_init_paths_
1582 # Create directory for package.env 2366 # Create directory for package.env
1583 dodir "${JAVA_PKG_SHAREPATH}" 2367 dodir "${JAVA_PKG_SHAREPATH}"
1584 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2368 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2369 "${JAVA_PKG_DEPEND_FILE}" || -f \
2370 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1585 # Create package.env 2371 # Create package.env
1586 ( 2372 (
1587 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2373 echo "DESCRIPTION=\"${DESCRIPTION}\""
1588 echo "GENERATION=\"2\"" 2374 echo "GENERATION=\"2\""
2375 echo "SLOT=\"${SLOT}\""
2376 echo "CATEGORY=\"${CATEGORY}\""
2377 echo "PVR=\"${PVR}\""
1589 2378
1590 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2379 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1591 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2380 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1592 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2381 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1593 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2382 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2383 && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
2384 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2385 && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
1594 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2386 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2387 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2388 && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
1595 ) > "${JAVA_PKG_ENV}" 2389 ) > "${JAVA_PKG_ENV}"
1596 2390
1597 # register target/source 2391 # register target/source
1598 local target="$(java-pkg_get-target)" 2392 local target="$(java-pkg_get-target)"
1599 local source="$(java-pkg_get-source)" 2393 local source="$(java-pkg_get-source)"
1609 2403
1610 2404
1611 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2405 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1612 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2406 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1613 2407
2408 # extra env variables
2409 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2410 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2411 # nested echo to remove leading/trailing spaces
2412 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2413 >> "${JAVA_PKG_ENV}" || die
2414 fi
2415
1614 # Strip unnecessary leading and trailing colons 2416 # Strip unnecessary leading and trailing colons
1615 # TODO try to cleanup if possible 2417 # TODO try to cleanup if possible
1616 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2418 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2419 else
2420 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2421 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2422 debug-print "write package.env."
1617 fi 2423 fi
1618} 2424}
1619
1620 2425
1621# ------------------------------------------------------------------------------ 2426# ------------------------------------------------------------------------------
1622# @internal-function java-pkg_record-jar_ 2427# @internal-function java-pkg_record-jar_
1623# 2428#
1624# Record a dependency to the package.env 2429# Record an (optional) dependency to the package.env
1625# 2430# @param --optional - record dependency as optional
2431# @param --build - record dependency as build_only
2432# @param $1 - package to record
2433# @param $2 - (optional) jar of package to record
1626# ------------------------------------------------------------------------------ 2434# ------------------------------------------------------------------------------
1627JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2435JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2436JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2437JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
1628 2438
1629java-pkg_record-jar_() { 2439java-pkg_record-jar_() {
1630 debug-print-function ${FUNCNAME} $* 2440 debug-print-function ${FUNCNAME} $*
2441
2442 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2443 case "${1}" in
2444 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2445 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2446 esac
1631 2447
1632 local pkg=${1} jar=${2} append 2448 local pkg=${1} jar=${2} append
1633 if [[ -z "${jar}" ]]; then 2449 if [[ -z "${jar}" ]]; then
1634 append="${pkg}" 2450 append="${pkg}"
1635 else 2451 else
1636 append="$(basename ${jar})@${pkg}" 2452 append="$(basename ${jar})@${pkg}"
1637 fi 2453 fi
1638 2454
1639 echo ${append} >> ${JAVA_PKG_DEPEND} 2455 echo "${append}" >> "${depend_file}"
1640} 2456}
1641 2457
1642# ------------------------------------------------------------------------------ 2458# ------------------------------------------------------------------------------
1643# @internal-function java-pkg_append_ 2459# @internal-function java-pkg_append_
1644# 2460#
1688# 2504#
1689# @return 0 - function is declared 2505# @return 0 - function is declared
1690# @return 1 - function is undeclared 2506# @return 1 - function is undeclared
1691# ------------------------------------------------------------------------------ 2507# ------------------------------------------------------------------------------
1692java-pkg_func-exists() { 2508java-pkg_func-exists() {
1693 if [[ -n "$(declare -f ${1})" ]]; then 2509 declare -F ${1} > /dev/null
1694 return 0
1695 else
1696 return 1
1697 fi
1698} 2510}
1699 2511
1700# ------------------------------------------------------------------------------ 2512# ------------------------------------------------------------------------------
1701# @internal-function java-pkg_setup-vm 2513# @internal-function java-pkg_setup-vm
1702# 2514#
1705# ------------------------------------------------------------------------------ 2517# ------------------------------------------------------------------------------
1706java-pkg_setup-vm() { 2518java-pkg_setup-vm() {
1707 debug-print-function ${FUNCNAME} $* 2519 debug-print-function ${FUNCNAME} $*
1708 2520
1709 local vendor="$(java-pkg_get-vm-vendor)" 2521 local vendor="$(java-pkg_get-vm-vendor)"
1710 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2522 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1711 addpredict "/dev/random" 2523 addpredict "/dev/random"
1712 elif [[ "${vendor}" == "ibm" ]]; then 2524 elif [[ "${vendor}" == "ibm" ]]; then
1713 addpredict "/proc/self/maps" 2525 addpredict "/proc/self/maps"
1714 addpredict "/proc/cpuinfo" 2526 addpredict "/proc/cpuinfo"
1715 export LANG="C" LC_ALL="C" 2527 addpredict "/proc/self/coredump_filter"
2528 elif [[ "${vendor}" == "oracle" ]]; then
2529 addpredict "/dev/random"
2530 addpredict "/proc/self/coredump_filter"
2531 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2532 addpredict "/dev/random"
2533 addpredict "/proc/self/coredump_filter"
1716 elif [[ "${vendor}" == "jrockit" ]]; then 2534 elif [[ "${vendor}" == "jrockit" ]]; then
1717 addpredict "/proc/cpuinfo" 2535 addpredict "/proc/cpuinfo"
1718 fi 2536 fi
1719} 2537}
1720 2538
1727# @return 1 - Package does not depend on virtual/jdk 2545# @return 1 - Package does not depend on virtual/jdk
1728# ------------------------------------------------------------------------------ 2546# ------------------------------------------------------------------------------
1729java-pkg_needs-vm() { 2547java-pkg_needs-vm() {
1730 debug-print-function ${FUNCNAME} $* 2548 debug-print-function ${FUNCNAME} $*
1731 2549
1732 if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then 2550 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
1733 return 0 2551 return 0
1734 fi 2552 fi
1735 2553
1736 return 1 2554 return 1
1737} 2555}
1775# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2593# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1776# verify that the current VM is sufficient. 2594# verify that the current VM is sufficient.
1777# Setup the environment for the VM being used. 2595# Setup the environment for the VM being used.
1778# ------------------------------------------------------------------------------ 2596# ------------------------------------------------------------------------------
1779java-pkg_switch-vm() { 2597java-pkg_switch-vm() {
2598 debug-print-function ${FUNCNAME} $*
2599
1780 if java-pkg_needs-vm; then 2600 if java-pkg_needs-vm; then
1781 # Use the VM specified by JAVA_PKG_FORCE_VM 2601 # Use the VM specified by JAVA_PKG_FORCE_VM
1782 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2602 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1783 # If you're forcing the VM, I hope you know what your doing... 2603 # If you're forcing the VM, I hope you know what your doing...
2604 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1784 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2605 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1785 # if we're allowed to switch the vm... 2606 # if we're allowed to switch the vm...
1786 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2607 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}" 2608 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}}")" 2609 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2610 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2611 eerror "Unable to determine VM for building from dependencies:"
2612 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2613 die "Failed to determine VM for building."
1790 else 2614 else
1791 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2615 export GENTOO_VM
1792 fi 2616 fi
1793 # otherwise just make sure the current VM is sufficient 2617 # otherwise just make sure the current VM is sufficient
1794 else 2618 else
1795 java-pkg_ensure-vm-version-sufficient 2619 java-pkg_ensure-vm-version-sufficient
1796 fi 2620 fi
1798 2622
1799 java-pkg_setup-vm 2623 java-pkg_setup-vm
1800 2624
1801 export JAVA=$(java-config --java) 2625 export JAVA=$(java-config --java)
1802 export JAVAC=$(java-config --javac) 2626 export JAVAC=$(java-config --javac)
1803 export JAVACFLAGS="$(java-pkg_javac-args)" 2627 JAVACFLAGS="$(java-pkg_javac-args)"
2628 if [[ ${?} != 0 ]]; then
2629 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2630 die "java-pkg_javac-args failed"
2631 fi
1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2632 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2633 export JAVACFLAGS
1805 2634
1806 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2635 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1807 export JDK_HOME=${JAVA_HOME} 2636 export JDK_HOME=${JAVA_HOME}
1808 2637
1809 #TODO If you know a better solution let us know. 2638 #TODO If you know a better solution let us know.
1810 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2639 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1811 2640
1812 local tann="${T}/announced-vm" 2641 local tann="${T}/announced-vm"
2642 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2643 # if people have for example modified eclasses some where
1813 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2644 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)" 2645 einfo "Using: $(java-config -f)"
1819 [[ ! -f "${tann}" ]] && touch "${tann}" 2646 [[ ! -f "${tann}" ]] && touch "${tann}"
1820 fi
1821 fi 2647 fi
1822 2648
1823 else 2649 else
1824 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2650 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1825 fi 2651 fi
1830# 2656#
1831# Enhanced die for Java packages, which displays some information that may be 2657# Enhanced die for Java packages, which displays some information that may be
1832# useful for debugging bugs on bugzilla. 2658# useful for debugging bugs on bugzilla.
1833# ------------------------------------------------------------------------------ 2659# ------------------------------------------------------------------------------
1834#register_die_hook java-pkg_die 2660#register_die_hook java-pkg_die
1835if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then 2661if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
1836 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die" 2662 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
1837fi 2663fi
1838 2664
1839java-pkg_die() { 2665java-pkg_die() {
1840 echo "!!! When you file a bug report, please include the following information:" >&2 2666 echo "!!! When you file a bug report, please include the following information:" >&2
1855 einfo "Classes" 2681 einfo "Classes"
1856 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2682 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1857 fi 2683 fi
1858} 2684}
1859 2685
1860# TODO document 2686# ------------------------------------------------------------------------------
2687# @internal-function java-pkg_verify-classes
2688#
1861# Verify that the classes were compiled for the right source / target 2689# Verify that the classes were compiled for the right source / target. Dies if
2690# not.
2691# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2692# ------------------------------------------------------------------------------
1862java-pkg_verify-classes() { 2693java-pkg_verify-classes() {
1863 ebegin "Verifying java class versions"
1864 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2694 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1865 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2695
2696 local version_verify="/usr/bin/class-version-verify.py"
2697
2698 if [[ ! -x "${version_verify}" ]]; then
2699 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2700 fi
2701
2702 if [[ ! -x "${version_verify}" ]]; then
2703 ewarn "Unable to perform class version checks as"
2704 ewarn "class-version-verify.py is unavailable"
2705 ewarn "Please install dev-java/javatoolkit."
2706 return
2707 fi
2708
2709 local target=$(java-pkg_get-target)
2710 local result
2711 local log="${T}/class-version-verify.log"
2712 if [[ -n "${1}" ]]; then
2713 ${version_verify} -v -t ${target} "${1}" > "${log}"
1866 result=$? 2714 result=$?
1867 eend ${result}
1868 if [[ ${result} == 0 ]]; then
1869 einfo "All good"
1870 else 2715 else
1871 ewarn "Possible problem" 2716 ebegin "Verifying java class versions (target: ${target})"
1872 die "Bad class files found" 2717 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2718 result=$?
2719 eend ${result}
2720 fi
2721 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2722 if [[ ${result} != 0 ]]; then
2723 eerror "Incorrect bytecode version found"
2724 [[ -n "${1}" ]] && eerror "in file: ${1}"
2725 eerror "See ${log} for more details."
2726 die "Incorrect bytecode found"
2727 fi
2728}
2729
2730# ----------------------------------------------------------------------------
2731# @internal-function java-pkg_ensure-dep
2732# Check that a package being used in jarfrom, getjars and getjar is contained
2733# within DEPEND or RDEPEND.
2734# @param $1 - empty - check both vars; "runtime" or "build" - check only
2735# RDEPEND, resp. DEPEND
2736# @param $2 - Package name and slot.
2737
2738java-pkg_ensure-dep() {
2739 debug-print-function ${FUNCNAME} $*
2740
2741 local limit_to="${1}"
2742 local target_pkg="${2}"
2743 local dev_error=""
2744
2745 # remove the version specification, which may include globbing (* and [123])
2746 local stripped_pkg=$(echo "${target_pkg}" | sed \
2747 's/-\([0-9*]*\(\[[0-9]*\]\)*\)*\(\.\([0-9*]*\(\[[0-9]*\]\)*\)*\)*$//')
2748
2749 debug-print "Matching against: ${stripped_pkg}"
2750
2751 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2752 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2753 dev_error="${dev_error} declared in DEPEND."
2754 if is-java-strict; then
2755 eerror "${dev_error}"
2756 die "${dev_error}"
2757 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2758 eerror "${dev_error}"
2759 elog "Because you have this package installed the package will"
2760 elog "build without problems, but please report this to"
2761 elog "http://bugs.gentoo.org"
1873 fi 2762 fi
1874} 2763 fi
1875 2764
2765 if [[ ${limit_to} != build ]]; then
2766 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2767 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2768 dev_error="The ebuild is attempting to use ${target_pkg},"
2769 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2770 dev_error="${dev_error} or PDEPEND."
2771 if is-java-strict; then
2772 eerror "${dev_error}"
2773 die "${dev_error}"
2774 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2775 eerror "${dev_error}"
2776 elog "The package will build without problems, but may fail to run"
2777 elog "if you don't have ${target_pkg} installed, so please report"
2778 elog "this to http://bugs.gentoo.org"
2779 fi
2780 fi
2781 fi
2782 fi
2783}
1876 2784
1877# ------------------------------------------------------------------------------ 2785# ------------------------------------------------------------------------------
1878# @section-end internal 2786# @section-end internal
1879# ------------------------------------------------------------------------------ 2787# ------------------------------------------------------------------------------
1880 2788
1881java-pkg_check-phase() { 2789java-pkg_check-phase() {
1882 local phase=${1} 2790 local phase=${1}
1883 local funcname=${2} 2791 local funcname=${FUNCNAME[1]}
1884 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2792 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1885 java-pkg_announce-qa-violation \
1886 "${funcname} used outside of src_${phase}" 2793 local msg="${funcname} used outside of src_${phase}"
2794 java-pkg_announce-qa-violation "${msg}"
1887 fi 2795 fi
1888} 2796}
1889 2797
1890java-pkg_check-versioned-jar() { 2798java-pkg_check-versioned-jar() {
1891 local jar=${1} 2799 local jar=${1}
1894 java-pkg_announce-qa-violation "installing versioned jar '${jar}'" 2802 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
1895 fi 2803 fi
1896} 2804}
1897 2805
1898java-pkg_check-jikes() { 2806java-pkg_check-jikes() {
1899 if hasq jikes ${IUSE}; then 2807 if has jikes ${IUSE}; then
1900 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2808 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1901 fi 2809 fi
1902} 2810}
1903 2811
1904java-pkg_announce-qa-violation() { 2812java-pkg_announce-qa-violation() {
1905 if is-java-strict; then 2813 local nodie
2814 if [[ ${1} == "--nodie" ]]; then
2815 nodie="true"
2816 shift
2817 fi
1906 echo "Java QA Notice: $@" >&2 2818 echo "Java QA Notice: $@" >&2
1907 increment-qa-violations 2819 increment-qa-violations
1908 fi 2820 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1909} 2821}
1910 2822
1911increment-qa-violations() { 2823increment-qa-violations() {
1912 let "JAVA_PKG_QA_VIOLATIONS+=1" 2824 let "JAVA_PKG_QA_VIOLATIONS+=1"
1913 export JAVA_PKG_QA_VIOLATIONS 2825 export JAVA_PKG_QA_VIOLATIONS
1916is-java-strict() { 2828is-java-strict() {
1917 [[ -n ${JAVA_PKG_STRICT} ]] 2829 [[ -n ${JAVA_PKG_STRICT} ]]
1918 return $? 2830 return $?
1919} 2831}
1920 2832
2833
1921# ------------------------------------------------------------------------------ 2834# ------------------------------------------------------------------------------
1922# @eclass-end 2835# @eclass-end
1923# ------------------------------------------------------------------------------ 2836# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20