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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.37 - (show annotations) (download)
Mon Jul 7 16:48:45 2008 UTC (6 years, 2 months ago) by betelgeuse
Branch: MAIN
Changes since 1.36: +34 -5 lines
Always put junit to gentoo.classpath when ANT_TASKS has ant-junit. Fixes bug #225981.

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

  ViewVC Help
Powered by ViewVC 1.1.20