/[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.83 Revision 1.90
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.83 2007/05/04 17:20:08 caster Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.90 2007/06/19 21:08:57 caster Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
70# 69#
71# This is a convience variable to be used from the other java eclasses. This is 70# This is a convience variable to be used from the other java eclasses. This is
72# the version of java-config we want to use. We also need a recent version 71# the version of java-config we want to use. We also need a recent version
73# portage, that includes phase hooks. 72# portage, that includes phase hooks.
74# ----------------------------------------------------------------------------- 73# -----------------------------------------------------------------------------
75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}" 74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.32 ${JAVA_PKG_PORTAGE_DEP}"
76 75
77# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
79# @variable-default yes 78# @variable-default yes
80# 79#
1077# from a package, into package.env DEPEND line. Can only be called in 1076# from a package, into package.env DEPEND line. Can only be called in
1078# src_install phase. 1077# src_install phase.
1079# Intended for binary packages where you don't need to symlink the jars or get 1078# 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 1079# their classpath during build. As such, the dependencies only need to be
1081# specified in ebuild's RDEPEND, and should be omitted in DEPEND. 1080# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1082# Get the classpath provided by any number of packages.
1083# 1081#
1084# @param $1 - comma-separated list of packages, or a single package 1082# @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 1083# @param $2 - if param $1 is a single package, optionally specify the jar
1086# to depend on 1084# to depend on
1087# 1085#
1118 die "${FUNCNAME} called with both package list and jar name" 1116 die "${FUNCNAME} called with both package list and jar name"
1119 java-pkg_ensure-dep runtime "${pkgs}" 1117 java-pkg_ensure-dep runtime "${pkgs}"
1120 java-pkg_record-jar_ "${pkgs}" "${jar}" 1118 java-pkg_record-jar_ "${pkgs}" "${jar}"
1121 fi 1119 fi
1122 1120
1123 java-pkg_do_write_ 1121 java-pkg_do_write_
1122}
1123
1124# ------------------------------------------------------------------------------
1125# @ebuild-function java-pkg_register-optional-dependency
1126#
1127# Registers optional runtime dependency on a package, list of packages, or a
1128# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1129# called in src_install phase.
1130# Intended for packages that can use other packages when those are in classpath.
1131# Will be put on classpath by launcher if they are installed. Typical case is
1132# JDBC implementations for various databases. It's better than having USE flag
1133# for each implementation triggering hard dependency.
1134#
1135# @param $1 - comma-separated list of packages, or a single package
1136# @param $2 - if param $1 is a single package, optionally specify the jar
1137# to depend on
1138#
1139# Example: Record the optional dependency on some jdbc providers
1140# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1141#
1142# Note: Passing both list of packages as the first parameter AND specifying the
1143# jar as the second is not allowed and will cause the function to die. We assume
1144# that there's more chance one passes such combination as a mistake, than that
1145# there are more packages providing identically named jar without class
1146# collisions.
1147# ------------------------------------------------------------------------------
1148java-pkg_register-optional-dependency() {
1149 debug-print-function ${FUNCNAME} $*
1150
1151 java-pkg_check-phase install
1152
1153 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1154
1155 local pkgs="${1}"
1156 local jar="${2}"
1157
1158 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1159
1160 if [[ -z "${jar}" ]]; then
1161 for pkg in ${pkgs//,/ }; do
1162 java-pkg_record-jar_ --optional "${pkg}"
1163 done
1164 else
1165 [[ ${pkgs} == *,* ]] && \
1166 die "${FUNCNAME} called with both package list and jar name"
1167 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1168 fi
1169
1170 java-pkg_do_write_
1171}
1172
1173# ------------------------------------------------------------------------------
1174# @ebuild-function java-pkg_register-environment-variable
1175#
1176# Register an arbitrary environment variable into package.env. The gjl launcher
1177# for this package or any package depending on this will export it into
1178# environement before executing java command.
1179# Must only be called in src_install phase.
1180#
1181# @param $1 - variable name
1182# @param $2 - variable value
1183# ------------------------------------------------------------------------------
1184JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1185JAVA_PKG_EXTRA_ENV_VARS=""
1186java-pkg_register-environment-variable() {
1187 debug-print-function ${FUNCNAME} $*
1188
1189 java-pkg_check-phase install
1190
1191 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1192
1193 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1194 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1195
1196 java-pkg_do_write_
1124} 1197}
1125 1198
1126# This function reads stdin, and based on that input, figures out how to 1199# This function reads stdin, and based on that input, figures out how to
1127# populate jars from the filesystem. 1200# populate jars from the filesystem.
1128# Need to figure out a good way of making use of this, ie be able to use a 1201# Need to figure out a good way of making use of this, ie be able to use a
1651 return 0 1724 return 0
1652 fi 1725 fi
1653} 1726}
1654 1727
1655# ------------------------------------------------------------------------------ 1728# ------------------------------------------------------------------------------
1729# @ebuild-function ejunit
1730#
1731# Junit wrapper function. Makes it easier to run the tests and checks for
1732# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1733#
1734# Examples:
1735# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1736# ejunit org.blinkenlights.jid3.test.AllTests
1737#
1738# @param $1 - -cp or -classpath
1739# @param $2 - classpath; junit and recorded dependencies get appended
1740# @param $@ - the rest of the parameters are passed to java
1741# ------------------------------------------------------------------------------
1742ejunit() {
1743 debug-print-function ${FUNCNAME} $*
1744
1745 local pkgs
1746 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1747 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1748 done
1749
1750 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1751 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1752 cp="${2}:${cp}"
1753 shift 2
1754 else
1755 cp=".:${cp}"
1756 fi
1757
1758 local runner=junit.textui.TestRunner
1759 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1760 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1761}
1762
1763# ------------------------------------------------------------------------------
1656# @section-end helper 1764# @section-end helper
1657# ------------------------------------------------------------------------------ 1765# ------------------------------------------------------------------------------
1658 1766
1659# ------------------------------------------------------------------------------ 1767# ------------------------------------------------------------------------------
1660# @section-begin build 1768# @section-begin build
1726 echo "more info." 1834 echo "more info."
1727 fi 1835 fi
1728 fi 1836 fi
1729 done 1837 done
1730 1838
1839 # we use this in src_* so we run ant from /
1731 if has_version ">=dev-java/ant-core-1.7.0"; then 1840 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1732 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly 1841 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1733 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}" 1842 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1734 1843
1735 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set 1844 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1736 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}" 1845 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
2078# Writes the package.env out to disk. 2187# Writes the package.env out to disk.
2079# 2188#
2080# ------------------------------------------------------------------------------ 2189# ------------------------------------------------------------------------------
2081# TODO change to do-write, to match everything else 2190# TODO change to do-write, to match everything else
2082java-pkg_do_write_() { 2191java-pkg_do_write_() {
2192 debug-print-function ${FUNCNAME} $*
2083 java-pkg_init_paths_ 2193 java-pkg_init_paths_
2084 # Create directory for package.env 2194 # Create directory for package.env
2085 dodir "${JAVA_PKG_SHAREPATH}" 2195 dodir "${JAVA_PKG_SHAREPATH}"
2086 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2196 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2197 "${JAVA_PKG_DEPEND_FILE}" || -f \
2198 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
2087 # Create package.env 2199 # Create package.env
2088 ( 2200 (
2089 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2201 echo "DESCRIPTION=\"${DESCRIPTION}\""
2090 echo "GENERATION=\"2\"" 2202 echo "GENERATION=\"2\""
2091 2203
2092 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2204 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
2093 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2205 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
2094 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2206 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
2095 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2207 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2208 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2209 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2210 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2096 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2211 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2097 ) > "${JAVA_PKG_ENV}" 2212 ) > "${JAVA_PKG_ENV}"
2098 2213
2099 # register target/source 2214 # register target/source
2100 local target="$(java-pkg_get-target)" 2215 local target="$(java-pkg_get-target)"
2111 2226
2112 2227
2113 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2228 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
2114 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2229 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
2115 2230
2231 # extra env variables
2232 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2233 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2234 # nested echo to remove leading/trailing spaces
2235 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2236 >> "${JAVA_PKG_ENV}" || die
2237 fi
2238
2116 # Strip unnecessary leading and trailing colons 2239 # Strip unnecessary leading and trailing colons
2117 # TODO try to cleanup if possible 2240 # TODO try to cleanup if possible
2118 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2241 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2242 else
2243 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2244 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2245 debug-print "write package.env."
2119 fi 2246 fi
2120} 2247}
2121 2248
2122# ------------------------------------------------------------------------------ 2249# ------------------------------------------------------------------------------
2123# @internal-function java-pkg_record-jar_ 2250# @internal-function java-pkg_record-jar_
2124# 2251#
2125# Record a dependency to the package.env 2252# Record an (optional) dependency to the package.env
2126# 2253# @param --optional - record dependency as optional
2254# @param $1 - package to record
2255# @param $2 - (optional) jar of package to record
2127# ------------------------------------------------------------------------------ 2256# ------------------------------------------------------------------------------
2128JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2257JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2258JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2129 2259
2130java-pkg_record-jar_() { 2260java-pkg_record-jar_() {
2131 debug-print-function ${FUNCNAME} $* 2261 debug-print-function ${FUNCNAME} $*
2262
2263 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2264 if [[ "${1}" == "--optional" ]]; then
2265 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2266 shift
2267 fi
2132 2268
2133 local pkg=${1} jar=${2} append 2269 local pkg=${1} jar=${2} append
2134 if [[ -z "${jar}" ]]; then 2270 if [[ -z "${jar}" ]]; then
2135 append="${pkg}" 2271 append="${pkg}"
2136 else 2272 else
2137 append="$(basename ${jar})@${pkg}" 2273 append="$(basename ${jar})@${pkg}"
2138 fi 2274 fi
2139 2275
2140 echo ${append} >> ${JAVA_PKG_DEPEND} 2276 echo "${append}" >> "${depend_file}"
2141} 2277}
2142 2278
2143# ------------------------------------------------------------------------------ 2279# ------------------------------------------------------------------------------
2144# @internal-function java-pkg_append_ 2280# @internal-function java-pkg_append_
2145# 2281#
2410# Check that a package being used in jarfrom, getjars and getjar is contained 2546# Check that a package being used in jarfrom, getjars and getjar is contained
2411# within DEPEND or RDEPEND. 2547# within DEPEND or RDEPEND.
2412# @param $1 - empty - check both vars; "runtime" or "build" - check only 2548# @param $1 - empty - check both vars; "runtime" or "build" - check only
2413# RDEPEND, resp. DEPEND 2549# RDEPEND, resp. DEPEND
2414# @param $2 - Package name and slot. 2550# @param $2 - Package name and slot.
2551
2415java-pkg_ensure-dep() { 2552java-pkg_ensure-dep() {
2416 debug-print-function ${FUNCNAME} $* 2553 debug-print-function ${FUNCNAME} $*
2417 2554
2418 local limit_to="${1}" 2555 local limit_to="${1}"
2419 local target_pkg="${2}" 2556 local target_pkg="${2}"
2420 local dev_error="" 2557 local dev_error=""
2421 2558
2422 local stripped_pkg=$(echo "${target_pkg}" | sed \ 2559 local stripped_pkg=$(echo "${target_pkg}" | sed \
2423 's/-[0-9]*\(\.[0-9]\)*$//') 2560 's/-[0-9]*\(\.[0-9]\)*$//')
2561
2562 debug-print "Matching against: ${stripped_pkg}"
2424 2563
2425 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then 2564 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2426 dev_error="The ebuild is attempting to use ${target_pkg} that is not" 2565 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2427 dev_error="${dev_error} declared in DEPEND." 2566 dev_error="${dev_error} declared in DEPEND."
2428 if is-java-strict; then 2567 if is-java-strict; then
2568 eerror "${dev_error}"
2429 die "${dev_error}" 2569 die "${dev_error}"
2430 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2570 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2431 eerror "${dev_error}" 2571 eerror "${dev_error}"
2432 elog "Because you have this package installed the package will" 2572 elog "Because you have this package installed the package will"
2433 elog "build without problems, but please report this to" 2573 elog "build without problems, but please report this to"
2434 elog "http://bugs.gentoo.org" 2574 elog "http://bugs.gentoo.org"
2435 fi 2575 fi
2436 fi 2576 fi
2437 2577
2578 if [[ ${limit_to} != build ]]; then
2438 if [[ ${limit_to} != build && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then 2579 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2580 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2439 dev_error="The ebuild is attempting to use ${target_pkg}," 2581 dev_error="The ebuild is attempting to use ${target_pkg},"
2440 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND." 2582 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2583 dev_error="${dev_error} or PDEPEND."
2441 if is-java-strict; then 2584 if is-java-strict; then
2585 eerror "${dev_error}"
2442 die "${dev_error}" 2586 die "${dev_error}"
2443 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2587 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2444 eerror "${dev_error}" 2588 eerror "${dev_error}"
2445 elog "The package will build without problems, but may fail to run" 2589 elog "The package will build without problems, but may fail to run"
2446 elog "if you don't have ${target_pkg} installed, so please report" 2590 elog "if you don't have ${target_pkg} installed, so please report"
2447 elog "this to http://bugs.gentoo.org" 2591 elog "this to http://bugs.gentoo.org"
2592 fi
2593 fi
2448 fi 2594 fi
2449 fi 2595 fi
2450} 2596}
2451 2597
2452# ------------------------------------------------------------------------------ 2598# ------------------------------------------------------------------------------

Legend:
Removed from v.1.83  
changed lines
  Added in v.1.90

  ViewVC Help
Powered by ViewVC 1.1.20