/[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.75 Revision 1.93
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.75 2007/04/20 16:13:46 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.93 2007/09/27 19:47:08 betelgeuse 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
58#WANT_ANT_TASKS 57#WANT_ANT_TASKS
59 58
60# ----------------------------------------------------------------------------- 59# -----------------------------------------------------------------------------
61# @variable-internal JAVA_PKG_PORTAGE_DEP 60# @variable-internal JAVA_PKG_PORTAGE_DEP
62# 61#
63# The version of portage we need to function properly. At this moment it's 62# The version of portage we need to function properly. Previously it was
64# portage with phase hooks support. 63# portage with phase hooks support but now we use a version with proper env
64# saving.
65# ----------------------------------------------------------------------------- 65# -----------------------------------------------------------------------------
66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
67 67
68# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
69# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
70# 70#
71# This is a convience variable to be used from the other java eclasses. This is 71# 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 72# the version of java-config we want to use. Usually the latest stable version
73# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
74# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.31 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
76 76
77# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 78# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
79# @variable-default yes 79# @variable-default yes
80# 80#
195# 195#
196# @example 196# @example
197# java-pkg_doexamples demo 197# java-pkg_doexamples demo
198# java-pkg_doexamples demo/* examples/* 198# java-pkg_doexamples demo/* examples/*
199# 199#
200# @param --subdir - If the examples need a certain directory structure
200# @param $* - list of files to install 201# @param $* - list of files to install
201# ------------------------------------------------------------------------------ 202# ------------------------------------------------------------------------------
202java-pkg_doexamples() { 203java-pkg_doexamples() {
203 debug-print-function ${FUNCNAME} $* 204 debug-print-function ${FUNCNAME} $*
204 205
205 [[ ${#} -lt 1 ]] && die "At least one argument needed" 206 [[ ${#} -lt 1 ]] && die "At least one argument needed"
206 207
207 java-pkg_check-phase install 208 java-pkg_check-phase install
208 209
209 local dest=/usr/share/doc/${PF}/examples 210 local dest=/usr/share/doc/${PF}/examples
211 if [[ ${1} == --subdir ]]; then
212 local dest=${dest}/${2}
213 dodir ${dest}
214 shift 2
215 fi
216
210 if [[ ${#} = 1 && -d ${1} ]]; then 217 if [[ ${#} = 1 && -d ${1} ]]; then
211 ( # dont want to pollute calling env 218 ( # dont want to pollute calling env
212 insinto "${dest}" 219 insinto "${dest}"
213 doins -r ${1}/* 220 doins -r ${1}/*
214 ) || die "Installing examples failed" 221 ) || die "Installing examples failed"
832# --build-only - makes the jar(s) not added into package.env DEPEND line. 839# --build-only - makes the jar(s) not added into package.env DEPEND line.
833# (assumed automatically when called inside src_test) 840# (assumed automatically when called inside src_test)
834# --with-dependencies - get jars also from requested package's dependencies 841# --with-dependencies - get jars also from requested package's dependencies
835# transitively. 842# transitively.
836# --into $dir - symlink jar(s) into $dir (must exist) instead of . 843# --into $dir - symlink jar(s) into $dir (must exist) instead of .
837# @param $1 - Package to get jars from. 844# @param $1 - Package to get jars from, or comma-separated list of packages in
845# case other parameters are not used.
838# @param $2 - jar from package. If not specified, all jars will be used. 846# @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 847# @param $3 - When a single jar is specified, destination filename of the
840# symlink. Defaults to the name of the jar. 848# symlink. Defaults to the name of the jar.
841# ------------------------------------------------------------------------------ 849# ------------------------------------------------------------------------------
842# TODO could probably be cleaned up a little 850# TODO could probably be cleaned up a little
845 853
846 local build_only="" 854 local build_only=""
847 local destdir="." 855 local destdir="."
848 local deep="" 856 local deep=""
849 857
850 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 858 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
851 859
852 while [[ "${1}" == --* ]]; do 860 while [[ "${1}" == --* ]]; do
853 if [[ "${1}" = "--build-only" ]]; then 861 if [[ "${1}" = "--build-only" ]]; then
854 build_only="true" 862 build_only="build"
855 elif [[ "${1}" = "--with-dependencies" ]]; then 863 elif [[ "${1}" = "--with-dependencies" ]]; then
856 deep="--with-dependencies" 864 deep="--with-dependencies"
857 elif [[ "${1}" = "--into" ]]; then 865 elif [[ "${1}" = "--into" ]]; then
858 destdir="${2}" 866 destdir="${2}"
859 shift 867 shift
873 local error_msg="There was a problem getting the classpath for ${target_pkg}." 881 local error_msg="There was a problem getting the classpath for ${target_pkg}."
874 local classpath 882 local classpath
875 classpath="$(java-config ${deep} --classpath=${target_pkg})" 883 classpath="$(java-config ${deep} --classpath=${target_pkg})"
876 [[ $? != 0 ]] && die ${error_msg} 884 [[ $? != 0 ]] && die ${error_msg}
877 885
886 # When we have commas this functions is called to bring jars from multiple
887 # packages. This affects recording of dependencencies performed later
888 # which expects one package only, so we do it here.
889 if [[ ${target_pkg} = *,* ]]; then
890 for pkg in ${target_pkg//,/ }; do
891 java-pkg_ensure-dep "${build_only}" "${pkg}"
892 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
893 done
894 # setting this disables further record-jar_ calls later
895 build_only="build"
896 else
878 java-pkg_ensure-dep "${build_only}" "${target_pkg}" 897 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
898 fi
879 899
880 pushd ${destdir} > /dev/null \ 900 pushd ${destdir} > /dev/null \
881 || die "failed to change directory to ${destdir}" 901 || 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 902
891 local jar 903 local jar
892 for jar in ${classpath//:/ }; do 904 for jar in ${classpath//:/ }; do
893 local jar_name=$(basename "${jar}") 905 local jar_name=$(basename "${jar}")
894 if [[ ! -f "${jar}" ]] ; then 906 if [[ ! -f "${jar}" ]] ; then
957 debug-print-function ${FUNCNAME} $* 969 debug-print-function ${FUNCNAME} $*
958 970
959 local build_only="" 971 local build_only=""
960 local deep="" 972 local deep=""
961 973
962 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 974 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
963 975
964 while [[ "${1}" == --* ]]; do 976 while [[ "${1}" == --* ]]; do
965 if [[ "${1}" = "--build-only" ]]; then 977 if [[ "${1}" = "--build-only" ]]; then
966 build_only="true" 978 build_only="build"
967 elif [[ "${1}" = "--with-dependencies" ]]; then 979 elif [[ "${1}" = "--with-dependencies" ]]; then
968 deep="--with-dependencies" 980 deep="--with-dependencies"
969 else 981 else
970 die "java-pkg_jar-from called with unknown parameter: ${1}" 982 die "java-pkg_jar-from called with unknown parameter: ${1}"
971 fi 983 fi
990 classpath="${classpath}:${jars}" 1002 classpath="${classpath}:${jars}"
991 fi 1003 fi
992 1004
993 # Only record jars that aren't build-only 1005 # Only record jars that aren't build-only
994 if [[ -z "${build_only}" ]]; then 1006 if [[ -z "${build_only}" ]]; then
995 oldifs="${IFS}"
996 IFS=","
997 for pkg in ${pkgs}; do 1007 for pkg in ${pkgs//,/ }; do
998 java-pkg_record-jar_ "${pkg}" 1008 java-pkg_record-jar_ "${pkg}"
999 done 1009 done
1000 IFS="${oldifs}"
1001 fi 1010 fi
1002 1011
1003 echo "${classpath}" 1012 echo "${classpath}"
1004} 1013}
1005 1014
1025java-pkg_getjar() { 1034java-pkg_getjar() {
1026 debug-print-function ${FUNCNAME} $* 1035 debug-print-function ${FUNCNAME} $*
1027 1036
1028 local build_only="" 1037 local build_only=""
1029 1038
1030 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 1039 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1031 1040
1032 while [[ "${1}" == --* ]]; do 1041 while [[ "${1}" == --* ]]; do
1033 if [[ "${1}" = "--build-only" ]]; then 1042 if [[ "${1}" = "--build-only" ]]; then
1034 build_only="true" 1043 build_only="build"
1035 else 1044 else
1036 die "java-pkg_jar-from called with unknown parameter: ${1}" 1045 die "java-pkg_jar-from called with unknown parameter: ${1}"
1037 fi 1046 fi
1038 shift 1047 shift
1039 done 1048 done
1064 fi 1073 fi
1065 done 1074 done
1066 1075
1067 die "Could not find ${target_jar} in ${pkg}" 1076 die "Could not find ${target_jar} in ${pkg}"
1068 return 1 1077 return 1
1078}
1079
1080# ------------------------------------------------------------------------------
1081# @ebuild-function java-pkg_register-dependency
1082#
1083# Registers runtime dependency on a package, list of packages, or a single jar
1084# from a package, into package.env DEPEND line. Can only be called in
1085# src_install phase.
1086# Intended for binary packages where you don't need to symlink the jars or get
1087# their classpath during build. As such, the dependencies only need to be
1088# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1089#
1090# @param $1 - comma-separated list of packages, or a single package
1091# @param $2 - if param $1 is a single package, optionally specify the jar
1092# to depend on
1093#
1094# Example: Record the dependency on whole xerces-2 and xalan,
1095# java-pkg_register-dependency xerces-2,xalan
1096# Example: Record the dependency on ant.jar from ant-core
1097# java-pkg_register-dependency ant-core ant.jar
1098#
1099# Note: Passing both list of packages as the first parameter AND specifying the
1100# jar as the second is not allowed and will cause the function to die. We assume
1101# that there's more chance one passes such combination as a mistake, than that
1102# there are more packages providing identically named jar without class
1103# collisions.
1104# ------------------------------------------------------------------------------
1105java-pkg_register-dependency() {
1106 debug-print-function ${FUNCNAME} $*
1107
1108 java-pkg_check-phase install
1109
1110 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1111
1112 local pkgs="${1}"
1113 local jar="${2}"
1114
1115 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1116
1117 if [[ -z "${jar}" ]]; then
1118 for pkg in ${pkgs//,/ }; do
1119 java-pkg_ensure-dep runtime "${pkg}"
1120 java-pkg_record-jar_ "${pkg}"
1121 done
1122 else
1123 [[ ${pkgs} == *,* ]] && \
1124 die "${FUNCNAME} called with both package list and jar name"
1125 java-pkg_ensure-dep runtime "${pkgs}"
1126 java-pkg_record-jar_ "${pkgs}" "${jar}"
1127 fi
1128
1129 java-pkg_do_write_
1130}
1131
1132# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_register-optional-dependency
1134#
1135# Registers optional runtime dependency on a package, list of packages, or a
1136# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1137# called in src_install phase.
1138# Intended for packages that can use other packages when those are in classpath.
1139# Will be put on classpath by launcher if they are installed. Typical case is
1140# JDBC implementations for various databases. It's better than having USE flag
1141# for each implementation triggering hard dependency.
1142#
1143# @param $1 - comma-separated list of packages, or a single package
1144# @param $2 - if param $1 is a single package, optionally specify the jar
1145# to depend on
1146#
1147# Example: Record the optional dependency on some jdbc providers
1148# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1149#
1150# Note: Passing both list of packages as the first parameter AND specifying the
1151# jar as the second is not allowed and will cause the function to die. We assume
1152# that there's more chance one passes such combination as a mistake, than that
1153# there are more packages providing identically named jar without class
1154# collisions.
1155# ------------------------------------------------------------------------------
1156java-pkg_register-optional-dependency() {
1157 debug-print-function ${FUNCNAME} $*
1158
1159 java-pkg_check-phase install
1160
1161 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1162
1163 local pkgs="${1}"
1164 local jar="${2}"
1165
1166 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1167
1168 if [[ -z "${jar}" ]]; then
1169 for pkg in ${pkgs//,/ }; do
1170 java-pkg_record-jar_ --optional "${pkg}"
1171 done
1172 else
1173 [[ ${pkgs} == *,* ]] && \
1174 die "${FUNCNAME} called with both package list and jar name"
1175 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1176 fi
1177
1178 java-pkg_do_write_
1179}
1180
1181# ------------------------------------------------------------------------------
1182# @ebuild-function java-pkg_register-environment-variable
1183#
1184# Register an arbitrary environment variable into package.env. The gjl launcher
1185# for this package or any package depending on this will export it into
1186# environement before executing java command.
1187# Must only be called in src_install phase.
1188#
1189# @param $1 - variable name
1190# @param $2 - variable value
1191# ------------------------------------------------------------------------------
1192JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1193JAVA_PKG_EXTRA_ENV_VARS=""
1194java-pkg_register-environment-variable() {
1195 debug-print-function ${FUNCNAME} $*
1196
1197 java-pkg_check-phase install
1198
1199 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1200
1201 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1202 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1203
1204 java-pkg_do_write_
1069} 1205}
1070 1206
1071# This function reads stdin, and based on that input, figures out how to 1207# This function reads stdin, and based on that input, figures out how to
1072# populate jars from the filesystem. 1208# populate jars from the filesystem.
1073# Need to figure out a good way of making use of this, ie be able to use a 1209# Need to figure out a good way of making use of this, ie be able to use a
1561 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true 1697 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1562 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true 1698 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1563 done 1699 done
1564 1700
1565 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then 1701 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1566 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks" 1702 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1567 echo "all" 1703 echo "all"
1568 else 1704 else
1569 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant 1705 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1570 # so we deactivate all tasks that may be installed 1706 # so we deactivate all tasks that may be installed
1571 echo "none" 1707 echo "none"
1596 return 0 1732 return 0
1597 fi 1733 fi
1598} 1734}
1599 1735
1600# ------------------------------------------------------------------------------ 1736# ------------------------------------------------------------------------------
1737# @ebuild-function ejunit
1738#
1739# Junit wrapper function. Makes it easier to run the tests and checks for
1740# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1741#
1742# Examples:
1743# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1744# ejunit org.blinkenlights.jid3.test.AllTests
1745#
1746# @param $1 - -cp or -classpath
1747# @param $2 - classpath; junit and recorded dependencies get appended
1748# @param $@ - the rest of the parameters are passed to java
1749# ------------------------------------------------------------------------------
1750ejunit() {
1751 debug-print-function ${FUNCNAME} $*
1752
1753 local pkgs
1754 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1755 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1756 done
1757
1758 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1759 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1760 cp="${2}:${cp}"
1761 shift 2
1762 else
1763 cp=".:${cp}"
1764 fi
1765
1766 local runner=junit.textui.TestRunner
1767 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1768 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1769}
1770
1771# ------------------------------------------------------------------------------
1601# @section-end helper 1772# @section-end helper
1602# ------------------------------------------------------------------------------ 1773# ------------------------------------------------------------------------------
1603 1774
1604# ------------------------------------------------------------------------------ 1775# ------------------------------------------------------------------------------
1605# @section-begin build 1776# @section-begin build
1616# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS, 1787# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1617# variables: 1788# variables:
1618# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the 1789# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1619# gentoo.classpath property. Be sure to call 1790# gentoo.classpath property. Be sure to call
1620# java-ant_rewrite-classpath in src_unpack. 1791# java-ant_rewrite-classpath in src_unpack.
1792# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1621# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. 1793# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1622# ------------------------------------------------------------------------------ 1794# ------------------------------------------------------------------------------
1623eant() { 1795eant() {
1624 debug-print-function ${FUNCNAME} $* 1796 debug-print-function ${FUNCNAME} $*
1625 1797
1626 # FIXME get this working 1798 if [[ ${EBUILD_PHASE} = compile ]]; then
1627# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1799 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1628# java-pkg_announce-qa-violation \ 1800 # finally get rid of the hooks without breaking stuff
1629# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1801
1802 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1803 && java-ant_ignore-system-classes "${S}/build.xml"
1804
1805 if hasq java-ant-2 ${INHERITED}; then
1806 java-ant_bsfix
1807 fi
1808
1809 # eant can be called multiple times
1810 JAVA_PKG_BSFIX="off"
1811
1812 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1813 echo "Searching for bundled jars:"
1814 java-pkg_find-normal-jars || echo "None found."
1815 echo "Searching for bundled classes (no output if none found):"
1816 find "${WORKDIR}" -name "*.class"
1817 echo "Search done."
1818 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1819 fi
1630# fi 1820 fi
1631 1821
1632 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then 1822 if ! hasq java-ant-2 ${INHERITED}; then
1633 local msg="You should inherit java-ant-2 when using eant" 1823 local msg="You should inherit java-ant-2 when using eant"
1634 java-pkg_announce-qa-violation ${msg} 1824 java-pkg_announce-qa-violation "${msg}"
1635 die ${msg}
1636 fi 1825 fi
1637 1826
1638 local antflags="-Dnoget=true -Dmaven.mode.offline=true" 1827 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1639 1828
1640 java-pkg_init-compiler_ 1829 java-pkg_init-compiler_
1641 local compiler="${GENTOO_COMPILER}" 1830 local compiler="${GENTOO_COMPILER}"
1642 1831
1643 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1832 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1644
1645 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1833 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1646 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1834 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1647 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1835 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1648 fi 1836 fi
1649 1837
1678 echo "more info." 1866 echo "more info."
1679 fi 1867 fi
1680 fi 1868 fi
1681 done 1869 done
1682 1870
1871 # we use this in src_* so we run ant from /
1683 if has_version ">=dev-java/ant-core-1.7.0"; then 1872 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1684 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly 1873 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1685 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}" 1874 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1686 1875
1687 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set 1876 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1688 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}" 1877 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1711 1900
1712 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug" 1901 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1713 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q" 1902 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1714 1903
1715 local gcp="${EANT_GENTOO_CLASSPATH}" 1904 local gcp="${EANT_GENTOO_CLASSPATH}"
1905 local getjarsarg=""
1716 1906
1717 if [[ ${EBUILD_PHASE} = "test" ]]; then 1907 if [[ ${EBUILD_PHASE} = "test" ]]; then
1718 antflags="${antflags} -DJunit.present=true" 1908 antflags="${antflags} -DJunit.present=true"
1719 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit" 1909 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1720 local getjarsarg="--with-dependencies" 1910 getjarsarg="--with-dependencies"
1721 fi 1911 fi
1722 1912
1723 local cp 1913 local cp
1724 1914
1725 for atom in ${gcp}; do 1915 for atom in ${gcp}; do
1858 unset _JAVA_OPTIONS 2048 unset _JAVA_OPTIONS
1859 # phase hooks make this run many times without this 2049 # phase hooks make this run many times without this
1860 I_WANT_GLOBAL_JAVA_OPTIONS="true" 2050 I_WANT_GLOBAL_JAVA_OPTIONS="true"
1861 fi 2051 fi
1862 2052
2053 if java-pkg_func-exists ant_src_unpack; then
2054 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2055 fi
2056
1863 java-pkg_init_paths_ 2057 java-pkg_init_paths_
1864 java-pkg_switch-vm 2058 java-pkg_switch-vm
1865 PATH=${JAVA_HOME}/bin:${PATH} 2059 PATH=${JAVA_HOME}/bin:${PATH}
1866 2060
1867 # TODO we will probably want to set JAVAC and JAVACFLAGS 2061 # TODO we will probably want to set JAVAC and JAVACFLAGS
2029# Writes the package.env out to disk. 2223# Writes the package.env out to disk.
2030# 2224#
2031# ------------------------------------------------------------------------------ 2225# ------------------------------------------------------------------------------
2032# TODO change to do-write, to match everything else 2226# TODO change to do-write, to match everything else
2033java-pkg_do_write_() { 2227java-pkg_do_write_() {
2228 debug-print-function ${FUNCNAME} $*
2034 java-pkg_init_paths_ 2229 java-pkg_init_paths_
2035 # Create directory for package.env 2230 # Create directory for package.env
2036 dodir "${JAVA_PKG_SHAREPATH}" 2231 dodir "${JAVA_PKG_SHAREPATH}"
2037 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2232 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2233 "${JAVA_PKG_DEPEND_FILE}" || -f \
2234 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
2038 # Create package.env 2235 # Create package.env
2039 ( 2236 (
2040 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2237 echo "DESCRIPTION=\"${DESCRIPTION}\""
2041 echo "GENERATION=\"2\"" 2238 echo "GENERATION=\"2\""
2042 2239
2043 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2240 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
2044 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2241 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
2045 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2242 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
2046 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2243 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2244 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2245 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2246 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2047 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2247 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2048 ) > "${JAVA_PKG_ENV}" 2248 ) > "${JAVA_PKG_ENV}"
2049 2249
2050 # register target/source 2250 # register target/source
2051 local target="$(java-pkg_get-target)" 2251 local target="$(java-pkg_get-target)"
2062 2262
2063 2263
2064 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2264 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
2065 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2265 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
2066 2266
2267 # extra env variables
2268 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2269 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2270 # nested echo to remove leading/trailing spaces
2271 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2272 >> "${JAVA_PKG_ENV}" || die
2273 fi
2274
2067 # Strip unnecessary leading and trailing colons 2275 # Strip unnecessary leading and trailing colons
2068 # TODO try to cleanup if possible 2276 # TODO try to cleanup if possible
2069 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2277 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2278 else
2279 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2280 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2281 debug-print "write package.env."
2070 fi 2282 fi
2071} 2283}
2072 2284
2073# ------------------------------------------------------------------------------ 2285# ------------------------------------------------------------------------------
2074# @internal-function java-pkg_record-jar_ 2286# @internal-function java-pkg_record-jar_
2075# 2287#
2076# Record a dependency to the package.env 2288# Record an (optional) dependency to the package.env
2077# 2289# @param --optional - record dependency as optional
2290# @param $1 - package to record
2291# @param $2 - (optional) jar of package to record
2078# ------------------------------------------------------------------------------ 2292# ------------------------------------------------------------------------------
2079JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2293JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2294JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2080 2295
2081java-pkg_record-jar_() { 2296java-pkg_record-jar_() {
2082 debug-print-function ${FUNCNAME} $* 2297 debug-print-function ${FUNCNAME} $*
2298
2299 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2300 if [[ "${1}" == "--optional" ]]; then
2301 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2302 shift
2303 fi
2083 2304
2084 local pkg=${1} jar=${2} append 2305 local pkg=${1} jar=${2} append
2085 if [[ -z "${jar}" ]]; then 2306 if [[ -z "${jar}" ]]; then
2086 append="${pkg}" 2307 append="${pkg}"
2087 else 2308 else
2088 append="$(basename ${jar})@${pkg}" 2309 append="$(basename ${jar})@${pkg}"
2089 fi 2310 fi
2090 2311
2091 echo ${append} >> ${JAVA_PKG_DEPEND} 2312 echo "${append}" >> "${depend_file}"
2092} 2313}
2093 2314
2094# ------------------------------------------------------------------------------ 2315# ------------------------------------------------------------------------------
2095# @internal-function java-pkg_append_ 2316# @internal-function java-pkg_append_
2096# 2317#
2156# 2377#
2157# ------------------------------------------------------------------------------ 2378# ------------------------------------------------------------------------------
2158java-pkg_setup-vm() { 2379java-pkg_setup-vm() {
2159 debug-print-function ${FUNCNAME} $* 2380 debug-print-function ${FUNCNAME} $*
2160 2381
2382 export LANG="C" LC_ALL="C"
2383
2161 local vendor="$(java-pkg_get-vm-vendor)" 2384 local vendor="$(java-pkg_get-vm-vendor)"
2162 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2385 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2163 addpredict "/dev/random" 2386 addpredict "/dev/random"
2164 elif [[ "${vendor}" == "ibm" ]]; then 2387 elif [[ "${vendor}" == "ibm" ]]; then
2165 addpredict "/proc/self/maps" 2388 addpredict "/proc/self/maps"
2166 addpredict "/proc/cpuinfo" 2389 addpredict "/proc/cpuinfo"
2167 export LANG="C" LC_ALL="C"
2168 elif [[ "${vendor}" == "jrockit" ]]; then 2390 elif [[ "${vendor}" == "jrockit" ]]; then
2169 addpredict "/proc/cpuinfo" 2391 addpredict "/proc/cpuinfo"
2170 fi 2392 fi
2171} 2393}
2172 2394
2276 2498
2277 #TODO If you know a better solution let us know. 2499 #TODO If you know a better solution let us know.
2278 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2500 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2279 2501
2280 local tann="${T}/announced-vm" 2502 local tann="${T}/announced-vm"
2503 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2504 # if people have for example modified eclasses some where
2281 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2505 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2282 # Add a check for setup/preinst phase... to avoid duplicate outputs
2283 # for when FEATURES=buildpkg
2284 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
2285 then
2286 einfo "Using: $(java-config -f)" 2506 einfo "Using: $(java-config -f)"
2287 [[ ! -f "${tann}" ]] && touch "${tann}" 2507 [[ ! -f "${tann}" ]] && touch "${tann}"
2288 fi
2289 fi 2508 fi
2290 2509
2291 else 2510 else
2292 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2511 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2293 fi 2512 fi
2357 2576
2358# ---------------------------------------------------------------------------- 2577# ----------------------------------------------------------------------------
2359# @internal-function java-pkg_ensure-dep 2578# @internal-function java-pkg_ensure-dep
2360# Check that a package being used in jarfrom, getjars and getjar is contained 2579# Check that a package being used in jarfrom, getjars and getjar is contained
2361# within DEPEND or RDEPEND. 2580# within DEPEND or RDEPEND.
2362# @param $1 - Is the package a runtime dependency 2581# @param $1 - empty - check both vars; "runtime" or "build" - check only
2582# RDEPEND, resp. DEPEND
2363# @param $2 - Package name and slot. 2583# @param $2 - Package name and slot.
2364 2584
2365java-pkg_ensure-dep() { 2585java-pkg_ensure-dep() {
2366 debug-print-function ${FUNCNAME} $* 2586 debug-print-function ${FUNCNAME} $*
2367 2587
2368 local build_only="${1}" 2588 local limit_to="${1}"
2369 local target_pkg="${2}" 2589 local target_pkg="${2}"
2370 local dev_error="" 2590 local dev_error=""
2371 2591
2372 local stripped_pkg=$(echo "${target_pkg}" | sed \ 2592 local stripped_pkg=$(echo "${target_pkg}" | sed \
2373 's/-[0-9]*\(\.[0-9]\)*$//') 2593 's/-[0-9]*\(\.[0-9]\)*$//')
2374 2594
2595 debug-print "Matching against: ${stripped_pkg}"
2596
2375 if [[ ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then 2597 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2376 dev_error="The ebuild is attempting to use ${target_pkg} that is not" 2598 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2377 dev_error="${dev_error} declared in DEPEND." 2599 dev_error="${dev_error} declared in DEPEND."
2378 if is-java-strict; then 2600 if is-java-strict; then
2601 eerror "${dev_error}"
2379 die "${dev_error}" 2602 die "${dev_error}"
2380 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2603 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2381 eerror "${dev_error}" 2604 eerror "${dev_error}"
2382 elog "Because you have this package installed the package will" 2605 elog "Because you have this package installed the package will"
2383 elog "build without problems, but please report this to" 2606 elog "build without problems, but please report this to"
2384 elog "http://bugs.gentoo.org" 2607 elog "http://bugs.gentoo.org"
2385 fi 2608 fi
2386 fi 2609 fi
2387 2610
2611 if [[ ${limit_to} != build ]]; then
2388 if [[ -z ${build_only} && ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then 2612 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2613 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2389 dev_error="The ebuild is attempting to use ${target_pkg}," 2614 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." 2615 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2616 dev_error="${dev_error} or PDEPEND."
2391 if is-java-strict; then 2617 if is-java-strict; then
2618 eerror "${dev_error}"
2392 die "${dev_error}" 2619 die "${dev_error}"
2393 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2620 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2394 eerror "${dev_error}" 2621 eerror "${dev_error}"
2395 elog "Because you have this package installed the package will" 2622 elog "The package will build without problems, but may fail to run"
2396 elog "build without problems, but please report this to" 2623 elog "if you don't have ${target_pkg} installed, so please report"
2397 elog "http://bugs.gentoo.org" 2624 elog "this to http://bugs.gentoo.org"
2625 fi
2626 fi
2398 fi 2627 fi
2399 fi 2628 fi
2400} 2629}
2401 2630
2402# ------------------------------------------------------------------------------ 2631# ------------------------------------------------------------------------------
2403# @section-end internal 2632# @section-end internal
2404# ------------------------------------------------------------------------------ 2633# ------------------------------------------------------------------------------
2405 2634
2406java-pkg_check-phase() { 2635java-pkg_check-phase() {
2407 local phase=${1} 2636 local phase=${1}
2408 local funcname=${2} 2637 local funcname=${FUNCNAME[1]}
2409 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2638 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2410 java-pkg_announce-qa-violation \
2411 "${funcname} used outside of src_${phase}" 2639 local msg="${funcname} used outside of src_${phase}"
2640 java-pkg_announce-qa-violation "${msg}"
2412 fi 2641 fi
2413} 2642}
2414 2643
2415java-pkg_check-versioned-jar() { 2644java-pkg_check-versioned-jar() {
2416 local jar=${1} 2645 local jar=${1}
2425 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2654 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2426 fi 2655 fi
2427} 2656}
2428 2657
2429java-pkg_announce-qa-violation() { 2658java-pkg_announce-qa-violation() {
2430 if is-java-strict; then 2659 local nodie
2660 if [[ ${1} == "--nodie" ]]; then
2661 nodie="true"
2662 shift
2663 fi
2431 echo "Java QA Notice: $@" >&2 2664 echo "Java QA Notice: $@" >&2
2432 increment-qa-violations 2665 increment-qa-violations
2433 fi 2666 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2434} 2667}
2435 2668
2436increment-qa-violations() { 2669increment-qa-violations() {
2437 let "JAVA_PKG_QA_VIOLATIONS+=1" 2670 let "JAVA_PKG_QA_VIOLATIONS+=1"
2438 export JAVA_PKG_QA_VIOLATIONS 2671 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.93

  ViewVC Help
Powered by ViewVC 1.1.20