/[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.39 - (show annotations) (download)
Sun Sep 28 15:47:48 2008 UTC (5 years, 10 months ago) by caster
Branch: MAIN
Changes since 1.38: +2 -2 lines
Raise javatoolkit dep to current stable.

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

  ViewVC Help
Powered by ViewVC 1.1.20