/[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.24 - (hide annotations) (download)
Tue Dec 18 00:23:06 2007 UTC (6 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.23: +2 -0 lines
java-ant_bsfix_files was returning 1 when JAVA_PKG_DEBUG is on.

1 nichoj 1.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 betelgeuse 1.10 # Changes:
6 betelgeuse 1.22 # 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 betelgeuse 1.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 nichoj 1.1 #
15     # Licensed under the GNU General Public License, v2
16     #
17 betelgeuse 1.23 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.22 2007/06/01 12:49:03 betelgeuse Exp $
18 nichoj 1.1
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 caster 1.14 # -----------------------------------------------------------------------------
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 caster 1.17 # -----------------------------------------------------------------------------
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 betelgeuse 1.15
49 caster 1.17 # 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 betelgeuse 1.15
60 caster 1.14 # 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 caster 1.17 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 caster 1.20 DEPEND=">=dev-java/javatoolkit-0.2.0-r1 ${JAVA_PKG_PORTAGE_DEP} ${JAVA_ANT_E_DEPEND}"
81 nichoj 1.1
82     # ------------------------------------------------------------------------------
83 nichoj 1.7 # @global JAVA_PKG_BSFIX
84 nichoj 1.1 #
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 nichoj 1.7 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
91 nichoj 1.1
92     # ------------------------------------------------------------------------------
93 nichoj 1.7 # @global JAVA_PKG_BSFIX_ALL
94 nichoj 1.1 #
95     # If we're fixing build files, should we try to fix all the ones we can find?
96     #
97     # default: yes
98     # ------------------------------------------------------------------------------
99 nichoj 1.7 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
100 nichoj 1.1
101     # ------------------------------------------------------------------------------
102 nichoj 1.5 # @global JAVA_PKG_BSFIX_NAME
103 nichoj 1.1 #
104     # Filename of build files to fix/search for
105     #
106     # default: build.xml
107     # ------------------------------------------------------------------------------
108 nichoj 1.7 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
109 nichoj 1.1
110     # ------------------------------------------------------------------------------
111 nichoj 1.7 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
112 nichoj 1.1 #
113     # Targets to fix the 'source' attribute in
114     #
115     # default: javac xjavac javac.preset
116     # ------------------------------------------------------------------------------
117 nichoj 1.7 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
118 nichoj 1.1
119     # ------------------------------------------------------------------------------
120 nichoj 1.7 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
121 nichoj 1.1 #
122     # Targets to fix the 'target' attribute in
123     #
124     # default: javacdoc javac xjavac javac.preset
125     # ------------------------------------------------------------------------------
126 nichoj 1.7 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
127 nichoj 1.1
128     # ------------------------------------------------------------------------------
129 betelgeuse 1.23 # @global JAVA_ANT_IGNORE_SYSTEM_CLASSES
130 nichoj 1.1 #
131 betelgeuse 1.23 # Rewrites available tasks to ignore ant classpath.
132 nichoj 1.1 #
133 betelgeuse 1.23 # default: off
134 nichoj 1.1 # ------------------------------------------------------------------------------
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 nelchael 1.4 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
149     if ! java-pkg_needs-vm; then
150 nichoj 1.1 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
151     fi
152    
153 betelgeuse 1.10 pushd "${S}" >/dev/null
154 nelchael 1.4
155 nichoj 1.7 local find_args=""
156     [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
157 swegener 1.8
158 nichoj 1.7 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
159 nichoj 1.1
160 betelgeuse 1.10 # This voodoo is done for paths with spaces
161     local bsfix_these
162 nichoj 1.1 while read line; do
163     [[ -z ${line} ]] && continue
164 betelgeuse 1.10 bsfix_these="${bsfix_these} '${line}'"
165 swegener 1.8 done <<-EOF
166 flameeyes 1.3 $(find . ${find_args})
167 nichoj 1.1 EOF
168    
169 betelgeuse 1.10 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
170    
171     popd > /dev/null
172 nelchael 1.4 }
173    
174 betelgeuse 1.11 _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 nelchael 1.4 # ------------------------------------------------------------------------------
188 betelgeuse 1.10 # @public java-ant_bsfix_files
189 nelchael 1.4 #
190 betelgeuse 1.10 # Attempts to fix named build files. The following variables will affect its behavior
191 nelchael 1.4 # as listed above:
192     # JAVA_PKG_BSFIX_SOURCE_TAGS
193     # JAVA_PKG_BSFIX_TARGET_TAGS
194 betelgeuse 1.22 # 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 betelgeuse 1.10 # When changing this function, make sure that it works with paths with spaces in
208     # them.
209 nelchael 1.4 # ------------------------------------------------------------------------------
210 betelgeuse 1.10 java-ant_bsfix_files() {
211 nelchael 1.4 debug-print-function ${FUNCNAME} $*
212    
213 betelgeuse 1.10 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
214 nelchael 1.4
215 nichoj 1.1 local want_source="$(java-pkg_get-source)"
216     local want_target="$(java-pkg_get-target)"
217    
218 betelgeuse 1.10 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
219 nichoj 1.1
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 betelgeuse 1.10 local files
226 nelchael 1.4
227 betelgeuse 1.10 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
228 nelchael 1.4
229 betelgeuse 1.10 for file in "${@}"; do
230     debug-print "${FUNCNAME}: ${file}"
231 nelchael 1.4
232 betelgeuse 1.10 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
233     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
234     fi
235    
236     if [[ ! -w "${file}" ]]; then
237     chmod u+w "${file}" || die "chmod u+w ${file} failed"
238     fi
239    
240     files="${files} -f '${file}'"
241    
242     if [[ -z "${using_new}" ]]; then
243 betelgeuse 1.18 echo "Rewriting $file (using xml-rewrite.py)"
244 betelgeuse 1.10 # Doing this twice because otherwise the source attributes would
245     # get added to target tags too and javadoc does not like target
246 betelgeuse 1.11 xml-rewrite.py -f "${file}" \
247     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
248     -a source -v ${want_source} || _bsfix_die "xml-rewrite failed: ${file}"
249     xml-rewrite.py -f "${file}" \
250     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
251     -a target -v ${want_target} || _bsfix_die "xml-rewrite failed: ${file}"
252 betelgeuse 1.10 fi
253     done
254    
255     if [[ "${using_new}" ]]; then
256 betelgeuse 1.18 # Play nice with paludis
257     if [[ $(type -t quiet_mode) = function ]] && quiet_mode; then
258     local output=">/dev/null"
259     fi
260 betelgeuse 1.22
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     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     else
280     debug-print "Using third generation rewriter"
281     eval echo "Rewriting attributes" ${output}
282     local bsfix_extra_args=""
283     # WARNING KEEP THE ORDER, ESPECIALLY FOR CHANGED ATTRIBUTES!
284     if [[ -n ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
285     bsfix_extra_args="${bsfix_extra_args} -g -e javac -e xjavac "
286     bsfix_extra_args="${bsfix_extra_args} -a classpath -v '\${gentoo.classpath}'"
287     fi
288     if [[ -n ${JAVA_ANT_JAVADOC_INPUT_DIRS} ]]; then
289     if [[ -n ${JAVA_ANT_JAVADOC_OUTPUT_DIR} ]]; then
290     die "Do not define JAVA_ANT_JAVADOC_OUTPUT_DIR!"
291     fi
292     # Where will our generated javadoc go.
293     readonly JAVA_ANT_JAVADOC_OUTPUT_DIR=${WORKDIR}/gentoo_javadoc
294     mkdir -p "${JAVA_ANT_JAVADOC_OUTPUT_DIR}" || die
295    
296     if hasq doc ${IUSE}; then
297     if use doc; then
298     if [[ -z ${EANT_DOC_TARGET} ]]; then
299     EANT_DOC_TARGET="gentoojavadoc"
300     else
301     die "You can't use javadoc adding and set EANT_DOC_TARGET too."
302     fi
303    
304     for dir in ${JAVA_ANT_JAVADOC_INPUT_DIRS};do
305     if [[ ! -d ${dir} ]]; then
306     eerror "This dir: ${dir} doesnt' exists"
307     die "You must specify directories for javadoc input/output dirs."
308     fi
309     done
310     bsfix_extra_args="${bsfix_extra_args} --javadoc --source-directory "
311     # filter third/double spaces
312     JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
313     JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
314     bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_JAVADOC_INPUT_DIRS// / --source-directory }"
315     bsfix_extra_args="${bsfix_extra_args} --output-directory ${JAVA_ANT_JAVADOC_OUTPUT_DIR}"
316     fi
317     else
318     die "You need to have doc in IUSE when using JAVA_ANT_JAVADOC_INPUT_DIRS"
319     fi
320     fi
321    
322     [[ -n ${JAVA_ANT_BSFIX_EXTRA_ARGS} ]] \
323     && bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_BSFIX_EXTRA_ARGS}"
324    
325     eval ${rewriter3} ${files} \
326     -c --source-element ${JAVA_PKG_BSFIX_SOURCE_TAGS// / --source-element } \
327     --source-attribute source --source-value ${want_source} \
328     --target-element ${JAVA_PKG_BSFIX_TARGET_TAGS// / --target-element } \
329     --target-attribute target --target-value ${want_target} \
330     --target-attribute nowarn --target-value yes \
331     ${bsfix_extra_args} \
332     ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
333     fi
334 betelgeuse 1.10 fi
335 nelchael 1.4
336     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
337 betelgeuse 1.10 for file in "${@}"; do
338     diff -NurbB "${file}.orig" "${file}"
339     done
340 nelchael 1.4 fi
341 nichoj 1.1 fi
342 betelgeuse 1.24 return 0 # so that the 1 for diff doesn't get reported
343 nichoj 1.1 }
344 nelchael 1.6
345 betelgeuse 1.10
346     # ------------------------------------------------------------------------------
347     # @public java-ant_bsfix_one
348     #
349     # Attempts to fix named build file. The following variables will affect its behavior
350     # as listed above:
351     # JAVA_PKG_BSFIX_SOURCE_TAGS
352     # JAVA_PKG_BSFIX_TARGET_TAGS
353     # ------------------------------------------------------------------------------
354     java-ant_bsfix_one() {
355     debug-print-function ${FUNCNAME} $*
356    
357     if [ -z "${1}" ]; then
358     eerror "${FUNCNAME} needs one argument"
359     die "${FUNCNAME} needs one argument"
360     fi
361    
362     java-ant_bsfix_files "${1}"
363     }
364    
365 nelchael 1.6 # ------------------------------------------------------------------------------
366     # @public java-ant_rewrite-classpath
367     #
368     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
369 betelgeuse 1.12 # @param $1 - the file to rewrite (defaults to build.xml)
370 nelchael 1.6 # ------------------------------------------------------------------------------
371     java-ant_rewrite-classpath() {
372     debug-print-function ${FUNCNAME} $*
373    
374 betelgeuse 1.12 local file="${1}"
375     [[ -z "${1}" ]] && file=build.xml
376 betelgeuse 1.24 [[ ${#} -gt 1 ]] && die "${FUNCNAME} currently can only rewrite one file."
377 nelchael 1.6
378     echo "Adding gentoo.classpath to ${file}"
379     debug-print "java-ant_rewrite-classpath: ${file}"
380    
381     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
382    
383     chmod u+w "${file}"
384    
385 betelgeuse 1.12 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
386 nelchael 1.6
387     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
388     diff -NurbB "${file}.orig" "${file}"
389     fi
390     }
391 betelgeuse 1.12
392     # ------------------------------------------------------------------------------
393     # @public java-ant_ignore-system-classes
394     #
395     # Makes the available task ignore classes in the system classpath
396     # @param $1 - the file to rewrite (defaults to build.xml)
397     # ------------------------------------------------------------------------------
398     java-ant_ignore-system-classes() {
399     debug-print-function ${FUNCNAME} $*
400     local file="${1}"
401     [[ -z "${1}" ]] && file=build.xml
402     echo "Changing ignoresystemclasses to true for available tasks"
403     java-ant_xml-rewrite -f "${file}" --change \
404     -e available -a ignoresystemclasses -v "true"
405     }
406    
407     # ------------------------------------------------------------------------------
408     # @public java-ant_xml-rewrite
409     # Run the right xml-rewrite binary with the given arguments
410     # ------------------------------------------------------------------------------
411     java-ant_xml-rewrite() {
412     local bindir="${ROOT}/usr/bin/"
413     local gen2="${bindir}/xml-rewrite-2.py"
414     local gen1="${bindir}/xml-rewrite.py"
415     if [[ -x "${gen2}" ]]; then
416     ${gen2} "${@}" || die "${gen2} failed"
417     elif [[ -x "${gen1}" ]]; then
418     ${gen1} "${@}" || die "${gen1} failed"
419     else
420     eerror "No binary for rewriting found."
421     eerror "Do you have dev-java/javatoolkit installed?"
422     die "xml-rewrite not found"
423     fi
424     }

  ViewVC Help
Powered by ViewVC 1.1.20