/[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.2 Revision 1.24
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
33# ----------------------------------------------------------------------------- 33# -----------------------------------------------------------------------------
34 34
35# Make sure we use java-config-2 35# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 36export WANT_JAVA_CONFIG="2"
37 37
38# TODO document
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
40
38# ----------------------------------------------------------------------------- 41# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 42# @variable-internal JAVA_PKG_E_DEPEND
40# 43#
41# This is a convience variable to be used from the other java eclasses. This is 44# This is a convience variable to be used from the other java eclasses. This is
42# the version of java-config we want to use. We also need a recent version 45# the version of java-config we want to use. We also need a recent version
43# portage, that includes phase hooks. 46# portage, that includes phase hooks.
44# ----------------------------------------------------------------------------- 47# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
46 49
47# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 52# @variable-default yes
50# 53#
97# ----------------------------------------------------------------------------- 100# -----------------------------------------------------------------------------
98 101
99# ----------------------------------------------------------------------------- 102# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 103# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 104# @default /usr/share/java-config-2/compiler
102# 105#
103# Directory where compiler settings are saved, without trailing slash. 106# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 107# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 108# -----------------------------------------------------------------------------
106JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
107 110
117 120
118# ----------------------------------------------------------------------------- 121# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 122# @variable-external JAVA_PKG_FORCE_COMPILER
120# 123#
121# Explicitly set a list of compilers to use. This is normally read from 124# Explicitly set a list of compilers to use. This is normally read from
122# JAVA_PKG_COMPILERS_CONF. 125# JAVA_PKG_COMPILERS_CONF.
123# 126#
124# @note This should only be used internally or for testing. 127# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 128# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 129# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 130# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 150# @ebuild-function java-pkg_dojar
148# 151#
149# Installs any number of jars. 152# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 154# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 155# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 156# Instead, use java-pkg_newjar defined below.
154# 157#
155# @example 158# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 160#
206# Records an already installed jar in the package.env 209# Records an already installed jar in the package.env
207# This would mostly be used if the package has make or a custom script to 210# This would mostly be used if the package has make or a custom script to
208# install things. 211# install things.
209# 212#
210# Example: 213# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 214# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
215#
216# WARNING:
217# if you want to use shell expansion, you have to use ${D}/... as the for in
218# this function will not be able to expand the path, here's an example:
219#
220# java-pkg_regjar /opt/my-java/lib/*.jar
221#
222# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist
227#
228# you have to use it as:
229#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 231#
213# @param $@ - jars to record 232# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 233# ------------------------------------------------------------------------------
215# TODO fix me! 234# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 235java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 236 debug-print-function ${FUNCNAME} $*
218 237
219 java-pkg_check-phase install 238 java-pkg_check-phase install
220 239
224 243
225 local jar jar_dir jar_file 244 local jar jar_dir jar_file
226 for jar in "$@"; do 245 for jar in "$@"; do
227 # TODO use java-pkg_check-versioned-jar 246 # TODO use java-pkg_check-versioned-jar
228 if [[ -e "${jar}" ]]; then 247 if [[ -e "${jar}" ]]; then
248 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env
229 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar}" 253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
230 elif [[ -e "${D}${jar}" ]]; then 254 elif [[ -e "${D}${jar}" ]]; then
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 256 else
233 die "${jar} does not exist" 257 die "${jar} does not exist"
234 fi 258 fi
255 local original_jar="${1}" 279 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 280 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 281 local new_jar_dest="${T}/${new_jar}"
258 282
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 283 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!"
261 285
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 287 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 288 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 289 java-pkg_dojar "${new_jar_dest}"
281} 305}
282 306
283 307
284# ------------------------------------------------------------------------------ 308# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 309# @ebuild-function java-pkg_doso
286# 310#
287# Installs any number of JNI libraries 311# Installs any number of JNI libraries
288# They will be installed into /usr/lib by default, but java-pkg_sointo 312# They will be installed into /usr/lib by default, but java-pkg_sointo
289# can be used change this path 313# can be used change this path
290# 314#
291# Example: 315# Example:
346 java-pkg_check-phase install 370 java-pkg_check-phase install
347 371
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 372 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 373
350 java-pkg_init_paths_ 374 java-pkg_init_paths_
351 375
352 local lib target_dir 376 local lib target_dir
353 for lib in "$@" ; do 377 for lib in "$@" ; do
354 # Check the absolute path of the lib 378 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 379 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 380 target_dir="$(java-pkg_expand_dir_ ${lib})"
434} 458}
435 459
436# ------------------------------------------------------------------------------ 460# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 461# @ebuild-function java-pkg_dosrc
438# 462#
439# Installs a zip containing the source for a package, so it can used in 463# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 464# from IDEs like eclipse and netbeans.
441# 465#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 466# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 467#
444# It also should be controlled by USE=source. 468# It also should be controlled by USE=source.
445# 469#
446# @example: 470# @example:
447# java-pkg_dosrc src/* 471# java-pkg_dosrc src/*
448# 472#
449# ------------------------------------------------------------------------------ 473# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 474# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 475# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 476# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 477# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 478# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 479java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 480 debug-print-function ${FUNCNAME} $*
457 481
458 [ ${#} -lt 1 ] && die "At least one argument needed" 482 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then 483 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi 485 fi
462 486
463 java-pkg_check-phase install 487 java-pkg_check-phase install
464 488
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 489 [[ ${#} -lt 1 ]] && die "At least one argument needed"
466 490
467 java-pkg_init_paths_ 491 java-pkg_init_paths_
468 492
469 local zip_name="${PN}-src.zip" 493 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 494 local zip_path="${T}/${zip_name}"
498# 522#
499# @param $1 - filename of launcher to create 523# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 524# @param $2 - options, as follows:
501# --main the.main.class.too.start 525# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 526# --jar /the/jar/too/launch.jar
503# --java_args 'Extra arguments to pass too jave' 527# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 528# --pkg_args 'Extra arguments too pass to the package'
505# --pwd 529# --pwd
506# -into 530# -into
507# -pre 531# -pre
508# ------------------------------------------------------------------------------ 532# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 533java-pkg_dolauncher() {
516 java-pkg_init_paths_ 540 java-pkg_init_paths_
517 541
518 local name="${1}" 542 local name="${1}"
519 # TODO rename to launcher 543 # TODO rename to launcher
520 local target="${T}/${name}" 544 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 546 local target_dir pre
522 shift 547 shift
523 548
524 echo "#!/bin/bash" > "${target}" 549 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 550 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 551 local var=${1} value=${2}
527 if [[ "${var:0:2}" == "--" ]]; then 552 if [[ "${var:0:2}" == "--" ]]; then
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}"
529 elif [[ "${var}" == "-into" ]]; then 554 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 555 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 556 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 557 pre="${value}"
533 fi 558 fi
534 shift 2 559 shift 2
535 done 560 done
561
562 # Write the actual script
563 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 566 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 569
540 if [[ -n "${into}" ]]; then 570 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 571 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 572 local ret=$?
543 return ${ret} 573 return ${ret}
544 else 574 else
545 dobin "${target}" 575 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 603 echo "dowar: warning, skipping directory ${war}"
574 continue 604 continue
575 else 605 else
576 warpath="${war}" 606 warpath="${war}"
577 fi 607 fi
578 608
579 # Install those files like you mean it 609 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 610 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 611 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 612 doins ${warpath}
583 done 613 done
618# @ebuild-function java-pkg_jar-from 648# @ebuild-function java-pkg_jar-from
619# 649#
620# Makes a symlink to a jar from a certain package 650# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 651# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 652# You can use this function to replace these bundled dependencies.
653# The dependency is recorded into package.env DEPEND line, unless "--build-only"
654# is passed as the very first argument, for jars that have to be present only
655# at build time and are not needed on runtime (junit testing etc).
623# 656#
624# Example: get all jars from xerces slot 2 657# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 658# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 659# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 660# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 661# Example: get a specific jar from xerces slot 2, and name it diffrently
629# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 662# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar
630# 665#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into
667# package.env DEPEND line.
631# @param $1 - Package to get jars from. 668# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 669# @param $2 - jar from package. If not specified, all jars will be used.
633# @param $3 - When a single jar is specified, destination filename of the 670# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 671# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 672# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 673# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 674java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 675 debug-print-function ${FUNCNAME} $*
639 676
677 local build_only=""
678
679 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true"
681 shift
682 fi
683
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 684 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 685
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 686 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 687
644 # default destjar to the target jar 688 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 689 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 690
691 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 693 classpath="$(java-config --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 694 [[ $? != 0 ]] && die ${error_msg}
649 695
650 local jar 696 local jar
651 for jar in ${classpath//:/ }; do 697 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 698 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 699 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 703 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 704 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 705 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 706 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 707 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 708 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 709 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 711 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 712 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 713 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 715 return 0
670 fi 716 fi
671 done 717 done
672 # if no target was specified, we're ok 718 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 719 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 736# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 737# @ebuild-function java-pkg_getjars
692# 738#
693# Get the classpath provided by any number of packages 739# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 740# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
741# 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
743# that have to be present only at build time and are not needed on runtime
744# (junit testing etc).
695# 745#
696# Example: Get the classpath for xerces-2, 746# Example: Get the classpath for xerces-2,
697# java-pkg_getjars xerces-2 xalan 747# java-pkg_getjars xerces-2 xalan
698# Example Return: 748# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 750#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into
752# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 753# @param $@ - list of packages to get jars from
702# ------------------------------------------------------------------------------ 754# ------------------------------------------------------------------------------
703java-pkg_getjars() { 755java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 756 debug-print-function ${FUNCNAME} $*
757
758 local build_only=""
759
760 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true"
762 shift
763 fi
705 764
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 765 [[ ${#} -lt 1 ]] && die "At least one argument needed"
707 766
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 767 # NOTE could probably just pass $@ to java-config --classpath. and return it
709 local classpath pkg 768 local classpath pkg
710 for pkg in ${@//,/ }; do 769 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 770 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 771 jars="$(java-config --classpath=${pkg})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
713 debug-print "${pkg}:${jars}" 773 debug-print "${pkg}:${jars}"
714 # TODO should we ensure jars exist? 774
715 if [[ -z "${classpath}" ]]; then 775 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 776 classpath="${jars}"
717 else 777 else
718 classpath="${classpath}:${jars}" 778 classpath="${classpath}:${jars}"
719 fi 779 fi
720 java-pkg_record-jar_ "${pkg}" 780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
721 done 782 done
722 echo "${classpath}" 783 echo "${classpath}"
723} 784}
724 785
725# ------------------------------------------------------------------------------ 786# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 787# @ebuild-function java-pkg_getjar
727# 788#
728# Get the filename of a single jar from a package 789# Get the filename of a single jar from a package
790# The providing package is recorded as runtime dependency into package.env
791# DEPEND line, unless "--build-only" is passed as the very first argument, for
792# jars that have to be present only at build time and are not needed on runtime
793# (junit testing etc).
729# 794#
730# @example 795# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 796# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 797# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 798# /usr/share/xerces-2/lib/xml-apis.jar
734# 799#
800# @param $1 - (optional) "--build-only" makes the jar not added into
801# package.env DEPEND line.
735# @param $1 - package to use 802# @param $1 - package to use
736# @param $2 - jar to get 803# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 804# ------------------------------------------------------------------------------
738java-pkg_getjar() { 805java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 806 debug-print-function ${FUNCNAME} $*
807
808 local build_only=""
809
810 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true"
812 shift
813 fi
740 814
741 local pkg="${1}" target_jar="${2}" jar 815 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 817 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 818
745 # TODO check that package is actually installed 819 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
820 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 821 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 822 [[ $? != 0 ]] && die ${error_msg}
823
748 for jar in ${classpath//:/ }; do 824 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 825 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 826 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 827 fi
752 828
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 829 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 830 # Only record jars that aren't build-only
831 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 832 echo "${jar}"
756 return 0 833 return 0
757 fi 834 fi
758 done 835 done
759 836
760 die "Could not find ${target_jar} in ${pkg}" 837 die "Could not find ${target_jar} in ${pkg}"
761 return 1 838 return 1
762} 839}
763 840
764# This function reads stdin, and based on that input, figures out how to 841# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 855# line="${line// /}"
779# 856#
780# # format: path=jarinfo 857# # format: path=jarinfo
781# local path=${line%%=*} 858# local path=${line%%=*}
782# local jarinfo=${line##*=} 859# local jarinfo=${line##*=}
783# 860#
784# # format: jar@package 861# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 862# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 863# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 864# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 865# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 878# @section-end query
802# ------------------------------------------------------------------------------ 879# ------------------------------------------------------------------------------
803 880
804# ------------------------------------------------------------------------------ 881# ------------------------------------------------------------------------------
805# @section-begin helper 882# @section-begin helper
806# @section-summary Helper functions 883# @section-summary Helper functions
807# 884#
808# Various other functions to use from an ebuild 885# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 886# ------------------------------------------------------------------------------
810 887
811# ------------------------------------------------------------------------------ 888# ------------------------------------------------------------------------------
817# jdbc-stdext 894# jdbc-stdext
818# jaf 895# jaf
819# jdbc-rowset 896# jdbc-rowset
820# jms 897# jms
821# 898#
822# @param $1 - Optionally indicate that the dependencies are controlled by 899# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 900# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 901# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 902# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 903# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 904# TODO rewrite to parse a line based declaration file instead -- karltk
921 fi 998 fi
922} 999}
923 1000
924# ------------------------------------------------------------------------------ 1001# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1002# @internal-function java-pkg_is-vm-version-sufficient
926# 1003#
927# @return zero - VM is sufficient 1004# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1005# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1006# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1007java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1008 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1028 die "Active Java VM too old"
952 fi 1029 fi
953} 1030}
954 1031
955# ------------------------------------------------------------------------------ 1032# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1033# @internal-function java-pkg_is-vm-version-eq
957# 1034#
958# @param $@ - VM version to compare current VM to 1035# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1036# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1037# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1038# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1039java-pkg_is-vm-version-eq() {
992# 1069#
993# @param $@ - VM version to compare current to 1070# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1071# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1072java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1073 debug-print-function ${FUNCNAME} $*
997 1074
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1075 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1076 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1077 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1078 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1079 die "Active Java VM too old"
1003 fi 1080 fi
1004} 1081}
1005 1082
1006# ------------------------------------------------------------------------------ 1083# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1084# @internal-function java-pkg_is-vm-version-ge
1008# 1085#
1009# @param $@ - VM version to compare current VM to 1086# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1087# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1088# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1089# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1090java-pkg_is-vm-version-ge() {
1027 return 1 1104 return 1
1028 fi 1105 fi
1029 fi 1106 fi
1030} 1107}
1031 1108
1109java-pkg_set-current-vm() {
1110 export GENTOO_VM=${1}
1111}
1112
1113java-pkg_get-current-vm() {
1114 echo ${GENTOO_VM}
1115}
1116
1117java-pkg_current-vm-matches() {
1118 hasq $(java-pkg_get-current-vm) ${@}
1119 return $?
1120}
1121
1032# ------------------------------------------------------------------------------ 1122# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1123# @ebuild-function java-pkg_get-source
1034# 1124#
1035# Determines what source version should be used, for passing to -source. 1125# Determines what source version should be used, for passing to -source.
1036# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1126# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1127#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1128# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1129# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1134# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1135# @ebuild-function java-pkg_get-target
1046# 1136#
1047# Determines what target version should be used, for passing to -target. 1137# Determines what target version should be used, for passing to -target.
1048# If you don't care about lower versions, you can set _WANT_TARGET to the 1138# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1139# version of your JDK.
1050# Remember doing this will mostly like cause things to break. 1140# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend. 1141# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm. 1142# Doesn't allow it to be higher then the active vm.
1053# 1143#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1145# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1146java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1147 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1148 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1149 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1060 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then 1150 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1061 echo ${JAVA_PKG_WANT_TARGET} 1151 echo ${JAVA_PKG_WANT_TARGET}
1062 else 1152 else
1070} 1160}
1071 1161
1072java-pkg_get-javac() { 1162java-pkg_get-javac() {
1073 debug-print-function ${FUNCNAME} $* 1163 debug-print-function ${FUNCNAME} $*
1074 1164
1075 java-pkg_init-compiler_ 1165
1076 local compiler="${GENTOO_COMPILER}" 1166 local compiler="${GENTOO_COMPILER}"
1077 1167
1078 local compiler_executable 1168 local compiler_executable
1079 if [[ "${compiler}" = "javac" ]]; then 1169 if [[ "${compiler}" = "javac" ]]; then
1080 # nothing fancy needs to be done for javac 1170 # nothing fancy needs to be done for javac
1088 unset JAVAC 1178 unset JAVAC
1089 # try to get value of JAVAC 1179 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1181 export JAVAC=${old_javac}
1092 1182
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1183 if [[ -z ${compiler_executable} ]]; then
1094 1184 echo "JAVAC is empty or undefined in ${compiler_env}"
1185 return 1
1186 fi
1187
1095 # check that it's executable 1188 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1189 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1190 echo "${compiler_executable} doesn't exist, or isn't executable"
1191 return 1
1099 fi 1192 fi
1100 else 1193 else
1101 eerror "Could not find environment file for ${compiler}" 1194 echo "Could not find environment file for ${compiler}"
1102 die "Could not find ${compiler_env}" 1195 return 1
1103 fi 1196 fi
1104 fi 1197 fi
1105 echo ${compiler_executable} 1198 echo ${compiler_executable}
1106} 1199}
1107 1200
1108# ------------------------------------------------------------------------------ 1201# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1202# @ebuild-function java-pkg_javac-args
1110# 1203#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1204# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1205# to know what -source/-target to use.
1113# 1206#
1114# @return string - arguments to pass to javac, complete with -target and -source 1207# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1210 debug-print-function ${FUNCNAME} $*
1118 1211
1119 local want_source="$(java-pkg_get-source)" 1212 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1213 local want_target="$(java-pkg_get-target)"
1121 1214
1122 local source_str="-source ${want_source}" 1215 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1216 local target_str="-target ${want_target}"
1124 1217
1125 debug-print "want source: ${want_source}" 1218 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1219 debug-print "want target: ${want_target}"
1127 1220
1128 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1221 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1129 debug-print "could not find valid -source/-target values" 1222 debug-print "could not find valid -source/-target values for javac"
1130 die "Could not find valid -source/-target values" 1223 echo "Could not find valid -source/-target values for javac"
1224 return 1
1131 else 1225 else
1132 if java-pkg_is-vm-version-ge "1.4"; then 1226 if java-pkg_is-vm-version-ge "1.4"; then
1133 echo "${source_str} ${target_str}" 1227 echo "${source_str} ${target_str}"
1134 else 1228 else
1135 echo "${target_str}" 1229 echo "${target_str}"
1139 1233
1140# TODO document 1234# TODO document
1141java-pkg_get-jni-cflags() { 1235java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1236 local flags="-I${JAVA_HOME}/include"
1143 1237
1238 # TODO do a check that the directories are valid
1144 # TODO figure out how to cope with other things than linux... 1239 # TODO figure out how to cope with other things than linux...
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1240 flags="${flags} -I${JAVA_HOME}/include/linux"
1146 1241
1147 echo ${flags} 1242 echo ${flags}
1148} 1243}
1149 1244
1245java-pkg_ensure-gcj() {
1246 if ! built_with_use sys-devel/gcc gcj ; then
1247 ewarn
1248 ewarn "You must build gcc with the gcj support to build with gcj"
1249 ewarn
1250 ebeep 5
1251 die "No GCJ support found!"
1252 fi
1253}
1254
1255java-pkg_ensure-test() {
1256 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1257 eerror "You specified FEATURES=test, but USE=test is needed"
1258 eerror "to pull in the additional dependencies for testing"
1259 die "Need USE=test enabled"
1260 fi
1261}
1262
1150# ------------------------------------------------------------------------------ 1263# ------------------------------------------------------------------------------
1151# @section-end helper 1264# @section-end helper
1152# ------------------------------------------------------------------------------ 1265# ------------------------------------------------------------------------------
1153 1266
1154# ------------------------------------------------------------------------------ 1267# ------------------------------------------------------------------------------
1166# compiler. 1279# compiler.
1167# 1280#
1168# ------------------------------------------------------------------------------ 1281# ------------------------------------------------------------------------------
1169eant() { 1282eant() {
1170 debug-print-function ${FUNCNAME} $* 1283 debug-print-function ${FUNCNAME} $*
1284
1285 # FIXME get this working
1286# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1287# java-pkg_announce-qa-violation \
1288# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1289# fi
1171 1290
1172 local antflags 1291 local antflags
1173 java-pkg_init-compiler_ 1292 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1293 local compiler="${GENTOO_COMPILER}"
1175 1294
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1308 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1190 if [[ -n ${build_compiler_deps} ]]; then 1309 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1310 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1311 fi
1193 fi 1312 fi
1194 1313
1314 if is-java-strict; then
1315 einfo "Disabling system classpath for ant"
1316 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1317 fi
1318
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1319 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1320 antflags="${antflags} -debug"
1197 fi 1321 fi
1198 1322
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1323 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1324 ant ${antflags} "${@}" || die "eant failed"
1201 1325
1202} 1326}
1203 1327
1204# ------------------------------------------------------------------------------ 1328# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1329# @ebuild-function ejavac
1206# 1330#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1331# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1332# /etc/java-config/compilers.conf
1209# 1333#
1210# @param $@ - Arguments to be passed to the compiler 1334# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1335# ------------------------------------------------------------------------------
1212ejavac() { 1336ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1337 debug-print-function ${FUNCNAME} $*
1214 1338
1339 java-pkg_init-compiler_
1340
1341 local compiler_executable
1215 local compiler_executable=$(java-pkg_get-javac) 1342 compiler_executable=$(java-pkg_get-javac)
1343 if [[ ${?} != 0 ]]; then
1344 eerror "There was a problem determining compiler: ${compiler_executable}"
1345 die "get-javac failed"
1346 fi
1216 1347
1348 local javac_args
1349 javac_args="$(java-pkg_javac-args)"
1350 if [[ ${?} != 0 ]]; then
1351 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1352 die "java-pkg_javac-args failed"
1353 fi
1354
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1355 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1356 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1219} 1357}
1220 1358
1221# ------------------------------------------------------------------------------ 1359# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1360# @ebuild-function java-pkg_filter-compiler
1223# 1361#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1362# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1363# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1364#
1227# @param $@ - compilers to filter 1365# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1366# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1367java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1368 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1369}
1232 1370
1233# ------------------------------------------------------------------------------ 1371# ------------------------------------------------------------------------------
1372# @ebuild-function java-pkg_force-compiler
1373#
1374# Used to force the use of particular compilers. Should be used in src_compile.
1375# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1376# OutOfMemoryErrors that may come up.
1377#
1378# @param $@ - compilers to force
1379# ------------------------------------------------------------------------------
1380java-pkg_force-compiler() {
1381 JAVA_PKG_FORCE_COMPILER="$@"
1382}
1383
1384# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1385# @ebuild-function use_doc
1235# 1386#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1387# Helper function for getting ant to build javadocs. If the user has USE=doc,
1237# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1388# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1389#
1239# The output of this should be passed to ant. 1390# The output of this should be passed to ant.
1240# 1391#
1241# Example: build javadocs by calling 'javadoc' target 1392# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1393# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1394# Example: build javadocs by calling 'apidoc' target
1251} 1402}
1252 1403
1253# ------------------------------------------------------------------------------ 1404# ------------------------------------------------------------------------------
1254# @section-end build 1405# @section-end build
1255# ------------------------------------------------------------------------------ 1406# ------------------------------------------------------------------------------
1256 1407
1257# ------------------------------------------------------------------------------ 1408# ------------------------------------------------------------------------------
1258# @section-begin internal 1409# @section-begin internal
1259# @section-summary Internal functions 1410# @section-summary Internal functions
1260# 1411#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1412# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1413# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1414# ------------------------------------------------------------------------------
1264 1415
1265# ----------------------------------------------------------------------------- 1416# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1417# @function-internal java-pkg_init
1267# 1418#
1268# The purpose of this function, as the name might imply, is to initialize the 1419# The purpose of this function, as the name might imply, is to initialize the
1269# Java environment. It ensures that that there aren't any environment variables 1420# Java environment. It ensures that that there aren't any environment variables
1270# that'll muss things up. It initializes some variables, which are used 1421# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1422# internally. And most importantly, it'll switch the VM if necessary.
1272# 1423#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1435 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1436
1286 # Do some QA checks 1437 # Do some QA checks
1287 java-pkg_check-jikes 1438 java-pkg_check-jikes
1288 1439
1289 # When users have crazy classpaths some packages can fail to compile. 1440 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1441 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1442 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1443 # from the CLASSPATH.
1293 unset CLASSPATH 1444 unset CLASSPATH
1294} 1445}
1295 1446
1296# ------------------------------------------------------------------------------ 1447# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1448# @function-internal java-pkg-init-compiler_
1298# 1449#
1299# This function attempts to figure out what compiler should be used. It does 1450# This function attempts to figure out what compiler should be used. It does
1300# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1451# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1452# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1453# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1454#
1304# It will go through the list of compilers, and verify that it supports the 1455# It will go through the list of compilers, and verify that it supports the
1305# target and source that are needed. If it is not suitable, then the next 1456# target and source that are needed. If it is not suitable, then the next
1306# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1457# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1458# isn't done.
1308# 1459#
1324 if [[ -n ${GENTOO_COMPILER} ]]; then 1475 if [[ -n ${GENTOO_COMPILER} ]]; then
1325 debug-print "GENTOO_COMPILER already set" 1476 debug-print "GENTOO_COMPILER already set"
1326 return 1477 return
1327 fi 1478 fi
1328 1479
1480 local compilers;
1481 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1329 local compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1482 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1483 else
1484 compilers=${JAVA_PKG_FORCE_COMPILER}
1485 fi
1486
1330 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1487 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1331 1488
1332 # Figure out if we should announce what compiler we're using 1489 # Figure out if we should announce what compiler we're using
1333 local compiler 1490 local compiler
1334 for compiler in ${compilers}; do 1491 for compiler in ${compilers}; do
1337 if [[ ${compiler} = "javac" ]]; then 1494 if [[ ${compiler} = "javac" ]]; then
1338 debug-print "Found javac... breaking" 1495 debug-print "Found javac... breaking"
1339 export GENTOO_COMPILER="javac" 1496 export GENTOO_COMPILER="javac"
1340 break 1497 break
1341 fi 1498 fi
1342 1499
1343 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1500 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1344 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1501 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1345 einfo "Filtering ${compiler}" 1502 einfo "Filtering ${compiler}"
1346 continue 1503 continue
1347 fi 1504 fi
1348 fi 1505 fi
1349 1506
1350 # for non-javac, we need to make sure it supports the right target and 1507 # for non-javac, we need to make sure it supports the right target and
1351 # source 1508 # source
1352 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1509 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1353 if [[ -f ${compiler_env} ]]; then 1510 if [[ -f ${compiler_env} ]]; then
1354 local desired_target="$(java-pkg_get-target)" 1511 local desired_target="$(java-pkg_get-target)"
1450 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1607 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1451 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1608 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1452 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1609 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1453 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1610 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1454 ) > "${JAVA_PKG_ENV}" 1611 ) > "${JAVA_PKG_ENV}"
1455 1612
1456 # register target/source 1613 # register target/source
1457 local target="$(java-pkg_get-target)" 1614 local target="$(java-pkg_get-target)"
1458 local source="$(java-pkg_get-source)" 1615 local source="$(java-pkg_get-source)"
1459 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1616 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1460 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1617 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1527 fi 1684 fi
1528} 1685}
1529 1686
1530# ------------------------------------------------------------------------------ 1687# ------------------------------------------------------------------------------
1531# @internal-function java-pkg_expand_dir_ 1688# @internal-function java-pkg_expand_dir_
1532# 1689#
1533# Gets the full path of the file/directory's parent. 1690# Gets the full path of the file/directory's parent.
1534# @param $1 - file/directory to find parent directory for 1691# @param $1 - file/directory to find parent directory for
1535# @return - path to $1's parent directory 1692# @return - path to $1's parent directory
1536# ------------------------------------------------------------------------------ 1693# ------------------------------------------------------------------------------
1537java-pkg_expand_dir_() { 1694java-pkg_expand_dir_() {
1564# ------------------------------------------------------------------------------ 1721# ------------------------------------------------------------------------------
1565java-pkg_setup-vm() { 1722java-pkg_setup-vm() {
1566 debug-print-function ${FUNCNAME} $* 1723 debug-print-function ${FUNCNAME} $*
1567 1724
1568 local vendor="$(java-pkg_get-vm-vendor)" 1725 local vendor="$(java-pkg_get-vm-vendor)"
1569 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1726 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1570 addpredict "/dev/random" 1727 addpredict "/dev/random"
1571 elif [[ "${vendor}" == "ibm" ]]; then 1728 elif [[ "${vendor}" == "ibm" ]]; then
1572 addpredict "/proc/self/maps" 1729 addpredict "/proc/self/maps"
1573 addpredict "/proc/cpuinfo" 1730 addpredict "/proc/cpuinfo"
1574 export LANG="C" LC_ALL="C" 1731 export LANG="C" LC_ALL="C"
1623# @return - The version of the current VM 1780# @return - The version of the current VM
1624# ------------------------------------------------------------------------------ 1781# ------------------------------------------------------------------------------
1625java-pkg_get-vm-version() { 1782java-pkg_get-vm-version() {
1626 debug-print-function ${FUNCNAME} $* 1783 debug-print-function ${FUNCNAME} $*
1627 1784
1628 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1785 java-config -g PROVIDES_VERSION
1629} 1786}
1630 1787
1631# ------------------------------------------------------------------------------ 1788# ------------------------------------------------------------------------------
1632# @internal-function java-pkg_switch-vm 1789# @internal-function java-pkg_switch-vm
1633# 1790#
1634# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1791# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1635# verify that the current VM is sufficient. 1792# verify that the current VM is sufficient.
1636# Setup the environment for the VM being used. 1793# Setup the environment for the VM being used.
1637# ------------------------------------------------------------------------------ 1794# ------------------------------------------------------------------------------
1638java-pkg_switch-vm() { 1795java-pkg_switch-vm() {
1639 if java-pkg_needs-vm; then 1796 if java-pkg_needs-vm; then
1643 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1800 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1644 # if we're allowed to switch the vm... 1801 # if we're allowed to switch the vm...
1645 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1802 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1646 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1803 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1647 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1804 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1648 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1805 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1649 else 1806 else
1650 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1807 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1808 fi
1809 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1810 eerror "Unable to determine VM for building from dependencies."
1811 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1812 echo "VNEED: ${JAVA_PKG_VNEED}"
1813 else
1814 export GENTOO_VM
1651 fi 1815 fi
1652 # otherwise just make sure the current VM is sufficient 1816 # otherwise just make sure the current VM is sufficient
1653 else 1817 else
1654 java-pkg_ensure-vm-version-sufficient 1818 java-pkg_ensure-vm-version-sufficient
1655 fi 1819 fi
1656 debug-print "Using: $(java-config -f)" 1820 debug-print "Using: $(java-config -f)"
1657 1821
1658 java-pkg_setup-vm 1822 java-pkg_setup-vm
1659 1823
1824 export JAVA=$(java-config --java)
1825 export JAVAC=$(java-config --javac)
1660 export JAVACFLAGS="$(java-pkg_javac-args)" 1826 JAVACFLAGS="$(java-pkg_javac-args)"
1827 if [[ ${?} != 0 ]]; then
1828 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1829 die "java-pkg_javac-args failed"
1830 fi
1661 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1831 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1832 export JAVACFLAGS
1662 1833
1663 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1834 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1664 export JDK_HOME=${JAVA_HOME} 1835 export JDK_HOME=${JAVA_HOME}
1665 1836
1666 #TODO If you know a better solution let us know. 1837 #TODO If you know a better solution let us know.
1667 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1838 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1668 1839
1669 local tann="${T}/announced-vm" 1840 local tann="${T}/announced-vm"
1670 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1841 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1671 # Add a check for setup/preinst phase... to avoid duplicate outputs 1842 # Add a check for setup/preinst phase... to avoid duplicate outputs
1672 # for when FEATURES=buildpkg 1843 # for when FEATURES=buildpkg
1673 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1844 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1698 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1869 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1699 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1870 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1700 echo "and of course, the output of emerge --info" >&2 1871 echo "and of course, the output of emerge --info" >&2
1701} 1872}
1702 1873
1874
1875# TODO document
1876# List jars in the source directory, ${S}
1877java-pkg_jar-list() {
1878 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1879 einfo "Linked Jars"
1880 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1881 einfo "Jars"
1882 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1883 einfo "Classes"
1884 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1885 fi
1886}
1887
1888# TODO document
1889# Verify that the classes were compiled for the right source / target
1890java-pkg_verify-classes() {
1891 ebegin "Verifying java class versions"
1892 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1893 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1894 result=$?
1895 eend ${result}
1896 if [[ ${result} == 0 ]]; then
1897 einfo "All good"
1898 else
1899 ewarn "Possible problem"
1900 die "Bad class files found"
1901 fi
1902}
1903
1904
1703# ------------------------------------------------------------------------------ 1905# ------------------------------------------------------------------------------
1704# @section-end internal 1906# @section-end internal
1705# ------------------------------------------------------------------------------ 1907# ------------------------------------------------------------------------------
1706 1908
1707java-pkg_check-phase() { 1909java-pkg_check-phase() {
1708 local phase=${1} 1910 local phase=${1}
1709 local funcname=${2} 1911 local funcname=${2}
1710 # TODO add check for java-stricter
1711 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 1912 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1712 java-pkg_announce-qa-violation \ 1913 java-pkg_announce-qa-violation \
1713 "${funcname} used outside of src_${phase}" 1914 "${funcname} used outside of src_${phase}"
1714 fi 1915 fi
1715} 1916}
1716 1917
1727 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 1928 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1728 fi 1929 fi
1729} 1930}
1730 1931
1731java-pkg_announce-qa-violation() { 1932java-pkg_announce-qa-violation() {
1732 if hasq java-strict ${FEATURES}; then 1933 if is-java-strict; then
1733 echo "Java QA Notice: $@" >&2 1934 echo "Java QA Notice: $@" >&2
1734 increment-qa-violations 1935 increment-qa-violations
1735 fi 1936 fi
1736} 1937}
1737 1938
1738increment-qa-violations() { 1939increment-qa-violations() {
1739 let "JAVA_PKG_QA_VIOLATIONS+=1" 1940 let "JAVA_PKG_QA_VIOLATIONS+=1"
1740 export JAVA_PKG_QA_VIOLATIONS 1941 export JAVA_PKG_QA_VIOLATIONS
1741} 1942}
1742 1943
1944is-java-strict() {
1945 [[ -n ${JAVA_PKG_STRICT} ]]
1946 return $?
1947}
1948
1743# ------------------------------------------------------------------------------ 1949# ------------------------------------------------------------------------------
1744# @eclass-end 1950# @eclass-end
1745# ------------------------------------------------------------------------------ 1951# ------------------------------------------------------------------------------

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.24

  ViewVC Help
Powered by ViewVC 1.1.20