From dd871b518433f262f063eced0f8ac06faaf602a2 Mon Sep 17 00:00:00 2001 From: Vlastimil Babka Date: Sun, 21 Jan 2007 01:20:21 +0000 Subject: [PATCH] Add split-ant functionality to relevant eclasses. ---------------------------------------------------------------------- --- eclass/java-ant-2.eclass | 19 +++- eclass/java-utils-2.eclass | 177 +++++++++++++++++++++++++++++++++++-- 2 files changed, 190 insertions(+), 6 deletions(-) diff --git a/eclass/java-ant-2.eclass b/eclass/java-ant-2.eclass index a82ab469b5e9..484d7126915c 100644 --- a/eclass/java-ant-2.eclass +++ b/eclass/java-ant-2.eclass @@ -10,7 +10,7 @@ # # Licensed under the GNU General Public License, v2 # -# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.13 2007/01/20 22:27:34 betelgeuse Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.14 2007/01/21 01:20:21 caster Exp $ inherit java-utils-2 @@ -18,9 +18,26 @@ inherit java-utils-2 # ant to build. In particular, it will attempt to fix build.xml files, so that # they use the appropriate 'target' and 'source' attributes. +# ----------------------------------------------------------------------------- +# @variable-preinherit WANT_ANT_TASKS +# @variable-default "" +# +# Please see the description in java-utils-2.eclass. +#WANT_ANT_TASKS + # We need some tools from javatoolkit. We also need portage 2.1 for phase hooks DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}" +# add ant-core into DEPEND, unless disabled [[ "${JAVA_ANT_DISABLE_ANT_CORE_DEP:-true}" ]] || DEPEND="${DEPEND} dev-java/ant-core" +# add ant tasks specified in WANT_ANT_TASKS to DEPEND +local ANT_TASKS_DEPEND; +ANT_TASKS_DEPEND="$(java-pkg_ant-tasks-depend)" +# check that java-pkg_ant-tasks-depend didn't fail +if [[ $? != 0 ]]; then + eerror "${ANT_TASKS_DEPEND}" + die "java-pkg_ant-tasks-depend() failed" +fi +DEPEND="${DEPEND} ${ANT_TASKS_DEPEND}" # ------------------------------------------------------------------------------ # @global JAVA_PKG_BSFIX diff --git a/eclass/java-utils-2.eclass b/eclass/java-utils-2.eclass index cb0baf5e68f0..d7dcd1236121 100644 --- a/eclass/java-utils-2.eclass +++ b/eclass/java-utils-2.eclass @@ -6,7 +6,7 @@ # # Licensed under the GNU General Public License, v2 # -# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.45 2007/01/20 20:50:33 betelgeuse Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.46 2007/01/21 01:20:21 caster Exp $ # ----------------------------------------------------------------------------- @@ -38,7 +38,30 @@ IUSE="elibc_FreeBSD" # Make sure we use java-config-2 export WANT_JAVA_CONFIG="2" -# TODO document +# ----------------------------------------------------------------------------- +# @variable-external WANT_ANT_TASKS +# @variable-default "" +# +# An $IFS separated list of ant tasks. +# Ebuild can specify this variable before inheriting java-ant-2 eclass to +# determine ANT_TASKS it needs. They will be automatically translated to +# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override +# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching. +# Ebuilds that need to depend conditionally on certain tasks and specify them +# differently for different eant calls can't use this simplified approach. +# You also cannot specify version or anything else than ant-*. +# +# @example WANT_ANT_TASKS="ant-junit ant-trax" +# +# @seealso JAVA_PKG_FORCE_ANT_TASKS +# ----------------------------------------------------------------------------- +#WANT_ANT_TASKS + +# @variable-internal JAVA_PKG_PORTAGE_DEP +# +# The version of portage we need to function properly. At this moment it's +# portage with phase hooks support. +# ----------------------------------------------------------------------------- JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" # ----------------------------------------------------------------------------- @@ -132,6 +155,20 @@ JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/com # JAVA_PKG_FORCE_COMPILER="jikes javac" # ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- +# @variable-external JAVA_PKG_FORCE_ANT_TASKS +# +# An $IFS separated list of ant tasks. Can be set in environment before calling +# emerge/ebuild to override variables set in ebuild, mainly for testing before +# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in +# eant() call, not the dependencies specified in WANT_ANT_TASKS. +# +# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \ +# ebuild foo.ebuild compile +# +# @seealso WANT_ANT_TASKS +# ----------------------------------------------------------------------------- + # TODO document me JAVA_PKG_QA_VIOLATIONS=0 @@ -1343,6 +1380,103 @@ java-pkg_ensure-test() { fi } +# ------------------------------------------------------------------------------ +# @ebuild-function java-pkg_register-ant-task +# +# Register this package as ant task, so that ant will load it when no specific +# ANT_TASKS are specified. Note that even without this registering, all packages +# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks +# packages, but can be also used by other ebuilds that used to symlink their +# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards +# compatibility. +# +# @param --version x.y Register only for ant version x.y (otherwise for any ant +# version). Used by the ant-* packages to prevent loading of mismatched +# ant-core ant tasks after core was updated, before the tasks are updated, +# without a need for blockers. +# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT]) +# ------------------------------------------------------------------------------ +java-pkg_register-ant-task() { + local TASKS_DIR="tasks" + + # check for --version x.y parameters + while [[ -n "${1}" && -n "${2}" ]]; do + local var="${1#--}" + local val="${2}" + if [[ "${var}" == "version" ]]; then + TASKS_DIR="tasks-${val}" + else + die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}" + fi + shift 2 + done + + local TASK_NAME="${1:-${JAVA_PKG_NAME}}" + + dodir /usr/share/ant/${TASKS_DIR} + touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}" +} + +# ------------------------------------------------------------------------------ +# @internal-function java-pkg_ant-tasks-from-deps +# +# Function to determine ANT_TASKS from DEPEND variable for backwards +# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or +# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains +# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise +# "none". It's not smart enough to cope with USE flag depends but that shouldn't +# be a problem, the worst it can do is activace all tasks when not needed. +# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with +# insufficient dependencies, otherwise all available tasks are used for +# backwards compatilbility. +# +# @return "all" or "none" +# ------------------------------------------------------------------------------ +java-pkg_ant-tasks-from-deps() { + local found_ant found_ant_tasks + + for dep in ${DEPEND} + do + local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})" + [[ "${ant}" == "dev-java/ant" ]] && found_ant=true + [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true + done + + if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then + java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks" + echo "all" + else + # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant + # so we deactivate all tasks that may be installed + echo "none" + fi +} + +# ------------------------------------------------------------------------------ +# @internal-function java-pkg_ant-tasks-depend +# +# Translates the WANT_ANT_TASKS variable into valid dependencies. +# ------------------------------------------------------------------------------ +java-pkg_ant-tasks-depend() { + debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS} + + if [[ -n "${WANT_ANT_TASKS}" ]]; then + local DEP="" + for i in ${WANT_ANT_TASKS} + do + if [[ ${i} != ant-* ]]; then + echo "Invalid atom in WANT_ANT_TASKS: ${i}" + return 1 + fi + DEP="${DEP}dev-java/${i} " + done + echo ${DEP} + return 0 + else + return 0 + fi +} + # ------------------------------------------------------------------------------ # @section-end helper # ------------------------------------------------------------------------------ @@ -1359,12 +1493,12 @@ java-pkg_ensure-test() { # @ebuild-function eant # # Ant wrapper function. Will use the appropriate compiler, based on user-defined -# compiler. +# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS, # variables: # EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the # gentoo.classpath property. Be sure to call # java-ant_rewrite-classpath in src_unpack. -# +# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. # ------------------------------------------------------------------------------ eant() { debug-print-function ${FUNCNAME} $* @@ -1403,7 +1537,36 @@ eant() { antflags="${antflags} -Dbuild.sysclasspath=ignore" fi - [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} -debug" + if has_version ">=dev-java/ant-core-1.7.0"; then + # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly + ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}" + + # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set + ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}" + + if is-java-strict; then + # if ant-tasks were not set by ebuild or forced, try to determine them from depends + if [[ -z "${ANT_TASKS}" ]]; then + ANT_TASKS="$(java-pkg_ant-tasks-from-deps)" + fi + else + # if ant-tasks is not set by ebuild or forced, activate all of them + ANT_TASKS="${ANT_TASKS:-all}" + fi + + # at this point, ANT_TASKS should be "all", "none" or explicit list + if [[ "${ANT_TASKS}" == "all" ]]; then + einfo "Using all available ANT_TASKS" + elif [[ "${ANT_TASKS}" == "none" ]]; then + einfo "Disabling all optional ANT_TASKS" + else + einfo "Using following ANT_TASKS: ${ANT_TASKS}" + fi + + export ANT_TASKS + fi + + [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug" [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q" local gcp="${EANT_GENTOO_CLASSPATH}" @@ -1538,6 +1701,10 @@ java-pkg_init() { # This also helps prevent unexpected dependencies on random things # from the CLASSPATH. unset CLASSPATH + + # Unset external ANT_ stuff + unset ANT_TASKS + unset ANT_OPTS } # ------------------------------------------------------------------------------ -- 2.26.2