/[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.33 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# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.33 2006/12/07 02:27:22 flameeyes Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.115 2008/10/05 16:53:38 betelgeuse Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# 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# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 68JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
43 69
44# ----------------------------------------------------------------------------- 70# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 71# @variable-internal JAVA_PKG_E_DEPEND
46# 72#
47# 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
48# 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
49# portage, that includes phase hooks. 75# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
51JAVA_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 )"
52 79
53# ----------------------------------------------------------------------------- 80# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 81# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 82# @variable-default yes
56# 83#
130# @note This should only be used internally or for testing. 157# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 158# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 159# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 160# -----------------------------------------------------------------------------
134 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
135# TODO document me 176# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 177JAVA_PKG_QA_VIOLATIONS=0
137 178
138# ----------------------------------------------------------------------------- 179# -----------------------------------------------------------------------------
139# @section-end variables 180# @section-end variables
146# 187#
147# 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
148# libraries, etc. 189# libraries, etc.
149# ----------------------------------------------------------------------------- 190# -----------------------------------------------------------------------------
150 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}
151 232
152# ----------------------------------------------------------------------------- 233# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 234# @ebuild-function java-pkg_dojar
154# 235#
155# Installs any number of jars. 236# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 255 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 256 dodir ${JAVA_PKG_JARDEST}
176 257
177 local jar 258 local jar
178 # for each jar 259 # for each jar
179 for jar in "$@"; do 260 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 261 local jar_basename=$(basename "${jar}")
181 262
182 java-pkg_check-versioned-jar ${jar_basename} 263 java-pkg_check-versioned-jar ${jar_basename}
183 264
184 # check if it exists 265 # check if it exists
185 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
186 # install it into JARDEST if it's a non-symlink 274 # install it into JARDEST if it's a non-symlink
187 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
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 279 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 280 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 281 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 282 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 283 # make a symlink to the original jar if it's symlink
202 done 293 done
203 294
204 java-pkg_do_write_ 295 java-pkg_do_write_
205} 296}
206 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# ------------------------------------------------------------------------------
207 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}
208 311
209# ------------------------------------------------------------------------------ 312# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 313# @ebuild-function java-pkg_regjar
211# 314#
212# Records an already installed jar in the package.env 315# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 346 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 347
245 java-pkg_init_paths_ 348 java-pkg_init_paths_
246 349
247 local jar jar_dir jar_file 350 local jar jar_dir jar_file
248 for jar in "$@"; do 351 for jar in "${@}"; do
249 # TODO use java-pkg_check-versioned-jar 352 # TODO use java-pkg_check-versioned-jar
250 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
251 # 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:
252 # imagine such call: 361 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 362 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 363 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 364 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 365 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
257 elif [[ -e "${D}${jar}" ]]; then
258 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
259 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
260 die "${jar} does not exist" 372 die "${jar} does not exist"
261 fi 373 fi
262 done 374 done
263 375
264 java-pkg_do_write_ 376 java-pkg_do_write_
265} 377}
266
267 378
268# ------------------------------------------------------------------------------ 379# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 380# @ebuild-function java-pkg_newjar
270# 381#
271# Installs a jar with a new name 382# Installs a jar with a new name
282 local original_jar="${1}" 393 local original_jar="${1}"
283 local new_jar="${2:-${PN}.jar}" 394 local new_jar="${2:-${PN}.jar}"
284 local new_jar_dest="${T}/${new_jar}" 395 local new_jar_dest="${T}/${new_jar}"
285 396
286 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 397 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
287 [[ ! -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!"
288 400
289 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}"
290 cp "${original_jar}" "${new_jar_dest}" \ 402 cp "${original_jar}" "${new_jar_dest}" \
291 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 403 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
292 java-pkg_dojar "${new_jar_dest}" 404 java-pkg_dojar "${new_jar_dest}"
335 if [[ -e "${lib}" ]] ; then 447 if [[ -e "${lib}" ]] ; then
336 # install if it isn't a symlink 448 # install if it isn't a symlink
337 if [[ ! -L "${lib}" ]] ; then 449 if [[ ! -L "${lib}" ]] ; then
338 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 450 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
339 INSOPTIONS="${LIBOPTIONS}" \ 451 INSOPTIONS="${LIBOPTIONS}" \
340 doins "${lib}" || "failed to install ${lib}" 452 doins "${lib}" || die "failed to install ${lib}"
341 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 453 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
342 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 454 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
343 # otherwise make a symlink to the symlink's origin 455 # otherwise make a symlink to the symlink's origin
344 else 456 else
345 # TODO use dosym 457 # TODO use dosym
458 ln -s "$(readlink "${lib}")" \
346 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 459 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
347 debug-print "${lib} is a symlink, linking accordanly" 460 debug-print "${lib} is a symlink, linking accordanly"
348 fi 461 fi
349 # otherwise die 462 # otherwise die
350 else 463 else
351 die "${lib} does not exist" 464 die "${lib} does not exist"
445# ------------------------------------------------------------------------------ 558# ------------------------------------------------------------------------------
446# @ebuild-function java-pkg_dojavadoc 559# @ebuild-function java-pkg_dojavadoc
447# 560#
448# Installs javadoc documentation. This should be controlled by the doc use flag. 561# Installs javadoc documentation. This should be controlled by the doc use flag.
449# 562#
563# @param $1: optional --symlink creates to symlink like this for html
564# documentation bundles.
450# @param $1: - The javadoc root directory. 565# @param $2: - The javadoc root directory.
451# 566#
452# @example: 567# @example:
453# java-pkg_dojavadoc docs/api 568# java-pkg_dojavadoc docs/api
569# java-pkg_dojavadoc --symlink apidocs docs/api
454# 570#
455# ------------------------------------------------------------------------------ 571# ------------------------------------------------------------------------------
456java-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
457 local dir="$1" 582 local dir="$1"
583 local dest=/usr/share/doc/${PF}/html
584
585 # QA checks
458 586
459 java-pkg_check-phase install 587 java-pkg_check-phase install
460 588
461 [[ -z "${dir}" ]] && die "Must specify a directory!" 589 [[ -z "${dir}" ]] && die "Must specify a directory!"
462 [[ ! -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
463 603
464 local dir_to_install="${dir}" 604 local dir_to_install="${dir}"
465 if [[ "$(basename "${dir}")" != "api" ]]; then 605 if [[ "$(basename "${dir}")" != "api" ]]; then
466 dir_to_install="${T}/api" 606 dir_to_install="${T}/api"
467 # TODO use doins 607 # TODO use doins
468 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 608 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
469 fi 609 fi
470 610
611 # Actual installation
612
471 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
472} 622}
473 623
474# ------------------------------------------------------------------------------ 624# ------------------------------------------------------------------------------
475# @ebuild-function java-pkg_dosrc 625# @ebuild-function java-pkg_dosrc
476# 626#
492# FIXME apparently this fails if you give it an empty directories 642# FIXME apparently this fails if you give it an empty directories
493java-pkg_dosrc() { 643java-pkg_dosrc() {
494 debug-print-function ${FUNCNAME} $* 644 debug-print-function ${FUNCNAME} $*
495 645
496 [ ${#} -lt 1 ] && die "At least one argument needed" 646 [ ${#} -lt 1 ] && die "At least one argument needed"
497 if ! hasq source ${IUSE}; then
498 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
499 fi
500 647
501 java-pkg_check-phase install 648 java-pkg_check-phase install
502 649
503 [[ ${#} -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
504 656
505 java-pkg_init_paths_ 657 java-pkg_init_paths_
506 658
507 local zip_name="${PN}-src.zip" 659 local zip_name="${PN}-src.zip"
508 local zip_path="${T}/${zip_name}" 660 local zip_path="${T}/${zip_name}"
509 local dir 661 local dir
510 for dir in ${@}; do 662 for dir in "${@}"; do
511 local dir_parent=$(dirname "${dir}") 663 local dir_parent=$(dirname "${dir}")
512 local dir_name=$(basename "${dir}") 664 local dir_name=$(basename "${dir}")
513 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 665 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
514 zip -q -r ${zip_path} ${dir_name} -i '*.java' 666 zip -q -r ${zip_path} ${dir_name} -i '*.java'
515 local result=$? 667 local result=$?
540# @param $1 - filename of launcher to create 692# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 693# @param $2 - options, as follows:
542# --main the.main.class.too.start 694# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 695# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 696# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 697# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 698# --pwd Directory the launcher changes to before executing java
547# -into 699# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 700# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 701# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 702java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 703 debug-print-function ${FUNCNAME} $*
552 704
553 java-pkg_check-phase install 705 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 717 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 718 local target_dir pre
567 719
568 # Process the other the rest of the arguments 720 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 721 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 722 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 723 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 724 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 725 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 726 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 727 elif [[ "${var}" == "-into" ]]; then
594 fi 746 fi
595 fi 747 fi
596 748
597 # Write the actual script 749 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 750 echo "#!/bin/bash" > "${target}"
599 [[ -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
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 758 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 759 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 760 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 761 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 762
696# 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
697# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 855# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
698# Example: get junit.jar which is needed only for building 856# Example: get junit.jar which is needed only for building
699# java-pkg_jar-from --build-only junit junit.jar 857# java-pkg_jar-from --build-only junit junit.jar
700# 858#
701# @param $1 - (optional) "--build-only" makes the jar(s) not added into 859# @param $opt
702# package.env DEPEND line. 860# --build-only - makes the jar(s) not added into package.env DEPEND line.
703# @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.
704# @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.
705# @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
706# symlink. Defaults to the name of the jar. 871# symlink. Defaults to the name of the jar.
707# ------------------------------------------------------------------------------ 872# ------------------------------------------------------------------------------
708# TODO could probably be cleaned up a little 873# TODO could probably be cleaned up a little
709java-pkg_jar-from() { 874java-pkg_jar-from() {
710 debug-print-function ${FUNCNAME} $* 875 debug-print-function ${FUNCNAME} $*
711 876
712 local build_only="" 877 local build_only=""
878 local destdir="."
879 local deep=""
880 local virtual=""
713 881
882 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
883
884 while [[ "${1}" == --* ]]; do
714 if [[ "${1}" = "--build-only" ]]; then 885 if [[ "${1}" = "--build-only" ]]; then
715 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
716 shift 897 shift
717 fi 898 done
718 899
719 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 900 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
720 901
721 [[ -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
722 907
723 # default destjar to the target jar 908 # default destjar to the target jar
724 [[ -z "${destjar}" ]] && destjar="${target_jar}" 909 [[ -z "${destjar}" ]] && destjar="${target_jar}"
725 910
726 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}."
727 local classpath 912 local classpath
728 classpath="$(java-config --classpath=${target_pkg})" 913 classpath="$(java-config ${deep} --classpath=${target_pkg})"
729 [[ $? != 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}"
730 940
731 local jar 941 local jar
732 for jar in ${classpath//:/ }; do 942 for jar in ${classpath//:/ }; do
733 local jar_name=$(basename "${jar}") 943 local jar_name=$(basename "${jar}")
734 if [[ ! -f "${jar}" ]] ; then 944 if [[ ! -f "${jar}" ]] ; then
745 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 955 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
746 [[ -f "${destjar}" ]] && rm "${destjar}" 956 [[ -f "${destjar}" ]] && rm "${destjar}"
747 ln -snf "${jar}" "${destjar}" \ 957 ln -snf "${jar}" "${destjar}" \
748 || die "Failed to make symlink from ${jar} to ${destjar}" 958 || die "Failed to make symlink from ${jar} to ${destjar}"
749 [[ -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
750 return 0 961 return 0
751 fi 962 fi
752 done 963 done
964 popd > /dev/null
753 # if no target was specified, we're ok 965 # if no target was specified, we're ok
754 if [[ -z "${target_jar}" ]] ; then 966 if [[ -z "${target_jar}" ]] ; then
755 return 0 967 return 0
756 # otherwise, die bitterly 968 # otherwise, die bitterly
757 else 969 else
781# Example: Get the classpath for xerces-2 and xalan, 993# Example: Get the classpath for xerces-2 and xalan,
782# java-pkg_getjars xerces-2,xalan 994# java-pkg_getjars xerces-2,xalan
783# Example Return: 995# Example Return:
784# /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
785# 997#
786# @param $1 - (optional) "--build-only" makes the jar(s) not added into 998# @param $opt
787# 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.
788# @param $2 - list of packages to get jars from 1003# @param $1 - list of packages to get jars from
789# (passed to java-config --classpath) 1004# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 1005# ------------------------------------------------------------------------------
791java-pkg_getjars() { 1006java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 1007 debug-print-function ${FUNCNAME} $*
793 1008
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 1009 local build_only=""
1010 local deep=""
795 1011
1012 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1013
1014 while [[ "${1}" == --* ]]; do
796 if [[ "${1}" = "--build-only" ]]; then 1015 if [[ "${1}" = "--build-only" ]]; then
797 local 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
798 shift 1022 shift
799 fi 1023 done
800 1024
1025 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1026
1027
801 local classpath pkgs="${1}" 1028 local pkgs="${1}"
1029
1030 if [[ "${EAPI}" == "1" ]]; then
1031 pkgs="${pkgs//:/-}"
1032 fi
1033
802 jars="$(java-config --classpath=${pkgs})" 1034 jars="$(java-config ${deep} --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1035 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 1036 debug-print "${pkgs}:${jars}"
805 1037
806 if [[ -z "${classpath}" ]]; then 1038 for pkg in ${pkgs//,/ }; do
807 classpath="${jars}" 1039 java-pkg_ensure-dep "${build_only}" "${pkg}"
808 else 1040 done
809 classpath="${classpath}:${jars}"
810 fi
811 1041
812 # Only record jars that aren't build-only 1042 # Only record jars that aren't build-only
813 if [[ -z "${build_only}" ]]; then 1043 if [[ -z "${build_only}" ]]; then
814 oldifs="${IFS}"
815 IFS=","
816 for pkg in ${pkgs}; do 1044 for pkg in ${pkgs//,/ }; do
817 java-pkg_record-jar_ "${pkg}" 1045 java-pkg_record-jar_ "${pkg}"
818 done 1046 done
819 IFS="${oldifs}"
820 fi 1047 fi
821 1048
822 echo "${classpath}" 1049 echo "${jars}"
823} 1050}
824 1051
825# ------------------------------------------------------------------------------ 1052# ------------------------------------------------------------------------------
826# @ebuild-function java-pkg_getjar 1053# @ebuild-function java-pkg_getjar
827# 1054#
834# @example 1061# @example
835# java-pkg_getjar xerces-2 xml-apis.jar 1062# java-pkg_getjar xerces-2 xml-apis.jar
836# @example-return 1063# @example-return
837# /usr/share/xerces-2/lib/xml-apis.jar 1064# /usr/share/xerces-2/lib/xml-apis.jar
838# 1065#
839# @param $1 - (optional) "--build-only" makes the jar not added into 1066# @param $opt
840# 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.
841# @param $1 - package to use 1070# @param $1 - package to use
842# @param $2 - jar to get 1071# @param $2 - jar to get
843# ------------------------------------------------------------------------------ 1072# ------------------------------------------------------------------------------
844java-pkg_getjar() { 1073java-pkg_getjar() {
845 debug-print-function ${FUNCNAME} $* 1074 debug-print-function ${FUNCNAME} $*
846 1075
847 local build_only="" 1076 local build_only=""
1077 local virtual=""
848 1078
1079 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1080
1081 while [[ "${1}" == --* ]]; do
849 if [[ "${1}" = "--build-only" ]]; then 1082 if [[ "${1}" = "--build-only" ]]; then
850 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
851 shift 1089 shift
852 fi 1090 done
1091
1092 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
853 1093
854 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
855 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1100 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
856 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1101 [[ -z ${target_jar} ]] && die "Must specify jar to get"
857 1102
858 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?"
859 local classpath 1104 local classpath
860 classpath=$(java-config --classpath=${pkg}) 1105 classpath=$(java-config --classpath=${pkg})
861 [[ $? != 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
862 1116
863 for jar in ${classpath//:/ }; do 1117 for jar in ${classpath//:/ }; do
864 if [[ ! -f "${jar}" ]] ; then 1118 if [[ ! -f "${jar}" ]] ; then
865 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1119 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
866 fi 1120 fi
873 fi 1127 fi
874 done 1128 done
875 1129
876 die "Could not find ${target_jar} in ${pkg}" 1130 die "Could not find ${target_jar} in ${pkg}"
877 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_
878} 1267}
879 1268
880# 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
881# populate jars from the filesystem. 1270# populate jars from the filesystem.
882# 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
999# 1388#
1000# export DEPEND="${DEPEND} ${depstr}" 1389# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}" 1390# export RDEPEND="${RDEPEND} ${depstr}"
1002#} 1391#}
1003 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.
1004# 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
1005# TODO document 1417# to system jar files or bundled jars removed.
1418# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1419java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1420 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1421
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1422 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1423 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1424 echo "Bundled jars found:"
1013 local jar 1425 local jar
1014 for jar in ${bundled_jars}; do 1426 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1427 echo $(pwd)${jar/./}
1016 done 1428 done
1017 die "Bundled jars found!" 1429 die "Bundled jars found!"
1018
1019 fi 1430 fi
1020 popd >/dev/null 2>/dev/null
1021} 1431}
1022 1432
1023# ------------------------------------------------------------------------------ 1433# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1434# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1435#
1174# @ebuild-function java-pkg_get-target 1584# @ebuild-function java-pkg_get-target
1175# 1585#
1176# Determines what target version should be used, for passing to -target. 1586# Determines what target version should be used, for passing to -target.
1177# 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
1178# version of your JDK. 1588# version of your JDK.
1179# Remember doing this will mostly like cause things to break.
1180# Doesn't allow it to be lower then the one in depend.
1181# Doesn't allow it to be higher then the active vm.
1182# 1589#
1183# @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
1184# ------------------------------------------------------------------------------ 1591# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1592java-pkg_get-target() {
1186 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1187 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1188 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1189 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1190 echo ${JAVA_PKG_WANT_TARGET}
1191 else
1192 echo ${min}
1193 fi
1194 else
1195 echo ${min}
1196 fi
1197
1198 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1593 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1594}
1200 1595
1201java-pkg_get-javac() { 1596java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1597 debug-print-function ${FUNCNAME} $*
1203 1598
1292 die "No GCJ support found!" 1687 die "No GCJ support found!"
1293 fi 1688 fi
1294} 1689}
1295 1690
1296java-pkg_ensure-test() { 1691java-pkg_ensure-test() {
1297 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
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1695 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1696 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1697 die "Need USE=test enabled"
1301 fi 1698 fi
1302} 1699}
1303 1700
1304# ------------------------------------------------------------------------------ 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# ------------------------------------------------------------------------------
1305# @section-end helper 1804# @section-end helper
1306# ------------------------------------------------------------------------------ 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}
1307 1824
1308# ------------------------------------------------------------------------------ 1825# ------------------------------------------------------------------------------
1309# @section-begin build 1826# @section-begin build
1310# @section-summary Build functions 1827# @section-summary Build functions
1311# 1828#
1315 1832
1316# ------------------------------------------------------------------------------ 1833# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1834# @ebuild-function eant
1318# 1835#
1319# 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
1320# compiler. 1837# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1321# 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.
1322# ------------------------------------------------------------------------------ 1844# ------------------------------------------------------------------------------
1323eant() { 1845eant() {
1324 debug-print-function ${FUNCNAME} $* 1846 debug-print-function ${FUNCNAME} $*
1325 1847
1326 # FIXME get this working 1848 if [[ ${EBUILD_PHASE} = compile ]]; then
1327# 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"
1328# java-pkg_announce-qa-violation \ 1855 java-pkg_announce-qa-violation "${msg}"
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1856 fi
1331 1857
1332 local antflags 1858 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1859
1333 java-pkg_init-compiler_ 1860 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1861 local compiler="${GENTOO_COMPILER}"
1335 1862
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1863 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1337
1338 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})"
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1865 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1866 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1867 fi
1342 1868
1343 if [[ ${compiler} != "javac" ]]; then 1869 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1870 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # 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
1346 # from javac 1872 # from javac
1347 # 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
1348 # java-config -p 1874 # java-config -p
1349 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})"
1350 if [[ -n ${build_compiler_deps} ]]; then 1876 if [[ -n ${build_compiler_deps} ]]; then
1351 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1877 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1352 fi 1878 fi
1353 fi 1879 fi
1354 1880
1881 for arg in "${@}"; do
1882 if [[ ${arg} = -lib ]]; then
1355 if is-java-strict; then 1883 if is-java-strict; then
1356 einfo "Disabling system classpath for ant" 1884 eerror "You should not use the -lib argument to eant because it will fail"
1357 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
1358 fi 1894 fi
1895 done
1359 1896
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1897 # parse WANT_ANT_TASKS for atoms
1361 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}\""
1362 fi 1952 fi
1363 1953
1364 [[ -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} ${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1956 ant ${antflags} "${@}" || die "eant failed"
1366
1367} 1957}
1368 1958
1369# ------------------------------------------------------------------------------ 1959# ------------------------------------------------------------------------------
1370# @ebuild-function ejavac 1960# @ebuild-function ejavac
1371# 1961#
1440# ------------------------------------------------------------------------------ 2030# ------------------------------------------------------------------------------
1441use_doc() { 2031use_doc() {
1442 use doc && echo ${@:-javadoc} 2032 use doc && echo ${@:-javadoc}
1443} 2033}
1444 2034
2035
1445# ------------------------------------------------------------------------------ 2036# ------------------------------------------------------------------------------
1446# @section-end build 2037# @section-end build
1447# ------------------------------------------------------------------------------ 2038# ------------------------------------------------------------------------------
1448 2039
1449# ------------------------------------------------------------------------------ 2040# ------------------------------------------------------------------------------
1465# 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
1466# call it during each of the phases of the merge process. 2057# call it during each of the phases of the merge process.
1467# 2058#
1468# ----------------------------------------------------------------------------- 2059# -----------------------------------------------------------------------------
1469java-pkg_init() { 2060java-pkg_init() {
2061 debug-print-function ${FUNCNAME} $*
1470 unset JAVAC 2062 unset JAVAC
1471 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
1472 java-pkg_init_paths_ 2090 java-pkg_init_paths_
1473 java-pkg_switch-vm 2091 java-pkg_switch-vm
1474 PATH=${JAVA_HOME}/bin:${PATH} 2092 PATH=${JAVA_HOME}/bin:${PATH}
1475 2093
1476 # TODO we will probably want to set JAVAC and JAVACFLAGS 2094 # TODO we will probably want to set JAVAC and JAVACFLAGS
1477 2095
1478 # Do some QA checks 2096 # Do some QA checks
1479 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
1480 2101
1481 # When users have crazy classpaths some packages can fail to compile. 2102 # When users have crazy classpaths some packages can fail to compile.
1482 # and everything should work with empty CLASSPATH. 2103 # and everything should work with empty CLASSPATH.
1483 # This also helps prevent unexpected dependencies on random things 2104 # This also helps prevent unexpected dependencies on random things
1484 # from the CLASSPATH. 2105 # from the CLASSPATH.
1485 unset CLASSPATH 2106 export CLASSPATH=
2107
2108 # Unset external ANT_ stuff
2109 export ANT_TASKS=
2110 export ANT_OPTS=
1486} 2111}
1487 2112
1488# ------------------------------------------------------------------------------ 2113# ------------------------------------------------------------------------------
1489# @function-internal java-pkg-init-compiler_ 2114# @function-internal java-pkg-init-compiler_
1490# 2115#
1581 done 2206 done
1582 2207
1583 # If it hasn't been defined already, default to javac 2208 # If it hasn't been defined already, default to javac
1584 if [[ -z ${GENTOO_COMPILER} ]]; then 2209 if [[ -z ${GENTOO_COMPILER} ]]; then
1585 if [[ -n ${compilers} ]]; then 2210 if [[ -n ${compilers} ]]; then
1586 einfo "No suitable compiler found: defaulting javac for compilation" 2211 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1587 else 2212 else
1588 # probably don't need to notify users about the default. 2213 # probably don't need to notify users about the default.
1589 :;#einfo "Defaulting to javac for compilation" 2214 :;#einfo "Defaulting to javac for compilation"
1590 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
1591 export GENTOO_COMPILER=javac 2219 export GENTOO_COMPILER=javac
2220 fi
1592 else 2221 else
1593 einfo "Using ${GENTOO_COMPILER} for compilation" 2222 einfo "Using ${GENTOO_COMPILER} for compilation"
1594 fi 2223 fi
1595 2224
1596} 2225}
1612 fi 2241 fi
1613 2242
1614 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2243 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1615 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2244 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1616 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}"
1617 2248
1618 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2249 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1619 [[ -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}"
1620 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2251 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1621 2252
1634# Writes the package.env out to disk. 2265# Writes the package.env out to disk.
1635# 2266#
1636# ------------------------------------------------------------------------------ 2267# ------------------------------------------------------------------------------
1637# TODO change to do-write, to match everything else 2268# TODO change to do-write, to match everything else
1638java-pkg_do_write_() { 2269java-pkg_do_write_() {
2270 debug-print-function ${FUNCNAME} $*
1639 java-pkg_init_paths_ 2271 java-pkg_init_paths_
1640 # Create directory for package.env 2272 # Create directory for package.env
1641 dodir "${JAVA_PKG_SHAREPATH}" 2273 dodir "${JAVA_PKG_SHAREPATH}"
1642 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
1643 # Create package.env 2277 # Create package.env
1644 ( 2278 (
1645 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2279 echo "DESCRIPTION=\"${DESCRIPTION}\""
1646 echo "GENERATION=\"2\"" 2280 echo "GENERATION=\"2\""
2281 echo "SLOT=\"${SLOT}\""
1647 2282
1648 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2283 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1649 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2284 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1650 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2285 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1651 [[ -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' ':')\""
1652 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 !
1653 ) > "${JAVA_PKG_ENV}" 2291 ) > "${JAVA_PKG_ENV}"
1654 2292
1655 # register target/source 2293 # register target/source
1656 local target="$(java-pkg_get-target)" 2294 local target="$(java-pkg_get-target)"
1667 2305
1668 2306
1669 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2307 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1670 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2308 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1671 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
1672 # Strip unnecessary leading and trailing colons 2318 # Strip unnecessary leading and trailing colons
1673 # TODO try to cleanup if possible 2319 # TODO try to cleanup if possible
1674 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."
1675 fi 2325 fi
1676} 2326}
1677 2327
1678# ------------------------------------------------------------------------------ 2328# ------------------------------------------------------------------------------
1679# @internal-function java-pkg_record-jar_ 2329# @internal-function java-pkg_record-jar_
1680# 2330#
1681# Record a dependency to the package.env 2331# Record an (optional) dependency to the package.env
1682# 2332# @param --optional - record dependency as optional
2333# @param $1 - package to record
2334# @param $2 - (optional) jar of package to record
1683# ------------------------------------------------------------------------------ 2335# ------------------------------------------------------------------------------
1684JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2336JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2337JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1685 2338
1686java-pkg_record-jar_() { 2339java-pkg_record-jar_() {
1687 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
1688 2347
1689 local pkg=${1} jar=${2} append 2348 local pkg=${1} jar=${2} append
1690 if [[ -z "${jar}" ]]; then 2349 if [[ -z "${jar}" ]]; then
1691 append="${pkg}" 2350 append="${pkg}"
1692 else 2351 else
1693 append="$(basename ${jar})@${pkg}" 2352 append="$(basename ${jar})@${pkg}"
1694 fi 2353 fi
1695 2354
1696 echo ${append} >> ${JAVA_PKG_DEPEND} 2355 echo "${append}" >> "${depend_file}"
1697} 2356}
1698 2357
1699# ------------------------------------------------------------------------------ 2358# ------------------------------------------------------------------------------
1700# @internal-function java-pkg_append_ 2359# @internal-function java-pkg_append_
1701# 2360#
1761# 2420#
1762# ------------------------------------------------------------------------------ 2421# ------------------------------------------------------------------------------
1763java-pkg_setup-vm() { 2422java-pkg_setup-vm() {
1764 debug-print-function ${FUNCNAME} $* 2423 debug-print-function ${FUNCNAME} $*
1765 2424
2425 export LANG="C" LC_ALL="C"
2426
1766 local vendor="$(java-pkg_get-vm-vendor)" 2427 local vendor="$(java-pkg_get-vm-vendor)"
1767 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
1768 addpredict "/dev/random" 2429 addpredict "/dev/random"
1769 elif [[ "${vendor}" == "ibm" ]]; then 2430 elif [[ "${vendor}" == "ibm" ]]; then
1770 addpredict "/proc/self/maps" 2431 addpredict "/proc/self/maps"
1771 addpredict "/proc/cpuinfo" 2432 addpredict "/proc/cpuinfo"
1772 export LANG="C" LC_ALL="C"
1773 elif [[ "${vendor}" == "jrockit" ]]; then 2433 elif [[ "${vendor}" == "jrockit" ]]; then
1774 addpredict "/proc/cpuinfo" 2434 addpredict "/proc/cpuinfo"
1775 fi 2435 fi
1776} 2436}
1777 2437
1832# 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
1833# verify that the current VM is sufficient. 2493# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 2494# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 2495# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 2496java-pkg_switch-vm() {
2497 debug-print-function ${FUNCNAME} $*
2498
1837 if java-pkg_needs-vm; then 2499 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 2500 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2501 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # 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}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2504 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 2505 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2506 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1844 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}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2508 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1878 2541
1879 #TODO If you know a better solution let us know. 2542 #TODO If you know a better solution let us know.
1880 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2543 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1881 2544
1882 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
1883 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2548 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1884 # Add a check for setup/preinst phase... to avoid duplicate outputs
1885 # for when FEATURES=buildpkg
1886 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1887 then
1888 einfo "Using: $(java-config -f)" 2549 einfo "Using: $(java-config -f)"
1889 [[ ! -f "${tann}" ]] && touch "${tann}" 2550 [[ ! -f "${tann}" ]] && touch "${tann}"
1890 fi
1891 fi 2551 fi
1892 2552
1893 else 2553 else
1894 [[ -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!!!"
1895 fi 2555 fi
1925 einfo "Classes" 2585 einfo "Classes"
1926 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},"
1927 fi 2587 fi
1928} 2588}
1929 2589
1930# TODO document 2590# ------------------------------------------------------------------------------
2591# @internal-function java-pkg_verify-classes
2592#
1931# 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# ------------------------------------------------------------------------------
1932java-pkg_verify-classes() { 2597java-pkg_verify-classes() {
1933 ebegin "Verifying java class versions"
1934 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2598 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1935 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}"
1936 result=$? 2618 result=$?
1937 eend ${result}
1938 if [[ ${result} == 0 ]]; then
1939 einfo "All good"
1940 else 2619 else
1941 ewarn "Possible problem" 2620 ebegin "Verifying java class versions (target: ${target})"
1942 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"
2665 fi
2666 fi
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
1943 fi 2685 fi
1944} 2686}
1945 2687
1946# ------------------------------------------------------------------------------ 2688# ------------------------------------------------------------------------------
1947# @section-end internal 2689# @section-end internal
1948# ------------------------------------------------------------------------------ 2690# ------------------------------------------------------------------------------
1949 2691
1950java-pkg_check-phase() { 2692java-pkg_check-phase() {
1951 local phase=${1} 2693 local phase=${1}
1952 local funcname=${2} 2694 local funcname=${FUNCNAME[1]}
1953 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2695 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1954 java-pkg_announce-qa-violation \
1955 "${funcname} used outside of src_${phase}" 2696 local msg="${funcname} used outside of src_${phase}"
2697 java-pkg_announce-qa-violation "${msg}"
1956 fi 2698 fi
1957} 2699}
1958 2700
1959java-pkg_check-versioned-jar() { 2701java-pkg_check-versioned-jar() {
1960 local jar=${1} 2702 local jar=${1}
1969 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2711 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1970 fi 2712 fi
1971} 2713}
1972 2714
1973java-pkg_announce-qa-violation() { 2715java-pkg_announce-qa-violation() {
1974 if is-java-strict; then 2716 local nodie
2717 if [[ ${1} == "--nodie" ]]; then
2718 nodie="true"
2719 shift
2720 fi
1975 echo "Java QA Notice: $@" >&2 2721 echo "Java QA Notice: $@" >&2
1976 increment-qa-violations 2722 increment-qa-violations
1977 fi 2723 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1978} 2724}
1979 2725
1980increment-qa-violations() { 2726increment-qa-violations() {
1981 let "JAVA_PKG_QA_VIOLATIONS+=1" 2727 let "JAVA_PKG_QA_VIOLATIONS+=1"
1982 export JAVA_PKG_QA_VIOLATIONS 2728 export JAVA_PKG_QA_VIOLATIONS
1985is-java-strict() { 2731is-java-strict() {
1986 [[ -n ${JAVA_PKG_STRICT} ]] 2732 [[ -n ${JAVA_PKG_STRICT} ]]
1987 return $? 2733 return $?
1988} 2734}
1989 2735
2736
1990# ------------------------------------------------------------------------------ 2737# ------------------------------------------------------------------------------
1991# @eclass-end 2738# @eclass-end
1992# ------------------------------------------------------------------------------ 2739# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20