/[gentoo-x86]/eclass/java-ant-2.eclass
Gentoo

Diff of /eclass/java-ant-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.58
1# eclass for ant based Java packages 1# eclass for ant based Java packages
2# 2#
3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org> 3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org>
4# Copyright (c) 2004-2005, Gentoo Foundation 4# Copyright (c) 2004-2011, Gentoo Foundation
5# Changes:
6# May 2007:
7# Made bsfix make one pass for all things and add some glocal targets for
8# setting up the whole thing. Contributed by kiorky
9# (kiorky@cryptelium.net).
10# December 2006:
11# I pretty much rewrote the logic of the bsfix functions
12# and xml-rewrite.py because they were so slow
13# Petteri Räty (betelgeuse@gentoo.org)
5# 14#
6# Licensed under the GNU General Public License, v2 15# Licensed under the GNU General Public License, v2
7# 16#
17# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.58 2014/03/31 16:48:51 mgorny Exp $
8 18
19# @ECLASS: java-ant-2.eclass
20# @MAINTAINER:
21# java@gentoo.org
22# @AUTHOR:
23# kiorky (kiorky@cryptelium.net), Petteri Räty (betelgeuse@gentoo.org)
24# @BLURB: eclass for ant based Java packages
25# @DESCRIPTION:
26# Eclass for Ant-based Java packages. Provides support for both automatic and
27# manual manipulation of build.xml files. Should be inherited after java-pkg-2
28# or java-pkg-opt-2 eclass.
29
9inherit java-utils-2 30inherit java-utils-2 multilib
10 31
11# This eclass provides functionality for Java packages which use 32# This eclass provides functionality for Java packages which use
12# ant to build. In particular, it will attempt to fix build.xml files, so that 33# ant to build. In particular, it will attempt to fix build.xml files, so that
13# they use the appropriate 'target' and 'source' attributes. 34# they use the appropriate 'target' and 'source' attributes.
14 35
36# @ECLASS-VARIABLE: WANT_ANT_TASKS
37# @DEFAULT_UNSET
38# @DESCRIPTION:
39# An $IFS separated list of ant tasks.
40# Ebuild can specify this variable before inheriting java-ant-2 eclass to
41# determine ANT_TASKS it needs. They will be automatically translated to
42# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
43# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
44# Ebuilds that need to depend conditionally on certain tasks and specify them
45# differently for different eant calls can't use this simplified approach.
46# You also cannot specify version or anything else than ant-*.
47#
48# @CODE
49# WANT_ANT_TASKS="ant-junit ant-trax"
50# @CODE
51
52#The implementation of dependencies is handled by java-utils-2.eclass
53#WANT_ANT_TASKS
54
55# @ECLASS-VARIABLE: JAVA_ANT_DISABLE_ANT_CORE_DEP
56# @DEFAULT_UNSET
57# @DESCRIPTION:
58# Setting this variable non-empty before inheriting java-ant-2 disables adding
59# dev-java/ant-core into DEPEND.
60if [[ -z "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]]; then
61 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} >=dev-java/ant-core-1.8.2"
62fi
63
64# add ant tasks specified in WANT_ANT_TASKS to DEPEND
65local ANT_TASKS_DEPEND;
66ANT_TASKS_DEPEND="$(java-pkg_ant-tasks-depend)"
67# check that java-pkg_ant-tasks-depend didn't fail
68if [[ $? != 0 ]]; then
69 eerror "${ANT_TASKS_DEPEND}"
70 die "java-pkg_ant-tasks-depend() failed"
71fi
72
15# We need some tools from javatoolkit. We also need portage 2.1 for phase hooks 73# We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
16DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}" 74# and ant dependencies constructed above. Python is there for
75# java-ant_remove-taskdefs
76JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND}
77 ${ANT_TASKS_DEPEND}
78 ${JAVA_PKG_PORTAGE_DEP}
79 >=dev-java/javatoolkit-0.3.0-r2"
17 80
18# ------------------------------------------------------------------------------ 81# this eclass must be inherited after java-pkg-2 or java-pkg-opt-2
19# @global JAVA_ANT_BSFIX 82# if it's java-pkg-opt-2, ant dependencies are pulled based on USE flag
20# 83if has java-pkg-opt-2 ${INHERITED}; then
84 JAVA_ANT_E_DEPEND="${JAVA_PKG_OPT_USE}? ( ${JAVA_ANT_E_DEPEND} )"
85elif ! has java-pkg-2 ${INHERITED}; then
86 eerror "java-ant-2 eclass can only be inherited AFTER java-pkg-2 or java-pkg-opt-2"
87fi
88
89DEPEND="${JAVA_ANT_E_DEPEND}"
90
91# @ECLASS-VARIABLE: JAVA_PKG_BSFIX
92# @DESCRIPTION:
21# Should we attempt to 'fix' ant build files to include the source/target 93# Should we attempt to 'fix' ant build files to include the source/target
22# attributes when calling javac? 94# attributes when calling javac?
23#
24# default: on
25# ------------------------------------------------------------------------------
26JAVA_ANT_BSFIX=${JAVA_PKG_BSFIX:="on"} 95JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
27 96
28# ------------------------------------------------------------------------------ 97# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_ALL
29# @global JAVA_ANT_BSFIX_ALL 98# @DESCRIPTION:
30#
31# If we're fixing build files, should we try to fix all the ones we can find? 99# If we're fixing build files, should we try to fix all the ones we can find?
32#
33# default: yes
34# ------------------------------------------------------------------------------
35JAVA_ANT_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:="yes"} 100JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
36 101
37# ------------------------------------------------------------------------------ 102# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_NAME
38# @global JAVA_ANT_BSFIX_NAME 103# @DESCRIPTION:
39#
40# Filename of build files to fix/search for 104# Filename of build files to fix/search for
41#
42# default: build.xml
43# ------------------------------------------------------------------------------
44JAVA_ANT_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:="build.xml"} 105JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
45 106
46# ------------------------------------------------------------------------------ 107# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_TARGET_TAGS
47# @global JAVA_ANT_BSFIX_TARGETS_TAGS 108# @DESCRIPTION:
48#
49# Targets to fix the 'source' attribute in 109# Targets to fix the 'source' attribute in
50#
51# default: javac xjavac javac.preset
52# ------------------------------------------------------------------------------
53JAVA_ANT_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:="javac xjavac javac.preset"} 110JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
54 111
55# ------------------------------------------------------------------------------ 112# @ECLASS-VARIABLE: JAVA_PKG_BSFIX_SOURCE_TAGS
56# @global JAVA_ANT_BSFIX_SOURCE_TAGS 113# @DESCRIPTION:
57#
58# Targets to fix the 'target' attribute in 114# Targets to fix the 'target' attribute in
59#
60# default: javacdoc javac xjavac javac.preset
61# ------------------------------------------------------------------------------
62JAVA_ANT_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:="javadoc javac xjavac javac.preset"} 115JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
63 116
64# ------------------------------------------------------------------------------ 117# @ECLASS-VARIABLE: JAVA_ANT_CLASSPATH_TAGS
65# @public java-ant_src_unpack 118# @DESCRIPTION:
66# 119# Targets to add the classpath attribute to
67# Unpacks the source, and attempts to fix build files. 120JAVA_ANT_CLASSPATH_TAGS="javac xjavac"
68# ------------------------------------------------------------------------------ 121
69post_src_unpack() { 122# @ECLASS-VARIABLE: JAVA_ANT_IGNORE_SYSTEM_CLASSES
70 if java-pkg_func-exists ant_src_unpack; then 123# @DEFAULT_UNSET
71 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack" 124# @DESCRIPTION:
72 ant_src_unpack 125# When set, <available> Ant tasks are rewritten to ignore Ant's runtime classpath.
126
127case "${EAPI:-0}" in
128 0|1) : ;;
129 *) EXPORT_FUNCTIONS src_configure ;;
130esac
131
132# @FUNCTION: java-ant-2_src_configure
133# @DESCRIPTION:
134# src_configure rewrites the build.xml files automatically, unless EAPI is undefined, 0 or 1.
135java-ant-2_src_configure() {
136 # if java support is optional, don't perform this when the USE flag is off
137 if has java-pkg-opt-2 ${INHERITED}; then
138 use ${JAVA_PKG_OPT_USE} || return
73 fi 139 fi
140
141 # eant will call us unless called by Portage
142 [[ -e "${T}/java-ant-2_src_configure-run" ]] && return
143
144 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
145 && java-ant_ignore-system-classes "${S}/build.xml"
146
74 java-ant_bsfix 147 java-ant_bsfix
148 touch "${T}/java-ant-2_src_configure-run"
75} 149}
76 150
77# ------------------------------------------------------------------------------ 151# @FUNCTION: java-ant_bsfix
78# @private ant_src_unpack 152# @INTERNAL
153# @DESCRIPTION:
154# Attempts to fix build files.
79# 155#
80# Helper function which does the actual unpacking 156# @CODE
81# ------------------------------------------------------------------------------ 157# Affected by variables:
82# TODO maybe use base.eclass for some patching love?
83#ant_src_unpack() {
84# debug-print-function ${FUNCNAME} $*
85# if [[ -n "${A}" ]]; then
86# unpack ${A}
87# fi
88#}
89
90# ------------------------------------------------------------------------------
91# @private java-ant_bsfix
92#
93# Attempts to fix build files. The following variables will affect its behavior
94# as listed above:
95# JAVA_PKG_BSFIX 158# JAVA_PKG_BSFIX
96# JAVA_PKG_BSFIX_ALL 159# JAVA_PKG_BSFIX_ALL
97# JAVA_PKG_BSFIX_NAME, 160# JAVA_PKG_BSFIX_NAME,
98# JAVA_PKG_BSFIX_SOURCE_TAGS 161# @CODE
99# JAVA_PKG_BSFIX_TARGET_TAGS)
100# ------------------------------------------------------------------------------
101java-ant_bsfix() { 162java-ant_bsfix() {
102 debug-print-function ${FUNCNAME} $* 163 debug-print-function ${FUNCNAME} $*
103 164
104 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return 165 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
105 if ! java-pkg_needs-vm; then 166 if ! java-pkg_needs-vm; then
106 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM" 167 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
107 fi 168 fi
108 169
109 cd "${S}" 170 pushd "${S}" >/dev/null
110 171
111 local find_args="-type f" 172 local find_args=""
112 if [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]]; then 173 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
174
113 find_args="${find_args} -name ${JAVA_PKG_BSFIX_NAME// / -o -name }" 175 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
114 else
115 find_args="${find_args} -maxdepth 1 -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
116 fi
117 176
118 local i=0 177 # This voodoo is done for paths with spaces
119 local -a bsfix_these 178 local bsfix_these
120 while read line; do 179 while read line; do
121 [[ -z ${line} ]] && continue 180 [[ -z ${line} ]] && continue
122 bsfix_these[${i}]="${line}" 181 bsfix_these="${bsfix_these} '${line}'"
123 let i+=1
124 done <<-EOF 182 done <<-EOF
125 $(find ${find_args}) 183 $(find . ${find_args})
126 EOF 184 EOF
185
186 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
187
188 popd > /dev/null
189}
190
191_bsfix_die() {
192 if has_version dev-python/pyxml; then
193 eerror "If the output above contains:"
194 eerror "ImportError:"
195 eerror "/usr/lib/python2.4/site-packages/_xmlplus/parsers/pyexpat.so:"
196 eerror "undefined symbol: PyUnicodeUCS2_DecodeUTF8"
197 eerror "Try re-emerging dev-python/pyxml"
198 die ${1} " Look at the eerror message above"
199 else
200 die ${1}
201 fi
202}
203
204# @FUNCTION: java-ant_bsfix_files
205# @USAGE: <path/to/first/build.xml> [path/to/second.build.xml ...]
206# @DESCRIPTION:
207# Attempts to fix named build files.
208#
209# @CODE
210# Affected by variables:
211# JAVA_PKG_BSFIX_SOURCE_TAGS
212# JAVA_PKG_BSFIX_TARGET_TAGS
213# JAVA_ANT_REWRITE_CLASSPATH
214# JAVA_ANT_JAVADOC_INPUT_DIRS: Where we can find java sources for javadoc
215# input. Can be a space separated list of
216# directories
217# JAVA_ANT_BSFIX_EXTRA_ARGS: You can use this to pass extra variables to the
218# rewriter if you know what you are doing.
219# @CODE
220#
221# If JAVA_ANT_JAVADOC_INPUT_DIRS is set, we will turn on the adding of a basic
222# javadoc target to the ant's build.xml with the javadoc xml-rewriter feature.
223# Then we will set EANT DOC TARGET to the added javadoc target
224# NOTE: the variable JAVA_ANT_JAVADOC_OUTPUT_DIR points where we will
225# generate the javadocs. This is a read-only variable, dont change it.
226
227# When changing this function, make sure that it works with paths with spaces in
228# them.
229java-ant_bsfix_files() {
230 debug-print-function ${FUNCNAME} $*
231
232 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
127 233
128 local want_source="$(java-pkg_get-source)" 234 local want_source="$(java-pkg_get-source)"
129 local want_target="$(java-pkg_get-target)" 235 local want_target="$(java-pkg_get-target)"
130 236
131 debug-print "bsfix: target: ${want_target} source: ${want_source}" 237 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
132 238
133 if [ -z "${want_source}" -o -z "${want_target}" ]; then 239 if [ -z "${want_source}" -o -z "${want_target}" ]; then
134 eerror "Could not find valid -source/-target values" 240 eerror "Could not find valid -source/-target values"
135 eerror "Please file a bug about this on bugs.gentoo.org" 241 eerror "Please file a bug about this on bugs.gentoo.org"
136 die "Could not find valid -source/-target values" 242 die "Could not find valid -source/-target values"
137 else 243 else
138 for (( i = 0 ; i < ${#bsfix_these[@]} ; i++ )); do 244 local files
139 local file="${bsfix_these[${i}]}" 245
140 echo "Rewriting ${file}" 246 for file in "${@}"; do
141 debug-print "bsfix: ${file}" 247 debug-print "${FUNCNAME}: ${file}"
142
143 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
144
145 chmod u+w "${file}"
146
147 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } -a source -v ${want_source} || die "xml-rewrite failed: ${file}"
148 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } -a target -v ${want_target} || die "xml-rewrite failed: ${file}"
149 248
150 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then 249 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
250 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
251 fi
252
253 if [[ ! -w "${file}" ]]; then
254 chmod u+w "${file}" || die "chmod u+w ${file} failed"
255 fi
256
257 files="${files} -f '${file}'"
258 done
259
260 # for javadoc target and all in one pass, we need the new rewriter.
261 local rewriter3="/usr/share/javatoolkit/xml-rewrite-3.py"
262 if [[ ! -f ${rewriter3} ]]; then
263 rewriter3="/usr/$(get_libdir)/javatoolkit/bin/xml-rewrite-3.py"
264 fi
265
266 local rewriter4="/usr/$(get_libdir)/javatoolkit/bin/build-xml-rewrite"
267
268 if [[ -x ${rewriter4} && ${JAVA_ANT_ENCODING} ]]; then
269 [[ ${JAVA_ANT_REWRITE_CLASSPATH} ]] && local gcp="-g"
270 [[ ${JAVA_ANT_ENCODING} ]] && local enc="-e ${JAVA_ANT_ENCODING}"
271 eval echo "cElementTree rewriter"
272 debug-print "${rewriter4} extra args: ${gcp} ${enc}"
273 ${rewriter4} ${gcp} ${enc} \
274 -c "${JAVA_PKG_BSFIX_SOURCE_TAGS}" source ${want_source} \
275 -c "${JAVA_PKG_BSFIX_TARGET_TAGS}" target ${want_target} \
276 "${@}" || die "build-xml-rewrite failed"
277 elif [[ ! -f ${rewriter3} ]]; then
278 debug-print "Using second generation rewriter"
279 eval echo "Rewriting source attributes"
280 eval xml-rewrite-2.py ${files} \
281 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
282 -a source -v ${want_source} || _bsfix_die "xml-rewrite2 failed: ${file}"
283
284 eval echo "Rewriting target attributes"
285 eval xml-rewrite-2.py ${files} \
286 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
287 -a target -v ${want_target} || _bsfix_die "xml-rewrite2 failed: ${file}"
288
289 eval echo "Rewriting nowarn attributes"
290 eval xml-rewrite-2.py ${files} \
291 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
292 -a nowarn -v yes || _bsfix_die "xml-rewrite2 failed: ${file}"
293
294 if [[ ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
295 eval echo "Adding gentoo.classpath to javac tasks"
296 eval xml-rewrite-2.py ${files} \
297 -c -e javac -e xjavac -a classpath -v \
298 '\${gentoo.classpath}' \
299 || _bsfix_die "xml-rewrite2 failed"
300 fi
301 else
302 debug-print "Using third generation rewriter"
303 eval echo "Rewriting attributes"
304 local bsfix_extra_args=""
305 # WARNING KEEP THE ORDER, ESPECIALLY FOR CHANGED ATTRIBUTES!
306 if [[ -n ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
307 local cp_tags="${JAVA_ANT_CLASSPATH_TAGS// / -e }"
308 bsfix_extra_args="${bsfix_extra_args} -g -e ${cp_tags}"
309 bsfix_extra_args="${bsfix_extra_args} -a classpath -v '\${gentoo.classpath}'"
310 fi
311 if [[ -n ${JAVA_ANT_JAVADOC_INPUT_DIRS} ]]; then
312 if [[ -n ${JAVA_ANT_JAVADOC_OUTPUT_DIR} ]]; then
313 die "Do not define JAVA_ANT_JAVADOC_OUTPUT_DIR!"
314 fi
315 # Where will our generated javadoc go.
316 readonly JAVA_ANT_JAVADOC_OUTPUT_DIR="${WORKDIR}/gentoo_javadoc"
317 mkdir -p "${JAVA_ANT_JAVADOC_OUTPUT_DIR}" || die
318
319 if has doc ${IUSE}; then
320 if use doc; then
321 if [[ -z ${EANT_DOC_TARGET} ]]; then
322 EANT_DOC_TARGET="gentoojavadoc"
323 else
324 die "You can't use javadoc adding and set EANT_DOC_TARGET too."
325 fi
326
327 for dir in ${JAVA_ANT_JAVADOC_INPUT_DIRS};do
328 if [[ ! -d ${dir} ]]; then
329 eerror "This dir: ${dir} doesnt' exists"
330 die "You must specify directories for javadoc input/output dirs."
331 fi
332 done
333 bsfix_extra_args="${bsfix_extra_args} --javadoc --source-directory "
334 # filter third/double spaces
335 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
336 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
337 bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_JAVADOC_INPUT_DIRS// / --source-directory }"
338 bsfix_extra_args="${bsfix_extra_args} --output-directory ${JAVA_ANT_JAVADOC_OUTPUT_DIR}"
339 fi
340 else
341 die "You need to have doc in IUSE when using JAVA_ANT_JAVADOC_INPUT_DIRS"
342 fi
343 fi
344
345 [[ -n ${JAVA_ANT_BSFIX_EXTRA_ARGS} ]] \
346 && bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_BSFIX_EXTRA_ARGS}"
347
348 debug-print "bsfix_extra_args: ${bsfix_extra_args}"
349
350 eval ${rewriter3} ${files} \
351 -c --source-element ${JAVA_PKG_BSFIX_SOURCE_TAGS// / --source-element } \
352 --source-attribute source --source-value ${want_source} \
353 --target-element ${JAVA_PKG_BSFIX_TARGET_TAGS// / --target-element } \
354 --target-attribute target --target-value ${want_target} \
355 --target-attribute nowarn --target-value yes \
356 ${bsfix_extra_args} \
357 || _bsfix_die "xml-rewrite2 failed: ${file}"
358 fi
359
360 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
361 for file in "${@}"; do
151 diff -NurbB "${file}.orig" "${file}" 362 diff -NurbB "${file}.orig" "${file}"
152 fi
153 done 363 done
154 fi 364 fi
365 fi
366 return 0 # so that the 1 for diff doesn't get reported
155} 367}
368
369
370# @FUNCTION: java-ant_bsfix_one
371# @USAGE: <path/to/build.xml>
372# @DESCRIPTION:
373# Attempts to fix named build file.
374#
375# @CODE
376# Affected by variables:
377# JAVA_PKG_BSFIX_SOURCE_TAGS
378# JAVA_PKG_BSFIX_TARGET_TAGS
379# @CODE
380java-ant_bsfix_one() {
381 debug-print-function ${FUNCNAME} $*
382
383 if [ -z "${1}" ]; then
384 eerror "${FUNCNAME} needs one argument"
385 die "${FUNCNAME} needs one argument"
386 fi
387
388 java-ant_bsfix_files "${1}"
389}
390
391# @FUNCTION: java-ant_rewrite-classpath
392# @USAGE: [path/to/build.xml]
393# @DESCRIPTION:
394# Adds 'classpath="${gentoo.classpath}"' to specified build file.
395#
396# Affected by:
397# JAVA_ANT_CLASSPATH_TAGS
398#
399# Parameter defaults to build.xml when not specified
400java-ant_rewrite-classpath() {
401 debug-print-function ${FUNCNAME} $*
402
403 local file="${1}"
404 [[ -z "${1}" ]] && file=build.xml
405 [[ ${#} -gt 1 ]] && die "${FUNCNAME} currently can only rewrite one file."
406
407 echo "Adding gentoo.classpath to ${file}"
408 debug-print "java-ant_rewrite-classpath: ${file}"
409
410 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
411
412 chmod u+w "${file}"
413
414 java-ant_xml-rewrite -f "${file}" --change \
415 -e ${JAVA_ANT_CLASSPATH_TAGS// / -e } -a classpath -v '${gentoo.classpath}'
416
417 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
418 diff -NurbB "${file}.orig" "${file}"
419 fi
420}
421
422# @FUNCTION: java-ant_remove-taskdefs
423# @USAGE: [--name NAME] [path/to/build.xml]
424# @DESCRIPTION:
425# Removes (named) taskdef elements from the build.xml file.
426# When --name NAME is specified, only remove taskdef with name NAME. Otherwise,
427# all taskdefs are removed.
428# The file to rewrite defaults to build.xml when not specified.
429java-ant_remove-taskdefs() {
430 debug-print-function ${FUNCNAME} $*
431
432 die "${FUNCNAME} has been banned, see bug #479838."
433
434 local task_name
435 if [[ "${1}" == --name ]]; then
436 task_name="${2}"
437 shift 2
438 fi
439 local file="${1:-build.xml}"
440 echo "Removing taskdefs from ${file}"
441 python <<EOF
442import sys
443from xml.dom.minidom import parse
444dom = parse("${file}")
445for elem in dom.getElementsByTagName('taskdef'):
446 if (len("${task_name}") == 0 or elem.getAttribute("name") == "${task_name}"):
447 elem.parentNode.removeChild(elem)
448 elem.unlink()
449f = open("${file}", "w")
450dom.writexml(f)
451f.close()
452EOF
453 [[ $? != 0 ]] && die "Removing taskdefs failed"
454}
455
456# @FUNCTION: java-ant_ignore-system-classes
457# @USAGE: [path/to/build.xml]
458# @DESCRIPTION:
459# Makes the available task ignore classes in the system classpath
460# Parameter defaults to build.xml when not specified
461java-ant_ignore-system-classes() {
462 debug-print-function ${FUNCNAME} $*
463 local file=${1:-build.xml}
464 echo "Changing ignoresystemclasses to true for available tasks in ${file}"
465 java-ant_xml-rewrite -f "${file}" --change \
466 -e available -a ignoresystemclasses -v "true"
467}
468
469# @FUNCTION: java-ant_xml-rewrite
470# @USAGE: <xml rewriter arguments>
471# @DESCRIPTION:
472# Run the right xml-rewrite binary with the given arguments
473java-ant_xml-rewrite() {
474 local gen2="/usr/bin/xml-rewrite-2.py"
475 local gen2_1="/usr/$(get_libdir)/javatoolkit/bin/xml-rewrite-2.py"
476 # gen1 is deprecated
477 if [[ -x "${gen2}" ]]; then
478 ${gen2} "${@}" || die "${gen2} failed"
479 elif [[ -x "${gen2_1}" ]]; then
480 ${gen2_1} "${@}" || die "${gen2_1} failed"
481 else
482 eerror "No binary for rewriting found."
483 eerror "Do you have dev-java/javatoolkit installed?"
484 die "xml-rewrite not found"
485 fi
486}
487
488# @FUNCTION: java-ant_rewrite-bootclasspath
489# @USAGE: <version> [path/to/build.xml] [prepend] [append]
490# @DESCRIPTION:
491# Adds bootclasspath to javac-like tasks in build.xml filled with jars of a
492# bootclasspath package of given version.
493#
494# @CODE
495# Affected by:
496# JAVA_PKG_BSFIX_TARGET_TAGS - the tags of javac tasks
497#
498# Parameters:
499# $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
500# of the current JDK
501# $2 - path to desired build.xml file, defaults to 'build.xml'
502# $3 - (optional) what to prepend the bootclasspath with (to override)
503# $4 - (optional) what to append to the bootclasspath
504# @CODE
505java-ant_rewrite-bootclasspath() {
506 local version="${1}"
507 local file="${2-build.xml}"
508 local extra_before="${3}"
509 local extra_after="${4}"
510
511 local bcp="$(java-pkg_get-bootclasspath "${version}")"
512
513 if [[ -n "${extra_before}" ]]; then
514 bcp="${extra_before}:${bcp}"
515 fi
516 if [[ -n "${extra_after}" ]]; then
517 bcp="${bcp}:${extra_after}"
518 fi
519
520 java-ant_xml-rewrite -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
521 -a bootclasspath -v "${bcp}"
522}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.58

  ViewVC Help
Powered by ViewVC 1.1.20