/[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.20 Revision 1.115
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.115 2008/10/05 16:53:38 betelgeuse 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[[ "${EAPI:-0}" == "2" ]] && EXPORT_FUNCTIONS src_prepare
41
42# -----------------------------------------------------------------------------
43# @variable-external WANT_ANT_TASKS
44# @variable-default ""
45#
46# An $IFS separated list of ant tasks.
47# Ebuild can specify this variable before inheriting java-ant-2 eclass to
48# determine ANT_TASKS it needs. They will be automatically translated to
49# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
50# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
51# Ebuilds that need to depend conditionally on certain tasks and specify them
52# differently for different eant calls can't use this simplified approach.
53# You also cannot specify version or anything else than ant-*.
54#
55# @example WANT_ANT_TASKS="ant-junit ant-trax"
56#
57# @seealso JAVA_PKG_FORCE_ANT_TASKS
58# -----------------------------------------------------------------------------
59#WANT_ANT_TASKS
60
61# -----------------------------------------------------------------------------
62# @variable-internal JAVA_PKG_PORTAGE_DEP
63#
64# The version of portage we need to function properly. Previously it was
65# portage with phase hooks support but now we use a version with proper env
66# saving.
67# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 68JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
40 69
41# ----------------------------------------------------------------------------- 70# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 71# @variable-internal JAVA_PKG_E_DEPEND
43# 72#
44# This is a convience variable to be used from the other java eclasses. This is 73# 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 74# the version of java-config we want to use. Usually the latest stable version
46# portage, that includes phase hooks. 75# so that ebuilds can use new features without depending on specific versions.
47# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 77JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
78hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
49 79
50# ----------------------------------------------------------------------------- 80# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 81# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 82# @variable-default yes
53# 83#
127# @note This should only be used internally or for testing. 157# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 158# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 159# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 160# -----------------------------------------------------------------------------
131 161
162# -----------------------------------------------------------------------------
163# @variable-external JAVA_PKG_FORCE_ANT_TASKS
164#
165# An $IFS separated list of ant tasks. Can be set in environment before calling
166# emerge/ebuild to override variables set in ebuild, mainly for testing before
167# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
168# eant() call, not the dependencies specified in WANT_ANT_TASKS.
169#
170# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
171# ebuild foo.ebuild compile
172#
173# @seealso WANT_ANT_TASKS
174# -----------------------------------------------------------------------------
175
132# TODO document me 176# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 177JAVA_PKG_QA_VIOLATIONS=0
134 178
135# ----------------------------------------------------------------------------- 179# -----------------------------------------------------------------------------
136# @section-end variables 180# @section-end variables
143# 187#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 188# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 189# libraries, etc.
146# ----------------------------------------------------------------------------- 190# -----------------------------------------------------------------------------
147 191
192# -----------------------------------------------------------------------------
193# @ebuild-function java-pkg_doexamples
194#
195# Installs given arguments to /usr/share/doc/${PF}/examples
196# If you give it only one parameter and it is a directory it will install
197# everything in that directory to the examples directory.
198#
199# @example
200# java-pkg_doexamples demo
201# java-pkg_doexamples demo/* examples/*
202#
203# @param --subdir - If the examples need a certain directory structure
204# @param $* - list of files to install
205# ------------------------------------------------------------------------------
206java-pkg_doexamples() {
207 debug-print-function ${FUNCNAME} $*
208
209 [[ ${#} -lt 1 ]] && die "At least one argument needed"
210
211 java-pkg_check-phase install
212
213 local dest=/usr/share/doc/${PF}/examples
214 if [[ ${1} == --subdir ]]; then
215 local dest=${dest}/${2}
216 dodir ${dest}
217 shift 2
218 fi
219
220 if [[ ${#} = 1 && -d ${1} ]]; then
221 ( # dont want to pollute calling env
222 insinto "${dest}"
223 doins -r ${1}/*
224 ) || die "Installing examples failed"
225 else
226 ( # dont want to pollute calling env
227 insinto "${dest}"
228 doins -r "$@"
229 ) || die "Installing examples failed"
230 fi
231}
148 232
149# ----------------------------------------------------------------------------- 233# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 234# @ebuild-function java-pkg_dojar
151# 235#
152# Installs any number of jars. 236# Installs any number of jars.
171 # Create JARDEST if it doesn't exist 255 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 256 dodir ${JAVA_PKG_JARDEST}
173 257
174 local jar 258 local jar
175 # for each jar 259 # for each jar
176 for jar in "$@"; do 260 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 261 local jar_basename=$(basename "${jar}")
178 262
179 java-pkg_check-versioned-jar ${jar_basename} 263 java-pkg_check-versioned-jar ${jar_basename}
180 264
181 # check if it exists 265 # check if it exists
182 if [[ -e "${jar}" ]] ; then 266 if [[ -e "${jar}" ]] ; then
267 # Don't overwrite if jar has already been installed with the same
268 # name
269 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
270 if [[ -e "${dest}" ]]; then
271 ewarn "Overwriting ${dest}"
272 fi
273
183 # install it into JARDEST if it's a non-symlink 274 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 275 if [[ ! -L "${jar}" ]] ; then
276 #but first check class version when in strict mode.
277 is-java-strict && java-pkg_verify-classes "${jar}"
278
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 279 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 280 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 281 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 282 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 283 # make a symlink to the original jar if it's symlink
199 done 293 done
200 294
201 java-pkg_do_write_ 295 java-pkg_do_write_
202} 296}
203 297
298# ------------------------------------------------------------------------------
299# @internal-function depend-java-query
300#
301# Wrapper for the depend-java-query binary to enable passing USE in env.
302# Using env variables keeps this eclass working with java-config versions that
303# do not handle use flags.
304# ------------------------------------------------------------------------------
204 305
306depend-java-query() {
307 # Used to have a which call here but it caused endless loops for some people
308 # that had some weird bashrc voodoo for which.
309 USE="${USE}" /usr/bin/depend-java-query "${@}"
310}
205 311
206# ------------------------------------------------------------------------------ 312# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 313# @ebuild-function java-pkg_regjar
208# 314#
209# Records an already installed jar in the package.env 315# Records an already installed jar in the package.env
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 346 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 347
242 java-pkg_init_paths_ 348 java-pkg_init_paths_
243 349
244 local jar jar_dir jar_file 350 local jar jar_dir jar_file
245 for jar in "$@"; do 351 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 352 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 353 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
354 [[ -d "${jar}" || -d "${D}${jar}" ]] \
355 && die "Called ${FUNCNAME} on a directory $*"
356
357 #check that class version correct when in strict mode
358 is-java-strict && java-pkg_verify-classes "${jar}"
359
248 # nelchael: we should strip ${D} in this case too, here's why: 360 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 361 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 362 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 363 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 364 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 365 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 366 else
367 if [[ ${jar} = *\** ]]; then
368 eerror "The argument ${jar} to ${FUNCNAME}"
369 eerror "has * in it. If you want it to glob in"
370 eerror '${D} add ${D} to the argument.'
371 fi
257 die "${jar} does not exist" 372 die "${jar} does not exist"
258 fi 373 fi
259 done 374 done
260 375
261 java-pkg_do_write_ 376 java-pkg_do_write_
262} 377}
263
264 378
265# ------------------------------------------------------------------------------ 379# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 380# @ebuild-function java-pkg_newjar
267# 381#
268# Installs a jar with a new name 382# Installs a jar with a new name
279 local original_jar="${1}" 393 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 394 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 395 local new_jar_dest="${T}/${new_jar}"
282 396
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 397 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 398 [[ ! -f ${original_jar} ]] \
399 && die "${original_jar} does not exist or is not a file!"
285 400
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 401 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 402 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 403 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 404 java-pkg_dojar "${new_jar_dest}"
290} 405}
291 406
292
293# ------------------------------------------------------------------------------ 407# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 408# @ebuild-function java-pkg_addcp
295# 409#
296# Add something to the package's classpath. For jars, you should use dojar, 410# 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. 411# newjar, or regjar. This is typically used to add directories to the classpath.
301# ------------------------------------------------------------------------------ 415# ------------------------------------------------------------------------------
302java-pkg_addcp() { 416java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 417 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 418 java-pkg_do_write_
305} 419}
306
307 420
308# ------------------------------------------------------------------------------ 421# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 422# @ebuild-function java-pkg_doso
310# 423#
311# Installs any number of JNI libraries 424# Installs any number of JNI libraries
334 if [[ -e "${lib}" ]] ; then 447 if [[ -e "${lib}" ]] ; then
335 # install if it isn't a symlink 448 # install if it isn't a symlink
336 if [[ ! -L "${lib}" ]] ; then 449 if [[ ! -L "${lib}" ]] ; then
337 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 450 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
338 INSOPTIONS="${LIBOPTIONS}" \ 451 INSOPTIONS="${LIBOPTIONS}" \
339 doins "${lib}" || "failed to install ${lib}" 452 doins "${lib}" || die "failed to install ${lib}"
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 453 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 454 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 455 # otherwise make a symlink to the symlink's origin
343 else 456 else
344 # TODO use dosym 457 # TODO use dosym
458 ln -s "$(readlink "${lib}")" \
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 459 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
346 debug-print "${lib} is a symlink, linking accordanly" 460 debug-print "${lib} is a symlink, linking accordanly"
347 fi 461 fi
348 # otherwise die 462 # otherwise die
349 else 463 else
350 die "${lib} does not exist" 464 die "${lib} does not exist"
428# ------------------------------------------------------------------------------ 542# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 543java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 544 debug-print-function ${FUNCNAME} $*
431 545
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 546 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 547
548 # from /usr/lib/portage/bin/dohtml -h
549 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 550 dohtml -f package-list "$@"
551
435 # this probably shouldn't be here but it provides 552 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 553 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 554 # old ebuilds.
438 java-pkg_recordjavadoc 555 java-pkg_recordjavadoc
439} 556}
440 557
441# TODO document 558# ------------------------------------------------------------------------------
559# @ebuild-function java-pkg_dojavadoc
560#
561# Installs javadoc documentation. This should be controlled by the doc use flag.
562#
563# @param $1: optional --symlink creates to symlink like this for html
564# documentation bundles.
565# @param $2: - The javadoc root directory.
566#
567# @example:
568# java-pkg_dojavadoc docs/api
569# java-pkg_dojavadoc --symlink apidocs docs/api
570#
571# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 572java-pkg_dojavadoc() {
573 debug-print-function ${FUNCNAME} $*
574
575 # For html documentation bundles that link to Javadoc
576 local symlink
577 if [[ ${1} = --symlink ]]; then
578 symlink=${2}
579 shift 2
580 fi
581
443 local dir="$1" 582 local dir="$1"
583 local dest=/usr/share/doc/${PF}/html
584
585 # QA checks
444 586
445 java-pkg_check-phase install 587 java-pkg_check-phase install
446 588
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 589 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 590 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
591 if [[ ! -e "${dir}/index.html" ]]; then
592 local msg="No index.html in javadoc directory"
593 ewarn "${msg}"
594 is-java-strict && die "${msg}"
595 fi
596
597 if [[ -e ${D}/${dest}/api ]]; then
598 eerror "${dest} already exists. Will not overwrite."
599 die "${dest}"
600 fi
601
602 # Renaming to match our directory layout
449 603
450 local dir_to_install="${dir}" 604 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 605 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 606 dir_to_install="${T}/api"
453 # TODO use doins 607 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 608 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 609 fi
456 610
611 # Actual installation
612
457 java-pkg_dohtml -r ${dir_to_install} 613 java-pkg_dohtml -r "${dir_to_install}"
614
615 # Let's make a symlink to the directory we have everything else under
616 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
617
618 if [[ ${symlink} ]]; then
619 debug-print "symlinking ${dest}/{api,${symlink}}"
620 dosym ${dest}/{api,${symlink}} || die
621 fi
458} 622}
459 623
460# ------------------------------------------------------------------------------ 624# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 625# @ebuild-function java-pkg_dosrc
462# 626#
478# FIXME apparently this fails if you give it an empty directories 642# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 643java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 644 debug-print-function ${FUNCNAME} $*
481 645
482 [ ${#} -lt 1 ] && die "At least one argument needed" 646 [ ${#} -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 647
487 java-pkg_check-phase install 648 java-pkg_check-phase install
488 649
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 650 [[ ${#} -lt 1 ]] && die "At least one argument needed"
651
652 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
653 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
654 java-pkg_announce-qa-violation ${msg}
655 fi
490 656
491 java-pkg_init_paths_ 657 java-pkg_init_paths_
492 658
493 local zip_name="${PN}-src.zip" 659 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 660 local zip_path="${T}/${zip_name}"
495 local dir 661 local dir
496 for dir in ${@}; do 662 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 663 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 664 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 665 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 666 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 667 local result=$?
518# @ebuild-function java-pkg_dolauncher 684# @ebuild-function java-pkg_dolauncher
519# 685#
520# Make a wrapper script to lauch/start this package 686# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 687# If necessary, the wrapper will switch to the appropriate VM.
522# 688#
689# Can be called without parameters if the package installs only one jar
690# that has the Main-class attribute set. The wrapper will be named ${PN}.
691#
523# @param $1 - filename of launcher to create 692# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 693# @param $2 - options, as follows:
525# --main the.main.class.too.start 694# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 695# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass to java' 696# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to the package' 697# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 698# --pwd Directory the launcher changes to before executing java
530# -into 699# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 700# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 701# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 702java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 703 debug-print-function ${FUNCNAME} $*
535 704
536 java-pkg_check-phase install 705 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 706 java-pkg_init_paths_
541 707
708 if [[ ${#} = 0 ]]; then
709 local name="${PN}"
710 else
542 local name="${1}" 711 local name="${1}"
712 shift
713 fi
714
543 # TODO rename to launcher 715 # TODO rename to launcher
544 local target="${T}/${name}" 716 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp" 717 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 718 local target_dir pre
547 shift
548 719
549 # Process the other the rest of the arguments 720 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 721 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 722 local var="${1}" value="${2}"
552 if [[ "${var:0:2}" == "--" ]]; then 723 if [[ "${var:0:2}" == "--" ]]; then
724 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 725 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
726 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 727 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 728 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 729 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 730 pre="${value}"
558 fi 731 fi
559 shift 2 732 shift 2
560 done 733 done
561 734
735 # Test if no --jar and --main arguments were given and
736 # in that case check if the package only installs one jar
737 # and use that jar.
738 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
739 local cp="${JAVA_PKG_CLASSPATH}"
740 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
741 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
742 else
743 local msg="Not enough information to create a launcher given."
744 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
745 die "${msg}"
746 fi
747 fi
748
562 # Write the actual script 749 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 750 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 751 if [[ -n "${pre}" ]]; then
752 if [[ -f "${pre}" ]]; then
753 cat "${pre}" >> "${target}"
754 else
755 die "-pre specified file '${pre}' does not exist"
756 fi
757 fi
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 758 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
566 cat "${var_tmp}" >> "${target}" 759 cat "${var_tmp}" >> "${target}"
760 rm -f "${var_tmp}"
567 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 761 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
568 762
569 if [[ -n "${target_dir}" ]]; then 763 if [[ -n "${target_dir}" ]]; then
570 DESTTREE="${target_dir}" dobin "${target}" 764 DESTTREE="${target_dir}" dobin "${target}"
571 local ret=$? 765 local ret=$?
660# Example: get a specific jar from xerces slot 2, and name it diffrently 854# Example: get a specific jar from xerces slot 2, and name it diffrently
661# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 855# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
662# Example: get junit.jar which is needed only for building 856# Example: get junit.jar which is needed only for building
663# java-pkg_jar-from --build-only junit junit.jar 857# java-pkg_jar-from --build-only junit junit.jar
664# 858#
665# @param $1 - (optional) "--build-only" makes the jar(s) not added into 859# @param $opt
666# package.env DEPEND line. 860# --build-only - makes the jar(s) not added into package.env DEPEND line.
667# @param $1 - Package to get jars from. 861# (assumed automatically when called inside src_test)
862# --with-dependencies - get jars also from requested package's dependencies
863# transitively.
864# --virtual - Packages passed to this function are to be handled as virtuals
865# and will not have individual jar dependencies recorded.
866# --into $dir - symlink jar(s) into $dir (must exist) instead of .
867# @param $1 - Package to get jars from, or comma-separated list of packages in
868# case other parameters are not used.
668# @param $2 - jar from package. If not specified, all jars will be used. 869# @param $2 - jar from package. If not specified, all jars will be used.
669# @param $3 - When a single jar is specified, destination filename of the 870# @param $3 - When a single jar is specified, destination filename of the
670# symlink. Defaults to the name of the jar. 871# symlink. Defaults to the name of the jar.
671# ------------------------------------------------------------------------------ 872# ------------------------------------------------------------------------------
672# TODO could probably be cleaned up a little 873# TODO could probably be cleaned up a little
673java-pkg_jar-from() { 874java-pkg_jar-from() {
674 debug-print-function ${FUNCNAME} $* 875 debug-print-function ${FUNCNAME} $*
675 876
676 local build_only="" 877 local build_only=""
878 local destdir="."
879 local deep=""
880 local virtual=""
677 881
882 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
883
884 while [[ "${1}" == --* ]]; do
678 if [[ "${1}" = "--build-only" ]]; then 885 if [[ "${1}" = "--build-only" ]]; then
679 build_only="true" 886 build_only="build"
887 elif [[ "${1}" = "--with-dependencies" ]]; then
888 deep="--with-dependencies"
889 elif [[ "${1}" = "--virtual" ]]; then
890 virtual="true"
891 elif [[ "${1}" = "--into" ]]; then
892 destdir="${2}"
893 shift
894 else
895 die "java-pkg_jar-from called with unknown parameter: ${1}"
896 fi
680 shift 897 shift
681 fi 898 done
682 899
683 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 900 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
684 901
685 [[ -z ${target_pkg} ]] && die "Must specify a package" 902 [[ -z ${target_pkg} ]] && die "Must specify a package"
903
904 if [[ "${EAPI}" == "1" ]]; then
905 target_pkg="${target_pkg//:/-}"
906 fi
686 907
687 # default destjar to the target jar 908 # default destjar to the target jar
688 [[ -z "${destjar}" ]] && destjar="${target_jar}" 909 [[ -z "${destjar}" ]] && destjar="${target_jar}"
689 910
690 local error_msg="There was a problem getting the classpath for ${target_pkg}." 911 local error_msg="There was a problem getting the classpath for ${target_pkg}."
691 local classpath 912 local classpath
692 classpath="$(java-config --classpath=${target_pkg})" 913 classpath="$(java-config ${deep} --classpath=${target_pkg})"
693 [[ $? != 0 ]] && die ${error_msg} 914 [[ $? != 0 ]] && die ${error_msg}
915
916 # When we have commas this functions is called to bring jars from multiple
917 # packages. This affects recording of dependencencies performed later
918 # which expects one package only, so we do it here.
919 if [[ ${target_pkg} = *,* ]]; then
920 for pkg in ${target_pkg//,/ }; do
921 java-pkg_ensure-dep "${build_only}" "${pkg}"
922 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
923 done
924 # setting this disables further record-jar_ calls later
925 build_only="build"
926 else
927 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
928 fi
929
930 # Record the entire virtual as a dependency so that
931 # no jars are missed.
932 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
933 java-pkg_record-jar_ "${target_pkg}"
934 # setting this disables further record-jars_ calls later
935 build_only="build"
936 fi
937
938 pushd ${destdir} > /dev/null \
939 || die "failed to change directory to ${destdir}"
694 940
695 local jar 941 local jar
696 for jar in ${classpath//:/ }; do 942 for jar in ${classpath//:/ }; do
697 local jar_name=$(basename "${jar}") 943 local jar_name=$(basename "${jar}")
698 if [[ ! -f "${jar}" ]] ; then 944 if [[ ! -f "${jar}" ]] ; then
709 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 955 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
710 [[ -f "${destjar}" ]] && rm "${destjar}" 956 [[ -f "${destjar}" ]] && rm "${destjar}"
711 ln -snf "${jar}" "${destjar}" \ 957 ln -snf "${jar}" "${destjar}" \
712 || die "Failed to make symlink from ${jar} to ${destjar}" 958 || die "Failed to make symlink from ${jar} to ${destjar}"
713 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 959 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
960 popd > /dev/null
714 return 0 961 return 0
715 fi 962 fi
716 done 963 done
964 popd > /dev/null
717 # if no target was specified, we're ok 965 # if no target was specified, we're ok
718 if [[ -z "${target_jar}" ]] ; then 966 if [[ -z "${target_jar}" ]] ; then
719 return 0 967 return 0
720 # otherwise, die bitterly 968 # otherwise, die bitterly
721 else 969 else
740# The providing packages are recorded as dependencies into package.env DEPEND 988# The providing packages are recorded as dependencies into package.env DEPEND
741# line, unless "--build-only" is passed as the very first argument, for jars 989# line, unless "--build-only" is passed as the very first argument, for jars
742# that have to be present only at build time and are not needed on runtime 990# that have to be present only at build time and are not needed on runtime
743# (junit testing etc). 991# (junit testing etc).
744# 992#
745# Example: Get the classpath for xerces-2, 993# Example: Get the classpath for xerces-2 and xalan,
746# java-pkg_getjars xerces-2 xalan 994# java-pkg_getjars xerces-2,xalan
747# Example Return: 995# Example Return:
748# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 996# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
749# 997#
750# @param $1 - (optional) "--build-only" makes the jar(s) not added into 998# @param $opt
751# package.env DEPEND line. 999# --build-only - makes the jar(s) not added into package.env DEPEND line.
1000# (assumed automatically when called inside src_test)
1001# --with-dependencies - get jars also from requested package's dependencies
1002# transitively.
752# @param $@ - list of packages to get jars from 1003# @param $1 - list of packages to get jars from
1004# (passed to java-config --classpath)
753# ------------------------------------------------------------------------------ 1005# ------------------------------------------------------------------------------
754java-pkg_getjars() { 1006java-pkg_getjars() {
755 debug-print-function ${FUNCNAME} $* 1007 debug-print-function ${FUNCNAME} $*
756 1008
757 local build_only="" 1009 local build_only=""
1010 local deep=""
758 1011
1012 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1013
1014 while [[ "${1}" == --* ]]; do
759 if [[ "${1}" = "--build-only" ]]; then 1015 if [[ "${1}" = "--build-only" ]]; then
760 build_only="true" 1016 build_only="build"
1017 elif [[ "${1}" = "--with-dependencies" ]]; then
1018 deep="--with-dependencies"
1019 else
1020 die "java-pkg_jar-from called with unknown parameter: ${1}"
1021 fi
761 shift 1022 shift
762 fi
763
764 [[ ${#} -lt 1 ]] && die "At least one argument needed"
765
766 # NOTE could probably just pass $@ to java-config --classpath. and return it
767 local classpath pkg
768 for pkg in ${@//,/ }; do
769 #for pkg in $(echo "$@" | tr ',' ' '); do
770 jars="$(java-config --classpath=${pkg})"
771 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
772 debug-print "${pkg}:${jars}"
773
774 if [[ -z "${classpath}" ]]; then
775 classpath="${jars}"
776 else
777 classpath="${classpath}:${jars}"
778 fi
779 # Only record jars that aren't build-only
780 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
781 done 1023 done
782 echo "${classpath}" 1024
1025 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1026
1027
1028 local pkgs="${1}"
1029
1030 if [[ "${EAPI}" == "1" ]]; then
1031 pkgs="${pkgs//:/-}"
1032 fi
1033
1034 jars="$(java-config ${deep} --classpath=${pkgs})"
1035 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1036 debug-print "${pkgs}:${jars}"
1037
1038 for pkg in ${pkgs//,/ }; do
1039 java-pkg_ensure-dep "${build_only}" "${pkg}"
1040 done
1041
1042 # Only record jars that aren't build-only
1043 if [[ -z "${build_only}" ]]; then
1044 for pkg in ${pkgs//,/ }; do
1045 java-pkg_record-jar_ "${pkg}"
1046 done
1047 fi
1048
1049 echo "${jars}"
783} 1050}
784 1051
785# ------------------------------------------------------------------------------ 1052# ------------------------------------------------------------------------------
786# @ebuild-function java-pkg_getjar 1053# @ebuild-function java-pkg_getjar
787# 1054#
794# @example 1061# @example
795# java-pkg_getjar xerces-2 xml-apis.jar 1062# java-pkg_getjar xerces-2 xml-apis.jar
796# @example-return 1063# @example-return
797# /usr/share/xerces-2/lib/xml-apis.jar 1064# /usr/share/xerces-2/lib/xml-apis.jar
798# 1065#
799# @param $1 - (optional) "--build-only" makes the jar not added into 1066# @param $opt
800# package.env DEPEND line. 1067# --build-only - makes the jar not added into package.env DEPEND line.
1068# --virtual - Packages passed to this function are to be handled as virtuals
1069# and will not have individual jar dependencies recorded.
801# @param $1 - package to use 1070# @param $1 - package to use
802# @param $2 - jar to get 1071# @param $2 - jar to get
803# ------------------------------------------------------------------------------ 1072# ------------------------------------------------------------------------------
804java-pkg_getjar() { 1073java-pkg_getjar() {
805 debug-print-function ${FUNCNAME} $* 1074 debug-print-function ${FUNCNAME} $*
806 1075
807 local build_only="" 1076 local build_only=""
1077 local virtual=""
808 1078
1079 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1080
1081 while [[ "${1}" == --* ]]; do
809 if [[ "${1}" = "--build-only" ]]; then 1082 if [[ "${1}" = "--build-only" ]]; then
810 build_only="true" 1083 build_only="build"
1084 elif [[ "${1}" == "--virtual" ]]; then
1085 virtual="true"
1086 else
1087 die "java-pkg_getjar called with unknown parameter: ${1}"
1088 fi
811 shift 1089 shift
812 fi 1090 done
1091
1092 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
813 1093
814 local pkg="${1}" target_jar="${2}" jar 1094 local pkg="${1}" target_jar="${2}" jar
1095
1096 if [[ "${EAPI}" == "1" ]]; then
1097 pkg="${pkg//:/-}"
1098 fi
1099
815 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1100 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
816 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1101 [[ -z ${target_jar} ]] && die "Must specify jar to get"
817 1102
818 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1103 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
819 local classpath 1104 local classpath
820 classpath=$(java-config --classpath=${pkg}) 1105 classpath=$(java-config --classpath=${pkg})
821 [[ $? != 0 ]] && die ${error_msg} 1106 [[ $? != 0 ]] && die ${error_msg}
1107
1108 java-pkg_ensure-dep "${build_only}" "${pkg}"
1109
1110 # Record the package(Virtual) as a dependency and then set build_only
1111 # So that individual jars are not recorded.
1112 if [[ -n "${virtual}" ]]; then
1113 java-pkg_record-jar_ "${pkg}"
1114 build_only="true"
1115 fi
822 1116
823 for jar in ${classpath//:/ }; do 1117 for jar in ${classpath//:/ }; do
824 if [[ ! -f "${jar}" ]] ; then 1118 if [[ ! -f "${jar}" ]] ; then
825 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1119 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
826 fi 1120 fi
833 fi 1127 fi
834 done 1128 done
835 1129
836 die "Could not find ${target_jar} in ${pkg}" 1130 die "Could not find ${target_jar} in ${pkg}"
837 return 1 1131 return 1
1132}
1133
1134# ------------------------------------------------------------------------------
1135# @ebuild-function java-pkg_register-dependency
1136#
1137# Registers runtime dependency on a package, list of packages, or a single jar
1138# from a package, into package.env DEPEND line. Can only be called in
1139# src_install phase.
1140# Intended for binary packages where you don't need to symlink the jars or get
1141# their classpath during build. As such, the dependencies only need to be
1142# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1143#
1144# @param $1 - comma-separated list of packages, or a single package
1145# @param $2 - if param $1 is a single package, optionally specify the jar
1146# to depend on
1147#
1148# Example: Record the dependency on whole xerces-2 and xalan,
1149# java-pkg_register-dependency xerces-2,xalan
1150# Example: Record the dependency on ant.jar from ant-core
1151# java-pkg_register-dependency ant-core ant.jar
1152#
1153# Note: Passing both list of packages as the first parameter AND specifying the
1154# jar as the second is not allowed and will cause the function to die. We assume
1155# that there's more chance one passes such combination as a mistake, than that
1156# there are more packages providing identically named jar without class
1157# collisions.
1158# ------------------------------------------------------------------------------
1159java-pkg_register-dependency() {
1160 debug-print-function ${FUNCNAME} $*
1161
1162 java-pkg_check-phase install
1163
1164 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1165
1166 local pkgs="${1}"
1167 local jar="${2}"
1168
1169 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1170
1171 if [[ "${EAPI}" == "1" ]]; then
1172 pkgs="${pkgs//:/-}"
1173 fi
1174
1175 if [[ -z "${jar}" ]]; then
1176 for pkg in ${pkgs//,/ }; do
1177 java-pkg_ensure-dep runtime "${pkg}"
1178 java-pkg_record-jar_ "${pkg}"
1179 done
1180 else
1181 [[ ${pkgs} == *,* ]] && \
1182 die "${FUNCNAME} called with both package list and jar name"
1183 java-pkg_ensure-dep runtime "${pkgs}"
1184 java-pkg_record-jar_ "${pkgs}" "${jar}"
1185 fi
1186
1187 java-pkg_do_write_
1188}
1189
1190# ------------------------------------------------------------------------------
1191# @ebuild-function java-pkg_register-optional-dependency
1192#
1193# Registers optional runtime dependency on a package, list of packages, or a
1194# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1195# called in src_install phase.
1196# Intended for packages that can use other packages when those are in classpath.
1197# Will be put on classpath by launcher if they are installed. Typical case is
1198# JDBC implementations for various databases. It's better than having USE flag
1199# for each implementation triggering hard dependency.
1200#
1201# @param $1 - comma-separated list of packages, or a single package
1202# @param $2 - if param $1 is a single package, optionally specify the jar
1203# to depend on
1204#
1205# Example: Record the optional dependency on some jdbc providers
1206# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1207#
1208# Note: Passing both list of packages as the first parameter AND specifying the
1209# jar as the second is not allowed and will cause the function to die. We assume
1210# that there's more chance one passes such combination as a mistake, than that
1211# there are more packages providing identically named jar without class
1212# collisions.
1213# ------------------------------------------------------------------------------
1214java-pkg_register-optional-dependency() {
1215 debug-print-function ${FUNCNAME} $*
1216
1217 java-pkg_check-phase install
1218
1219 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1220
1221 local pkgs="${1}"
1222 local jar="${2}"
1223
1224 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1225
1226 if [[ "${EAPI}" == "1" ]]; then
1227 pkgs="${pkgs//:/-}"
1228 fi
1229
1230 if [[ -z "${jar}" ]]; then
1231 for pkg in ${pkgs//,/ }; do
1232 java-pkg_record-jar_ --optional "${pkg}"
1233 done
1234 else
1235 [[ ${pkgs} == *,* ]] && \
1236 die "${FUNCNAME} called with both package list and jar name"
1237 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1238 fi
1239
1240 java-pkg_do_write_
1241}
1242
1243# ------------------------------------------------------------------------------
1244# @ebuild-function java-pkg_register-environment-variable
1245#
1246# Register an arbitrary environment variable into package.env. The gjl launcher
1247# for this package or any package depending on this will export it into
1248# environement before executing java command.
1249# Must only be called in src_install phase.
1250#
1251# @param $1 - variable name
1252# @param $2 - variable value
1253# ------------------------------------------------------------------------------
1254JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1255JAVA_PKG_EXTRA_ENV_VARS=""
1256java-pkg_register-environment-variable() {
1257 debug-print-function ${FUNCNAME} $*
1258
1259 java-pkg_check-phase install
1260
1261 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1262
1263 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1264 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1265
1266 java-pkg_do_write_
838} 1267}
839 1268
840# This function reads stdin, and based on that input, figures out how to 1269# This function reads stdin, and based on that input, figures out how to
841# populate jars from the filesystem. 1270# populate jars from the filesystem.
842# Need to figure out a good way of making use of this, ie be able to use a 1271# Need to figure out a good way of making use of this, ie be able to use a
959# 1388#
960# export DEPEND="${DEPEND} ${depstr}" 1389# export DEPEND="${DEPEND} ${depstr}"
961# export RDEPEND="${RDEPEND} ${depstr}" 1390# export RDEPEND="${RDEPEND} ${depstr}"
962#} 1391#}
963 1392
1393# ------------------------------------------------------------------------------
1394# @ebuild-function java-pkg_find-normal-jars
1395#
1396# Find the files with suffix .jar file in the given directory or $WORKDIR
1397#
1398# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1399# ------------------------------------------------------------------------------
1400java-pkg_find-normal-jars() {
1401 local dir=$1
1402 [[ "${dir}" ]] || dir="${WORKDIR}"
1403 local found
1404 for jar in $(find "${dir}" -name "*.jar" -type f); do
1405 echo "${jar}"
1406 found="true"
1407 done
1408 [[ "${found}" ]]
1409 return $?
1410}
1411
1412# ------------------------------------------------------------------------------
1413# @ebuild-function java-pkg_ensure-no-bundled-jars
1414#
1415# Try to locate bundled jar files in ${WORKDIR} and die if found.
964# This should be used after S has been populated with symlinks to jars 1416# This function should be called after WORKDIR has been populated with symlink
965# TODO document 1417# to system jar files or bundled jars removed.
1418# ------------------------------------------------------------------------------
966java-pkg_ensure-no-bundled-jars() { 1419java-pkg_ensure-no-bundled-jars() {
967 debug-print-function ${FUNCNAME} $* 1420 debug-print-function ${FUNCNAME} $*
968 pushd ${WORKDIR} >/dev/null 2>/dev/null
969 1421
970 local bundled_jars=$(find . -name "*.jar" -type f) 1422 local bundled_jars=$(java-pkg_find-normal-jars)
971 if [[ -n ${bundled_jars} ]]; then 1423 if [[ -n ${bundled_jars} ]]; then
972 echo "Bundled jars found:" 1424 echo "Bundled jars found:"
973 local jar 1425 local jar
974 for jar in ${bundled_jars}; do 1426 for jar in ${bundled_jars}; do
975 echo $(pwd)${jar/./} 1427 echo $(pwd)${jar/./}
976 done 1428 done
977 die "Bundled jars found!" 1429 die "Bundled jars found!"
978
979 fi 1430 fi
980 popd >/dev/null 2>/dev/null
981} 1431}
982 1432
983# ------------------------------------------------------------------------------ 1433# ------------------------------------------------------------------------------
984# @internal-function java-pkg_ensure-vm-version-sufficient 1434# @internal-function java-pkg_ensure-vm-version-sufficient
985# 1435#
1134# @ebuild-function java-pkg_get-target 1584# @ebuild-function java-pkg_get-target
1135# 1585#
1136# Determines what target version should be used, for passing to -target. 1586# Determines what target version should be used, for passing to -target.
1137# If you don't care about lower versions, you can set _WANT_TARGET to the 1587# If you don't care about lower versions, you can set _WANT_TARGET to the
1138# version of your JDK. 1588# version of your JDK.
1139# Remember doing this will mostly like cause things to break.
1140# Doesn't allow it to be lower then the one in depend.
1141# Doesn't allow it to be higher then the active vm.
1142# 1589#
1143# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1590# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1144# ------------------------------------------------------------------------------ 1591# ------------------------------------------------------------------------------
1145java-pkg_get-target() { 1592java-pkg_get-target() {
1146 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1147 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1148 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1149 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1150 echo ${JAVA_PKG_WANT_TARGET}
1151 else
1152 echo ${min}
1153 fi
1154 else
1155 echo ${min}
1156 fi
1157
1158 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1593 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1159} 1594}
1160 1595
1161java-pkg_get-javac() { 1596java-pkg_get-javac() {
1162 debug-print-function ${FUNCNAME} $* 1597 debug-print-function ${FUNCNAME} $*
1163 1598
1164 java-pkg_init-compiler_ 1599
1165 local compiler="${GENTOO_COMPILER}" 1600 local compiler="${GENTOO_COMPILER}"
1166 1601
1167 local compiler_executable 1602 local compiler_executable
1168 if [[ "${compiler}" = "javac" ]]; then 1603 if [[ "${compiler}" = "javac" ]]; then
1169 # nothing fancy needs to be done for javac 1604 # nothing fancy needs to be done for javac
1177 unset JAVAC 1612 unset JAVAC
1178 # try to get value of JAVAC 1613 # try to get value of JAVAC
1179 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1614 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1180 export JAVAC=${old_javac} 1615 export JAVAC=${old_javac}
1181 1616
1182 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1617 if [[ -z ${compiler_executable} ]]; then
1618 echo "JAVAC is empty or undefined in ${compiler_env}"
1619 return 1
1620 fi
1183 1621
1184 # check that it's executable 1622 # check that it's executable
1185 if [[ ! -x ${compiler_executable} ]]; then 1623 if [[ ! -x ${compiler_executable} ]]; then
1186 eerror "Could not find ${compiler_executable}!"
1187 die "${compiler_executable} doesn't exist, or isn't executable" 1624 echo "${compiler_executable} doesn't exist, or isn't executable"
1625 return 1
1188 fi 1626 fi
1189 else 1627 else
1190 eerror "Could not find environment file for ${compiler}" 1628 echo "Could not find environment file for ${compiler}"
1191 die "Could not find ${compiler_env}" 1629 return 1
1192 fi 1630 fi
1193 fi 1631 fi
1194 echo ${compiler_executable} 1632 echo ${compiler_executable}
1195} 1633}
1196 1634
1213 1651
1214 debug-print "want source: ${want_source}" 1652 debug-print "want source: ${want_source}"
1215 debug-print "want target: ${want_target}" 1653 debug-print "want target: ${want_target}"
1216 1654
1217 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1655 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1218 debug-print "could not find valid -source/-target values" 1656 debug-print "could not find valid -source/-target values for javac"
1219 die "Could not find valid -source/-target values" 1657 echo "Could not find valid -source/-target values for javac"
1658 return 1
1220 else 1659 else
1221 if java-pkg_is-vm-version-ge "1.4"; then 1660 if java-pkg_is-vm-version-ge "1.4"; then
1222 echo "${source_str} ${target_str}" 1661 echo "${source_str} ${target_str}"
1223 else 1662 else
1224 echo "${target_str}" 1663 echo "${target_str}"
1228 1667
1229# TODO document 1668# TODO document
1230java-pkg_get-jni-cflags() { 1669java-pkg_get-jni-cflags() {
1231 local flags="-I${JAVA_HOME}/include" 1670 local flags="-I${JAVA_HOME}/include"
1232 1671
1672 local platform="linux"
1673 use elibc_FreeBSD && platform="freebsd"
1674
1233 # TODO do a check that the directories are valid 1675 # TODO do a check that the directories are valid
1234 # TODO figure out how to cope with other things than linux...
1235 flags="${flags} -I${JAVA_HOME}/include/linux" 1676 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1236 1677
1237 echo ${flags} 1678 echo ${flags}
1238} 1679}
1239 1680
1240java-pkg_ensure-gcj() { 1681java-pkg_ensure-gcj() {
1246 die "No GCJ support found!" 1687 die "No GCJ support found!"
1247 fi 1688 fi
1248} 1689}
1249 1690
1250java-pkg_ensure-test() { 1691java-pkg_ensure-test() {
1251 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1692 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1693 && hasq test ${IUSE} && ! use test;
1694 then
1252 eerror "You specified FEATURES=test, but USE=test is needed" 1695 eerror "You specified FEATURES=test, but USE=test is needed"
1253 eerror "to pull in the additional dependencies for testing" 1696 eerror "to pull in the additional dependencies for testing"
1254 die "Need USE=test enabled" 1697 die "Need USE=test enabled"
1255 fi 1698 fi
1256} 1699}
1257 1700
1258# ------------------------------------------------------------------------------ 1701# ------------------------------------------------------------------------------
1702# @ebuild-function java-pkg_register-ant-task
1703#
1704# Register this package as ant task, so that ant will load it when no specific
1705# ANT_TASKS are specified. Note that even without this registering, all packages
1706# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1707# packages, but can be also used by other ebuilds that used to symlink their
1708# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1709# compatibility.
1710#
1711# @param --version x.y Register only for ant version x.y (otherwise for any ant
1712# version). Used by the ant-* packages to prevent loading of mismatched
1713# ant-core ant tasks after core was updated, before the tasks are updated,
1714# without a need for blockers.
1715# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1716# ------------------------------------------------------------------------------
1717java-pkg_register-ant-task() {
1718 local TASKS_DIR="tasks"
1719
1720 # check for --version x.y parameters
1721 while [[ -n "${1}" && -n "${2}" ]]; do
1722 local var="${1#--}"
1723 local val="${2}"
1724 if [[ "${var}" == "version" ]]; then
1725 TASKS_DIR="tasks-${val}"
1726 else
1727 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1728 fi
1729 shift 2
1730 done
1731
1732 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1733
1734 dodir /usr/share/ant/${TASKS_DIR}
1735 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1736}
1737
1738# ------------------------------------------------------------------------------
1739# @internal-function java-pkg_ant-tasks-depend
1740#
1741# Translates the WANT_ANT_TASKS variable into valid dependencies.
1742# ------------------------------------------------------------------------------
1743java-pkg_ant-tasks-depend() {
1744 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1745
1746 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1747 local DEP=""
1748 for i in ${WANT_ANT_TASKS}
1749 do
1750 if [[ ${i} = ant-* ]]; then
1751 DEP="${DEP}dev-java/${i} "
1752 elif [[ ${i} = */*:* ]]; then
1753 DEP="${DEP}${i} "
1754 else
1755 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1756 return 1
1757 fi
1758 done
1759 echo ${DEP}
1760 return 0
1761 else
1762 return 0
1763 fi
1764}
1765
1766# ------------------------------------------------------------------------------
1767# @ebuild-function ejunit
1768#
1769# Junit wrapper function. Makes it easier to run the tests and checks for
1770# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1771#
1772# Examples:
1773# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1774# ejunit org.blinkenlights.jid3.test.AllTests
1775#
1776# @param $1 - -cp or -classpath
1777# @param $2 - classpath; junit and recorded dependencies get appended
1778# @param $@ - the rest of the parameters are passed to java
1779# ------------------------------------------------------------------------------
1780ejunit() {
1781 debug-print-function ${FUNCNAME} $*
1782
1783 local pkgs
1784 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1785 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1786 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1787 done
1788 fi
1789
1790 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1791 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1792 cp="${2}:${cp}"
1793 shift 2
1794 else
1795 cp=".:${cp}"
1796 fi
1797
1798 local runner=junit.textui.TestRunner
1799 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1800 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1801}
1802
1803# ------------------------------------------------------------------------------
1259# @section-end helper 1804# @section-end helper
1260# ------------------------------------------------------------------------------ 1805# ------------------------------------------------------------------------------
1806
1807# ------------------------------------------------------------------------------
1808# @eclass-src_prepare
1809#
1810# src_prepare Searches for bundled jars
1811# ------------------------------------------------------------------------------
1812
1813java-utils-2_src_prepare() {
1814 # Remember that eant will call this unless called via Portage
1815 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1816 echo "Searching for bundled jars:"
1817 java-pkg_find-normal-jars || echo "None found."
1818 echo "Searching for bundled classes (no output if none found):"
1819 find "${WORKDIR}" -name "*.class"
1820 echo "Search done."
1821 fi
1822 touch "${T}/java-utils-2_src_prepare-run"
1823}
1261 1824
1262# ------------------------------------------------------------------------------ 1825# ------------------------------------------------------------------------------
1263# @section-begin build 1826# @section-begin build
1264# @section-summary Build functions 1827# @section-summary Build functions
1265# 1828#
1269 1832
1270# ------------------------------------------------------------------------------ 1833# ------------------------------------------------------------------------------
1271# @ebuild-function eant 1834# @ebuild-function eant
1272# 1835#
1273# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1836# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1274# compiler. 1837# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1275# 1838# variables:
1839# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1840# gentoo.classpath property. Be sure to call
1841# java-ant_rewrite-classpath in src_unpack.
1842# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1843# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1276# ------------------------------------------------------------------------------ 1844# ------------------------------------------------------------------------------
1277eant() { 1845eant() {
1278 debug-print-function ${FUNCNAME} $* 1846 debug-print-function ${FUNCNAME} $*
1279 1847
1280 # FIXME get this working 1848 if [[ ${EBUILD_PHASE} = compile ]]; then
1281# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1849 java-ant-2_src_configure
1850 java-utils-2_src_prepare
1851 fi
1852
1853 if ! hasq java-ant-2 ${INHERITED}; then
1854 local msg="You should inherit java-ant-2 when using eant"
1282# java-pkg_announce-qa-violation \ 1855 java-pkg_announce-qa-violation "${msg}"
1283# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1284# fi 1856 fi
1285 1857
1286 local antflags 1858 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1859
1287 java-pkg_init-compiler_ 1860 java-pkg_init-compiler_
1288 local compiler="${GENTOO_COMPILER}" 1861 local compiler="${GENTOO_COMPILER}"
1289 1862
1290 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1863 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1291
1292 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1864 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1293 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1865 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1294 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1866 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1295 fi 1867 fi
1296 1868
1297 if [[ ${compiler} != "javac" ]]; then 1869 if [[ ${compiler} != "javac" ]]; then
1298 antflags="-Dbuild.compiler=${build_compiler}" 1870 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1299 # Figure out any extra stuff to put on the classpath for compilers aside 1871 # Figure out any extra stuff to put on the classpath for compilers aside
1300 # from javac 1872 # from javac
1301 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1873 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1302 # java-config -p 1874 # java-config -p
1303 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1875 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1304 if [[ -n ${build_compiler_deps} ]]; then 1876 if [[ -n ${build_compiler_deps} ]]; then
1305 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1877 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1306 fi 1878 fi
1307 fi 1879 fi
1308 1880
1881 for arg in "${@}"; do
1882 if [[ ${arg} = -lib ]]; then
1309 if is-java-strict; then 1883 if is-java-strict; then
1310 einfo "Disabling system classpath for ant" 1884 eerror "You should not use the -lib argument to eant because it will fail"
1311 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1885 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1886 eerror "or ant properties to make dependencies available."
1887 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1888 eerror "split ant (>=dev-java/ant-core-1.7)."
1889 die "eant -lib is deprecated/forbidden"
1890 else
1891 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1892 echo "more info."
1893 fi
1312 fi 1894 fi
1895 done
1313 1896
1314 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1897 # parse WANT_ANT_TASKS for atoms
1315 antflags="${antflags} -debug" 1898 local want_ant_tasks
1899 for i in ${WANT_ANT_TASKS}; do
1900 if [[ ${i} = */*:* ]]; then
1901 i=${i#*/}
1902 i=${i%:0}
1903 want_ant_tasks+="${i/:/-} "
1904 else
1905 want_ant_tasks+="${i} "
1906 fi
1907 done
1908 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1909 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1910
1911 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1912 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1913
1914 # if ant-tasks is not set by ebuild or forced, use none
1915 ANT_TASKS="${ANT_TASKS:-none}"
1916
1917 # at this point, ANT_TASKS should be "all", "none" or explicit list
1918 if [[ "${ANT_TASKS}" == "all" ]]; then
1919 einfo "Using all available ANT_TASKS"
1920 elif [[ "${ANT_TASKS}" == "none" ]]; then
1921 einfo "Disabling all optional ANT_TASKS"
1922 else
1923 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1924 fi
1925
1926 export ANT_TASKS
1927
1928 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1929 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1930
1931 local gcp="${EANT_GENTOO_CLASSPATH}"
1932 local getjarsarg=""
1933
1934 if [[ ${EBUILD_PHASE} = "test" ]]; then
1935 antflags="${antflags} -DJunit.present=true"
1936 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1937 getjarsarg="--with-dependencies"
1938 fi
1939
1940 local cp
1941
1942 for atom in ${gcp}; do
1943 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1944 done
1945
1946 if [[ ${cp} ]]; then
1947 # It seems ant does not like single quotes around ${cp}
1948 cp=${cp#:}
1949 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1950 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1951 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1316 fi 1952 fi
1317 1953
1318 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1954 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1955 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1319 ant ${antflags} "${@}" || die "eant failed" 1956 ant ${antflags} "${@}" || die "eant failed"
1320
1321} 1957}
1322 1958
1323# ------------------------------------------------------------------------------ 1959# ------------------------------------------------------------------------------
1324# @ebuild-function ejavac 1960# @ebuild-function ejavac
1325# 1961#
1329# @param $@ - Arguments to be passed to the compiler 1965# @param $@ - Arguments to be passed to the compiler
1330# ------------------------------------------------------------------------------ 1966# ------------------------------------------------------------------------------
1331ejavac() { 1967ejavac() {
1332 debug-print-function ${FUNCNAME} $* 1968 debug-print-function ${FUNCNAME} $*
1333 1969
1334 # FIXME using get-javac ends up printing stuff with einfo 1970 java-pkg_init-compiler_
1971
1972 local compiler_executable
1335# local compiler_executable=$(java-pkg_get-javac) 1973 compiler_executable=$(java-pkg_get-javac)
1336 local compiler_executable="javac" 1974 if [[ ${?} != 0 ]]; then
1975 eerror "There was a problem determining compiler: ${compiler_executable}"
1976 die "get-javac failed"
1977 fi
1337 1978
1979 local javac_args
1980 javac_args="$(java-pkg_javac-args)"
1981 if [[ ${?} != 0 ]]; then
1982 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1983 die "java-pkg_javac-args failed"
1984 fi
1985
1338 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1986 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1339 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1987 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1340} 1988}
1341 1989
1342# ------------------------------------------------------------------------------ 1990# ------------------------------------------------------------------------------
1343# @ebuild-function java-pkg_filter-compiler 1991# @ebuild-function java-pkg_filter-compiler
1344# 1992#
1382# ------------------------------------------------------------------------------ 2030# ------------------------------------------------------------------------------
1383use_doc() { 2031use_doc() {
1384 use doc && echo ${@:-javadoc} 2032 use doc && echo ${@:-javadoc}
1385} 2033}
1386 2034
2035
1387# ------------------------------------------------------------------------------ 2036# ------------------------------------------------------------------------------
1388# @section-end build 2037# @section-end build
1389# ------------------------------------------------------------------------------ 2038# ------------------------------------------------------------------------------
1390 2039
1391# ------------------------------------------------------------------------------ 2040# ------------------------------------------------------------------------------
1407# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2056# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1408# call it during each of the phases of the merge process. 2057# call it during each of the phases of the merge process.
1409# 2058#
1410# ----------------------------------------------------------------------------- 2059# -----------------------------------------------------------------------------
1411java-pkg_init() { 2060java-pkg_init() {
2061 debug-print-function ${FUNCNAME} $*
1412 unset JAVAC 2062 unset JAVAC
1413 unset JAVA_HOME 2063 unset JAVA_HOME
2064
2065 # People do all kinds of weird things.
2066 # http://forums.gentoo.org/viewtopic-p-3943166.html
2067 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2068 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2069 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2070 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2071 ewarn "sun-jdk vms and and as such break configure scripts that"
2072 ewarn "use it (for example app-office/openoffice) so we filter it out."
2073 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2074 ewarn "make.conf for example) to silence this warning or"
2075 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2076 fi
2077
2078 if [[ -z ${accept} ]]; then
2079 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2080 # -version output
2081 unset _JAVA_OPTIONS
2082 # phase hooks make this run many times without this
2083 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2084 fi
2085
2086 if java-pkg_func-exists ant_src_unpack; then
2087 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2088 fi
2089
1414 java-pkg_init_paths_ 2090 java-pkg_init_paths_
1415 java-pkg_switch-vm 2091 java-pkg_switch-vm
1416 PATH=${JAVA_HOME}/bin:${PATH} 2092 PATH=${JAVA_HOME}/bin:${PATH}
1417 2093
1418 # TODO we will probably want to set JAVAC and JAVACFLAGS 2094 # TODO we will probably want to set JAVAC and JAVACFLAGS
1419 2095
1420 # Do some QA checks 2096 # Do some QA checks
1421 java-pkg_check-jikes 2097 java-pkg_check-jikes
2098
2099 # Can't use unset here because Portage does not save the unset
2100 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1422 2101
1423 # When users have crazy classpaths some packages can fail to compile. 2102 # When users have crazy classpaths some packages can fail to compile.
1424 # and everything should work with empty CLASSPATH. 2103 # and everything should work with empty CLASSPATH.
1425 # This also helps prevent unexpected dependencies on random things 2104 # This also helps prevent unexpected dependencies on random things
1426 # from the CLASSPATH. 2105 # from the CLASSPATH.
1427 unset CLASSPATH 2106 export CLASSPATH=
2107
2108 # Unset external ANT_ stuff
2109 export ANT_TASKS=
2110 export ANT_OPTS=
1428} 2111}
1429 2112
1430# ------------------------------------------------------------------------------ 2113# ------------------------------------------------------------------------------
1431# @function-internal java-pkg-init-compiler_ 2114# @function-internal java-pkg-init-compiler_
1432# 2115#
1523 done 2206 done
1524 2207
1525 # If it hasn't been defined already, default to javac 2208 # If it hasn't been defined already, default to javac
1526 if [[ -z ${GENTOO_COMPILER} ]]; then 2209 if [[ -z ${GENTOO_COMPILER} ]]; then
1527 if [[ -n ${compilers} ]]; then 2210 if [[ -n ${compilers} ]]; then
1528 einfo "No suitable compiler found: defaulting javac for compilation" 2211 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1529 else 2212 else
1530 # probably don't need to notify users about the default. 2213 # probably don't need to notify users about the default.
1531 :;#einfo "Defaulting to javac for compilation" 2214 :;#einfo "Defaulting to javac for compilation"
1532 fi 2215 fi
2216 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2217 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2218 else
1533 export GENTOO_COMPILER=javac 2219 export GENTOO_COMPILER=javac
2220 fi
1534 else 2221 else
1535 einfo "Using ${GENTOO_COMPILER} for compilation" 2222 einfo "Using ${GENTOO_COMPILER} for compilation"
1536 fi 2223 fi
1537 2224
1538} 2225}
1554 fi 2241 fi
1555 2242
1556 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2243 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1557 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2244 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1558 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2245 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2246 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2247 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1559 2248
1560 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2249 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1561 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2250 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1562 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2251 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1563 2252
1576# Writes the package.env out to disk. 2265# Writes the package.env out to disk.
1577# 2266#
1578# ------------------------------------------------------------------------------ 2267# ------------------------------------------------------------------------------
1579# TODO change to do-write, to match everything else 2268# TODO change to do-write, to match everything else
1580java-pkg_do_write_() { 2269java-pkg_do_write_() {
2270 debug-print-function ${FUNCNAME} $*
2271 java-pkg_init_paths_
1581 # Create directory for package.env 2272 # Create directory for package.env
1582 dodir "${JAVA_PKG_SHAREPATH}" 2273 dodir "${JAVA_PKG_SHAREPATH}"
1583 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2274 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2275 "${JAVA_PKG_DEPEND_FILE}" || -f \
2276 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1584 # Create package.env 2277 # Create package.env
1585 ( 2278 (
1586 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2279 echo "DESCRIPTION=\"${DESCRIPTION}\""
1587 echo "GENERATION=\"2\"" 2280 echo "GENERATION=\"2\""
2281 echo "SLOT=\"${SLOT}\""
1588 2282
1589 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2283 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1590 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2284 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1591 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2285 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1592 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2286 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2287 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2288 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2289 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1593 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2290 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1594 ) > "${JAVA_PKG_ENV}" 2291 ) > "${JAVA_PKG_ENV}"
1595 2292
1596 # register target/source 2293 # register target/source
1597 local target="$(java-pkg_get-target)" 2294 local target="$(java-pkg_get-target)"
1608 2305
1609 2306
1610 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2307 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1611 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2308 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1612 2309
2310 # extra env variables
2311 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2312 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2313 # nested echo to remove leading/trailing spaces
2314 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2315 >> "${JAVA_PKG_ENV}" || die
2316 fi
2317
1613 # Strip unnecessary leading and trailing colons 2318 # Strip unnecessary leading and trailing colons
1614 # TODO try to cleanup if possible 2319 # TODO try to cleanup if possible
1615 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2320 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2321 else
2322 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2323 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2324 debug-print "write package.env."
1616 fi 2325 fi
1617} 2326}
1618
1619 2327
1620# ------------------------------------------------------------------------------ 2328# ------------------------------------------------------------------------------
1621# @internal-function java-pkg_record-jar_ 2329# @internal-function java-pkg_record-jar_
1622# 2330#
1623# Record a dependency to the package.env 2331# Record an (optional) dependency to the package.env
1624# 2332# @param --optional - record dependency as optional
2333# @param $1 - package to record
2334# @param $2 - (optional) jar of package to record
1625# ------------------------------------------------------------------------------ 2335# ------------------------------------------------------------------------------
1626JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2336JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2337JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1627 2338
1628java-pkg_record-jar_() { 2339java-pkg_record-jar_() {
1629 debug-print-function ${FUNCNAME} $* 2340 debug-print-function ${FUNCNAME} $*
2341
2342 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2343 if [[ "${1}" == "--optional" ]]; then
2344 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2345 shift
2346 fi
1630 2347
1631 local pkg=${1} jar=${2} append 2348 local pkg=${1} jar=${2} append
1632 if [[ -z "${jar}" ]]; then 2349 if [[ -z "${jar}" ]]; then
1633 append="${pkg}" 2350 append="${pkg}"
1634 else 2351 else
1635 append="$(basename ${jar})@${pkg}" 2352 append="$(basename ${jar})@${pkg}"
1636 fi 2353 fi
1637 2354
1638 echo ${append} >> ${JAVA_PKG_DEPEND} 2355 echo "${append}" >> "${depend_file}"
1639} 2356}
1640 2357
1641# ------------------------------------------------------------------------------ 2358# ------------------------------------------------------------------------------
1642# @internal-function java-pkg_append_ 2359# @internal-function java-pkg_append_
1643# 2360#
1703# 2420#
1704# ------------------------------------------------------------------------------ 2421# ------------------------------------------------------------------------------
1705java-pkg_setup-vm() { 2422java-pkg_setup-vm() {
1706 debug-print-function ${FUNCNAME} $* 2423 debug-print-function ${FUNCNAME} $*
1707 2424
2425 export LANG="C" LC_ALL="C"
2426
1708 local vendor="$(java-pkg_get-vm-vendor)" 2427 local vendor="$(java-pkg_get-vm-vendor)"
1709 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2428 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1710 addpredict "/dev/random" 2429 addpredict "/dev/random"
1711 elif [[ "${vendor}" == "ibm" ]]; then 2430 elif [[ "${vendor}" == "ibm" ]]; then
1712 addpredict "/proc/self/maps" 2431 addpredict "/proc/self/maps"
1713 addpredict "/proc/cpuinfo" 2432 addpredict "/proc/cpuinfo"
1714 export LANG="C" LC_ALL="C"
1715 elif [[ "${vendor}" == "jrockit" ]]; then 2433 elif [[ "${vendor}" == "jrockit" ]]; then
1716 addpredict "/proc/cpuinfo" 2434 addpredict "/proc/cpuinfo"
1717 fi 2435 fi
1718} 2436}
1719 2437
1763# @return - The version of the current VM 2481# @return - The version of the current VM
1764# ------------------------------------------------------------------------------ 2482# ------------------------------------------------------------------------------
1765java-pkg_get-vm-version() { 2483java-pkg_get-vm-version() {
1766 debug-print-function ${FUNCNAME} $* 2484 debug-print-function ${FUNCNAME} $*
1767 2485
1768 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2486 java-config -g PROVIDES_VERSION
1769} 2487}
1770 2488
1771# ------------------------------------------------------------------------------ 2489# ------------------------------------------------------------------------------
1772# @internal-function java-pkg_switch-vm 2490# @internal-function java-pkg_switch-vm
1773# 2491#
1774# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2492# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1775# verify that the current VM is sufficient. 2493# verify that the current VM is sufficient.
1776# Setup the environment for the VM being used. 2494# Setup the environment for the VM being used.
1777# ------------------------------------------------------------------------------ 2495# ------------------------------------------------------------------------------
1778java-pkg_switch-vm() { 2496java-pkg_switch-vm() {
2497 debug-print-function ${FUNCNAME} $*
2498
1779 if java-pkg_needs-vm; then 2499 if java-pkg_needs-vm; then
1780 # Use the VM specified by JAVA_PKG_FORCE_VM 2500 # Use the VM specified by JAVA_PKG_FORCE_VM
1781 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2501 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1782 # If you're forcing the VM, I hope you know what your doing... 2502 # If you're forcing the VM, I hope you know what your doing...
2503 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1783 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2504 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1784 # if we're allowed to switch the vm... 2505 # if we're allowed to switch the vm...
1785 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2506 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1786 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2507 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1787 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2508 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1788 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2509 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1789 else 2510 else
1790 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2511 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2512 fi
2513 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2514 eerror "Unable to determine VM for building from dependencies:"
2515 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2516 echo "VNEED: ${JAVA_PKG_VNEED}"
2517 die "Failed to determine VM for building."
2518 else
2519 export GENTOO_VM
1791 fi 2520 fi
1792 # otherwise just make sure the current VM is sufficient 2521 # otherwise just make sure the current VM is sufficient
1793 else 2522 else
1794 java-pkg_ensure-vm-version-sufficient 2523 java-pkg_ensure-vm-version-sufficient
1795 fi 2524 fi
1797 2526
1798 java-pkg_setup-vm 2527 java-pkg_setup-vm
1799 2528
1800 export JAVA=$(java-config --java) 2529 export JAVA=$(java-config --java)
1801 export JAVAC=$(java-config --javac) 2530 export JAVAC=$(java-config --javac)
1802 export JAVACFLAGS="$(java-pkg_javac-args)" 2531 JAVACFLAGS="$(java-pkg_javac-args)"
2532 if [[ ${?} != 0 ]]; then
2533 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2534 die "java-pkg_javac-args failed"
2535 fi
1803 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2536 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2537 export JAVACFLAGS
1804 2538
1805 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2539 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1806 export JDK_HOME=${JAVA_HOME} 2540 export JDK_HOME=${JAVA_HOME}
1807 2541
1808 #TODO If you know a better solution let us know. 2542 #TODO If you know a better solution let us know.
1809 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2543 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1810 2544
1811 local tann="${T}/announced-vm" 2545 local tann="${T}/announced-vm"
2546 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2547 # if people have for example modified eclasses some where
1812 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2548 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1813 # Add a check for setup/preinst phase... to avoid duplicate outputs
1814 # for when FEATURES=buildpkg
1815 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1816 then
1817 einfo "Using: $(java-config -f)" 2549 einfo "Using: $(java-config -f)"
1818 [[ ! -f "${tann}" ]] && touch "${tann}" 2550 [[ ! -f "${tann}" ]] && touch "${tann}"
1819 fi
1820 fi 2551 fi
1821 2552
1822 else 2553 else
1823 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2554 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1824 fi 2555 fi
1854 einfo "Classes" 2585 einfo "Classes"
1855 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2586 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1856 fi 2587 fi
1857} 2588}
1858 2589
1859# TODO document 2590# ------------------------------------------------------------------------------
2591# @internal-function java-pkg_verify-classes
2592#
1860# Verify that the classes were compiled for the right source / target 2593# Verify that the classes were compiled for the right source / target. Dies if
2594# not.
2595# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2596# ------------------------------------------------------------------------------
1861java-pkg_verify-classes() { 2597java-pkg_verify-classes() {
1862 ebegin "Verifying java class versions"
1863 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2598 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1864 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2599
2600 local version_verify="/usr/bin/class-version-verify.py"
2601
2602 if [[ ! -x "${version_verify}" ]]; then
2603 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2604 fi
2605
2606 if [[ ! -x "${version_verify}" ]]; then
2607 ewarn "Unable to perform class version checks as"
2608 ewarn "class-version-verify.py is unavailable"
2609 ewarn "Please install dev-java/javatoolkit."
2610 return
2611 fi
2612
2613 local target=$(java-pkg_get-target)
2614 local result
2615 local log="${T}/class-version-verify.log"
2616 if [[ -n "${1}" ]]; then
2617 ${version_verify} -v -t ${target} "${1}" > "${log}"
1865 result=$? 2618 result=$?
1866 eend ${result}
1867 if [[ ${result} == 0 ]]; then
1868 einfo "All good"
1869 else 2619 else
1870 ewarn "Possible problem" 2620 ebegin "Verifying java class versions (target: ${target})"
1871 die "Bad class files found" 2621 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2622 result=$?
2623 eend ${result}
2624 fi
2625 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2626 if [[ ${result} != 0 ]]; then
2627 eerror "Incorrect bytecode version found"
2628 [[ -n "${1}" ]] && eerror "in file: ${1}"
2629 eerror "See ${log} for more details."
2630 die "Incorrect bytecode found"
2631 fi
2632}
2633
2634# ----------------------------------------------------------------------------
2635# @internal-function java-pkg_ensure-dep
2636# Check that a package being used in jarfrom, getjars and getjar is contained
2637# within DEPEND or RDEPEND.
2638# @param $1 - empty - check both vars; "runtime" or "build" - check only
2639# RDEPEND, resp. DEPEND
2640# @param $2 - Package name and slot.
2641
2642java-pkg_ensure-dep() {
2643 debug-print-function ${FUNCNAME} $*
2644
2645 local limit_to="${1}"
2646 local target_pkg="${2}"
2647 local dev_error=""
2648
2649 local stripped_pkg=$(echo "${target_pkg}" | sed \
2650 's/-[0-9]*\(\.[0-9]\)*$//')
2651
2652 debug-print "Matching against: ${stripped_pkg}"
2653
2654 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2655 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2656 dev_error="${dev_error} declared in DEPEND."
2657 if is-java-strict; then
2658 eerror "${dev_error}"
2659 die "${dev_error}"
2660 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2661 eerror "${dev_error}"
2662 elog "Because you have this package installed the package will"
2663 elog "build without problems, but please report this to"
2664 elog "http://bugs.gentoo.org"
1872 fi 2665 fi
1873} 2666 fi
1874 2667
2668 if [[ ${limit_to} != build ]]; then
2669 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2670 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2671 dev_error="The ebuild is attempting to use ${target_pkg},"
2672 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2673 dev_error="${dev_error} or PDEPEND."
2674 if is-java-strict; then
2675 eerror "${dev_error}"
2676 die "${dev_error}"
2677 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2678 eerror "${dev_error}"
2679 elog "The package will build without problems, but may fail to run"
2680 elog "if you don't have ${target_pkg} installed, so please report"
2681 elog "this to http://bugs.gentoo.org"
2682 fi
2683 fi
2684 fi
2685 fi
2686}
1875 2687
1876# ------------------------------------------------------------------------------ 2688# ------------------------------------------------------------------------------
1877# @section-end internal 2689# @section-end internal
1878# ------------------------------------------------------------------------------ 2690# ------------------------------------------------------------------------------
1879 2691
1880java-pkg_check-phase() { 2692java-pkg_check-phase() {
1881 local phase=${1} 2693 local phase=${1}
1882 local funcname=${2} 2694 local funcname=${FUNCNAME[1]}
1883 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2695 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1884 java-pkg_announce-qa-violation \
1885 "${funcname} used outside of src_${phase}" 2696 local msg="${funcname} used outside of src_${phase}"
2697 java-pkg_announce-qa-violation "${msg}"
1886 fi 2698 fi
1887} 2699}
1888 2700
1889java-pkg_check-versioned-jar() { 2701java-pkg_check-versioned-jar() {
1890 local jar=${1} 2702 local jar=${1}
1899 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2711 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1900 fi 2712 fi
1901} 2713}
1902 2714
1903java-pkg_announce-qa-violation() { 2715java-pkg_announce-qa-violation() {
1904 if is-java-strict; then 2716 local nodie
2717 if [[ ${1} == "--nodie" ]]; then
2718 nodie="true"
2719 shift
2720 fi
1905 echo "Java QA Notice: $@" >&2 2721 echo "Java QA Notice: $@" >&2
1906 increment-qa-violations 2722 increment-qa-violations
1907 fi 2723 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1908} 2724}
1909 2725
1910increment-qa-violations() { 2726increment-qa-violations() {
1911 let "JAVA_PKG_QA_VIOLATIONS+=1" 2727 let "JAVA_PKG_QA_VIOLATIONS+=1"
1912 export JAVA_PKG_QA_VIOLATIONS 2728 export JAVA_PKG_QA_VIOLATIONS
1915is-java-strict() { 2731is-java-strict() {
1916 [[ -n ${JAVA_PKG_STRICT} ]] 2732 [[ -n ${JAVA_PKG_STRICT} ]]
1917 return $? 2733 return $?
1918} 2734}
1919 2735
2736
1920# ------------------------------------------------------------------------------ 2737# ------------------------------------------------------------------------------
1921# @eclass-end 2738# @eclass-end
1922# ------------------------------------------------------------------------------ 2739# ------------------------------------------------------------------------------

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.115

  ViewVC Help
Powered by ViewVC 1.1.20