/[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.22 Revision 1.31
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.31 2006/12/03 18:41:25 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
287 cp "${original_jar}" "${new_jar_dest}" \ 288 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 289 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 290 java-pkg_dojar "${new_jar_dest}"
290} 291}
291 292
292
293# ------------------------------------------------------------------------------ 293# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 294# @ebuild-function java-pkg_addcp
295# 295#
296# Add something to the package's classpath. For jars, you should use dojar, 296# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 297# newjar, or regjar. This is typically used to add directories to the classpath.
301# ------------------------------------------------------------------------------ 301# ------------------------------------------------------------------------------
302java-pkg_addcp() { 302java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 304 java-pkg_do_write_
305} 305}
306
307 306
308# ------------------------------------------------------------------------------ 307# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 308# @ebuild-function java-pkg_doso
310# 309#
311# Installs any number of JNI libraries 310# Installs any number of JNI libraries
428# ------------------------------------------------------------------------------ 427# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 428java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 429 debug-print-function ${FUNCNAME} $*
431 430
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 431 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 432
433 # from /usr/lib/portage/bin/dohtml -h
434 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 435 dohtml -f package-list "$@"
436
435 # this probably shouldn't be here but it provides 437 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 438 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 439 # old ebuilds.
438 java-pkg_recordjavadoc 440 java-pkg_recordjavadoc
439} 441}
440 442
441# TODO document 443# ------------------------------------------------------------------------------
444# @ebuild-function java-pkg_dojavadoc
445#
446# Installs javadoc documentation. This should be controlled by the doc use flag.
447#
448# @param $1: - The javadoc root directory.
449#
450# @example:
451# java-pkg_dojavadoc docs/api
452#
453# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 454java-pkg_dojavadoc() {
443 local dir="$1" 455 local dir="$1"
444 456
445 java-pkg_check-phase install 457 java-pkg_check-phase install
446 458
518# @ebuild-function java-pkg_dolauncher 530# @ebuild-function java-pkg_dolauncher
519# 531#
520# Make a wrapper script to lauch/start this package 532# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 533# If necessary, the wrapper will switch to the appropriate VM.
522# 534#
535# Can be called without parameters if the package installs only one jar
536# that has the Main-class attribute set. The wrapper will be named ${PN}.
537#
523# @param $1 - filename of launcher to create 538# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 539# @param $2 - options, as follows:
525# --main the.main.class.too.start 540# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 541# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass to java' 542# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'Extra arguments too pass to the package' 543# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 544# --pwd
530# -into 545# -into
531# -pre 546# -pre
532# ------------------------------------------------------------------------------ 547# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 548java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 549 debug-print-function ${FUNCNAME} $*
535 550
536 java-pkg_check-phase install 551 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 552 java-pkg_init_paths_
541 553
554 if [[ ${#} = 0 ]]; then
555 local name="${PN}"
556 else
542 local name="${1}" 557 local name="${1}"
558 shift
559 fi
560
543 # TODO rename to launcher 561 # TODO rename to launcher
544 local target="${T}/${name}" 562 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp" 563 local var_tmp="${T}/launcher_variables_tmp"
546 local target_dir pre 564 local target_dir pre
547 shift
548 565
549 # Process the other the rest of the arguments 566 # Process the other the rest of the arguments
550 while [[ -n "${1}" && -n "${2}" ]]; do 567 while [[ -n "${1}" && -n "${2}" ]]; do
551 local var=${1} value=${2} 568 local var=${1} value=${2}
552 if [[ "${var:0:2}" == "--" ]]; then 569 if [[ "${var:0:2}" == "--" ]]; then
570 local var=${var:2}
553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}" 571 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
572 local gjl_${var}="${value}"
554 elif [[ "${var}" == "-into" ]]; then 573 elif [[ "${var}" == "-into" ]]; then
555 target_dir="${value}" 574 target_dir="${value}"
556 elif [[ "${var}" == "-pre" ]]; then 575 elif [[ "${var}" == "-pre" ]]; then
557 pre="${value}" 576 pre="${value}"
558 fi 577 fi
559 shift 2 578 shift 2
560 done 579 done
580
581 # Test if no --jar and --main arguments were given and
582 # in that case check if the package only installs one jar
583 # and use that jar.
584 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
585 local cp="${JAVA_PKG_CLASSPATH}"
586 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
587 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
588 else
589 local msg="Not enough information to create a launcher given."
590 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
591 die "${msg}"
592 fi
593 fi
561 594
562 # Write the actual script 595 # Write the actual script
563 echo "#!/bin/bash" > "${target}" 596 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 597 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 598 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
741# The providing packages are recorded as dependencies into package.env DEPEND 774# The providing packages are recorded as dependencies into package.env DEPEND
742# line, unless "--build-only" is passed as the very first argument, for jars 775# line, unless "--build-only" is passed as the very first argument, for jars
743# that have to be present only at build time and are not needed on runtime 776# that have to be present only at build time and are not needed on runtime
744# (junit testing etc). 777# (junit testing etc).
745# 778#
746# Example: Get the classpath for xerces-2, 779# Example: Get the classpath for xerces-2 and xalan,
747# java-pkg_getjars xerces-2 xalan 780# java-pkg_getjars xerces-2,xalan
748# Example Return: 781# Example Return:
749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 782# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
750# 783#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into 784# @param $1 - (optional) "--build-only" makes the jar(s) not added into
752# package.env DEPEND line. 785# package.env DEPEND line.
753# @param $@ - list of packages to get jars from 786# @param $2 - list of packages to get jars from
787# (passed to java-config --classpath)
754# ------------------------------------------------------------------------------ 788# ------------------------------------------------------------------------------
755java-pkg_getjars() { 789java-pkg_getjars() {
756 debug-print-function ${FUNCNAME} $* 790 debug-print-function ${FUNCNAME} $*
757 791
758 local build_only="" 792 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments"
759 793
760 if [[ "${1}" = "--build-only" ]]; then 794 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true" 795 local build_only="true"
762 shift 796 shift
763 fi 797 fi
764 798
765 [[ ${#} -lt 1 ]] && die "At least one argument needed"
766
767 # NOTE could probably just pass $@ to java-config --classpath. and return it
768 local classpath pkg 799 local classpath pkgs="${1}"
769 for pkg in ${@//,/ }; do
770 #for pkg in $(echo "$@" | tr ',' ' '); do
771 jars="$(java-config --classpath=${pkg})" 800 jars="$(java-config --classpath=${pkgs})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed" 801 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
773 debug-print "${pkg}:${jars}" 802 debug-print "${pkgs}:${jars}"
774 803
775 if [[ -z "${classpath}" ]]; then 804 if [[ -z "${classpath}" ]]; then
776 classpath="${jars}" 805 classpath="${jars}"
777 else 806 else
778 classpath="${classpath}:${jars}" 807 classpath="${classpath}:${jars}"
779 fi 808 fi
809
780 # Only record jars that aren't build-only 810 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" 811 if [[ -z "${build_only}" ]]; then
812 oldifs="${IFS}"
813 IFS=","
814 for pkg in ${pkgs}; do
815 java-pkg_record-jar_ "${pkg}"
782 done 816 done
817 IFS="${oldifs}"
818 fi
819
783 echo "${classpath}" 820 echo "${classpath}"
784} 821}
785 822
786# ------------------------------------------------------------------------------ 823# ------------------------------------------------------------------------------
787# @ebuild-function java-pkg_getjar 824# @ebuild-function java-pkg_getjar
1160} 1197}
1161 1198
1162java-pkg_get-javac() { 1199java-pkg_get-javac() {
1163 debug-print-function ${FUNCNAME} $* 1200 debug-print-function ${FUNCNAME} $*
1164 1201
1165 java-pkg_init-compiler_ 1202
1166 local compiler="${GENTOO_COMPILER}" 1203 local compiler="${GENTOO_COMPILER}"
1167 1204
1168 local compiler_executable 1205 local compiler_executable
1169 if [[ "${compiler}" = "javac" ]]; then 1206 if [[ "${compiler}" = "javac" ]]; then
1170 # nothing fancy needs to be done for javac 1207 # nothing fancy needs to be done for javac
1178 unset JAVAC 1215 unset JAVAC
1179 # try to get value of JAVAC 1216 # try to get value of JAVAC
1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1217 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1181 export JAVAC=${old_javac} 1218 export JAVAC=${old_javac}
1182 1219
1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1220 if [[ -z ${compiler_executable} ]]; then
1221 echo "JAVAC is empty or undefined in ${compiler_env}"
1222 return 1
1223 fi
1184 1224
1185 # check that it's executable 1225 # check that it's executable
1186 if [[ ! -x ${compiler_executable} ]]; then 1226 if [[ ! -x ${compiler_executable} ]]; then
1187 eerror "Could not find ${compiler_executable}!"
1188 die "${compiler_executable} doesn't exist, or isn't executable" 1227 echo "${compiler_executable} doesn't exist, or isn't executable"
1228 return 1
1189 fi 1229 fi
1190 else 1230 else
1191 eerror "Could not find environment file for ${compiler}" 1231 echo "Could not find environment file for ${compiler}"
1192 die "Could not find ${compiler_env}" 1232 return 1
1193 fi 1233 fi
1194 fi 1234 fi
1195 echo ${compiler_executable} 1235 echo ${compiler_executable}
1196} 1236}
1197 1237
1214 1254
1215 debug-print "want source: ${want_source}" 1255 debug-print "want source: ${want_source}"
1216 debug-print "want target: ${want_target}" 1256 debug-print "want target: ${want_target}"
1217 1257
1218 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1258 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1219 debug-print "could not find valid -source/-target values" 1259 debug-print "could not find valid -source/-target values for javac"
1220 die "Could not find valid -source/-target values" 1260 echo "Could not find valid -source/-target values for javac"
1261 return 1
1221 else 1262 else
1222 if java-pkg_is-vm-version-ge "1.4"; then 1263 if java-pkg_is-vm-version-ge "1.4"; then
1223 echo "${source_str} ${target_str}" 1264 echo "${source_str} ${target_str}"
1224 else 1265 else
1225 echo "${target_str}" 1266 echo "${target_str}"
1330# @param $@ - Arguments to be passed to the compiler 1371# @param $@ - Arguments to be passed to the compiler
1331# ------------------------------------------------------------------------------ 1372# ------------------------------------------------------------------------------
1332ejavac() { 1373ejavac() {
1333 debug-print-function ${FUNCNAME} $* 1374 debug-print-function ${FUNCNAME} $*
1334 1375
1335 # FIXME using get-javac ends up printing stuff with einfo 1376 java-pkg_init-compiler_
1377
1378 local compiler_executable
1336# local compiler_executable=$(java-pkg_get-javac) 1379 compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac" 1380 if [[ ${?} != 0 ]]; then
1381 eerror "There was a problem determining compiler: ${compiler_executable}"
1382 die "get-javac failed"
1383 fi
1338 1384
1385 local javac_args
1386 javac_args="$(java-pkg_javac-args)"
1387 if [[ ${?} != 0 ]]; then
1388 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1389 die "java-pkg_javac-args failed"
1390 fi
1391
1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1392 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1393 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1341} 1394}
1342 1395
1343# ------------------------------------------------------------------------------ 1396# ------------------------------------------------------------------------------
1344# @ebuild-function java-pkg_filter-compiler 1397# @ebuild-function java-pkg_filter-compiler
1345# 1398#
1577# Writes the package.env out to disk. 1630# Writes the package.env out to disk.
1578# 1631#
1579# ------------------------------------------------------------------------------ 1632# ------------------------------------------------------------------------------
1580# TODO change to do-write, to match everything else 1633# TODO change to do-write, to match everything else
1581java-pkg_do_write_() { 1634java-pkg_do_write_() {
1635 java-pkg_init_paths_
1582 # Create directory for package.env 1636 # Create directory for package.env
1583 dodir "${JAVA_PKG_SHAREPATH}" 1637 dodir "${JAVA_PKG_SHAREPATH}"
1584 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1638 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1585 # Create package.env 1639 # Create package.env
1586 ( 1640 (
1614 # Strip unnecessary leading and trailing colons 1668 # Strip unnecessary leading and trailing colons
1615 # TODO try to cleanup if possible 1669 # TODO try to cleanup if possible
1616 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1670 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1617 fi 1671 fi
1618} 1672}
1619
1620 1673
1621# ------------------------------------------------------------------------------ 1674# ------------------------------------------------------------------------------
1622# @internal-function java-pkg_record-jar_ 1675# @internal-function java-pkg_record-jar_
1623# 1676#
1624# Record a dependency to the package.env 1677# Record a dependency to the package.env
1705# ------------------------------------------------------------------------------ 1758# ------------------------------------------------------------------------------
1706java-pkg_setup-vm() { 1759java-pkg_setup-vm() {
1707 debug-print-function ${FUNCNAME} $* 1760 debug-print-function ${FUNCNAME} $*
1708 1761
1709 local vendor="$(java-pkg_get-vm-vendor)" 1762 local vendor="$(java-pkg_get-vm-vendor)"
1710 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1763 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1711 addpredict "/dev/random" 1764 addpredict "/dev/random"
1712 elif [[ "${vendor}" == "ibm" ]]; then 1765 elif [[ "${vendor}" == "ibm" ]]; then
1713 addpredict "/proc/self/maps" 1766 addpredict "/proc/self/maps"
1714 addpredict "/proc/cpuinfo" 1767 addpredict "/proc/cpuinfo"
1715 export LANG="C" LC_ALL="C" 1768 export LANG="C" LC_ALL="C"
1784 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1837 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1785 # if we're allowed to switch the vm... 1838 # if we're allowed to switch the vm...
1786 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1839 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1787 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1840 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1788 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1841 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1789 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1842 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1790 else 1843 else
1791 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1844 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1845 fi
1846 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1847 eerror "Unable to determine VM for building from dependencies."
1848 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1849 echo "VNEED: ${JAVA_PKG_VNEED}"
1850 else
1851 export GENTOO_VM
1792 fi 1852 fi
1793 # otherwise just make sure the current VM is sufficient 1853 # otherwise just make sure the current VM is sufficient
1794 else 1854 else
1795 java-pkg_ensure-vm-version-sufficient 1855 java-pkg_ensure-vm-version-sufficient
1796 fi 1856 fi
1798 1858
1799 java-pkg_setup-vm 1859 java-pkg_setup-vm
1800 1860
1801 export JAVA=$(java-config --java) 1861 export JAVA=$(java-config --java)
1802 export JAVAC=$(java-config --javac) 1862 export JAVAC=$(java-config --javac)
1803 export JAVACFLAGS="$(java-pkg_javac-args)" 1863 JAVACFLAGS="$(java-pkg_javac-args)"
1864 if [[ ${?} != 0 ]]; then
1865 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1866 die "java-pkg_javac-args failed"
1867 fi
1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1868 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1869 export JAVACFLAGS
1805 1870
1806 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1871 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1807 export JDK_HOME=${JAVA_HOME} 1872 export JDK_HOME=${JAVA_HOME}
1808 1873
1809 #TODO If you know a better solution let us know. 1874 #TODO If you know a better solution let us know.
1871 ewarn "Possible problem" 1936 ewarn "Possible problem"
1872 die "Bad class files found" 1937 die "Bad class files found"
1873 fi 1938 fi
1874} 1939}
1875 1940
1876
1877# ------------------------------------------------------------------------------ 1941# ------------------------------------------------------------------------------
1878# @section-end internal 1942# @section-end internal
1879# ------------------------------------------------------------------------------ 1943# ------------------------------------------------------------------------------
1880 1944
1881java-pkg_check-phase() { 1945java-pkg_check-phase() {

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.20