/[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.74 Revision 1.80
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.74 2007/04/20 15:23:28 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.80 2007/04/26 23:32:12 caster Exp $
10 10
11 11
12# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
13# @eclass-begin 13# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
832# --build-only - makes the jar(s) not added into package.env DEPEND line. 832# --build-only - makes the jar(s) not added into package.env DEPEND line.
833# (assumed automatically when called inside src_test) 833# (assumed automatically when called inside src_test)
834# --with-dependencies - get jars also from requested package's dependencies 834# --with-dependencies - get jars also from requested package's dependencies
835# transitively. 835# transitively.
836# --into $dir - symlink jar(s) into $dir (must exist) instead of . 836# --into $dir - symlink jar(s) into $dir (must exist) instead of .
837# @param $1 - Package to get jars from. 837# @param $1 - Package to get jars from, or comma-separated list of packages in
838# case other parameters are not used.
838# @param $2 - jar from package. If not specified, all jars will be used. 839# @param $2 - jar from package. If not specified, all jars will be used.
839# @param $3 - When a single jar is specified, destination filename of the 840# @param $3 - When a single jar is specified, destination filename of the
840# symlink. Defaults to the name of the jar. 841# symlink. Defaults to the name of the jar.
841# ------------------------------------------------------------------------------ 842# ------------------------------------------------------------------------------
842# TODO could probably be cleaned up a little 843# TODO could probably be cleaned up a little
845 846
846 local build_only="" 847 local build_only=""
847 local destdir="." 848 local destdir="."
848 local deep="" 849 local deep=""
849 850
850 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 851 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
851 852
852 while [[ "${1}" == --* ]]; do 853 while [[ "${1}" == --* ]]; do
853 if [[ "${1}" = "--build-only" ]]; then 854 if [[ "${1}" = "--build-only" ]]; then
854 build_only="true" 855 build_only="build"
855 elif [[ "${1}" = "--with-dependencies" ]]; then 856 elif [[ "${1}" = "--with-dependencies" ]]; then
856 deep="--with-dependencies" 857 deep="--with-dependencies"
857 elif [[ "${1}" = "--into" ]]; then 858 elif [[ "${1}" = "--into" ]]; then
858 destdir="${2}" 859 destdir="${2}"
859 shift 860 shift
873 local error_msg="There was a problem getting the classpath for ${target_pkg}." 874 local error_msg="There was a problem getting the classpath for ${target_pkg}."
874 local classpath 875 local classpath
875 classpath="$(java-config ${deep} --classpath=${target_pkg})" 876 classpath="$(java-config ${deep} --classpath=${target_pkg})"
876 [[ $? != 0 ]] && die ${error_msg} 877 [[ $? != 0 ]] && die ${error_msg}
877 878
879 # When we have commas this functions is called to bring jars from multiple
880 # packages. This affects recording of dependencencies performed later
881 # which expects one package only, so we do it here.
882 if [[ ${target_pkg} = *,* ]]; then
883 for pkg in ${target_pkg//,/ }; do
884 java-pkg_ensure-dep "${build_only}" "${pkg}"
885 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
886 done
887 # setting this disables further record-jar_ calls later
888 build_only="build"
889 else
878 java-pkg_ensure-dep "${build_only}" "${target_pkg}" 890 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
891 fi
879 892
880 pushd ${destdir} > /dev/null \ 893 pushd ${destdir} > /dev/null \
881 || die "failed to change directory to ${destdir}" 894 || die "failed to change directory to ${destdir}"
882
883 # When we have commas this functions is called to bring jars from multiple
884 # packages. This affects recording of dependencencies because that syntax uses :
885 # if we don't change them to : gjl and java-config -d -p break
886 if [[ ${target_pkg} = *,* ]]; then
887 build_only="true"
888 java-pkg_record-jar_ ${target_pkg//,/:}
889 fi
890 895
891 local jar 896 local jar
892 for jar in ${classpath//:/ }; do 897 for jar in ${classpath//:/ }; do
893 local jar_name=$(basename "${jar}") 898 local jar_name=$(basename "${jar}")
894 if [[ ! -f "${jar}" ]] ; then 899 if [[ ! -f "${jar}" ]] ; then
957 debug-print-function ${FUNCNAME} $* 962 debug-print-function ${FUNCNAME} $*
958 963
959 local build_only="" 964 local build_only=""
960 local deep="" 965 local deep=""
961 966
962 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 967 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
963 968
964 while [[ "${1}" == --* ]]; do 969 while [[ "${1}" == --* ]]; do
965 if [[ "${1}" = "--build-only" ]]; then 970 if [[ "${1}" = "--build-only" ]]; then
966 build_only="true" 971 build_only="build"
967 elif [[ "${1}" = "--with-dependencies" ]]; then 972 elif [[ "${1}" = "--with-dependencies" ]]; then
968 deep="--with-dependencies" 973 deep="--with-dependencies"
969 else 974 else
970 die "java-pkg_jar-from called with unknown parameter: ${1}" 975 die "java-pkg_jar-from called with unknown parameter: ${1}"
971 fi 976 fi
990 classpath="${classpath}:${jars}" 995 classpath="${classpath}:${jars}"
991 fi 996 fi
992 997
993 # Only record jars that aren't build-only 998 # Only record jars that aren't build-only
994 if [[ -z "${build_only}" ]]; then 999 if [[ -z "${build_only}" ]]; then
995 oldifs="${IFS}"
996 IFS=","
997 for pkg in ${pkgs}; do 1000 for pkg in ${pkgs//:/ }; do
998 java-pkg_record-jar_ "${pkg}" 1001 java-pkg_record-jar_ "${pkg}"
999 done 1002 done
1000 IFS="${oldifs}"
1001 fi 1003 fi
1002 1004
1003 echo "${classpath}" 1005 echo "${classpath}"
1004} 1006}
1005 1007
1025java-pkg_getjar() { 1027java-pkg_getjar() {
1026 debug-print-function ${FUNCNAME} $* 1028 debug-print-function ${FUNCNAME} $*
1027 1029
1028 local build_only="" 1030 local build_only=""
1029 1031
1030 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 1032 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1031 1033
1032 while [[ "${1}" == --* ]]; do 1034 while [[ "${1}" == --* ]]; do
1033 if [[ "${1}" = "--build-only" ]]; then 1035 if [[ "${1}" = "--build-only" ]]; then
1034 build_only="true" 1036 build_only="build"
1035 else 1037 else
1036 die "java-pkg_jar-from called with unknown parameter: ${1}" 1038 die "java-pkg_jar-from called with unknown parameter: ${1}"
1037 fi 1039 fi
1038 shift 1040 shift
1039 done 1041 done
1064 fi 1066 fi
1065 done 1067 done
1066 1068
1067 die "Could not find ${target_jar} in ${pkg}" 1069 die "Could not find ${target_jar} in ${pkg}"
1068 return 1 1070 return 1
1071}
1072
1073# ------------------------------------------------------------------------------
1074# @ebuild-function java-pkg_register-dependency
1075#
1076# Registers runtime dependency on a package, list of packages, or a single jar
1077# from a package, into package.env DEPEND line. Can only be called in
1078# src_install phase.
1079# Intended for binary packages where you don't need to symlink the jars or get
1080# their classpath during build. As such, the dependencies only need to be
1081# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1082# Get the classpath provided by any number of packages.
1083#
1084# @param $1 - comma-separated list of packages, or a single package
1085# @param $2 - if param $1 is a single package, optionally specify the jar
1086# to depend on
1087#
1088# Example: Record the dependency on whole xerces-2 and xalan,
1089# java-pkg_register-dependency xerces-2,xalan
1090# Example: Record the dependency on ant.jar from ant-core
1091# java-pkg_register-dependency ant-core ant.jar
1092#
1093# Note: Passing both list of packages as the first parameter AND specifying the
1094# jar as the second is not allowed and will cause the function to die. We assume
1095# that there's more chance one passes such combination as a mistake, than that
1096# there are more packages providing identically named jar without class
1097# collisions.
1098# ------------------------------------------------------------------------------
1099java-pkg_register-dependency() {
1100 debug-print-function ${FUNCNAME} $*
1101
1102 java-pkg_check-phase install
1103
1104 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1105
1106 local pkgs="${1}"
1107 local jar="${2}"
1108
1109 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1110
1111 if [[ -z "${jar}" ]]; then
1112 for pkg in ${pkgs//,/ }; do
1113 java-pkg_ensure-dep runtime "${pkg}"
1114 java-pkg_record-jar_ "${pkg}"
1115 done
1116 else
1117 [[ ${pkgs} == *,* ]] && \
1118 die "${FUNCNAME} called with both package list and jar name"
1119 java-pkg_ensure-dep runtime "${pkgs}"
1120 java-pkg_record-jar_ "${pkgs}" "${jar}"
1121 fi
1122
1123 java-pkg_do_write_
1069} 1124}
1070 1125
1071# This function reads stdin, and based on that input, figures out how to 1126# This function reads stdin, and based on that input, figures out how to
1072# populate jars from the filesystem. 1127# populate jars from the filesystem.
1073# Need to figure out a good way of making use of this, ie be able to use a 1128# Need to figure out a good way of making use of this, ie be able to use a
1711 1766
1712 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug" 1767 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1713 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q" 1768 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1714 1769
1715 local gcp="${EANT_GENTOO_CLASSPATH}" 1770 local gcp="${EANT_GENTOO_CLASSPATH}"
1771 local getjarsarg=""
1716 1772
1717 if [[ ${EBUILD_PHASE} = "test" ]]; then 1773 if [[ ${EBUILD_PHASE} = "test" ]]; then
1718 antflags="${antflags} -DJunit.present=true" 1774 antflags="${antflags} -DJunit.present=true"
1719 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit" 1775 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1776 getjarsarg="--with-dependencies"
1720 fi 1777 fi
1721 1778
1722 local cp 1779 local cp
1723 1780
1724 for atom in ${gcp}; do 1781 for atom in ${gcp}; do
1725 cp="${cp}:$(java-pkg_getjars ${atom})" 1782 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1726 done 1783 done
1727 1784
1728 if [[ ${cp} ]]; then 1785 if [[ ${cp} ]]; then
1729 # It seems ant does not like single quotes around ${cp} 1786 # It seems ant does not like single quotes around ${cp}
1730 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\"" 1787 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1731 fi 1788 fi
1732 1789
1733 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1790 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1734 debug-print "Calling ant: ${antflags} ${@}" 1791 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1735 ant ${antflags} "${@}" || die "eant failed" 1792 ant ${antflags} "${@}" || die "eant failed"
1736
1737} 1793}
1738 1794
1739# ------------------------------------------------------------------------------ 1795# ------------------------------------------------------------------------------
1740# @ebuild-function ejavac 1796# @ebuild-function ejavac
1741# 1797#
2357 2413
2358# ---------------------------------------------------------------------------- 2414# ----------------------------------------------------------------------------
2359# @internal-function java-pkg_ensure-dep 2415# @internal-function java-pkg_ensure-dep
2360# Check that a package being used in jarfrom, getjars and getjar is contained 2416# Check that a package being used in jarfrom, getjars and getjar is contained
2361# within DEPEND or RDEPEND. 2417# within DEPEND or RDEPEND.
2362# @param $1 - Is the package a runtime dependency 2418# @param $1 - empty - check both vars; "runtime" or "build" - check only
2419# RDEPEND, resp. DEPEND
2363# @param $2 - Package name and slot. 2420# @param $2 - Package name and slot.
2364
2365java-pkg_ensure-dep() { 2421java-pkg_ensure-dep() {
2366 debug-print-function ${FUNCNAME} $* 2422 debug-print-function ${FUNCNAME} $*
2367 2423
2368 local build_only="${1}" 2424 local limit_to="${1}"
2369 local target_pkg="${2}" 2425 local target_pkg="${2}"
2370 local dev_error="" 2426 local dev_error=""
2371 2427
2372 local stripped_pkg=$(echo "${target_pkg}" | sed \ 2428 local stripped_pkg=$(echo "${target_pkg}" | sed \
2373 's/-[0-9]*\(\.[0-9]\)*$//') 2429 's/-[0-9]*\(\.[0-9]\)*$//')
2374 2430
2375 if [[ ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then 2431 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2376 dev_error="The ebuild is attempting to use ${target_pkg} that is not" 2432 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2377 dev_error="${dev_error} declared in DEPEND." 2433 dev_error="${dev_error} declared in DEPEND."
2378 if is-java-strict; then 2434 if is-java-strict; then
2379 die "${dev_error}" 2435 die "${dev_error}"
2380 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2436 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2383 elog "build without problems, but please report this to" 2439 elog "build without problems, but please report this to"
2384 elog "http://bugs.gentoo.org" 2440 elog "http://bugs.gentoo.org"
2385 fi 2441 fi
2386 fi 2442 fi
2387 2443
2388 if [[ -z ${build_only} && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then 2444 if [[ ${limit_to} != build && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2389 dev_error="The ebuild is attempting to use ${target_pkg}," 2445 dev_error="The ebuild is attempting to use ${target_pkg},"
2390 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND." 2446 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND."
2391 if is-java-strict; then 2447 if is-java-strict; then
2392 die "${dev_error}" 2448 die "${dev_error}"
2393 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2449 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2394 eerror "${dev_error}" 2450 eerror "${dev_error}"
2395 elog "Because you have this package installed the package will" 2451 elog "The package will build without problems, but may fail to run"
2396 elog "build without problems, but please report this to" 2452 elog "if you don't have ${target_pkg} installed, so please report"
2397 elog "http://bugs.gentoo.org" 2453 elog "this to http://bugs.gentoo.org"
2398 fi 2454 fi
2399 fi 2455 fi
2400} 2456}
2401 2457
2402# ------------------------------------------------------------------------------ 2458# ------------------------------------------------------------------------------

Legend:
Removed from v.1.74  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.20