/[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.33 Revision 1.42
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.33 2006/12/07 02:27:22 flameeyes Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.42 2007/01/15 00:01:21 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
174 # Create JARDEST if it doesn't exist 174 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 175 dodir ${JAVA_PKG_JARDEST}
176 176
177 local jar 177 local jar
178 # for each jar 178 # for each jar
179 for jar in "$@"; do 179 for jar in ${@}; do
180 local jar_basename=$(basename "${jar}") 180 local jar_basename=$(basename "${jar}")
181 181
182 java-pkg_check-versioned-jar ${jar_basename} 182 java-pkg_check-versioned-jar ${jar_basename}
183 183
184 # check if it exists 184 # check if it exists
203 203
204 java-pkg_do_write_ 204 java-pkg_do_write_
205} 205}
206 206
207 207
208# ------------------------------------------------------------------------------
209# @internal-function depend-java-query
210#
211# Wrapper for the depend-java-query binary to enable passing USE in env.
212# Using env variables keeps this eclass working with java-config versions that
213# do not handle use flags.
214# ------------------------------------------------------------------------------
215
216depend-java-query() {
217 USE="${USE}" $(which depend-java-query) "${@}"
218}
208 219
209# ------------------------------------------------------------------------------ 220# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 221# @ebuild-function java-pkg_regjar
211# 222#
212# Records an already installed jar in the package.env 223# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 254 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 255
245 java-pkg_init_paths_ 256 java-pkg_init_paths_
246 257
247 local jar jar_dir jar_file 258 local jar jar_dir jar_file
248 for jar in "$@"; do 259 for jar in ${@}; do
249 # TODO use java-pkg_check-versioned-jar 260 # TODO use java-pkg_check-versioned-jar
250 if [[ -e "${jar}" ]]; then 261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*"
251 # nelchael: we should strip ${D} in this case too, here's why: 264 # nelchael: we should strip ${D} in this case too, here's why:
252 # imagine such call: 265 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 266 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 267 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 268 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 269 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
257 elif [[ -e "${D}${jar}" ]]; then
258 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
259 else 270 else
260 die "${jar} does not exist" 271 die "${jar} does not exist"
261 fi 272 fi
262 done 273 done
263 274
264 java-pkg_do_write_ 275 java-pkg_do_write_
265} 276}
266
267 277
268# ------------------------------------------------------------------------------ 278# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 279# @ebuild-function java-pkg_newjar
270# 280#
271# Installs a jar with a new name 281# Installs a jar with a new name
540# @param $1 - filename of launcher to create 550# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 551# @param $2 - options, as follows:
542# --main the.main.class.too.start 552# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 553# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 554# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 555# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 556# --pwd Directory the launcher changes to before executing java
547# -into 557# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 558# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 559# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 560java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 561 debug-print-function ${FUNCNAME} $*
552 562
553 java-pkg_check-phase install 563 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 575 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 576 local target_dir pre
567 577
568 # Process the other the rest of the arguments 578 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 579 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 580 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 581 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 582 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 583 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 584 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 585 elif [[ "${var}" == "-into" ]]; then
594 fi 604 fi
595 fi 605 fi
596 606
597 # Write the actual script 607 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 608 echo "#!/bin/bash" > "${target}"
599 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 609 if [[ -n "${pre}" ]]; then
610 if [[ -f "${pre}" ]]; then
611 cat "${pre}" >> "${target}"
612 else
613 die "-pre specified file '${pre}' does not exist"
614 fi
615 fi
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 616 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 617 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 618 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 619 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 620
789# (passed to java-config --classpath) 805# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 806# ------------------------------------------------------------------------------
791java-pkg_getjars() { 807java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 808 debug-print-function ${FUNCNAME} $*
793 809
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments"
795
796 if [[ "${1}" = "--build-only" ]]; then 810 if [[ "${1}" = "--build-only" ]]; then
797 local build_only="true" 811 local build_only="true"
798 shift 812 shift
799 fi 813 fi
814
815 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only"
800 816
801 local classpath pkgs="${1}" 817 local classpath pkgs="${1}"
802 jars="$(java-config --classpath=${pkgs})" 818 jars="$(java-config --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 819 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 820 debug-print "${pkgs}:${jars}"
999# 1015#
1000# export DEPEND="${DEPEND} ${depstr}" 1016# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}" 1017# export RDEPEND="${RDEPEND} ${depstr}"
1002#} 1018#}
1003 1019
1020# ------------------------------------------------------------------------------
1021# @ebuild-function java-pkg_find-normal-jars
1022#
1023# Find the files with suffix .jar file in the given directory or $WORKDIR
1024#
1025# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1026# ------------------------------------------------------------------------------
1027java-pkg_find-normal-jars() {
1028 local dir=$1
1029 [[ "${dir}" ]] || dir="${WORKDIR}"
1030 local found
1031 for jar in $(find "${dir}" -name "*.jar" -type f); do
1032 echo "${jar}"
1033 found="true"
1034 done
1035 [[ "${found}" ]]
1036 return $?
1037}
1038
1039# ------------------------------------------------------------------------------
1040# @ebuild-function java-pkg_ensure-no-bundled-jars
1041#
1042# Try to locate bundled jar files in ${WORKDIR} and die if found.
1004# This should be used after S has been populated with symlinks to jars 1043# This function should be called after WORKDIR has been populated with symlink
1005# TODO document 1044# to system jar files or bundled jars removed.
1045# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1046java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1047 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1048
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1049 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1050 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1051 echo "Bundled jars found:"
1013 local jar 1052 local jar
1014 for jar in ${bundled_jars}; do 1053 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1054 echo $(pwd)${jar/./}
1016 done 1055 done
1017 die "Bundled jars found!" 1056 die "Bundled jars found!"
1018
1019 fi 1057 fi
1020 popd >/dev/null 2>/dev/null
1021} 1058}
1022 1059
1023# ------------------------------------------------------------------------------ 1060# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1061# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1062#
1174# @ebuild-function java-pkg_get-target 1211# @ebuild-function java-pkg_get-target
1175# 1212#
1176# Determines what target version should be used, for passing to -target. 1213# Determines what target version should be used, for passing to -target.
1177# If you don't care about lower versions, you can set _WANT_TARGET to the 1214# If you don't care about lower versions, you can set _WANT_TARGET to the
1178# version of your JDK. 1215# version of your JDK.
1179# Remember doing this will mostly like cause things to break.
1180# Doesn't allow it to be lower then the one in depend.
1181# Doesn't allow it to be higher then the active vm.
1182# 1216#
1183# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1217# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1184# ------------------------------------------------------------------------------ 1218# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1219java-pkg_get-target() {
1186 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1187 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1188 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1189 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1190 echo ${JAVA_PKG_WANT_TARGET}
1191 else
1192 echo ${min}
1193 fi
1194 else
1195 echo ${min}
1196 fi
1197
1198 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1220 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1221}
1200 1222
1201java-pkg_get-javac() { 1223java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1224 debug-print-function ${FUNCNAME} $*
1203 1225
1292 die "No GCJ support found!" 1314 die "No GCJ support found!"
1293 fi 1315 fi
1294} 1316}
1295 1317
1296java-pkg_ensure-test() { 1318java-pkg_ensure-test() {
1297 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1319 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1320 && hasq test ${IUSE} && ! use test;
1321 then
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1322 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1323 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1324 die "Need USE=test enabled"
1301 fi 1325 fi
1302} 1326}
1316# ------------------------------------------------------------------------------ 1340# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1341# @ebuild-function eant
1318# 1342#
1319# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1343# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1320# compiler. 1344# compiler.
1345# variables:
1346# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1347# gentoo.classpath property. Be sure to call
1348# java-ant_rewrite-classpath in src_unpack.
1321# 1349#
1322# ------------------------------------------------------------------------------ 1350# ------------------------------------------------------------------------------
1323eant() { 1351eant() {
1324 debug-print-function ${FUNCNAME} $* 1352 debug-print-function ${FUNCNAME} $*
1325 1353
1327# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1355# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1328# java-pkg_announce-qa-violation \ 1356# java-pkg_announce-qa-violation \
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1357# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1358# fi
1331 1359
1332 local antflags 1360 local antflags="-Dnoget=true"
1333 java-pkg_init-compiler_ 1361 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1362 local compiler="${GENTOO_COMPILER}"
1335 1363
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1364 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1337 1365
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1367 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1368 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1369 fi
1342 1370
1343 if [[ ${compiler} != "javac" ]]; then 1371 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1372 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # Figure out any extra stuff to put on the classpath for compilers aside 1373 # Figure out any extra stuff to put on the classpath for compilers aside
1346 # from javac 1374 # from javac
1347 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1375 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1348 # java-config -p 1376 # java-config -p
1349 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1377 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1359 1387
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1388 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1361 antflags="${antflags} -debug" 1389 antflags="${antflags} -debug"
1362 fi 1390 fi
1363 1391
1392 local gcp="${EANT_GENTOO_CLASSPATH}"
1393
1394 if [[ "${gcp}" ]]; then
1395 local cp="$(java-pkg_getjars ${gcp})"
1396 # It seems ant does not like single quotes around ${cp}
1397 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1398 fi
1399
1364 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1400 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1401 ant ${antflags} "${@}" || die "eant failed"
1366 1402
1367} 1403}
1368 1404
1439# @return string - Name of the target to create javadocs 1475# @return string - Name of the target to create javadocs
1440# ------------------------------------------------------------------------------ 1476# ------------------------------------------------------------------------------
1441use_doc() { 1477use_doc() {
1442 use doc && echo ${@:-javadoc} 1478 use doc && echo ${@:-javadoc}
1443} 1479}
1480
1444 1481
1445# ------------------------------------------------------------------------------ 1482# ------------------------------------------------------------------------------
1446# @section-end build 1483# @section-end build
1447# ------------------------------------------------------------------------------ 1484# ------------------------------------------------------------------------------
1448 1485
1832# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1869# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1833# verify that the current VM is sufficient. 1870# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 1871# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 1872# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 1873java-pkg_switch-vm() {
1874 debug-print-function ${FUNCNAME} $*
1875
1837 if java-pkg_needs-vm; then 1876 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 1877 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 1878 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # If you're forcing the VM, I hope you know what your doing... 1879 # If you're forcing the VM, I hope you know what your doing...
1880 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1881 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 1882 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1883 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1844 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1884 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1885 if [[ -n ${JAVA_PKG_VNEED} ]]; then

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.42

  ViewVC Help
Powered by ViewVC 1.1.20