/[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.47 - (show annotations) (download)
Mon Feb 1 09:38:44 2010 UTC (4 years, 5 months ago) by caster
Branch: MAIN
Changes since 1.46: +5 -2 lines
Add EAPI=3 support for java eclasses. Bug #303061 and patch thanks to Ulrich Müller <ulm@gentoo.org>.

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

  ViewVC Help
Powered by ViewVC 1.1.20