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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.57

  ViewVC Help
Powered by ViewVC 1.1.20