/[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.26 - (hide annotations) (download)
Tue Jan 22 21:57:03 2008 UTC (6 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.25: +9 -1 lines
Add JAVA_ANT_REWRITE_CLASSPATH support when using generation 2 rewrite. Fixes bug #207084.

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

  ViewVC Help
Powered by ViewVC 1.1.20