/[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.52
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.52 2007/01/28 20:58:29 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
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 232 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 233 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 234 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 298 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 299
256 java-pkg_init_paths_ 300 java-pkg_init_paths_
257 301
258 local jar jar_dir jar_file 302 local jar jar_dir jar_file
259 for jar in "$@"; do 303 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 304 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 305 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 306 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*" 307 && die "Called ${FUNCNAME} on a directory $*"
264 # nelchael: we should strip ${D} in this case too, here's why: 308 # nelchael: we should strip ${D} in this case too, here's why:
292 local original_jar="${1}" 336 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 337 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 338 local new_jar_dest="${T}/${new_jar}"
295 339
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 340 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 341 [[ ! -f ${original_jar} ]] \
342 && die "${original_jar} does not exist or is not a file!"
298 343
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 344 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \ 345 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 346 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 347 java-pkg_dojar "${new_jar_dest}"
515 java-pkg_init_paths_ 560 java-pkg_init_paths_
516 561
517 local zip_name="${PN}-src.zip" 562 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 563 local zip_path="${T}/${zip_name}"
519 local dir 564 local dir
520 for dir in ${@}; do 565 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 566 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 567 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 568 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 569 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 570 local result=$?
550# @param $1 - filename of launcher to create 595# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 596# @param $2 - options, as follows:
552# --main the.main.class.too.start 597# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 598# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 599# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 600# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 601# --pwd Directory the launcher changes to before executing java
557# -into 602# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 603# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 604# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 605java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 606 debug-print-function ${FUNCNAME} $*
562 607
563 java-pkg_check-phase install 608 java-pkg_check-phase install
604 fi 649 fi
605 fi 650 fi
606 651
607 # Write the actual script 652 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 653 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 654 if [[ -n "${pre}" ]]; then
655 if [[ -f "${pre}" ]]; then
656 cat "${pre}" >> "${target}"
657 else
658 die "-pre specified file '${pre}' does not exist"
659 fi
660 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 661 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 662 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 663 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 664 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 665
706# Example: get a specific jar from xerces slot 2, and name it diffrently 757# 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 758# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 759# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 760# java-pkg_jar-from --build-only junit junit.jar
710# 761#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 762# @param $opt
712# package.env DEPEND line. 763# --build-only - makes the jar(s) not added into package.env DEPEND line.
764# (assumed automatically when called inside src_test)
765# --with-dependencies - get jars also from requested package's dependencies
766# transitively.
767# --into $dir - symlink jar(s) into $dir (must exist) instead of .
713# @param $1 - Package to get jars from. 768# @param $1 - Package to get jars from.
714# @param $2 - jar from package. If not specified, all jars will be used. 769# @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 770# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 771# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 772# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 773# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 774java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 775 debug-print-function ${FUNCNAME} $*
721 776
722 local build_only="" 777 local build_only=""
778 local destdir="."
779 local deep=""
780
781 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
723 782
783 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 784 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 785 build_only="true"
786 elif [[ "${1}" = "--with-dependencies" ]]; then
787 deep="--with-dependencies"
788 elif [[ "${1}" = "--into" ]]; then
789 destdir="${2}"
790 shift
791 else
792 die "java-pkg_jar-from called with unknown parameter: ${1}"
793 fi
726 shift 794 shift
727 fi 795 done
728 796
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 797 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 798
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 799 [[ -z ${target_pkg} ]] && die "Must specify a package"
732 800
733 # default destjar to the target jar 801 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 802 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 803
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 804 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 805 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 806 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 807 [[ $? != 0 ]] && die ${error_msg}
740 808
809 pushd ${destdir} > /dev/null \
810 || die "failed to change directory to ${destdir}"
741 local jar 811 local jar
742 for jar in ${classpath//:/ }; do 812 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 813 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 814 if [[ ! -f "${jar}" ]] ; then
745 debug-print "${jar} from ${target_pkg} does not exist" 815 debug-print "${jar} from ${target_pkg} does not exist"
758 || die "Failed to make symlink from ${jar} to ${destjar}" 828 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 829 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
760 return 0 830 return 0
761 fi 831 fi
762 done 832 done
833 popd > /dev/null
763 # if no target was specified, we're ok 834 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 835 if [[ -z "${target_jar}" ]] ; then
765 return 0 836 return 0
766 # otherwise, die bitterly 837 # otherwise, die bitterly
767 else 838 else
791# Example: Get the classpath for xerces-2 and xalan, 862# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 863# java-pkg_getjars xerces-2,xalan
793# Example Return: 864# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 865# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 866#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 867# @param $opt
797# package.env DEPEND line. 868# --build-only - makes the jar(s) not added into package.env DEPEND line.
869# (assumed automatically when called inside src_test)
870# --with-dependencies - get jars also from requested package's dependencies
871# transitively.
798# @param $2 - list of packages to get jars from 872# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 873# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 874# ------------------------------------------------------------------------------
801java-pkg_getjars() { 875java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 876 debug-print-function ${FUNCNAME} $*
803 877
878 local build_only=""
879 local deep=""
880
881 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
882
883 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 884 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 885 build_only="true"
886 elif [[ "${1}" = "--with-dependencies" ]]; then
887 deep="--with-dependencies"
888 else
889 die "java-pkg_jar-from called with unknown parameter: ${1}"
890 fi
806 shift 891 shift
807 fi 892 done
808 893
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 894 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
810 895
811 local classpath pkgs="${1}" 896 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})" 897 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 898 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 899 debug-print "${pkgs}:${jars}"
815 900
816 if [[ -z "${classpath}" ]]; then 901 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}" 902 classpath="${jars}"
844# @example 929# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 930# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 931# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 932# /usr/share/xerces-2/lib/xml-apis.jar
848# 933#
849# @param $1 - (optional) "--build-only" makes the jar not added into 934# @param $opt
850# package.env DEPEND line. 935# --build-only - makes the jar not added into package.env DEPEND line.
851# @param $1 - package to use 936# @param $1 - package to use
852# @param $2 - jar to get 937# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 938# ------------------------------------------------------------------------------
854java-pkg_getjar() { 939java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 940 debug-print-function ${FUNCNAME} $*
856 941
857 local build_only="" 942 local build_only=""
943
944 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true"
858 945
946 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 947 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 948 build_only="true"
949 else
950 die "java-pkg_jar-from called with unknown parameter: ${1}"
951 fi
861 shift 952 shift
862 fi 953 done
954
955 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 956
864 local pkg="${1}" target_jar="${2}" jar 957 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 958 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 959 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 960
1009# 1102#
1010# export DEPEND="${DEPEND} ${depstr}" 1103# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1104# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1105#}
1013 1106
1107# ------------------------------------------------------------------------------
1108# @ebuild-function java-pkg_find-normal-jars
1109#
1110# Find the files with suffix .jar file in the given directory or $WORKDIR
1111#
1112# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1113# ------------------------------------------------------------------------------
1114java-pkg_find-normal-jars() {
1115 local dir=$1
1116 [[ "${dir}" ]] || dir="${WORKDIR}"
1117 local found
1118 for jar in $(find "${dir}" -name "*.jar" -type f); do
1119 echo "${jar}"
1120 found="true"
1121 done
1122 [[ "${found}" ]]
1123 return $?
1124}
1125
1126# ------------------------------------------------------------------------------
1127# @ebuild-function java-pkg_ensure-no-bundled-jars
1128#
1129# 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 1130# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1131# to system jar files or bundled jars removed.
1132# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1133java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1134 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1135
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1136 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1137 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1138 echo "Bundled jars found:"
1023 local jar 1139 local jar
1024 for jar in ${bundled_jars}; do 1140 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1141 echo $(pwd)${jar/./}
1026 done 1142 done
1027 die "Bundled jars found!" 1143 die "Bundled jars found!"
1028
1029 fi 1144 fi
1030 popd >/dev/null 2>/dev/null
1031} 1145}
1032 1146
1033# ------------------------------------------------------------------------------ 1147# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1148# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1149#
1297 die "Need USE=test enabled" 1411 die "Need USE=test enabled"
1298 fi 1412 fi
1299} 1413}
1300 1414
1301# ------------------------------------------------------------------------------ 1415# ------------------------------------------------------------------------------
1416# @ebuild-function java-pkg_register-ant-task
1417#
1418# Register this package as ant task, so that ant will load it when no specific
1419# ANT_TASKS are specified. Note that even without this registering, all packages
1420# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1421# packages, but can be also used by other ebuilds that used to symlink their
1422# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1423# compatibility.
1424#
1425# @param --version x.y Register only for ant version x.y (otherwise for any ant
1426# version). Used by the ant-* packages to prevent loading of mismatched
1427# ant-core ant tasks after core was updated, before the tasks are updated,
1428# without a need for blockers.
1429# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1430# ------------------------------------------------------------------------------
1431java-pkg_register-ant-task() {
1432 local TASKS_DIR="tasks"
1433
1434 # check for --version x.y parameters
1435 while [[ -n "${1}" && -n "${2}" ]]; do
1436 local var="${1#--}"
1437 local val="${2}"
1438 if [[ "${var}" == "version" ]]; then
1439 TASKS_DIR="tasks-${val}"
1440 else
1441 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1442 fi
1443 shift 2
1444 done
1445
1446 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1447
1448 dodir /usr/share/ant/${TASKS_DIR}
1449 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1450}
1451
1452# ------------------------------------------------------------------------------
1453# @internal-function java-pkg_ant-tasks-from-deps
1454#
1455# Function to determine ANT_TASKS from DEPEND variable for backwards
1456# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1457# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1458# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1459# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1460# be a problem, the worst it can do is activace all tasks when not needed.
1461# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1462# insufficient dependencies, otherwise all available tasks are used for
1463# backwards compatilbility.
1464#
1465# @return "all" or "none"
1466# ------------------------------------------------------------------------------
1467java-pkg_ant-tasks-from-deps() {
1468 local found_ant found_ant_tasks
1469
1470 for dep in ${DEPEND}
1471 do
1472 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1473 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1474 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1475 done
1476
1477 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1478 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1479 echo "all"
1480 else
1481 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1482 # so we deactivate all tasks that may be installed
1483 echo "none"
1484 fi
1485}
1486
1487# ------------------------------------------------------------------------------
1488# @internal-function java-pkg_ant-tasks-depend
1489#
1490# Translates the WANT_ANT_TASKS variable into valid dependencies.
1491# ------------------------------------------------------------------------------
1492java-pkg_ant-tasks-depend() {
1493 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1494
1495 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1496 local DEP=""
1497 for i in ${WANT_ANT_TASKS}
1498 do
1499 if [[ ${i} != ant-* ]]; then
1500 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1501 return 1
1502 fi
1503 DEP="${DEP}dev-java/${i} "
1504 done
1505 echo ${DEP}
1506 return 0
1507 else
1508 return 0
1509 fi
1510}
1511
1512# ------------------------------------------------------------------------------
1302# @section-end helper 1513# @section-end helper
1303# ------------------------------------------------------------------------------ 1514# ------------------------------------------------------------------------------
1304 1515
1305# ------------------------------------------------------------------------------ 1516# ------------------------------------------------------------------------------
1306# @section-begin build 1517# @section-begin build
1312 1523
1313# ------------------------------------------------------------------------------ 1524# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1525# @ebuild-function eant
1315# 1526#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1527# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1528# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1529# variables:
1530# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1531# gentoo.classpath property. Be sure to call
1532# java-ant_rewrite-classpath in src_unpack.
1533# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1534# ------------------------------------------------------------------------------
1320eant() { 1535eant() {
1321 debug-print-function ${FUNCNAME} $* 1536 debug-print-function ${FUNCNAME} $*
1322 1537
1323 # FIXME get this working 1538 # FIXME get this working
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1539# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1325# java-pkg_announce-qa-violation \ 1540# java-pkg_announce-qa-violation \
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1541# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1542# fi
1328 1543
1329 local antflags="-Dnoget=true" 1544 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then
1545 local msg="You should inherit java-ant-2 when using eant"
1546 java-pkg_announce-qa-violation ${msg}
1547 die ${msg}
1548 fi
1549
1550 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1330 java-pkg_init-compiler_ 1551 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1552 local compiler="${GENTOO_COMPILER}"
1332 1553
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1554 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334 1555
1352 if is-java-strict; then 1573 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1574 einfo "Disabling system classpath for ant"
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1575 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1355 fi 1576 fi
1356 1577
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1578 for arg in "${@}"; do
1358 antflags="${antflags} -debug" 1579 if [[ ${arg} = -lib ]]; then
1580 if is-java-strict; then
1581 eerror "You should not use the -lib argument to eant because it will fail"
1582 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from or"
1583 eerror "or ant properties to make dependencies available."
1584 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1585 eerror "split ant (>=dev-java/ant-core-1.7)."
1586 die "eant -lib is deprecated/forbidden"
1587 else
1588 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1589 echo "more info."
1590 fi
1591 fi
1592 done
1593
1594 if has_version ">=dev-java/ant-core-1.7.0"; then
1595 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1596 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1597
1598 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1599 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1600
1601 if is-java-strict; then
1602 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1603 if [[ -z "${ANT_TASKS}" ]]; then
1604 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1605 fi
1606 else
1607 # if ant-tasks is not set by ebuild or forced, activate all of them
1608 ANT_TASKS="${ANT_TASKS:-all}"
1609 fi
1610
1611 # at this point, ANT_TASKS should be "all", "none" or explicit list
1612 if [[ "${ANT_TASKS}" == "all" ]]; then
1613 einfo "Using all available ANT_TASKS"
1614 elif [[ "${ANT_TASKS}" == "none" ]]; then
1615 einfo "Disabling all optional ANT_TASKS"
1616 else
1617 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1618 fi
1619
1620 export ANT_TASKS
1621 fi
1622
1623 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1624 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1625
1626 local gcp="${EANT_GENTOO_CLASSPATH}"
1627
1628 if [[ "${gcp}" ]]; then
1629 local cp="$(java-pkg_getjars ${gcp})"
1630 # It seems ant does not like single quotes around ${cp}
1631 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1359 fi 1632 fi
1360 1633
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1634 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1635 debug-print "Calling ant: ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1636 ant ${antflags} "${@}" || die "eant failed"
1363 1637
1364} 1638}
1365 1639
1366# ------------------------------------------------------------------------------ 1640# ------------------------------------------------------------------------------
1479 # When users have crazy classpaths some packages can fail to compile. 1753 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 1754 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 1755 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 1756 # from the CLASSPATH.
1483 unset CLASSPATH 1757 unset CLASSPATH
1758
1759 # Unset external ANT_ stuff
1760 unset ANT_TASKS
1761 unset ANT_OPTS
1484} 1762}
1485 1763
1486# ------------------------------------------------------------------------------ 1764# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 1765# @function-internal java-pkg-init-compiler_
1488# 1766#

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

  ViewVC Help
Powered by ViewVC 1.1.20