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

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

  ViewVC Help
Powered by ViewVC 1.1.20