/[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.22 - (show annotations) (download)
Fri Jun 1 12:49:03 2007 UTC (7 years, 1 month ago) by betelgeuse
Branch: MAIN
Changes since 1.21: +92 -16 lines
Apply third generation rewriting patch from kiorky. Only enabled when you have javatoolkit from java-overlay installed so there should be no changes for current users.

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.21 2007/04/26 23:32:12 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 WANT_SPLIT_ANT
34 # @variable-default ""
35 #
36 # If set, ant-core dependency specifies version with startup script that
37 # honours ANT_TASKS variable, i.e. >=1.7.0. Using WANT_ANT_TASKS implies
38 # split-ant already, so you need this only if you manually depend on some
39 # external package providing ant tasks and want to use it via ANT_TASKS.
40 [[ -n "${WANT_ANT_TASKS}" ]] && WANT_SPLIT_ANT="true"
41
42 # -----------------------------------------------------------------------------
43 # @variable-preinherit JAVA_ANT_DISABLE_ANT_CORE_DEP
44 # @variable-default unset for java-pkg-2, true for java-pkg-opt-2
45 #
46 # Setting this variable non-empty before inheriting java-ant-2 disables adding
47 # dev-java/ant-core into DEPEND.
48
49 # construct ant-speficic DEPEND
50 JAVA_ANT_E_DEPEND=""
51 # add ant-core into DEPEND, unless disabled; respect WANT_SPLIT_ANT
52 if [[ -z "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]]; then
53 if [[ -n "${WANT_SPLIT_ANT}" ]]; then
54 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} >=dev-java/ant-core-1.7.0"
55 else
56 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} dev-java/ant-core"
57 fi
58 fi
59
60 # add ant tasks specified in WANT_ANT_TASKS to DEPEND
61 local ANT_TASKS_DEPEND;
62 ANT_TASKS_DEPEND="$(java-pkg_ant-tasks-depend)"
63 # check that java-pkg_ant-tasks-depend didn't fail
64 if [[ $? != 0 ]]; then
65 eerror "${ANT_TASKS_DEPEND}"
66 die "java-pkg_ant-tasks-depend() failed"
67 fi
68 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} ${ANT_TASKS_DEPEND}"
69
70 # this eclass must be inherited after java-pkg-2 or java-pkg-opt-2
71 # if it's java-pkg-opt-2, ant dependencies are pulled based on USE flag
72 if hasq java-pkg-opt-2 ${INHERITED}; then
73 JAVA_ANT_E_DEPEND="${JAVA_PKG_OPT_USE}? ( ${JAVA_ANT_E_DEPEND} )"
74 elif ! hasq java-pkg-2 ${INHERITED}; then
75 eerror "java-ant-2 eclass can only be inherited AFTER java-pkg-2 or java-pkg-opt-2"
76 fi
77
78 # We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
79 # and ant dependencies constructed above
80 DEPEND=">=dev-java/javatoolkit-0.2.0-r1 ${JAVA_PKG_PORTAGE_DEP} ${JAVA_ANT_E_DEPEND}"
81
82 # ------------------------------------------------------------------------------
83 # @global JAVA_PKG_BSFIX
84 #
85 # Should we attempt to 'fix' ant build files to include the source/target
86 # attributes when calling javac?
87 #
88 # default: on
89 # ------------------------------------------------------------------------------
90 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
91
92 # ------------------------------------------------------------------------------
93 # @global JAVA_PKG_BSFIX_ALL
94 #
95 # If we're fixing build files, should we try to fix all the ones we can find?
96 #
97 # default: yes
98 # ------------------------------------------------------------------------------
99 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
100
101 # ------------------------------------------------------------------------------
102 # @global JAVA_PKG_BSFIX_NAME
103 #
104 # Filename of build files to fix/search for
105 #
106 # default: build.xml
107 # ------------------------------------------------------------------------------
108 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
109
110 # ------------------------------------------------------------------------------
111 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
112 #
113 # Targets to fix the 'source' attribute in
114 #
115 # default: javac xjavac javac.preset
116 # ------------------------------------------------------------------------------
117 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
118
119 # ------------------------------------------------------------------------------
120 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
121 #
122 # Targets to fix the 'target' attribute in
123 #
124 # default: javacdoc javac xjavac javac.preset
125 # ------------------------------------------------------------------------------
126 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
127
128 # ------------------------------------------------------------------------------
129 # @public java-ant_src_unpack
130 #
131 # Unpacks the source, and attempts to fix build files.
132 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
133 # ignore ant classpath in available tasks
134 # ------------------------------------------------------------------------------
135 post_src_unpack() {
136 if java-pkg_func-exists ant_src_unpack; then
137 die "ant_src_unpack is no longer support, should use just src_unpack"
138 fi
139 java-ant_bsfix
140 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
141 && java-ant_ignore-system-classes "${S}/build.xml"
142 }
143
144 # ------------------------------------------------------------------------------
145 # @private ant_src_unpack
146 #
147 # Helper function which does the actual unpacking
148 # ------------------------------------------------------------------------------
149 # TODO maybe use base.eclass for some patching love?
150 #ant_src_unpack() {
151 # debug-print-function ${FUNCNAME} $*
152 # if [[ -n "${A}" ]]; then
153 # unpack ${A}
154 # fi
155 #}
156
157 # ------------------------------------------------------------------------------
158 # @private java-ant_bsfix
159 #
160 # Attempts to fix build files. The following variables will affect its behavior
161 # as listed above:
162 # JAVA_PKG_BSFIX
163 # JAVA_PKG_BSFIX_ALL
164 # JAVA_PKG_BSFIX_NAME,
165 # ------------------------------------------------------------------------------
166 java-ant_bsfix() {
167 debug-print-function ${FUNCNAME} $*
168
169 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
170 if ! java-pkg_needs-vm; then
171 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
172 fi
173
174 pushd "${S}" >/dev/null
175
176 local find_args=""
177 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
178
179 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
180
181 # This voodoo is done for paths with spaces
182 local bsfix_these
183 while read line; do
184 [[ -z ${line} ]] && continue
185 bsfix_these="${bsfix_these} '${line}'"
186 done <<-EOF
187 $(find . ${find_args})
188 EOF
189
190 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
191
192 popd > /dev/null
193 }
194
195 _bsfix_die() {
196 if has_version dev-python/pyxml; then
197 eerror "If the output above contains:"
198 eerror "ImportError:"
199 eerror "/usr/lib/python2.4/site-packages/_xmlplus/parsers/pyexpat.so:"
200 eerror "undefined symbol: PyUnicodeUCS2_DecodeUTF8"
201 eerror "Try re-emerging dev-python/pyxml"
202 die ${1} " Look at the eerror message above"
203 else
204 die ${1}
205 fi
206 }
207
208 # ------------------------------------------------------------------------------
209 # @public java-ant_bsfix_files
210 #
211 # Attempts to fix named build files. The following variables will affect its behavior
212 # as listed above:
213 # JAVA_PKG_BSFIX_SOURCE_TAGS
214 # JAVA_PKG_BSFIX_TARGET_TAGS
215 # JAVA_ANT_REWRITE_CLASSPATH
216 # JAVA_ANT_JAVADOC_INPUT_DIRS: Where we can find java sources for javadoc
217 # input. Can be a space separated list of
218 # directories
219 # JAVA_ANT_BSFIX_EXTRA_ARGS: You can use this to pass extra variables to the
220 # rewriter if you know what you are doing.
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.
230 # ------------------------------------------------------------------------------
231 java-ant_bsfix_files() {
232 debug-print-function ${FUNCNAME} $*
233
234 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
235
236 local want_source="$(java-pkg_get-source)"
237 local want_target="$(java-pkg_get-target)"
238
239 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
240
241 if [ -z "${want_source}" -o -z "${want_target}" ]; then
242 eerror "Could not find valid -source/-target values"
243 eerror "Please file a bug about this on bugs.gentoo.org"
244 die "Could not find valid -source/-target values"
245 else
246 local files
247
248 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
249
250 for file in "${@}"; do
251 debug-print "${FUNCNAME}: ${file}"
252
253 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
254 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
255 fi
256
257 if [[ ! -w "${file}" ]]; then
258 chmod u+w "${file}" || die "chmod u+w ${file} failed"
259 fi
260
261 files="${files} -f '${file}'"
262
263 if [[ -z "${using_new}" ]]; then
264 echo "Rewriting $file (using xml-rewrite.py)"
265 # Doing this twice because otherwise the source attributes would
266 # get added to target tags too and javadoc does not like target
267 xml-rewrite.py -f "${file}" \
268 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
269 -a source -v ${want_source} || _bsfix_die "xml-rewrite failed: ${file}"
270 xml-rewrite.py -f "${file}" \
271 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
272 -a target -v ${want_target} || _bsfix_die "xml-rewrite failed: ${file}"
273 fi
274 done
275
276 if [[ "${using_new}" ]]; then
277 # Play nice with paludis
278 if [[ $(type -t quiet_mode) = function ]] && quiet_mode; then
279 local output=">/dev/null"
280 fi
281
282 # for javadoc target and all in one pass, we need the new rewriter.
283 local rewriter3="/usr/share/javatoolkit/xml-rewrite-3.py"
284 if [[ ! -f ${rewriter3} ]]; then
285 debug-print "Using second generation rewriter"
286 eval echo "Rewriting source attributes" ${output}
287 eval xml-rewrite-2.py ${files} \
288 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
289 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
290
291 eval echo "Rewriting target attributes" ${output}
292 eval xml-rewrite-2.py ${files} \
293 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
294 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
295
296 eval echo "Rewriting nowarn attributes" ${output}
297 eval xml-rewrite-2.py ${files} \
298 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
299 -a nowarn -v yes ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
300 else
301 debug-print "Using third generation rewriter"
302 eval echo "Rewriting attributes" ${output}
303 local bsfix_extra_args=""
304 # WARNING KEEP THE ORDER, ESPECIALLY FOR CHANGED ATTRIBUTES!
305 if [[ -n ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
306 bsfix_extra_args="${bsfix_extra_args} -g -e javac -e xjavac "
307 bsfix_extra_args="${bsfix_extra_args} -a classpath -v '\${gentoo.classpath}'"
308 fi
309 if [[ -n ${JAVA_ANT_JAVADOC_INPUT_DIRS} ]]; then
310 if [[ -n ${JAVA_ANT_JAVADOC_OUTPUT_DIR} ]]; then
311 die "Do not define JAVA_ANT_JAVADOC_OUTPUT_DIR!"
312 fi
313 # Where will our generated javadoc go.
314 readonly JAVA_ANT_JAVADOC_OUTPUT_DIR=${WORKDIR}/gentoo_javadoc
315 mkdir -p "${JAVA_ANT_JAVADOC_OUTPUT_DIR}" || die
316
317 if hasq doc ${IUSE}; then
318 if use doc; then
319 if [[ -z ${EANT_DOC_TARGET} ]]; then
320 EANT_DOC_TARGET="gentoojavadoc"
321 else
322 die "You can't use javadoc adding and set EANT_DOC_TARGET too."
323 fi
324
325 for dir in ${JAVA_ANT_JAVADOC_INPUT_DIRS};do
326 if [[ ! -d ${dir} ]]; then
327 eerror "This dir: ${dir} doesnt' exists"
328 die "You must specify directories for javadoc input/output dirs."
329 fi
330 done
331 bsfix_extra_args="${bsfix_extra_args} --javadoc --source-directory "
332 # filter third/double spaces
333 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
334 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
335 bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_JAVADOC_INPUT_DIRS// / --source-directory }"
336 bsfix_extra_args="${bsfix_extra_args} --output-directory ${JAVA_ANT_JAVADOC_OUTPUT_DIR}"
337 fi
338 else
339 die "You need to have doc in IUSE when using JAVA_ANT_JAVADOC_INPUT_DIRS"
340 fi
341 fi
342
343 [[ -n ${JAVA_ANT_BSFIX_EXTRA_ARGS} ]] \
344 && bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_BSFIX_EXTRA_ARGS}"
345
346 eval ${rewriter3} ${files} \
347 -c --source-element ${JAVA_PKG_BSFIX_SOURCE_TAGS// / --source-element } \
348 --source-attribute source --source-value ${want_source} \
349 --target-element ${JAVA_PKG_BSFIX_TARGET_TAGS// / --target-element } \
350 --target-attribute target --target-value ${want_target} \
351 --target-attribute nowarn --target-value yes \
352 ${bsfix_extra_args} \
353 ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
354 fi
355 fi
356
357 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
358 for file in "${@}"; do
359 diff -NurbB "${file}.orig" "${file}"
360 done
361 fi
362 fi
363 }
364
365
366 # ------------------------------------------------------------------------------
367 # @public java-ant_bsfix_one
368 #
369 # Attempts to fix named build file. The following variables will affect its behavior
370 # as listed above:
371 # JAVA_PKG_BSFIX_SOURCE_TAGS
372 # JAVA_PKG_BSFIX_TARGET_TAGS
373 # ------------------------------------------------------------------------------
374 java-ant_bsfix_one() {
375 debug-print-function ${FUNCNAME} $*
376
377 if [ -z "${1}" ]; then
378 eerror "${FUNCNAME} needs one argument"
379 die "${FUNCNAME} needs one argument"
380 fi
381
382 java-ant_bsfix_files "${1}"
383 }
384
385 # ------------------------------------------------------------------------------
386 # @public java-ant_rewrite-classpath
387 #
388 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
389 # @param $1 - the file to rewrite (defaults to build.xml)
390 # ------------------------------------------------------------------------------
391 java-ant_rewrite-classpath() {
392 debug-print-function ${FUNCNAME} $*
393
394 local file="${1}"
395 [[ -z "${1}" ]] && file=build.xml
396
397 echo "Adding gentoo.classpath to ${file}"
398 debug-print "java-ant_rewrite-classpath: ${file}"
399
400 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
401
402 chmod u+w "${file}"
403
404 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
405
406 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
407 diff -NurbB "${file}.orig" "${file}"
408 fi
409 }
410
411 # ------------------------------------------------------------------------------
412 # @public java-ant_ignore-system-classes
413 #
414 # Makes the available task ignore classes in the system classpath
415 # @param $1 - the file to rewrite (defaults to build.xml)
416 # ------------------------------------------------------------------------------
417 java-ant_ignore-system-classes() {
418 debug-print-function ${FUNCNAME} $*
419 local file="${1}"
420 [[ -z "${1}" ]] && file=build.xml
421 echo "Changing ignoresystemclasses to true for available tasks"
422 java-ant_xml-rewrite -f "${file}" --change \
423 -e available -a ignoresystemclasses -v "true"
424 }
425
426 # ------------------------------------------------------------------------------
427 # @public java-ant_xml-rewrite
428 # Run the right xml-rewrite binary with the given arguments
429 # ------------------------------------------------------------------------------
430 java-ant_xml-rewrite() {
431 local bindir="${ROOT}/usr/bin/"
432 local gen2="${bindir}/xml-rewrite-2.py"
433 local gen1="${bindir}/xml-rewrite.py"
434 if [[ -x "${gen2}" ]]; then
435 ${gen2} "${@}" || die "${gen2} failed"
436 elif [[ -x "${gen1}" ]]; then
437 ${gen1} "${@}" || die "${gen1} failed"
438 else
439 eerror "No binary for rewriting found."
440 eerror "Do you have dev-java/javatoolkit installed?"
441 die "xml-rewrite not found"
442 fi
443 }

  ViewVC Help
Powered by ViewVC 1.1.20