/[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.19
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}"
522 shift 546 shift
523 547
524 echo "#!/bin/bash" > "${target}" 548 echo "#!/bin/bash" > "${target}"
525 while [[ -n "${1}" && -n "${2}" ]]; do 549 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 550 local var=${1} value=${2}
527 if [[ "${var:0:2}" == "--" ]]; then 551 if [[ "${var:0:2}" == "--" ]]; then
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 552 echo "gjl_${var:2}=\"${value}\"" >> "${target}"
529 elif [[ "${var}" == "-into" ]]; then 553 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 554 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 555 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 556 pre="${value}"
534 shift 2 558 shift 2
535 done 559 done
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 563
540 if [[ -n "${into}" ]]; then 564 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 565 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 566 local ret=$?
543 return ${ret} 567 return ${ret}
544 else 568 else
545 dobin "${target}" 569 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 597 echo "dowar: warning, skipping directory ${war}"
574 continue 598 continue
575 else 599 else
576 warpath="${war}" 600 warpath="${war}"
577 fi 601 fi
578 602
579 # Install those files like you mean it 603 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 604 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 605 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 606 doins ${warpath}
583 done 607 done
618# @ebuild-function java-pkg_jar-from 642# @ebuild-function java-pkg_jar-from
619# 643#
620# Makes a symlink to a jar from a certain package 644# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 645# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 646# You can use this function to replace these bundled dependencies.
647# The dependency is recorded into package.env DEPEND line, unless "--build-only"
648# is passed as the very first argument, for jars that have to be present only
649# at build time and are not needed on runtime (junit testing etc).
623# 650#
624# Example: get all jars from xerces slot 2 651# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 652# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 653# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 654# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 655# 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 656# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
657# Example: get junit.jar which is needed only for building
658# java-pkg_jar-from --build-only junit junit.jar
630# 659#
660# @param $1 - (optional) "--build-only" makes the jar(s) not added into
661# package.env DEPEND line.
631# @param $1 - Package to get jars from. 662# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 663# @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 664# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 665# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 666# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 667# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 668java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 669 debug-print-function ${FUNCNAME} $*
639 670
671 local build_only=""
672
673 if [[ "${1}" = "--build-only" ]]; then
674 build_only="true"
675 shift
676 fi
677
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 678 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 679
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 680 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 681
644 # default destjar to the target jar 682 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 683 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 684
685 local error_msg="There was a problem getting the classpath for ${target_pkg}."
686 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 687 classpath="$(java-config --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 688 [[ $? != 0 ]] && die ${error_msg}
649 689
650 local jar 690 local jar
651 for jar in ${classpath//:/ }; do 691 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 692 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 693 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 697 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 698 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 699 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 700 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 701 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 702 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 703 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 704 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 705 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 706 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 707 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 708 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 709 return 0
670 fi 710 fi
671 done 711 done
672 # if no target was specified, we're ok 712 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 713 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 730# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 731# @ebuild-function java-pkg_getjars
692# 732#
693# Get the classpath provided by any number of packages 733# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 734# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
735# The providing packages are recorded as dependencies into package.env DEPEND
736# line, unless "--build-only" is passed as the very first argument, for jars
737# that have to be present only at build time and are not needed on runtime
738# (junit testing etc).
695# 739#
696# Example: Get the classpath for xerces-2, 740# Example: Get the classpath for xerces-2,
697# java-pkg_getjars xerces-2 xalan 741# java-pkg_getjars xerces-2 xalan
698# Example Return: 742# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 743# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 744#
745# @param $1 - (optional) "--build-only" makes the jar(s) not added into
746# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 747# @param $@ - list of packages to get jars from
702# ------------------------------------------------------------------------------ 748# ------------------------------------------------------------------------------
703java-pkg_getjars() { 749java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 750 debug-print-function ${FUNCNAME} $*
751
752 local build_only=""
753
754 if [[ "${1}" = "--build-only" ]]; then
755 build_only="true"
756 shift
757 fi
705 758
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 759 [[ ${#} -lt 1 ]] && die "At least one argument needed"
707 760
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 761 # NOTE could probably just pass $@ to java-config --classpath. and return it
709 local classpath pkg 762 local classpath pkg
710 for pkg in ${@//,/ }; do 763 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 764 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 765 jars="$(java-config --classpath=${pkg})"
766 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
713 debug-print "${pkg}:${jars}" 767 debug-print "${pkg}:${jars}"
714 # TODO should we ensure jars exist? 768
715 if [[ -z "${classpath}" ]]; then 769 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 770 classpath="${jars}"
717 else 771 else
718 classpath="${classpath}:${jars}" 772 classpath="${classpath}:${jars}"
719 fi 773 fi
720 java-pkg_record-jar_ "${pkg}" 774 # Only record jars that aren't build-only
775 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
721 done 776 done
722 echo "${classpath}" 777 echo "${classpath}"
723} 778}
724 779
725# ------------------------------------------------------------------------------ 780# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 781# @ebuild-function java-pkg_getjar
727# 782#
728# Get the filename of a single jar from a package 783# Get the filename of a single jar from a package
784# The providing package is recorded as runtime dependency into package.env
785# DEPEND line, unless "--build-only" is passed as the very first argument, for
786# jars that have to be present only at build time and are not needed on runtime
787# (junit testing etc).
729# 788#
730# @example 789# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 790# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 791# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 792# /usr/share/xerces-2/lib/xml-apis.jar
734# 793#
794# @param $1 - (optional) "--build-only" makes the jar not added into
795# package.env DEPEND line.
735# @param $1 - package to use 796# @param $1 - package to use
736# @param $2 - jar to get 797# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 798# ------------------------------------------------------------------------------
738java-pkg_getjar() { 799java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 800 debug-print-function ${FUNCNAME} $*
801
802 local build_only=""
803
804 if [[ "${1}" = "--build-only" ]]; then
805 build_only="true"
806 shift
807 fi
740 808
741 local pkg="${1}" target_jar="${2}" jar 809 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 810 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 811 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 812
745 # TODO check that package is actually installed 813 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
814 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 815 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 816 [[ $? != 0 ]] && die ${error_msg}
817
748 for jar in ${classpath//:/ }; do 818 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 819 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 820 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 821 fi
752 822
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 823 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 824 # Only record jars that aren't build-only
825 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 826 echo "${jar}"
756 return 0 827 return 0
757 fi 828 fi
758 done 829 done
759 830
760 die "Could not find ${target_jar} in ${pkg}" 831 die "Could not find ${target_jar} in ${pkg}"
761 return 1 832 return 1
762} 833}
763 834
764# This function reads stdin, and based on that input, figures out how to 835# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 849# line="${line// /}"
779# 850#
780# # format: path=jarinfo 851# # format: path=jarinfo
781# local path=${line%%=*} 852# local path=${line%%=*}
782# local jarinfo=${line##*=} 853# local jarinfo=${line##*=}
783# 854#
784# # format: jar@package 855# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 856# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 857# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 858# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 859# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 872# @section-end query
802# ------------------------------------------------------------------------------ 873# ------------------------------------------------------------------------------
803 874
804# ------------------------------------------------------------------------------ 875# ------------------------------------------------------------------------------
805# @section-begin helper 876# @section-begin helper
806# @section-summary Helper functions 877# @section-summary Helper functions
807# 878#
808# Various other functions to use from an ebuild 879# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 880# ------------------------------------------------------------------------------
810 881
811# ------------------------------------------------------------------------------ 882# ------------------------------------------------------------------------------
817# jdbc-stdext 888# jdbc-stdext
818# jaf 889# jaf
819# jdbc-rowset 890# jdbc-rowset
820# jms 891# jms
821# 892#
822# @param $1 - Optionally indicate that the dependencies are controlled by 893# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 894# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 895# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 896# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 897# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 898# TODO rewrite to parse a line based declaration file instead -- karltk
921 fi 992 fi
922} 993}
923 994
924# ------------------------------------------------------------------------------ 995# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 996# @internal-function java-pkg_is-vm-version-sufficient
926# 997#
927# @return zero - VM is sufficient 998# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 999# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1000# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1001java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1002 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1022 die "Active Java VM too old"
952 fi 1023 fi
953} 1024}
954 1025
955# ------------------------------------------------------------------------------ 1026# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1027# @internal-function java-pkg_is-vm-version-eq
957# 1028#
958# @param $@ - VM version to compare current VM to 1029# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1030# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1031# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1032# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1033java-pkg_is-vm-version-eq() {
992# 1063#
993# @param $@ - VM version to compare current to 1064# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1065# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1066java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1067 debug-print-function ${FUNCNAME} $*
997 1068
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1069 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1070 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1071 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1072 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1073 die "Active Java VM too old"
1003 fi 1074 fi
1004} 1075}
1005 1076
1006# ------------------------------------------------------------------------------ 1077# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1078# @internal-function java-pkg_is-vm-version-ge
1008# 1079#
1009# @param $@ - VM version to compare current VM to 1080# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1081# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1082# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1083# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1084java-pkg_is-vm-version-ge() {
1027 return 1 1098 return 1
1028 fi 1099 fi
1029 fi 1100 fi
1030} 1101}
1031 1102
1103java-pkg_set-current-vm() {
1104 export GENTOO_VM=${1}
1105}
1106
1107java-pkg_get-current-vm() {
1108 echo ${GENTOO_VM}
1109}
1110
1111java-pkg_current-vm-matches() {
1112 hasq $(java-pkg_get-current-vm) ${@}
1113 return $?
1114}
1115
1032# ------------------------------------------------------------------------------ 1116# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1117# @ebuild-function java-pkg_get-source
1034# 1118#
1035# Determines what source version should be used, for passing to -source. 1119# 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 1120# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1121#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1122# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1123# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1128# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1129# @ebuild-function java-pkg_get-target
1046# 1130#
1047# Determines what target version should be used, for passing to -target. 1131# 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 1132# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1133# version of your JDK.
1050# Remember doing this will mostly like cause things to break. 1134# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend. 1135# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm. 1136# Doesn't allow it to be higher then the active vm.
1053# 1137#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1138# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1139# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1140java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1141 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1142 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1143 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 1144 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} 1145 echo ${JAVA_PKG_WANT_TARGET}
1062 else 1146 else
1089 # try to get value of JAVAC 1173 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1174 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1175 export JAVAC=${old_javac}
1092 1176
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1177 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}"
1094 1178
1095 # check that it's executable 1179 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1180 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!" 1181 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1182 die "${compiler_executable} doesn't exist, or isn't executable"
1099 fi 1183 fi
1104 fi 1188 fi
1105 echo ${compiler_executable} 1189 echo ${compiler_executable}
1106} 1190}
1107 1191
1108# ------------------------------------------------------------------------------ 1192# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1193# @ebuild-function java-pkg_javac-args
1110# 1194#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1195# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1196# to know what -source/-target to use.
1113# 1197#
1114# @return string - arguments to pass to javac, complete with -target and -source 1198# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1201 debug-print-function ${FUNCNAME} $*
1118 1202
1119 local want_source="$(java-pkg_get-source)" 1203 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1204 local want_target="$(java-pkg_get-target)"
1121 1205
1122 local source_str="-source ${want_source}" 1206 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1207 local target_str="-target ${want_target}"
1124 1208
1125 debug-print "want source: ${want_source}" 1209 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1210 debug-print "want target: ${want_target}"
1127 1211
1139 1223
1140# TODO document 1224# TODO document
1141java-pkg_get-jni-cflags() { 1225java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1226 local flags="-I${JAVA_HOME}/include"
1143 1227
1228 # TODO do a check that the directories are valid
1144 # TODO figure out how to cope with other things than linux... 1229 # TODO figure out how to cope with other things than linux...
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1230 flags="${flags} -I${JAVA_HOME}/include/linux"
1146 1231
1147 echo ${flags} 1232 echo ${flags}
1148} 1233}
1149 1234
1235java-pkg_ensure-gcj() {
1236 if ! built_with_use sys-devel/gcc gcj ; then
1237 ewarn
1238 ewarn "You must build gcc with the gcj support to build with gcj"
1239 ewarn
1240 ebeep 5
1241 die "No GCJ support found!"
1242 fi
1243}
1244
1245java-pkg_ensure-test() {
1246 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1247 eerror "You specified FEATURES=test, but USE=test is needed"
1248 eerror "to pull in the additional dependencies for testing"
1249 die "Need USE=test enabled"
1250 fi
1251}
1252
1150# ------------------------------------------------------------------------------ 1253# ------------------------------------------------------------------------------
1151# @section-end helper 1254# @section-end helper
1152# ------------------------------------------------------------------------------ 1255# ------------------------------------------------------------------------------
1153 1256
1154# ------------------------------------------------------------------------------ 1257# ------------------------------------------------------------------------------
1166# compiler. 1269# compiler.
1167# 1270#
1168# ------------------------------------------------------------------------------ 1271# ------------------------------------------------------------------------------
1169eant() { 1272eant() {
1170 debug-print-function ${FUNCNAME} $* 1273 debug-print-function ${FUNCNAME} $*
1274
1275 # FIXME get this working
1276# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1277# java-pkg_announce-qa-violation \
1278# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1279# fi
1171 1280
1172 local antflags 1281 local antflags
1173 java-pkg_init-compiler_ 1282 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1283 local compiler="${GENTOO_COMPILER}"
1175 1284
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1298 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 1299 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1300 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1301 fi
1193 fi 1302 fi
1194 1303
1304 if is-java-strict; then
1305 einfo "Disabling system classpath for ant"
1306 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1307 fi
1308
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1309 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1310 antflags="${antflags} -debug"
1197 fi 1311 fi
1198 1312
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1313 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1314 ant ${antflags} "${@}" || die "eant failed"
1201 1315
1202} 1316}
1203 1317
1204# ------------------------------------------------------------------------------ 1318# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1319# @ebuild-function ejavac
1206# 1320#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1321# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1322# /etc/java-config/compilers.conf
1209# 1323#
1210# @param $@ - Arguments to be passed to the compiler 1324# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1325# ------------------------------------------------------------------------------
1212ejavac() { 1326ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1327 debug-print-function ${FUNCNAME} $*
1214 1328
1329 # FIXME using get-javac ends up printing stuff with einfo
1215 local compiler_executable=$(java-pkg_get-javac) 1330# local compiler_executable=$(java-pkg_get-javac)
1331 local compiler_executable="javac"
1216 1332
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1333 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1334 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed"
1219} 1335}
1220 1336
1221# ------------------------------------------------------------------------------ 1337# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1338# @ebuild-function java-pkg_filter-compiler
1223# 1339#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1340# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1341# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1342#
1227# @param $@ - compilers to filter 1343# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1344# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1345java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1346 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1347}
1232 1348
1233# ------------------------------------------------------------------------------ 1349# ------------------------------------------------------------------------------
1350# @ebuild-function java-pkg_force-compiler
1351#
1352# Used to force the use of particular compilers. Should be used in src_compile.
1353# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1354# OutOfMemoryErrors that may come up.
1355#
1356# @param $@ - compilers to force
1357# ------------------------------------------------------------------------------
1358java-pkg_force-compiler() {
1359 JAVA_PKG_FORCE_COMPILER="$@"
1360}
1361
1362# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1363# @ebuild-function use_doc
1235# 1364#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1365# 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. 1366# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1367#
1239# The output of this should be passed to ant. 1368# The output of this should be passed to ant.
1240# 1369#
1241# Example: build javadocs by calling 'javadoc' target 1370# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1371# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1372# Example: build javadocs by calling 'apidoc' target
1251} 1380}
1252 1381
1253# ------------------------------------------------------------------------------ 1382# ------------------------------------------------------------------------------
1254# @section-end build 1383# @section-end build
1255# ------------------------------------------------------------------------------ 1384# ------------------------------------------------------------------------------
1256 1385
1257# ------------------------------------------------------------------------------ 1386# ------------------------------------------------------------------------------
1258# @section-begin internal 1387# @section-begin internal
1259# @section-summary Internal functions 1388# @section-summary Internal functions
1260# 1389#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1390# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1391# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1392# ------------------------------------------------------------------------------
1264 1393
1265# ----------------------------------------------------------------------------- 1394# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1395# @function-internal java-pkg_init
1267# 1396#
1268# The purpose of this function, as the name might imply, is to initialize the 1397# 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 1398# 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 1399# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1400# internally. And most importantly, it'll switch the VM if necessary.
1272# 1401#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1413 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1414
1286 # Do some QA checks 1415 # Do some QA checks
1287 java-pkg_check-jikes 1416 java-pkg_check-jikes
1288 1417
1289 # When users have crazy classpaths some packages can fail to compile. 1418 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1419 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1420 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1421 # from the CLASSPATH.
1293 unset CLASSPATH 1422 unset CLASSPATH
1294} 1423}
1295 1424
1296# ------------------------------------------------------------------------------ 1425# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1426# @function-internal java-pkg-init-compiler_
1298# 1427#
1299# This function attempts to figure out what compiler should be used. It does 1428# 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 1429# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1430# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1431# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1432#
1304# It will go through the list of compilers, and verify that it supports the 1433# 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 1434# 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 1435# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1436# isn't done.
1308# 1437#
1324 if [[ -n ${GENTOO_COMPILER} ]]; then 1453 if [[ -n ${GENTOO_COMPILER} ]]; then
1325 debug-print "GENTOO_COMPILER already set" 1454 debug-print "GENTOO_COMPILER already set"
1326 return 1455 return
1327 fi 1456 fi
1328 1457
1458 local compilers;
1459 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1329 local compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1460 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1461 else
1462 compilers=${JAVA_PKG_FORCE_COMPILER}
1463 fi
1464
1330 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1465 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1331 1466
1332 # Figure out if we should announce what compiler we're using 1467 # Figure out if we should announce what compiler we're using
1333 local compiler 1468 local compiler
1334 for compiler in ${compilers}; do 1469 for compiler in ${compilers}; do
1337 if [[ ${compiler} = "javac" ]]; then 1472 if [[ ${compiler} = "javac" ]]; then
1338 debug-print "Found javac... breaking" 1473 debug-print "Found javac... breaking"
1339 export GENTOO_COMPILER="javac" 1474 export GENTOO_COMPILER="javac"
1340 break 1475 break
1341 fi 1476 fi
1342 1477
1343 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1478 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1344 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1479 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1345 einfo "Filtering ${compiler}" 1480 einfo "Filtering ${compiler}"
1346 continue 1481 continue
1347 fi 1482 fi
1348 fi 1483 fi
1349 1484
1350 # for non-javac, we need to make sure it supports the right target and 1485 # for non-javac, we need to make sure it supports the right target and
1351 # source 1486 # source
1352 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1487 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1353 if [[ -f ${compiler_env} ]]; then 1488 if [[ -f ${compiler_env} ]]; then
1354 local desired_target="$(java-pkg_get-target)" 1489 local desired_target="$(java-pkg_get-target)"
1450 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1585 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1451 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1586 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1452 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1587 [[ -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 ! 1588 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1454 ) > "${JAVA_PKG_ENV}" 1589 ) > "${JAVA_PKG_ENV}"
1455 1590
1456 # register target/source 1591 # register target/source
1457 local target="$(java-pkg_get-target)" 1592 local target="$(java-pkg_get-target)"
1458 local source="$(java-pkg_get-source)" 1593 local source="$(java-pkg_get-source)"
1459 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1594 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1460 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1595 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1527 fi 1662 fi
1528} 1663}
1529 1664
1530# ------------------------------------------------------------------------------ 1665# ------------------------------------------------------------------------------
1531# @internal-function java-pkg_expand_dir_ 1666# @internal-function java-pkg_expand_dir_
1532# 1667#
1533# Gets the full path of the file/directory's parent. 1668# Gets the full path of the file/directory's parent.
1534# @param $1 - file/directory to find parent directory for 1669# @param $1 - file/directory to find parent directory for
1535# @return - path to $1's parent directory 1670# @return - path to $1's parent directory
1536# ------------------------------------------------------------------------------ 1671# ------------------------------------------------------------------------------
1537java-pkg_expand_dir_() { 1672java-pkg_expand_dir_() {
1629} 1764}
1630 1765
1631# ------------------------------------------------------------------------------ 1766# ------------------------------------------------------------------------------
1632# @internal-function java-pkg_switch-vm 1767# @internal-function java-pkg_switch-vm
1633# 1768#
1634# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1769# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1635# verify that the current VM is sufficient. 1770# verify that the current VM is sufficient.
1636# Setup the environment for the VM being used. 1771# Setup the environment for the VM being used.
1637# ------------------------------------------------------------------------------ 1772# ------------------------------------------------------------------------------
1638java-pkg_switch-vm() { 1773java-pkg_switch-vm() {
1639 if java-pkg_needs-vm; then 1774 if java-pkg_needs-vm; then
1652 # otherwise just make sure the current VM is sufficient 1787 # otherwise just make sure the current VM is sufficient
1653 else 1788 else
1654 java-pkg_ensure-vm-version-sufficient 1789 java-pkg_ensure-vm-version-sufficient
1655 fi 1790 fi
1656 debug-print "Using: $(java-config -f)" 1791 debug-print "Using: $(java-config -f)"
1657 1792
1658 java-pkg_setup-vm 1793 java-pkg_setup-vm
1659 1794
1795 export JAVA=$(java-config --java)
1796 export JAVAC=$(java-config --javac)
1660 export JAVACFLAGS="$(java-pkg_javac-args)" 1797 export JAVACFLAGS="$(java-pkg_javac-args)"
1661 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1798 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1662 1799
1663 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1800 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1664 export JDK_HOME=${JAVA_HOME} 1801 export JDK_HOME=${JAVA_HOME}
1665 1802
1666 #TODO If you know a better solution let us know. 1803 #TODO If you know a better solution let us know.
1667 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1804 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1668 1805
1669 local tann="${T}/announced-vm" 1806 local tann="${T}/announced-vm"
1670 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1807 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1671 # Add a check for setup/preinst phase... to avoid duplicate outputs 1808 # Add a check for setup/preinst phase... to avoid duplicate outputs
1672 # for when FEATURES=buildpkg 1809 # for when FEATURES=buildpkg
1673 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1810 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1698 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1835 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1699 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1836 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1700 echo "and of course, the output of emerge --info" >&2 1837 echo "and of course, the output of emerge --info" >&2
1701} 1838}
1702 1839
1840
1841# TODO document
1842# List jars in the source directory, ${S}
1843java-pkg_jar-list() {
1844 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1845 einfo "Linked Jars"
1846 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1847 einfo "Jars"
1848 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1849 einfo "Classes"
1850 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1851 fi
1852}
1853
1854# TODO document
1855# Verify that the classes were compiled for the right source / target
1856java-pkg_verify-classes() {
1857 ebegin "Verifying java class versions"
1858 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1859 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1860 result=$?
1861 eend ${result}
1862 if [[ ${result} == 0 ]]; then
1863 einfo "All good"
1864 else
1865 ewarn "Possible problem"
1866 die "Bad class files found"
1867 fi
1868}
1869
1870
1703# ------------------------------------------------------------------------------ 1871# ------------------------------------------------------------------------------
1704# @section-end internal 1872# @section-end internal
1705# ------------------------------------------------------------------------------ 1873# ------------------------------------------------------------------------------
1706 1874
1707java-pkg_check-phase() { 1875java-pkg_check-phase() {
1708 local phase=${1} 1876 local phase=${1}
1709 local funcname=${2} 1877 local funcname=${2}
1710 # TODO add check for java-stricter
1711 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 1878 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1712 java-pkg_announce-qa-violation \ 1879 java-pkg_announce-qa-violation \
1713 "${funcname} used outside of src_${phase}" 1880 "${funcname} used outside of src_${phase}"
1714 fi 1881 fi
1715} 1882}
1716 1883
1727 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 1894 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1728 fi 1895 fi
1729} 1896}
1730 1897
1731java-pkg_announce-qa-violation() { 1898java-pkg_announce-qa-violation() {
1732 if hasq java-strict ${FEATURES}; then 1899 if is-java-strict; then
1733 echo "Java QA Notice: $@" >&2 1900 echo "Java QA Notice: $@" >&2
1734 increment-qa-violations 1901 increment-qa-violations
1735 fi 1902 fi
1736} 1903}
1737 1904
1738increment-qa-violations() { 1905increment-qa-violations() {
1739 let "JAVA_PKG_QA_VIOLATIONS+=1" 1906 let "JAVA_PKG_QA_VIOLATIONS+=1"
1740 export JAVA_PKG_QA_VIOLATIONS 1907 export JAVA_PKG_QA_VIOLATIONS
1741} 1908}
1742 1909
1910is-java-strict() {
1911 [[ -n ${JAVA_PKG_STRICT} ]]
1912 return $?
1913}
1914
1743# ------------------------------------------------------------------------------ 1915# ------------------------------------------------------------------------------
1744# @eclass-end 1916# @eclass-end
1745# ------------------------------------------------------------------------------ 1917# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20