/[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.38 Revision 1.55
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.38 2006/12/31 19:30:54 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.55 2007/01/30 12:50:25 betelgeuse 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
36# ----------------------------------------------------------------------------- 36# -----------------------------------------------------------------------------
37 37
38# Make sure we use java-config-2 38# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 39export WANT_JAVA_CONFIG="2"
40 40
41# TODO document 41# -----------------------------------------------------------------------------
42# @variable-external WANT_ANT_TASKS
43# @variable-default ""
44#
45# An $IFS separated list of ant tasks.
46# Ebuild can specify this variable before inheriting java-ant-2 eclass to
47# determine ANT_TASKS it needs. They will be automatically translated to
48# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
49# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
50# Ebuilds that need to depend conditionally on certain tasks and specify them
51# differently for different eant calls can't use this simplified approach.
52# You also cannot specify version or anything else than ant-*.
53#
54# @example WANT_ANT_TASKS="ant-junit ant-trax"
55#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS
59
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43 66
44# ----------------------------------------------------------------------------- 67# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
46# 69#
128# JAVA_PKG_COMPILERS_CONF. 151# JAVA_PKG_COMPILERS_CONF.
129# 152#
130# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
156# -----------------------------------------------------------------------------
157
158# -----------------------------------------------------------------------------
159# @variable-external JAVA_PKG_FORCE_ANT_TASKS
160#
161# An $IFS separated list of ant tasks. Can be set in environment before calling
162# emerge/ebuild to override variables set in ebuild, mainly for testing before
163# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
164# eant() call, not the dependencies specified in WANT_ANT_TASKS.
165#
166# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167# ebuild foo.ebuild compile
168#
169# @seealso WANT_ANT_TASKS
133# ----------------------------------------------------------------------------- 170# -----------------------------------------------------------------------------
134 171
135# TODO document me 172# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
137 174
174 # Create JARDEST if it doesn't exist 211 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 212 dodir ${JAVA_PKG_JARDEST}
176 213
177 local jar 214 local jar
178 # for each jar 215 # for each jar
179 for jar in "$@"; do 216 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 217 local jar_basename=$(basename "${jar}")
181 218
182 java-pkg_check-versioned-jar ${jar_basename} 219 java-pkg_check-versioned-jar ${jar_basename}
183 220
184 # check if it exists 221 # check if it exists
185 if [[ -e "${jar}" ]] ; then 222 if [[ -e "${jar}" ]] ; then
223 # Don't overwrite if jar has already been installed with the same
224 # name
225 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
226 if [[ -e "${dest}" ]]; then
227 ewarn "Overwriting ${dest}"
228 fi
229
186 # install it into JARDEST if it's a non-symlink 230 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 231 if [[ ! -L "${jar}" ]] ; then
232 #but first check class version when in strict mode.
233 is-java-strict && java-pkg_verify-classes "${jar}"
234
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 235 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 236 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 237 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 238 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 239 # make a symlink to the original jar if it's symlink
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 301 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 302
256 java-pkg_init_paths_ 303 java-pkg_init_paths_
257 304
258 local jar jar_dir jar_file 305 local jar jar_dir jar_file
259 for jar in "$@"; do 306 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 307 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 308 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 309 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*" 310 && die "Called ${FUNCNAME} on a directory $*"
311
312 #check that class version correct when in strict mode
313 is-java-strict && java-pkg_verify-classes "${jar}"
314
264 # nelchael: we should strip ${D} in this case too, here's why: 315 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call: 316 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar 317 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will 318 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env 319 # record paths with ${D} in package.env
292 local original_jar="${1}" 343 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 344 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 345 local new_jar_dest="${T}/${new_jar}"
295 346
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 347 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 348 [[ ! -f ${original_jar} ]] \
349 && die "${original_jar} does not exist or is not a file!"
298 350
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 351 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \ 352 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 353 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 354 java-pkg_dojar "${new_jar_dest}"
515 java-pkg_init_paths_ 567 java-pkg_init_paths_
516 568
517 local zip_name="${PN}-src.zip" 569 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 570 local zip_path="${T}/${zip_name}"
519 local dir 571 local dir
520 for dir in ${@}; do 572 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 573 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 574 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 575 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 576 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 577 local result=$?
550# @param $1 - filename of launcher to create 602# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 603# @param $2 - options, as follows:
552# --main the.main.class.too.start 604# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 605# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 606# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 607# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 608# --pwd Directory the launcher changes to before executing java
557# -into 609# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 610# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 611# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 612java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 613 debug-print-function ${FUNCNAME} $*
562 614
563 java-pkg_check-phase install 615 java-pkg_check-phase install
604 fi 656 fi
605 fi 657 fi
606 658
607 # Write the actual script 659 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 660 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 661 if [[ -n "${pre}" ]]; then
662 if [[ -f "${pre}" ]]; then
663 cat "${pre}" >> "${target}"
664 else
665 die "-pre specified file '${pre}' does not exist"
666 fi
667 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 668 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 669 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 670 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 671 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 672
706# Example: get a specific jar from xerces slot 2, and name it diffrently 764# Example: get a specific jar from xerces slot 2, and name it diffrently
707# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 765# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 766# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 767# java-pkg_jar-from --build-only junit junit.jar
710# 768#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 769# @param $opt
712# package.env DEPEND line. 770# --build-only - makes the jar(s) not added into package.env DEPEND line.
771# (assumed automatically when called inside src_test)
772# --with-dependencies - get jars also from requested package's dependencies
773# transitively.
774# --into $dir - symlink jar(s) into $dir (must exist) instead of .
713# @param $1 - Package to get jars from. 775# @param $1 - Package to get jars from.
714# @param $2 - jar from package. If not specified, all jars will be used. 776# @param $2 - jar from package. If not specified, all jars will be used.
715# @param $3 - When a single jar is specified, destination filename of the 777# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 778# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 779# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 780# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 781java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 782 debug-print-function ${FUNCNAME} $*
721 783
722 local build_only="" 784 local build_only=""
785 local destdir="."
786 local deep=""
787
788 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
723 789
790 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 791 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 792 build_only="true"
793 elif [[ "${1}" = "--with-dependencies" ]]; then
794 deep="--with-dependencies"
795 elif [[ "${1}" = "--into" ]]; then
796 destdir="${2}"
797 shift
798 else
799 die "java-pkg_jar-from called with unknown parameter: ${1}"
800 fi
726 shift 801 shift
727 fi 802 done
728 803
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 804 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 805
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 806 [[ -z ${target_pkg} ]] && die "Must specify a package"
732 807
733 # default destjar to the target jar 808 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 809 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 810
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 811 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 812 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 813 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 814 [[ $? != 0 ]] && die ${error_msg}
740 815
816 pushd ${destdir} > /dev/null \
817 || die "failed to change directory to ${destdir}"
741 local jar 818 local jar
742 for jar in ${classpath//:/ }; do 819 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 820 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 821 if [[ ! -f "${jar}" ]] ; then
745 debug-print "${jar} from ${target_pkg} does not exist" 822 debug-print "${jar} from ${target_pkg} does not exist"
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 832 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}" 833 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \ 834 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}" 835 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 836 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
837 popd > /dev/null
760 return 0 838 return 0
761 fi 839 fi
762 done 840 done
841 popd > /dev/null
763 # if no target was specified, we're ok 842 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 843 if [[ -z "${target_jar}" ]] ; then
765 return 0 844 return 0
766 # otherwise, die bitterly 845 # otherwise, die bitterly
767 else 846 else
791# Example: Get the classpath for xerces-2 and xalan, 870# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 871# java-pkg_getjars xerces-2,xalan
793# Example Return: 872# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 873# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 874#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 875# @param $opt
797# package.env DEPEND line. 876# --build-only - makes the jar(s) not added into package.env DEPEND line.
877# (assumed automatically when called inside src_test)
878# --with-dependencies - get jars also from requested package's dependencies
879# transitively.
798# @param $2 - list of packages to get jars from 880# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 881# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 882# ------------------------------------------------------------------------------
801java-pkg_getjars() { 883java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 884 debug-print-function ${FUNCNAME} $*
803 885
886 local build_only=""
887 local deep=""
888
889 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
890
891 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 892 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 893 build_only="true"
894 elif [[ "${1}" = "--with-dependencies" ]]; then
895 deep="--with-dependencies"
896 else
897 die "java-pkg_jar-from called with unknown parameter: ${1}"
898 fi
806 shift 899 shift
807 fi 900 done
808 901
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 902 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
810 903
811 local classpath pkgs="${1}" 904 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})" 905 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 906 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 907 debug-print "${pkgs}:${jars}"
815 908
816 if [[ -z "${classpath}" ]]; then 909 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}" 910 classpath="${jars}"
844# @example 937# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 938# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 939# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 940# /usr/share/xerces-2/lib/xml-apis.jar
848# 941#
849# @param $1 - (optional) "--build-only" makes the jar not added into 942# @param $opt
850# package.env DEPEND line. 943# --build-only - makes the jar not added into package.env DEPEND line.
851# @param $1 - package to use 944# @param $1 - package to use
852# @param $2 - jar to get 945# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 946# ------------------------------------------------------------------------------
854java-pkg_getjar() { 947java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 948 debug-print-function ${FUNCNAME} $*
856 949
857 local build_only="" 950 local build_only=""
951
952 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
858 953
954 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 955 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 956 build_only="true"
957 else
958 die "java-pkg_jar-from called with unknown parameter: ${1}"
959 fi
861 shift 960 shift
862 fi 961 done
962
963 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 964
864 local pkg="${1}" target_jar="${2}" jar 965 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 966 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 967 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 968
1009# 1110#
1010# export DEPEND="${DEPEND} ${depstr}" 1111# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1112# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1113#}
1013 1114
1115# ------------------------------------------------------------------------------
1116# @ebuild-function java-pkg_find-normal-jars
1117#
1118# Find the files with suffix .jar file in the given directory or $WORKDIR
1119#
1120# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1121# ------------------------------------------------------------------------------
1122java-pkg_find-normal-jars() {
1123 local dir=$1
1124 [[ "${dir}" ]] || dir="${WORKDIR}"
1125 local found
1126 for jar in $(find "${dir}" -name "*.jar" -type f); do
1127 echo "${jar}"
1128 found="true"
1129 done
1130 [[ "${found}" ]]
1131 return $?
1132}
1133
1134# ------------------------------------------------------------------------------
1135# @ebuild-function java-pkg_ensure-no-bundled-jars
1136#
1137# Try to locate bundled jar files in ${WORKDIR} and die if found.
1014# This should be used after S has been populated with symlinks to jars 1138# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1139# to system jar files or bundled jars removed.
1140# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1141java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1142 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1143
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1144 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1145 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1146 echo "Bundled jars found:"
1023 local jar 1147 local jar
1024 for jar in ${bundled_jars}; do 1148 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1149 echo $(pwd)${jar/./}
1026 done 1150 done
1027 die "Bundled jars found!" 1151 die "Bundled jars found!"
1028
1029 fi 1152 fi
1030 popd >/dev/null 2>/dev/null
1031} 1153}
1032 1154
1033# ------------------------------------------------------------------------------ 1155# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1156# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1157#
1297 die "Need USE=test enabled" 1419 die "Need USE=test enabled"
1298 fi 1420 fi
1299} 1421}
1300 1422
1301# ------------------------------------------------------------------------------ 1423# ------------------------------------------------------------------------------
1424# @ebuild-function java-pkg_register-ant-task
1425#
1426# Register this package as ant task, so that ant will load it when no specific
1427# ANT_TASKS are specified. Note that even without this registering, all packages
1428# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1429# packages, but can be also used by other ebuilds that used to symlink their
1430# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1431# compatibility.
1432#
1433# @param --version x.y Register only for ant version x.y (otherwise for any ant
1434# version). Used by the ant-* packages to prevent loading of mismatched
1435# ant-core ant tasks after core was updated, before the tasks are updated,
1436# without a need for blockers.
1437# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1438# ------------------------------------------------------------------------------
1439java-pkg_register-ant-task() {
1440 local TASKS_DIR="tasks"
1441
1442 # check for --version x.y parameters
1443 while [[ -n "${1}" && -n "${2}" ]]; do
1444 local var="${1#--}"
1445 local val="${2}"
1446 if [[ "${var}" == "version" ]]; then
1447 TASKS_DIR="tasks-${val}"
1448 else
1449 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1450 fi
1451 shift 2
1452 done
1453
1454 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1455
1456 dodir /usr/share/ant/${TASKS_DIR}
1457 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1458}
1459
1460# ------------------------------------------------------------------------------
1461# @internal-function java-pkg_ant-tasks-from-deps
1462#
1463# Function to determine ANT_TASKS from DEPEND variable for backwards
1464# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1465# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1466# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1467# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1468# be a problem, the worst it can do is activace all tasks when not needed.
1469# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1470# insufficient dependencies, otherwise all available tasks are used for
1471# backwards compatilbility.
1472#
1473# @return "all" or "none"
1474# ------------------------------------------------------------------------------
1475java-pkg_ant-tasks-from-deps() {
1476 local found_ant found_ant_tasks
1477
1478 for dep in ${DEPEND}
1479 do
1480 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1481 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1482 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1483 done
1484
1485 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1486 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1487 echo "all"
1488 else
1489 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1490 # so we deactivate all tasks that may be installed
1491 echo "none"
1492 fi
1493}
1494
1495# ------------------------------------------------------------------------------
1496# @internal-function java-pkg_ant-tasks-depend
1497#
1498# Translates the WANT_ANT_TASKS variable into valid dependencies.
1499# ------------------------------------------------------------------------------
1500java-pkg_ant-tasks-depend() {
1501 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1502
1503 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1504 local DEP=""
1505 for i in ${WANT_ANT_TASKS}
1506 do
1507 if [[ ${i} != ant-* ]]; then
1508 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1509 return 1
1510 fi
1511 DEP="${DEP}dev-java/${i} "
1512 done
1513 echo ${DEP}
1514 return 0
1515 else
1516 return 0
1517 fi
1518}
1519
1520# ------------------------------------------------------------------------------
1302# @section-end helper 1521# @section-end helper
1303# ------------------------------------------------------------------------------ 1522# ------------------------------------------------------------------------------
1304 1523
1305# ------------------------------------------------------------------------------ 1524# ------------------------------------------------------------------------------
1306# @section-begin build 1525# @section-begin build
1312 1531
1313# ------------------------------------------------------------------------------ 1532# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1533# @ebuild-function eant
1315# 1534#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1535# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1536# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1537# variables:
1538# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1539# gentoo.classpath property. Be sure to call
1540# java-ant_rewrite-classpath in src_unpack.
1541# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1542# ------------------------------------------------------------------------------
1320eant() { 1543eant() {
1321 debug-print-function ${FUNCNAME} $* 1544 debug-print-function ${FUNCNAME} $*
1322 1545
1323 # FIXME get this working 1546 # FIXME get this working
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1547# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1325# java-pkg_announce-qa-violation \ 1548# java-pkg_announce-qa-violation \
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1549# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1550# fi
1328 1551
1329 local antflags="-Dnoget=true" 1552 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1553 local msg="You should inherit java-ant-2 when using eant"
1554 java-pkg_announce-qa-violation ${msg}
1555 die ${msg}
1556 fi
1557
1558 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1330 java-pkg_init-compiler_ 1559 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1560 local compiler="${GENTOO_COMPILER}"
1332 1561
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1562 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334 1563
1352 if is-java-strict; then 1581 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1582 einfo "Disabling system classpath for ant"
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1583 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1355 fi 1584 fi
1356 1585
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1586 for arg in "${@}"; do
1358 antflags="${antflags} -debug" 1587 if [[ ${arg} = -lib ]]; then
1588 if is-java-strict; then
1589 eerror "You should not use the -lib argument to eant because it will fail"
1590 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1591 eerror "or ant properties to make dependencies available."
1592 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1593 eerror "split ant (>=dev-java/ant-core-1.7)."
1594 die "eant -lib is deprecated/forbidden"
1595 else
1596 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1597 echo "more info."
1598 fi
1599 fi
1600 done
1601
1602 if has_version ">=dev-java/ant-core-1.7.0"; then
1603 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1604 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1605
1606 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1607 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1608
1609 if is-java-strict; then
1610 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1611 if [[ -z "${ANT_TASKS}" ]]; then
1612 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1613 fi
1614 else
1615 # if ant-tasks is not set by ebuild or forced, activate all of them
1616 ANT_TASKS="${ANT_TASKS:-all}"
1617 fi
1618
1619 # at this point, ANT_TASKS should be "all", "none" or explicit list
1620 if [[ "${ANT_TASKS}" == "all" ]]; then
1621 einfo "Using all available ANT_TASKS"
1622 elif [[ "${ANT_TASKS}" == "none" ]]; then
1623 einfo "Disabling all optional ANT_TASKS"
1624 else
1625 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1626 fi
1627
1628 export ANT_TASKS
1629 fi
1630
1631 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1632 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1633
1634 local gcp="${EANT_GENTOO_CLASSPATH}"
1635
1636 if [[ "${gcp}" ]]; then
1637 local cp="$(java-pkg_getjars ${gcp})"
1638 # It seems ant does not like single quotes around ${cp}
1639 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1359 fi 1640 fi
1360 1641
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1642 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1643 debug-print "Calling ant: ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1644 ant ${antflags} "${@}" || die "eant failed"
1363 1645
1364} 1646}
1365 1647
1366# ------------------------------------------------------------------------------ 1648# ------------------------------------------------------------------------------
1479 # When users have crazy classpaths some packages can fail to compile. 1761 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 1762 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 1763 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 1764 # from the CLASSPATH.
1483 unset CLASSPATH 1765 unset CLASSPATH
1766
1767 # Unset external ANT_ stuff
1768 unset ANT_TASKS
1769 unset ANT_OPTS
1484} 1770}
1485 1771
1486# ------------------------------------------------------------------------------ 1772# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 1773# @function-internal java-pkg-init-compiler_
1488# 1774#
1928 fi 2214 fi
1929} 2215}
1930 2216
1931# TODO document 2217# TODO document
1932# Verify that the classes were compiled for the right source / target 2218# Verify that the classes were compiled for the right source / target
2219# If $1 is present will check that file otherwise the ${D} directory
2220# recursively.
1933java-pkg_verify-classes() { 2221java-pkg_verify-classes() {
1934 ebegin "Verifying java class versions"
1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2222 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2223 local target=$(java-pkg_get-target)
2224 ebegin "Verifying java class versions (target: ${target})"
2225 if [[ -n "${1}" ]]; then
2226 class-version-verify.py -t ${target} "${1}"
2227 else
1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2228 class-version-verify.py -t ${target} -r "${D}"
2229 fi
1937 result=$? 2230 result=$?
1938 eend ${result} 2231 eend ${result}
1939 if [[ ${result} == 0 ]]; then 2232 if [[ ${result} != 0 ]]; then
1940 einfo "All good"
1941 else
1942 ewarn "Possible problem" 2233 ewarn "Possible problem"
1943 die "Bad class files found" 2234 die "Bad class files found"
1944 fi 2235 fi
1945} 2236}
1946 2237

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.55

  ViewVC Help
Powered by ViewVC 1.1.20