/[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.21 - (hide annotations) (download)
Thu Apr 26 23:32:12 2007 UTC (7 years, 8 months ago) by caster
Branch: MAIN
Changes since 1.20: +6 -1 lines
Remove IFS mangling instance with potential breakage.

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     # December 2006:
7     # I pretty much rewrote the logic of the bsfix functions
8     # and xml-rewrite.py because they were so slow
9     # Petteri R├Ąty (betelgeuse@gentoo.org)
10 nichoj 1.1 #
11     # Licensed under the GNU General Public License, v2
12     #
13 caster 1.21 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.20 2007/03/15 13:31:50 caster Exp $
14 nichoj 1.1
15     inherit java-utils-2
16    
17     # This eclass provides functionality for Java packages which use
18     # ant to build. In particular, it will attempt to fix build.xml files, so that
19     # they use the appropriate 'target' and 'source' attributes.
20    
21 caster 1.14 # -----------------------------------------------------------------------------
22     # @variable-preinherit WANT_ANT_TASKS
23     # @variable-default ""
24     #
25     # Please see the description in java-utils-2.eclass.
26     #WANT_ANT_TASKS
27    
28 caster 1.17 # -----------------------------------------------------------------------------
29     # @variable-preinherit WANT_SPLIT_ANT
30     # @variable-default ""
31     #
32     # If set, ant-core dependency specifies version with startup script that
33     # honours ANT_TASKS variable, i.e. >=1.7.0. Using WANT_ANT_TASKS implies
34     # split-ant already, so you need this only if you manually depend on some
35     # external package providing ant tasks and want to use it via ANT_TASKS.
36     [[ -n "${WANT_ANT_TASKS}" ]] && WANT_SPLIT_ANT="true"
37    
38     # -----------------------------------------------------------------------------
39     # @variable-preinherit JAVA_ANT_DISABLE_ANT_CORE_DEP
40     # @variable-default unset for java-pkg-2, true for java-pkg-opt-2
41     #
42     # Setting this variable non-empty before inheriting java-ant-2 disables adding
43     # dev-java/ant-core into DEPEND.
44 betelgeuse 1.15
45 caster 1.17 # construct ant-speficic DEPEND
46     JAVA_ANT_E_DEPEND=""
47     # add ant-core into DEPEND, unless disabled; respect WANT_SPLIT_ANT
48     if [[ -z "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]]; then
49     if [[ -n "${WANT_SPLIT_ANT}" ]]; then
50     JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} >=dev-java/ant-core-1.7.0"
51     else
52     JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} dev-java/ant-core"
53     fi
54     fi
55 betelgeuse 1.15
56 caster 1.14 # add ant tasks specified in WANT_ANT_TASKS to DEPEND
57     local ANT_TASKS_DEPEND;
58     ANT_TASKS_DEPEND="$(java-pkg_ant-tasks-depend)"
59     # check that java-pkg_ant-tasks-depend didn't fail
60     if [[ $? != 0 ]]; then
61     eerror "${ANT_TASKS_DEPEND}"
62     die "java-pkg_ant-tasks-depend() failed"
63     fi
64 caster 1.17 JAVA_ANT_E_DEPEND="${JAVA_ANT_E_DEPEND} ${ANT_TASKS_DEPEND}"
65    
66     # this eclass must be inherited after java-pkg-2 or java-pkg-opt-2
67     # if it's java-pkg-opt-2, ant dependencies are pulled based on USE flag
68     if hasq java-pkg-opt-2 ${INHERITED}; then
69     JAVA_ANT_E_DEPEND="${JAVA_PKG_OPT_USE}? ( ${JAVA_ANT_E_DEPEND} )"
70     elif ! hasq java-pkg-2 ${INHERITED}; then
71     eerror "java-ant-2 eclass can only be inherited AFTER java-pkg-2 or java-pkg-opt-2"
72     fi
73    
74     # We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
75     # and ant dependencies constructed above
76 caster 1.20 DEPEND=">=dev-java/javatoolkit-0.2.0-r1 ${JAVA_PKG_PORTAGE_DEP} ${JAVA_ANT_E_DEPEND}"
77 nichoj 1.1
78     # ------------------------------------------------------------------------------
79 nichoj 1.7 # @global JAVA_PKG_BSFIX
80 nichoj 1.1 #
81     # Should we attempt to 'fix' ant build files to include the source/target
82     # attributes when calling javac?
83     #
84     # default: on
85     # ------------------------------------------------------------------------------
86 nichoj 1.7 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
87 nichoj 1.1
88     # ------------------------------------------------------------------------------
89 nichoj 1.7 # @global JAVA_PKG_BSFIX_ALL
90 nichoj 1.1 #
91     # If we're fixing build files, should we try to fix all the ones we can find?
92     #
93     # default: yes
94     # ------------------------------------------------------------------------------
95 nichoj 1.7 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
96 nichoj 1.1
97     # ------------------------------------------------------------------------------
98 nichoj 1.5 # @global JAVA_PKG_BSFIX_NAME
99 nichoj 1.1 #
100     # Filename of build files to fix/search for
101     #
102     # default: build.xml
103     # ------------------------------------------------------------------------------
104 nichoj 1.7 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
105 nichoj 1.1
106     # ------------------------------------------------------------------------------
107 nichoj 1.7 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
108 nichoj 1.1 #
109     # Targets to fix the 'source' attribute in
110     #
111     # default: javac xjavac javac.preset
112     # ------------------------------------------------------------------------------
113 nichoj 1.7 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
114 nichoj 1.1
115     # ------------------------------------------------------------------------------
116 nichoj 1.7 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
117 nichoj 1.1 #
118     # Targets to fix the 'target' attribute in
119     #
120     # default: javacdoc javac xjavac javac.preset
121     # ------------------------------------------------------------------------------
122 nichoj 1.7 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
123 nichoj 1.1
124     # ------------------------------------------------------------------------------
125     # @public java-ant_src_unpack
126     #
127     # Unpacks the source, and attempts to fix build files.
128 betelgeuse 1.13 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
129     # ignore ant classpath in available tasks
130 nichoj 1.1 # ------------------------------------------------------------------------------
131 nichoj 1.2 post_src_unpack() {
132     if java-pkg_func-exists ant_src_unpack; then
133 nichoj 1.19 die "ant_src_unpack is no longer support, should use just src_unpack"
134 nichoj 1.2 fi
135 nichoj 1.1 java-ant_bsfix
136 betelgeuse 1.13 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
137     && java-ant_ignore-system-classes "${S}/build.xml"
138 nichoj 1.1 }
139    
140     # ------------------------------------------------------------------------------
141     # @private ant_src_unpack
142     #
143     # Helper function which does the actual unpacking
144     # ------------------------------------------------------------------------------
145     # TODO maybe use base.eclass for some patching love?
146 nichoj 1.2 #ant_src_unpack() {
147     # debug-print-function ${FUNCNAME} $*
148     # if [[ -n "${A}" ]]; then
149     # unpack ${A}
150     # fi
151     #}
152 nichoj 1.1
153     # ------------------------------------------------------------------------------
154     # @private java-ant_bsfix
155     #
156     # Attempts to fix build files. The following variables will affect its behavior
157     # as listed above:
158     # JAVA_PKG_BSFIX
159     # JAVA_PKG_BSFIX_ALL
160     # JAVA_PKG_BSFIX_NAME,
161     # ------------------------------------------------------------------------------
162     java-ant_bsfix() {
163     debug-print-function ${FUNCNAME} $*
164    
165 nelchael 1.4 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
166     if ! java-pkg_needs-vm; then
167 nichoj 1.1 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
168     fi
169    
170 betelgeuse 1.10 pushd "${S}" >/dev/null
171 nelchael 1.4
172 nichoj 1.7 local find_args=""
173     [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
174 swegener 1.8
175 nichoj 1.7 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
176 nichoj 1.1
177 betelgeuse 1.10 # This voodoo is done for paths with spaces
178     local bsfix_these
179 nichoj 1.1 while read line; do
180     [[ -z ${line} ]] && continue
181 betelgeuse 1.10 bsfix_these="${bsfix_these} '${line}'"
182 swegener 1.8 done <<-EOF
183 flameeyes 1.3 $(find . ${find_args})
184 nichoj 1.1 EOF
185    
186 betelgeuse 1.10 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
187    
188     popd > /dev/null
189 nelchael 1.4 }
190    
191 betelgeuse 1.11 _bsfix_die() {
192     if has_version dev-python/pyxml; then
193     eerror "If the output above contains:"
194     eerror "ImportError:"
195     eerror "/usr/lib/python2.4/site-packages/_xmlplus/parsers/pyexpat.so:"
196     eerror "undefined symbol: PyUnicodeUCS2_DecodeUTF8"
197     eerror "Try re-emerging dev-python/pyxml"
198     die ${1} " Look at the eerror message above"
199     else
200     die ${1}
201     fi
202     }
203    
204 nelchael 1.4 # ------------------------------------------------------------------------------
205 betelgeuse 1.10 # @public java-ant_bsfix_files
206 nelchael 1.4 #
207 betelgeuse 1.10 # Attempts to fix named build files. The following variables will affect its behavior
208 nelchael 1.4 # as listed above:
209     # JAVA_PKG_BSFIX_SOURCE_TAGS
210     # JAVA_PKG_BSFIX_TARGET_TAGS
211 betelgeuse 1.10 #
212     # When changing this function, make sure that it works with paths with spaces in
213     # them.
214 nelchael 1.4 # ------------------------------------------------------------------------------
215 betelgeuse 1.10 java-ant_bsfix_files() {
216 nelchael 1.4 debug-print-function ${FUNCNAME} $*
217    
218 betelgeuse 1.10 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
219 nelchael 1.4
220 nichoj 1.1 local want_source="$(java-pkg_get-source)"
221     local want_target="$(java-pkg_get-target)"
222    
223 betelgeuse 1.10 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
224 nichoj 1.1
225     if [ -z "${want_source}" -o -z "${want_target}" ]; then
226     eerror "Could not find valid -source/-target values"
227     eerror "Please file a bug about this on bugs.gentoo.org"
228     die "Could not find valid -source/-target values"
229     else
230 betelgeuse 1.10 local files
231 nelchael 1.4
232 betelgeuse 1.10 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
233 nelchael 1.4
234 betelgeuse 1.10 for file in "${@}"; do
235     debug-print "${FUNCNAME}: ${file}"
236 nelchael 1.4
237 betelgeuse 1.10 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
238     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
239     fi
240    
241     if [[ ! -w "${file}" ]]; then
242     chmod u+w "${file}" || die "chmod u+w ${file} failed"
243     fi
244    
245     files="${files} -f '${file}'"
246    
247     if [[ -z "${using_new}" ]]; then
248 betelgeuse 1.18 echo "Rewriting $file (using xml-rewrite.py)"
249 betelgeuse 1.10 # Doing this twice because otherwise the source attributes would
250     # get added to target tags too and javadoc does not like target
251 betelgeuse 1.11 xml-rewrite.py -f "${file}" \
252     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
253     -a source -v ${want_source} || _bsfix_die "xml-rewrite failed: ${file}"
254     xml-rewrite.py -f "${file}" \
255     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
256     -a target -v ${want_target} || _bsfix_die "xml-rewrite failed: ${file}"
257 betelgeuse 1.10 fi
258     done
259    
260     if [[ "${using_new}" ]]; then
261 betelgeuse 1.18 # Play nice with paludis
262     if [[ $(type -t quiet_mode) = function ]] && quiet_mode; then
263     local output=">/dev/null"
264     fi
265     eval echo "Rewriting source attributes" ${output}
266 betelgeuse 1.10 eval xml-rewrite-2.py ${files} \
267     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
268 betelgeuse 1.11 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
269 betelgeuse 1.10
270 betelgeuse 1.18 eval echo "Rewriting target attributes" ${output}
271 betelgeuse 1.10 eval xml-rewrite-2.py ${files} \
272     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
273 betelgeuse 1.11 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
274 caster 1.21
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 betelgeuse 1.10 fi
280 nelchael 1.4
281     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
282 betelgeuse 1.10 for file in "${@}"; do
283     diff -NurbB "${file}.orig" "${file}"
284     done
285 nelchael 1.4 fi
286 nichoj 1.1 fi
287     }
288 nelchael 1.6
289 betelgeuse 1.10
290     # ------------------------------------------------------------------------------
291     # @public java-ant_bsfix_one
292     #
293     # Attempts to fix named build file. The following variables will affect its behavior
294     # as listed above:
295     # JAVA_PKG_BSFIX_SOURCE_TAGS
296     # JAVA_PKG_BSFIX_TARGET_TAGS
297     # ------------------------------------------------------------------------------
298     java-ant_bsfix_one() {
299     debug-print-function ${FUNCNAME} $*
300    
301     if [ -z "${1}" ]; then
302     eerror "${FUNCNAME} needs one argument"
303     die "${FUNCNAME} needs one argument"
304     fi
305    
306     java-ant_bsfix_files "${1}"
307     }
308    
309 nelchael 1.6 # ------------------------------------------------------------------------------
310     # @public java-ant_rewrite-classpath
311     #
312     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
313 betelgeuse 1.12 # @param $1 - the file to rewrite (defaults to build.xml)
314 nelchael 1.6 # ------------------------------------------------------------------------------
315     java-ant_rewrite-classpath() {
316     debug-print-function ${FUNCNAME} $*
317    
318 betelgeuse 1.12 local file="${1}"
319     [[ -z "${1}" ]] && file=build.xml
320 nelchael 1.6
321     echo "Adding gentoo.classpath to ${file}"
322     debug-print "java-ant_rewrite-classpath: ${file}"
323    
324     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
325    
326     chmod u+w "${file}"
327    
328 betelgeuse 1.12 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
329 nelchael 1.6
330     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
331     diff -NurbB "${file}.orig" "${file}"
332     fi
333     }
334 betelgeuse 1.12
335     # ------------------------------------------------------------------------------
336     # @public java-ant_ignore-system-classes
337     #
338     # Makes the available task ignore classes in the system classpath
339     # @param $1 - the file to rewrite (defaults to build.xml)
340     # ------------------------------------------------------------------------------
341     java-ant_ignore-system-classes() {
342     debug-print-function ${FUNCNAME} $*
343     local file="${1}"
344     [[ -z "${1}" ]] && file=build.xml
345     echo "Changing ignoresystemclasses to true for available tasks"
346     java-ant_xml-rewrite -f "${file}" --change \
347     -e available -a ignoresystemclasses -v "true"
348     }
349    
350     # ------------------------------------------------------------------------------
351     # @public java-ant_xml-rewrite
352     # Run the right xml-rewrite binary with the given arguments
353     # ------------------------------------------------------------------------------
354     java-ant_xml-rewrite() {
355     local bindir="${ROOT}/usr/bin/"
356     local gen2="${bindir}/xml-rewrite-2.py"
357     local gen1="${bindir}/xml-rewrite.py"
358     if [[ -x "${gen2}" ]]; then
359     ${gen2} "${@}" || die "${gen2} failed"
360     elif [[ -x "${gen1}" ]]; then
361     ${gen1} "${@}" || die "${gen1} failed"
362     else
363     eerror "No binary for rewriting found."
364     eerror "Do you have dev-java/javatoolkit installed?"
365     die "xml-rewrite not found"
366     fi
367     }

  ViewVC Help
Powered by ViewVC 1.1.20