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

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

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

Revision 1.22 Revision 1.57
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.57 2007/02/13 19:52:51 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
23# 24#
24# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
25 26
26inherit eutils versionator multilib 27inherit eutils versionator multilib
27 28
29IUSE="elibc_FreeBSD"
30
28# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
29# @section-begin variables 32# @section-begin variables
30# @section-title Variables 33# @section-title Variables
31# 34#
32# Summary of variables which control the behavior of building Java packges. 35# Summary of variables which control the behavior of building Java packges.
33# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
34 37
35# Make sure we use java-config-2 38# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
37 40
38# TODO document 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
40 66
41# ----------------------------------------------------------------------------- 67# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
43# 69#
125# JAVA_PKG_COMPILERS_CONF. 151# JAVA_PKG_COMPILERS_CONF.
126# 152#
127# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
156# -----------------------------------------------------------------------------
157
158# -----------------------------------------------------------------------------
159# @variable-external JAVA_PKG_FORCE_ANT_TASKS
160#
161# An $IFS separated list of ant tasks. Can be set in environment before calling
162# emerge/ebuild to override variables set in ebuild, mainly for testing before
163# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
164# eant() call, not the dependencies specified in WANT_ANT_TASKS.
165#
166# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167# ebuild foo.ebuild compile
168#
169# @seealso WANT_ANT_TASKS
130# ----------------------------------------------------------------------------- 170# -----------------------------------------------------------------------------
131 171
132# TODO document me 172# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
134 174
171 # Create JARDEST if it doesn't exist 211 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 212 dodir ${JAVA_PKG_JARDEST}
173 213
174 local jar 214 local jar
175 # for each jar 215 # for each jar
176 for jar in "$@"; do 216 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 217 local jar_basename=$(basename "${jar}")
178 218
179 java-pkg_check-versioned-jar ${jar_basename} 219 java-pkg_check-versioned-jar ${jar_basename}
180 220
181 # check if it exists 221 # check if it exists
182 if [[ -e "${jar}" ]] ; then 222 if [[ -e "${jar}" ]] ; then
223 # Don't overwrite if jar has already been installed with the same
224 # name
225 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
226 if [[ -e "${dest}" ]]; then
227 ewarn "Overwriting ${dest}"
228 fi
229
183 # install it into JARDEST if it's a non-symlink 230 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 231 if [[ ! -L "${jar}" ]] ; then
232 #but first check class version when in strict mode.
233 is-java-strict && java-pkg_verify-classes "${jar}"
234
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 235 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 236 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 237 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 238 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 239 # make a symlink to the original jar if it's symlink
200 250
201 java-pkg_do_write_ 251 java-pkg_do_write_
202} 252}
203 253
204 254
255# ------------------------------------------------------------------------------
256# @internal-function depend-java-query
257#
258# Wrapper for the depend-java-query binary to enable passing USE in env.
259# Using env variables keeps this eclass working with java-config versions that
260# do not handle use flags.
261# ------------------------------------------------------------------------------
262
263depend-java-query() {
264 USE="${USE}" $(which depend-java-query) "${@}"
265}
205 266
206# ------------------------------------------------------------------------------ 267# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 268# @ebuild-function java-pkg_regjar
208# 269#
209# Records an already installed jar in the package.env 270# Records an already installed jar in the package.env
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 301 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 302
242 java-pkg_init_paths_ 303 java-pkg_init_paths_
243 304
244 local jar jar_dir jar_file 305 local jar jar_dir jar_file
245 for jar in "$@"; do 306 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 307 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 308 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
309 [[ -d "${jar}" || -d "${D}${jar}" ]] \
310 && die "Called ${FUNCNAME} on a directory $*"
311
312 #check that class version correct when in strict mode
313 is-java-strict && java-pkg_verify-classes "${jar}"
314
248 # nelchael: we should strip ${D} in this case too, here's why: 315 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 316 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 317 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 318 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 319 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 320 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 321 else
257 die "${jar} does not exist" 322 die "${jar} does not exist"
258 fi 323 fi
259 done 324 done
260 325
261 java-pkg_do_write_ 326 java-pkg_do_write_
262} 327}
263
264 328
265# ------------------------------------------------------------------------------ 329# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 330# @ebuild-function java-pkg_newjar
267# 331#
268# Installs a jar with a new name 332# Installs a jar with a new name
279 local original_jar="${1}" 343 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 344 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 345 local new_jar_dest="${T}/${new_jar}"
282 346
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 347 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 348 [[ ! -f ${original_jar} ]] \
349 && die "${original_jar} does not exist or is not a file!"
285 350
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 351 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 352 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 353 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 354 java-pkg_dojar "${new_jar_dest}"
290} 355}
291 356
292
293# ------------------------------------------------------------------------------ 357# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 358# @ebuild-function java-pkg_addcp
295# 359#
296# Add something to the package's classpath. For jars, you should use dojar, 360# 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. 361# newjar, or regjar. This is typically used to add directories to the classpath.
301# ------------------------------------------------------------------------------ 365# ------------------------------------------------------------------------------
302java-pkg_addcp() { 366java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 367 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 368 java-pkg_do_write_
305} 369}
306
307 370
308# ------------------------------------------------------------------------------ 371# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 372# @ebuild-function java-pkg_doso
310# 373#
311# Installs any number of JNI libraries 374# Installs any number of JNI libraries
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 403 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 404 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 405 # otherwise make a symlink to the symlink's origin
343 else 406 else
344 # TODO use dosym 407 # TODO use dosym
408 ln -s "$(readlink "${lib}")" \
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 409 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
346 debug-print "${lib} is a symlink, linking accordanly" 410 debug-print "${lib} is a symlink, linking accordanly"
347 fi 411 fi
348 # otherwise die 412 # otherwise die
349 else 413 else
350 die "${lib} does not exist" 414 die "${lib} does not exist"
428# ------------------------------------------------------------------------------ 492# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 493java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 494 debug-print-function ${FUNCNAME} $*
431 495
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 496 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 497
498 # from /usr/lib/portage/bin/dohtml -h
499 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 500 dohtml -f package-list "$@"
501
435 # this probably shouldn't be here but it provides 502 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 503 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 504 # old ebuilds.
438 java-pkg_recordjavadoc 505 java-pkg_recordjavadoc
439} 506}
440 507
441# TODO document 508# ------------------------------------------------------------------------------
509# @ebuild-function java-pkg_dojavadoc
510#
511# Installs javadoc documentation. This should be controlled by the doc use flag.
512#
513# @param $1: - The javadoc root directory.
514#
515# @example:
516# java-pkg_dojavadoc docs/api
517#
518# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 519java-pkg_dojavadoc() {
443 local dir="$1" 520 local dir="$1"
444 521
445 java-pkg_check-phase install 522 java-pkg_check-phase install
446 523
491 java-pkg_init_paths_ 568 java-pkg_init_paths_
492 569
493 local zip_name="${PN}-src.zip" 570 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 571 local zip_path="${T}/${zip_name}"
495 local dir 572 local dir
496 for dir in ${@}; do 573 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 574 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 575 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 576 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 577 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 578 local result=$?
518# @ebuild-function java-pkg_dolauncher 595# @ebuild-function java-pkg_dolauncher
519# 596#
520# Make a wrapper script to lauch/start this package 597# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 598# If necessary, the wrapper will switch to the appropriate VM.
522# 599#
600# Can be called without parameters if the package installs only one jar
601# that has the Main-class attribute set. The wrapper will be named ${PN}.
602#
523# @param $1 - filename of launcher to create 603# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 604# @param $2 - options, as follows:
525# --main the.main.class.too.start 605# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 606# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass to java' 607# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to the package' 608# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 609# --pwd Directory the launcher changes to before executing java
530# -into 610# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 611# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 612# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 613java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 614 debug-print-function ${FUNCNAME} $*
535 615
536 java-pkg_check-phase install 616 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 617 java-pkg_init_paths_
541 618
619 if [[ ${#} = 0 ]]; then
620 local name="${PN}"
621 else
542 local name="${1}" 622 local name="${1}"
623 shift
624 fi
625
543 # TODO rename to launcher 626 # TODO rename to launcher
544 local target="${T}/${name}" 627 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp" 628 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 629 local target_dir pre
547 shift
548 630
549 # Process the other the rest of the arguments 631 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 632 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 633 local var="${1}" value="${2}"
552 if [[ "${var:0:2}" == "--" ]]; then 634 if [[ "${var:0:2}" == "--" ]]; then
635 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 636 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
637 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 638 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 639 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 640 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 641 pre="${value}"
558 fi 642 fi
559 shift 2 643 shift 2
560 done 644 done
561 645
646 # Test if no --jar and --main arguments were given and
647 # in that case check if the package only installs one jar
648 # and use that jar.
649 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
650 local cp="${JAVA_PKG_CLASSPATH}"
651 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
652 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
653 else
654 local msg="Not enough information to create a launcher given."
655 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
656 die "${msg}"
657 fi
658 fi
659
562 # Write the actual script 660 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 661 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 662 if [[ -n "${pre}" ]]; then
663 if [[ -f "${pre}" ]]; then
664 cat "${pre}" >> "${target}"
665 else
666 die "-pre specified file '${pre}' does not exist"
667 fi
668 fi
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 669 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
566 cat "${var_tmp}" >> "${target}" 670 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}" 671 rm -f "${var_tmp}"
568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 672 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
569 673
661# Example: get a specific jar from xerces slot 2, and name it diffrently 765# Example: get a specific jar from xerces slot 2, and name it diffrently
662# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 766# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building 767# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar 768# java-pkg_jar-from --build-only junit junit.jar
665# 769#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into 770# @param $opt
667# package.env DEPEND line. 771# --build-only - makes the jar(s) not added into package.env DEPEND line.
772# (assumed automatically when called inside src_test)
773# --with-dependencies - get jars also from requested package's dependencies
774# transitively.
775# --into $dir - symlink jar(s) into $dir (must exist) instead of .
668# @param $1 - Package to get jars from. 776# @param $1 - Package to get jars from.
669# @param $2 - jar from package. If not specified, all jars will be used. 777# @param $2 - jar from package. If not specified, all jars will be used.
670# @param $3 - When a single jar is specified, destination filename of the 778# @param $3 - When a single jar is specified, destination filename of the
671# symlink. Defaults to the name of the jar. 779# symlink. Defaults to the name of the jar.
672# ------------------------------------------------------------------------------ 780# ------------------------------------------------------------------------------
673# TODO could probably be cleaned up a little 781# TODO could probably be cleaned up a little
674java-pkg_jar-from() { 782java-pkg_jar-from() {
675 debug-print-function ${FUNCNAME} $* 783 debug-print-function ${FUNCNAME} $*
676 784
677 local build_only="" 785 local build_only=""
786 local destdir="."
787 local deep=""
788
789 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
678 790
791 while [[ "${1}" == --* ]]; do
679 if [[ "${1}" = "--build-only" ]]; then 792 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true" 793 build_only="true"
794 elif [[ "${1}" = "--with-dependencies" ]]; then
795 deep="--with-dependencies"
796 elif [[ "${1}" = "--into" ]]; then
797 destdir="${2}"
798 shift
799 else
800 die "java-pkg_jar-from called with unknown parameter: ${1}"
801 fi
681 shift 802 shift
682 fi 803 done
683 804
684 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 805 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
685 806
686 [[ -z ${target_pkg} ]] && die "Must specify a package" 807 [[ -z ${target_pkg} ]] && die "Must specify a package"
687 808
688 # default destjar to the target jar 809 # default destjar to the target jar
689 [[ -z "${destjar}" ]] && destjar="${target_jar}" 810 [[ -z "${destjar}" ]] && destjar="${target_jar}"
690 811
691 local error_msg="There was a problem getting the classpath for ${target_pkg}." 812 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath 813 local classpath
693 classpath="$(java-config --classpath=${target_pkg})" 814 classpath="$(java-config ${deep} --classpath=${target_pkg})"
694 [[ $? != 0 ]] && die ${error_msg} 815 [[ $? != 0 ]] && die ${error_msg}
695 816
817 pushd ${destdir} > /dev/null \
818 || die "failed to change directory to ${destdir}"
696 local jar 819 local jar
697 for jar in ${classpath//:/ }; do 820 for jar in ${classpath//:/ }; do
698 local jar_name=$(basename "${jar}") 821 local jar_name=$(basename "${jar}")
699 if [[ ! -f "${jar}" ]] ; then 822 if [[ ! -f "${jar}" ]] ; then
700 debug-print "${jar} from ${target_pkg} does not exist" 823 debug-print "${jar} from ${target_pkg} does not exist"
710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 833 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
711 [[ -f "${destjar}" ]] && rm "${destjar}" 834 [[ -f "${destjar}" ]] && rm "${destjar}"
712 ln -snf "${jar}" "${destjar}" \ 835 ln -snf "${jar}" "${destjar}" \
713 || die "Failed to make symlink from ${jar} to ${destjar}" 836 || die "Failed to make symlink from ${jar} to ${destjar}"
714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 837 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
838 popd > /dev/null
715 return 0 839 return 0
716 fi 840 fi
717 done 841 done
842 popd > /dev/null
718 # if no target was specified, we're ok 843 # if no target was specified, we're ok
719 if [[ -z "${target_jar}" ]] ; then 844 if [[ -z "${target_jar}" ]] ; then
720 return 0 845 return 0
721 # otherwise, die bitterly 846 # otherwise, die bitterly
722 else 847 else
741# The providing packages are recorded as dependencies into package.env DEPEND 866# The providing packages are recorded as dependencies into package.env DEPEND
742# line, unless "--build-only" is passed as the very first argument, for jars 867# line, unless "--build-only" is passed as the very first argument, for jars
743# that have to be present only at build time and are not needed on runtime 868# that have to be present only at build time and are not needed on runtime
744# (junit testing etc). 869# (junit testing etc).
745# 870#
746# Example: Get the classpath for xerces-2, 871# Example: Get the classpath for xerces-2 and xalan,
747# java-pkg_getjars xerces-2 xalan 872# java-pkg_getjars xerces-2,xalan
748# Example Return: 873# Example Return:
749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 874# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
750# 875#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into 876# @param $opt
752# package.env DEPEND line. 877# --build-only - makes the jar(s) not added into package.env DEPEND line.
878# (assumed automatically when called inside src_test)
879# --with-dependencies - get jars also from requested package's dependencies
880# transitively.
753# @param $@ - list of packages to get jars from 881# @param $1 - list of packages to get jars from
882# (passed to java-config --classpath)
754# ------------------------------------------------------------------------------ 883# ------------------------------------------------------------------------------
755java-pkg_getjars() { 884java-pkg_getjars() {
756 debug-print-function ${FUNCNAME} $* 885 debug-print-function ${FUNCNAME} $*
757 886
758 local build_only="" 887 local build_only=""
888 local deep=""
889
890 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
759 891
892 while [[ "${1}" == --* ]]; do
760 if [[ "${1}" = "--build-only" ]]; then 893 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true" 894 build_only="true"
895 elif [[ "${1}" = "--with-dependencies" ]]; then
896 deep="--with-dependencies"
897 else
898 die "java-pkg_jar-from called with unknown parameter: ${1}"
899 fi
762 shift 900 shift
763 fi
764
765 [[ ${#} -lt 1 ]] && die "At least one argument needed"
766
767 # NOTE could probably just pass $@ to java-config --classpath. and return it
768 local classpath pkg
769 for pkg in ${@//,/ }; do
770 #for pkg in $(echo "$@" | tr ',' ' '); do
771 jars="$(java-config --classpath=${pkg})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
773 debug-print "${pkg}:${jars}"
774
775 if [[ -z "${classpath}" ]]; then
776 classpath="${jars}"
777 else
778 classpath="${classpath}:${jars}"
779 fi
780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
782 done 901 done
902
903 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
904
905 local classpath pkgs="${1}"
906 jars="$(java-config ${deep} --classpath=${pkgs})"
907 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
908 debug-print "${pkgs}:${jars}"
909
910 if [[ -z "${classpath}" ]]; then
911 classpath="${jars}"
912 else
913 classpath="${classpath}:${jars}"
914 fi
915
916 # Only record jars that aren't build-only
917 if [[ -z "${build_only}" ]]; then
918 oldifs="${IFS}"
919 IFS=","
920 for pkg in ${pkgs}; do
921 java-pkg_record-jar_ "${pkg}"
922 done
923 IFS="${oldifs}"
924 fi
925
783 echo "${classpath}" 926 echo "${classpath}"
784} 927}
785 928
786# ------------------------------------------------------------------------------ 929# ------------------------------------------------------------------------------
787# @ebuild-function java-pkg_getjar 930# @ebuild-function java-pkg_getjar
795# @example 938# @example
796# java-pkg_getjar xerces-2 xml-apis.jar 939# java-pkg_getjar xerces-2 xml-apis.jar
797# @example-return 940# @example-return
798# /usr/share/xerces-2/lib/xml-apis.jar 941# /usr/share/xerces-2/lib/xml-apis.jar
799# 942#
800# @param $1 - (optional) "--build-only" makes the jar not added into 943# @param $opt
801# package.env DEPEND line. 944# --build-only - makes the jar not added into package.env DEPEND line.
802# @param $1 - package to use 945# @param $1 - package to use
803# @param $2 - jar to get 946# @param $2 - jar to get
804# ------------------------------------------------------------------------------ 947# ------------------------------------------------------------------------------
805java-pkg_getjar() { 948java-pkg_getjar() {
806 debug-print-function ${FUNCNAME} $* 949 debug-print-function ${FUNCNAME} $*
807 950
808 local build_only="" 951 local build_only=""
952
953 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
809 954
955 while [[ "${1}" == --* ]]; do
810 if [[ "${1}" = "--build-only" ]]; then 956 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true" 957 build_only="true"
958 else
959 die "java-pkg_jar-from called with unknown parameter: ${1}"
960 fi
812 shift 961 shift
813 fi 962 done
963
964 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
814 965
815 local pkg="${1}" target_jar="${2}" jar 966 local pkg="${1}" target_jar="${2}" jar
816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 967 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
817 [[ -z ${target_jar} ]] && die "Must specify jar to get" 968 [[ -z ${target_jar} ]] && die "Must specify jar to get"
818 969
960# 1111#
961# export DEPEND="${DEPEND} ${depstr}" 1112# export DEPEND="${DEPEND} ${depstr}"
962# export RDEPEND="${RDEPEND} ${depstr}" 1113# export RDEPEND="${RDEPEND} ${depstr}"
963#} 1114#}
964 1115
1116# ------------------------------------------------------------------------------
1117# @ebuild-function java-pkg_find-normal-jars
1118#
1119# Find the files with suffix .jar file in the given directory or $WORKDIR
1120#
1121# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1122# ------------------------------------------------------------------------------
1123java-pkg_find-normal-jars() {
1124 local dir=$1
1125 [[ "${dir}" ]] || dir="${WORKDIR}"
1126 local found
1127 for jar in $(find "${dir}" -name "*.jar" -type f); do
1128 echo "${jar}"
1129 found="true"
1130 done
1131 [[ "${found}" ]]
1132 return $?
1133}
1134
1135# ------------------------------------------------------------------------------
1136# @ebuild-function java-pkg_ensure-no-bundled-jars
1137#
1138# Try to locate bundled jar files in ${WORKDIR} and die if found.
965# This should be used after S has been populated with symlinks to jars 1139# This function should be called after WORKDIR has been populated with symlink
966# TODO document 1140# to system jar files or bundled jars removed.
1141# ------------------------------------------------------------------------------
967java-pkg_ensure-no-bundled-jars() { 1142java-pkg_ensure-no-bundled-jars() {
968 debug-print-function ${FUNCNAME} $* 1143 debug-print-function ${FUNCNAME} $*
969 pushd ${WORKDIR} >/dev/null 2>/dev/null
970 1144
971 local bundled_jars=$(find . -name "*.jar" -type f) 1145 local bundled_jars=$(java-pkg_find-normal-jars)
972 if [[ -n ${bundled_jars} ]]; then 1146 if [[ -n ${bundled_jars} ]]; then
973 echo "Bundled jars found:" 1147 echo "Bundled jars found:"
974 local jar 1148 local jar
975 for jar in ${bundled_jars}; do 1149 for jar in ${bundled_jars}; do
976 echo $(pwd)${jar/./} 1150 echo $(pwd)${jar/./}
977 done 1151 done
978 die "Bundled jars found!" 1152 die "Bundled jars found!"
979
980 fi 1153 fi
981 popd >/dev/null 2>/dev/null
982} 1154}
983 1155
984# ------------------------------------------------------------------------------ 1156# ------------------------------------------------------------------------------
985# @internal-function java-pkg_ensure-vm-version-sufficient 1157# @internal-function java-pkg_ensure-vm-version-sufficient
986# 1158#
1135# @ebuild-function java-pkg_get-target 1307# @ebuild-function java-pkg_get-target
1136# 1308#
1137# Determines what target version should be used, for passing to -target. 1309# Determines what target version should be used, for passing to -target.
1138# If you don't care about lower versions, you can set _WANT_TARGET to the 1310# If you don't care about lower versions, you can set _WANT_TARGET to the
1139# version of your JDK. 1311# version of your JDK.
1140# Remember doing this will mostly like cause things to break.
1141# Doesn't allow it to be lower then the one in depend.
1142# Doesn't allow it to be higher then the active vm.
1143# 1312#
1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1313# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1145# ------------------------------------------------------------------------------ 1314# ------------------------------------------------------------------------------
1146java-pkg_get-target() { 1315java-pkg_get-target() {
1147 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1148 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1149 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1150 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1151 echo ${JAVA_PKG_WANT_TARGET}
1152 else
1153 echo ${min}
1154 fi
1155 else
1156 echo ${min}
1157 fi
1158
1159 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1316 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1160} 1317}
1161 1318
1162java-pkg_get-javac() { 1319java-pkg_get-javac() {
1163 debug-print-function ${FUNCNAME} $* 1320 debug-print-function ${FUNCNAME} $*
1164 1321
1165 java-pkg_init-compiler_ 1322
1166 local compiler="${GENTOO_COMPILER}" 1323 local compiler="${GENTOO_COMPILER}"
1167 1324
1168 local compiler_executable 1325 local compiler_executable
1169 if [[ "${compiler}" = "javac" ]]; then 1326 if [[ "${compiler}" = "javac" ]]; then
1170 # nothing fancy needs to be done for javac 1327 # nothing fancy needs to be done for javac
1178 unset JAVAC 1335 unset JAVAC
1179 # try to get value of JAVAC 1336 # try to get value of JAVAC
1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1337 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1181 export JAVAC=${old_javac} 1338 export JAVAC=${old_javac}
1182 1339
1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1340 if [[ -z ${compiler_executable} ]]; then
1341 echo "JAVAC is empty or undefined in ${compiler_env}"
1342 return 1
1343 fi
1184 1344
1185 # check that it's executable 1345 # check that it's executable
1186 if [[ ! -x ${compiler_executable} ]]; then 1346 if [[ ! -x ${compiler_executable} ]]; then
1187 eerror "Could not find ${compiler_executable}!"
1188 die "${compiler_executable} doesn't exist, or isn't executable" 1347 echo "${compiler_executable} doesn't exist, or isn't executable"
1348 return 1
1189 fi 1349 fi
1190 else 1350 else
1191 eerror "Could not find environment file for ${compiler}" 1351 echo "Could not find environment file for ${compiler}"
1192 die "Could not find ${compiler_env}" 1352 return 1
1193 fi 1353 fi
1194 fi 1354 fi
1195 echo ${compiler_executable} 1355 echo ${compiler_executable}
1196} 1356}
1197 1357
1214 1374
1215 debug-print "want source: ${want_source}" 1375 debug-print "want source: ${want_source}"
1216 debug-print "want target: ${want_target}" 1376 debug-print "want target: ${want_target}"
1217 1377
1218 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1378 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1219 debug-print "could not find valid -source/-target values" 1379 debug-print "could not find valid -source/-target values for javac"
1220 die "Could not find valid -source/-target values" 1380 echo "Could not find valid -source/-target values for javac"
1381 return 1
1221 else 1382 else
1222 if java-pkg_is-vm-version-ge "1.4"; then 1383 if java-pkg_is-vm-version-ge "1.4"; then
1223 echo "${source_str} ${target_str}" 1384 echo "${source_str} ${target_str}"
1224 else 1385 else
1225 echo "${target_str}" 1386 echo "${target_str}"
1229 1390
1230# TODO document 1391# TODO document
1231java-pkg_get-jni-cflags() { 1392java-pkg_get-jni-cflags() {
1232 local flags="-I${JAVA_HOME}/include" 1393 local flags="-I${JAVA_HOME}/include"
1233 1394
1395 local platform="linux"
1396 use elibc_FreeBSD && platform="freebsd"
1397
1234 # TODO do a check that the directories are valid 1398 # TODO do a check that the directories are valid
1235 # TODO figure out how to cope with other things than linux...
1236 flags="${flags} -I${JAVA_HOME}/include/linux" 1399 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1237 1400
1238 echo ${flags} 1401 echo ${flags}
1239} 1402}
1240 1403
1241java-pkg_ensure-gcj() { 1404java-pkg_ensure-gcj() {
1247 die "No GCJ support found!" 1410 die "No GCJ support found!"
1248 fi 1411 fi
1249} 1412}
1250 1413
1251java-pkg_ensure-test() { 1414java-pkg_ensure-test() {
1252 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1415 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1416 && hasq test ${IUSE} && ! use test;
1417 then
1253 eerror "You specified FEATURES=test, but USE=test is needed" 1418 eerror "You specified FEATURES=test, but USE=test is needed"
1254 eerror "to pull in the additional dependencies for testing" 1419 eerror "to pull in the additional dependencies for testing"
1255 die "Need USE=test enabled" 1420 die "Need USE=test enabled"
1256 fi 1421 fi
1257} 1422}
1258 1423
1259# ------------------------------------------------------------------------------ 1424# ------------------------------------------------------------------------------
1425# @ebuild-function java-pkg_register-ant-task
1426#
1427# Register this package as ant task, so that ant will load it when no specific
1428# ANT_TASKS are specified. Note that even without this registering, all packages
1429# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1430# packages, but can be also used by other ebuilds that used to symlink their
1431# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1432# compatibility.
1433#
1434# @param --version x.y Register only for ant version x.y (otherwise for any ant
1435# version). Used by the ant-* packages to prevent loading of mismatched
1436# ant-core ant tasks after core was updated, before the tasks are updated,
1437# without a need for blockers.
1438# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1439# ------------------------------------------------------------------------------
1440java-pkg_register-ant-task() {
1441 local TASKS_DIR="tasks"
1442
1443 # check for --version x.y parameters
1444 while [[ -n "${1}" && -n "${2}" ]]; do
1445 local var="${1#--}"
1446 local val="${2}"
1447 if [[ "${var}" == "version" ]]; then
1448 TASKS_DIR="tasks-${val}"
1449 else
1450 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1451 fi
1452 shift 2
1453 done
1454
1455 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1456
1457 dodir /usr/share/ant/${TASKS_DIR}
1458 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1459}
1460
1461# ------------------------------------------------------------------------------
1462# @internal-function java-pkg_ant-tasks-from-deps
1463#
1464# Function to determine ANT_TASKS from DEPEND variable for backwards
1465# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1466# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1467# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1468# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1469# be a problem, the worst it can do is activace all tasks when not needed.
1470# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1471# insufficient dependencies, otherwise all available tasks are used for
1472# backwards compatilbility.
1473#
1474# @return "all" or "none"
1475# ------------------------------------------------------------------------------
1476java-pkg_ant-tasks-from-deps() {
1477 local found_ant found_ant_tasks
1478
1479 for dep in ${DEPEND}
1480 do
1481 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1482 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1483 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1484 done
1485
1486 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1487 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1488 echo "all"
1489 else
1490 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1491 # so we deactivate all tasks that may be installed
1492 echo "none"
1493 fi
1494}
1495
1496# ------------------------------------------------------------------------------
1497# @internal-function java-pkg_ant-tasks-depend
1498#
1499# Translates the WANT_ANT_TASKS variable into valid dependencies.
1500# ------------------------------------------------------------------------------
1501java-pkg_ant-tasks-depend() {
1502 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1503
1504 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1505 local DEP=""
1506 for i in ${WANT_ANT_TASKS}
1507 do
1508 if [[ ${i} != ant-* ]]; then
1509 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1510 return 1
1511 fi
1512 DEP="${DEP}dev-java/${i} "
1513 done
1514 echo ${DEP}
1515 return 0
1516 else
1517 return 0
1518 fi
1519}
1520
1521# ------------------------------------------------------------------------------
1260# @section-end helper 1522# @section-end helper
1261# ------------------------------------------------------------------------------ 1523# ------------------------------------------------------------------------------
1262 1524
1263# ------------------------------------------------------------------------------ 1525# ------------------------------------------------------------------------------
1264# @section-begin build 1526# @section-begin build
1270 1532
1271# ------------------------------------------------------------------------------ 1533# ------------------------------------------------------------------------------
1272# @ebuild-function eant 1534# @ebuild-function eant
1273# 1535#
1274# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1536# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1275# compiler. 1537# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1276# 1538# variables:
1539# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1540# gentoo.classpath property. Be sure to call
1541# java-ant_rewrite-classpath in src_unpack.
1542# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1277# ------------------------------------------------------------------------------ 1543# ------------------------------------------------------------------------------
1278eant() { 1544eant() {
1279 debug-print-function ${FUNCNAME} $* 1545 debug-print-function ${FUNCNAME} $*
1280 1546
1281 # FIXME get this working 1547 # FIXME get this working
1282# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1548# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1283# java-pkg_announce-qa-violation \ 1549# java-pkg_announce-qa-violation \
1284# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1550# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1285# fi 1551# fi
1286 1552
1287 local antflags 1553 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1554 local msg="You should inherit java-ant-2 when using eant"
1555 java-pkg_announce-qa-violation ${msg}
1556 die ${msg}
1557 fi
1558
1559 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1560
1288 java-pkg_init-compiler_ 1561 java-pkg_init-compiler_
1289 local compiler="${GENTOO_COMPILER}" 1562 local compiler="${GENTOO_COMPILER}"
1290 1563
1291 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1564 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1292 1565
1294 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1567 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1295 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1568 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1296 fi 1569 fi
1297 1570
1298 if [[ ${compiler} != "javac" ]]; then 1571 if [[ ${compiler} != "javac" ]]; then
1299 antflags="-Dbuild.compiler=${build_compiler}" 1572 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1300 # Figure out any extra stuff to put on the classpath for compilers aside 1573 # Figure out any extra stuff to put on the classpath for compilers aside
1301 # from javac 1574 # from javac
1302 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1575 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1303 # java-config -p 1576 # java-config -p
1304 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1577 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1310 if is-java-strict; then 1583 if is-java-strict; then
1311 einfo "Disabling system classpath for ant" 1584 einfo "Disabling system classpath for ant"
1312 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1585 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1313 fi 1586 fi
1314 1587
1315 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1588 for arg in "${@}"; do
1316 antflags="${antflags} -debug" 1589 if [[ ${arg} = -lib ]]; then
1590 if is-java-strict; then
1591 eerror "You should not use the -lib argument to eant because it will fail"
1592 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1593 eerror "or ant properties to make dependencies available."
1594 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1595 eerror "split ant (>=dev-java/ant-core-1.7)."
1596 die "eant -lib is deprecated/forbidden"
1597 else
1598 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1599 echo "more info."
1600 fi
1601 fi
1602 done
1603
1604 if has_version ">=dev-java/ant-core-1.7.0"; then
1605 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1606 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1607
1608 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1609 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1610
1611 if is-java-strict; then
1612 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1613 if [[ -z "${ANT_TASKS}" ]]; then
1614 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1615 fi
1616 else
1617 # if ant-tasks is not set by ebuild or forced, activate all of them
1618 ANT_TASKS="${ANT_TASKS:-all}"
1619 fi
1620
1621 # at this point, ANT_TASKS should be "all", "none" or explicit list
1622 if [[ "${ANT_TASKS}" == "all" ]]; then
1623 einfo "Using all available ANT_TASKS"
1624 elif [[ "${ANT_TASKS}" == "none" ]]; then
1625 einfo "Disabling all optional ANT_TASKS"
1626 else
1627 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1628 fi
1629
1630 export ANT_TASKS
1631 fi
1632
1633 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1634 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1635
1636 local gcp="${EANT_GENTOO_CLASSPATH}"
1637
1638 if [[ ${EBUILD_PHASE} = "test" ]]; then
1639 antflags="${antflags} -DJunit.present=true"
1640 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1641 fi
1642
1643 local cp
1644
1645 for atom in ${gcp}; do
1646 cp="${cp}:$(java-pkg_getjars ${atom})"
1647 done
1648
1649 if [[ ${cp} ]]; then
1650 # It seems ant does not like single quotes around ${cp}
1651 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1317 fi 1652 fi
1318 1653
1319 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1654 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1655 debug-print "Calling ant: ${antflags} ${@}"
1320 ant ${antflags} "${@}" || die "eant failed" 1656 ant ${antflags} "${@}" || die "eant failed"
1321 1657
1322} 1658}
1323 1659
1324# ------------------------------------------------------------------------------ 1660# ------------------------------------------------------------------------------
1330# @param $@ - Arguments to be passed to the compiler 1666# @param $@ - Arguments to be passed to the compiler
1331# ------------------------------------------------------------------------------ 1667# ------------------------------------------------------------------------------
1332ejavac() { 1668ejavac() {
1333 debug-print-function ${FUNCNAME} $* 1669 debug-print-function ${FUNCNAME} $*
1334 1670
1335 # FIXME using get-javac ends up printing stuff with einfo 1671 java-pkg_init-compiler_
1672
1673 local compiler_executable
1336# local compiler_executable=$(java-pkg_get-javac) 1674 compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac" 1675 if [[ ${?} != 0 ]]; then
1676 eerror "There was a problem determining compiler: ${compiler_executable}"
1677 die "get-javac failed"
1678 fi
1338 1679
1680 local javac_args
1681 javac_args="$(java-pkg_javac-args)"
1682 if [[ ${?} != 0 ]]; then
1683 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1684 die "java-pkg_javac-args failed"
1685 fi
1686
1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1687 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1688 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1341} 1689}
1342 1690
1343# ------------------------------------------------------------------------------ 1691# ------------------------------------------------------------------------------
1344# @ebuild-function java-pkg_filter-compiler 1692# @ebuild-function java-pkg_filter-compiler
1345# 1693#
1382# @return string - Name of the target to create javadocs 1730# @return string - Name of the target to create javadocs
1383# ------------------------------------------------------------------------------ 1731# ------------------------------------------------------------------------------
1384use_doc() { 1732use_doc() {
1385 use doc && echo ${@:-javadoc} 1733 use doc && echo ${@:-javadoc}
1386} 1734}
1735
1387 1736
1388# ------------------------------------------------------------------------------ 1737# ------------------------------------------------------------------------------
1389# @section-end build 1738# @section-end build
1390# ------------------------------------------------------------------------------ 1739# ------------------------------------------------------------------------------
1391 1740
1424 # When users have crazy classpaths some packages can fail to compile. 1773 # When users have crazy classpaths some packages can fail to compile.
1425 # and everything should work with empty CLASSPATH. 1774 # and everything should work with empty CLASSPATH.
1426 # This also helps prevent unexpected dependencies on random things 1775 # This also helps prevent unexpected dependencies on random things
1427 # from the CLASSPATH. 1776 # from the CLASSPATH.
1428 unset CLASSPATH 1777 unset CLASSPATH
1778
1779 # Unset external ANT_ stuff
1780 unset ANT_TASKS
1781 unset ANT_OPTS
1429} 1782}
1430 1783
1431# ------------------------------------------------------------------------------ 1784# ------------------------------------------------------------------------------
1432# @function-internal java-pkg-init-compiler_ 1785# @function-internal java-pkg-init-compiler_
1433# 1786#
1577# Writes the package.env out to disk. 1930# Writes the package.env out to disk.
1578# 1931#
1579# ------------------------------------------------------------------------------ 1932# ------------------------------------------------------------------------------
1580# TODO change to do-write, to match everything else 1933# TODO change to do-write, to match everything else
1581java-pkg_do_write_() { 1934java-pkg_do_write_() {
1935 java-pkg_init_paths_
1582 # Create directory for package.env 1936 # Create directory for package.env
1583 dodir "${JAVA_PKG_SHAREPATH}" 1937 dodir "${JAVA_PKG_SHAREPATH}"
1584 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1938 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1585 # Create package.env 1939 # Create package.env
1586 ( 1940 (
1614 # Strip unnecessary leading and trailing colons 1968 # Strip unnecessary leading and trailing colons
1615 # TODO try to cleanup if possible 1969 # TODO try to cleanup if possible
1616 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1970 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1617 fi 1971 fi
1618} 1972}
1619
1620 1973
1621# ------------------------------------------------------------------------------ 1974# ------------------------------------------------------------------------------
1622# @internal-function java-pkg_record-jar_ 1975# @internal-function java-pkg_record-jar_
1623# 1976#
1624# Record a dependency to the package.env 1977# Record a dependency to the package.env
1705# ------------------------------------------------------------------------------ 2058# ------------------------------------------------------------------------------
1706java-pkg_setup-vm() { 2059java-pkg_setup-vm() {
1707 debug-print-function ${FUNCNAME} $* 2060 debug-print-function ${FUNCNAME} $*
1708 2061
1709 local vendor="$(java-pkg_get-vm-vendor)" 2062 local vendor="$(java-pkg_get-vm-vendor)"
1710 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2063 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1711 addpredict "/dev/random" 2064 addpredict "/dev/random"
1712 elif [[ "${vendor}" == "ibm" ]]; then 2065 elif [[ "${vendor}" == "ibm" ]]; then
1713 addpredict "/proc/self/maps" 2066 addpredict "/proc/self/maps"
1714 addpredict "/proc/cpuinfo" 2067 addpredict "/proc/cpuinfo"
1715 export LANG="C" LC_ALL="C" 2068 export LANG="C" LC_ALL="C"
1775# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2128# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1776# verify that the current VM is sufficient. 2129# verify that the current VM is sufficient.
1777# Setup the environment for the VM being used. 2130# Setup the environment for the VM being used.
1778# ------------------------------------------------------------------------------ 2131# ------------------------------------------------------------------------------
1779java-pkg_switch-vm() { 2132java-pkg_switch-vm() {
2133 debug-print-function ${FUNCNAME} $*
2134
1780 if java-pkg_needs-vm; then 2135 if java-pkg_needs-vm; then
1781 # Use the VM specified by JAVA_PKG_FORCE_VM 2136 # Use the VM specified by JAVA_PKG_FORCE_VM
1782 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2137 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1783 # If you're forcing the VM, I hope you know what your doing... 2138 # If you're forcing the VM, I hope you know what your doing...
2139 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1784 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2140 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1785 # if we're allowed to switch the vm... 2141 # if we're allowed to switch the vm...
1786 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2142 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1787 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2143 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1788 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2144 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1789 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2145 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1790 else 2146 else
1791 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2147 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2148 fi
2149 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2150 eerror "Unable to determine VM for building from dependencies:"
2151 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2152 echo "VNEED: ${JAVA_PKG_VNEED}"
2153 die "Failed to determine VM for building."
2154 else
2155 export GENTOO_VM
1792 fi 2156 fi
1793 # otherwise just make sure the current VM is sufficient 2157 # otherwise just make sure the current VM is sufficient
1794 else 2158 else
1795 java-pkg_ensure-vm-version-sufficient 2159 java-pkg_ensure-vm-version-sufficient
1796 fi 2160 fi
1798 2162
1799 java-pkg_setup-vm 2163 java-pkg_setup-vm
1800 2164
1801 export JAVA=$(java-config --java) 2165 export JAVA=$(java-config --java)
1802 export JAVAC=$(java-config --javac) 2166 export JAVAC=$(java-config --javac)
1803 export JAVACFLAGS="$(java-pkg_javac-args)" 2167 JAVACFLAGS="$(java-pkg_javac-args)"
2168 if [[ ${?} != 0 ]]; then
2169 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2170 die "java-pkg_javac-args failed"
2171 fi
1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2172 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2173 export JAVACFLAGS
1805 2174
1806 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2175 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1807 export JDK_HOME=${JAVA_HOME} 2176 export JDK_HOME=${JAVA_HOME}
1808 2177
1809 #TODO If you know a better solution let us know. 2178 #TODO If you know a better solution let us know.
1855 einfo "Classes" 2224 einfo "Classes"
1856 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2225 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1857 fi 2226 fi
1858} 2227}
1859 2228
1860# TODO document 2229# ------------------------------------------------------------------------------
2230# @internal-function java-pkg_verify-classes
2231#
1861# Verify that the classes were compiled for the right source / target 2232# Verify that the classes were compiled for the right source / target. Dies if
2233# not.
2234# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2235# ------------------------------------------------------------------------------
1862java-pkg_verify-classes() { 2236java-pkg_verify-classes() {
1863 ebegin "Verifying java class versions"
1864 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2237 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1865 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2238 local target=$(java-pkg_get-target)
2239 local result
2240 local log="${T}/class-version-verify.log"
2241 if [[ -n "${1}" ]]; then
2242 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1866 result=$? 2243 result=$?
1867 eend ${result}
1868 if [[ ${result} == 0 ]]; then
1869 einfo "All good"
1870 else 2244 else
1871 ewarn "Possible problem" 2245 ebegin "Verifying java class versions (target: ${target})"
1872 die "Bad class files found" 2246 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2247 result=$?
2248 eend ${result}
1873 fi 2249 fi
2250 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2251 if [[ ${result} != 0 ]]; then
2252 eerror "Incorrect bytecode version found"
2253 [[ -n "${1}" ]] && eerror "in file: ${1}"
2254 eerror "See ${log} for more details."
2255 die "Incorrect bytecode found"
2256 fi
1874} 2257}
1875
1876 2258
1877# ------------------------------------------------------------------------------ 2259# ------------------------------------------------------------------------------
1878# @section-end internal 2260# @section-end internal
1879# ------------------------------------------------------------------------------ 2261# ------------------------------------------------------------------------------
1880 2262

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

  ViewVC Help
Powered by ViewVC 1.1.20