/[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.20 - (show annotations) (download)
Thu Mar 15 13:31:50 2007 UTC (7 years, 1 month ago) by caster
Branch: MAIN
Changes since 1.19: +2 -2 lines
Raise javatoolkit dep to 0.2.0-r1 so that build.xml files with entities don't break.

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 # 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 #
11 # Licensed under the GNU General Public License, v2
12 #
13 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.19 2007/03/11 22:51:25 nichoj Exp $
14
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 # -----------------------------------------------------------------------------
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 # -----------------------------------------------------------------------------
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
45 # 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
56 # 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 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 DEPEND=">=dev-java/javatoolkit-0.2.0-r1 ${JAVA_PKG_PORTAGE_DEP} ${JAVA_ANT_E_DEPEND}"
77
78 # ------------------------------------------------------------------------------
79 # @global JAVA_PKG_BSFIX
80 #
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 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
87
88 # ------------------------------------------------------------------------------
89 # @global JAVA_PKG_BSFIX_ALL
90 #
91 # If we're fixing build files, should we try to fix all the ones we can find?
92 #
93 # default: yes
94 # ------------------------------------------------------------------------------
95 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
96
97 # ------------------------------------------------------------------------------
98 # @global JAVA_PKG_BSFIX_NAME
99 #
100 # Filename of build files to fix/search for
101 #
102 # default: build.xml
103 # ------------------------------------------------------------------------------
104 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
105
106 # ------------------------------------------------------------------------------
107 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
108 #
109 # Targets to fix the 'source' attribute in
110 #
111 # default: javac xjavac javac.preset
112 # ------------------------------------------------------------------------------
113 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
114
115 # ------------------------------------------------------------------------------
116 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
117 #
118 # Targets to fix the 'target' attribute in
119 #
120 # default: javacdoc javac xjavac javac.preset
121 # ------------------------------------------------------------------------------
122 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
123
124 # ------------------------------------------------------------------------------
125 # @public java-ant_src_unpack
126 #
127 # Unpacks the source, and attempts to fix build files.
128 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
129 # ignore ant classpath in available tasks
130 # ------------------------------------------------------------------------------
131 post_src_unpack() {
132 if java-pkg_func-exists ant_src_unpack; then
133 die "ant_src_unpack is no longer support, should use just src_unpack"
134 fi
135 java-ant_bsfix
136 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
137 && java-ant_ignore-system-classes "${S}/build.xml"
138 }
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 #ant_src_unpack() {
147 # debug-print-function ${FUNCNAME} $*
148 # if [[ -n "${A}" ]]; then
149 # unpack ${A}
150 # fi
151 #}
152
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 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
166 if ! java-pkg_needs-vm; then
167 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
168 fi
169
170 pushd "${S}" >/dev/null
171
172 local find_args=""
173 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
174
175 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
176
177 # This voodoo is done for paths with spaces
178 local bsfix_these
179 while read line; do
180 [[ -z ${line} ]] && continue
181 bsfix_these="${bsfix_these} '${line}'"
182 done <<-EOF
183 $(find . ${find_args})
184 EOF
185
186 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
187
188 popd > /dev/null
189 }
190
191 _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 # ------------------------------------------------------------------------------
205 # @public java-ant_bsfix_files
206 #
207 # Attempts to fix named build files. The following variables will affect its behavior
208 # as listed above:
209 # JAVA_PKG_BSFIX_SOURCE_TAGS
210 # JAVA_PKG_BSFIX_TARGET_TAGS
211 #
212 # When changing this function, make sure that it works with paths with spaces in
213 # them.
214 # ------------------------------------------------------------------------------
215 java-ant_bsfix_files() {
216 debug-print-function ${FUNCNAME} $*
217
218 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
219
220 local want_source="$(java-pkg_get-source)"
221 local want_target="$(java-pkg_get-target)"
222
223 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
224
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 local files
231
232 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
233
234 for file in "${@}"; do
235 debug-print "${FUNCNAME}: ${file}"
236
237 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 echo "Rewriting $file (using xml-rewrite.py)"
249 # Doing this twice because otherwise the source attributes would
250 # get added to target tags too and javadoc does not like target
251 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 fi
258 done
259
260 if [[ "${using_new}" ]]; then
261 # 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 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 fi
275
276 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
277 for file in "${@}"; do
278 diff -NurbB "${file}.orig" "${file}"
279 done
280 fi
281 fi
282 }
283
284
285 # ------------------------------------------------------------------------------
286 # @public java-ant_bsfix_one
287 #
288 # Attempts to fix named build file. The following variables will affect its behavior
289 # as listed above:
290 # JAVA_PKG_BSFIX_SOURCE_TAGS
291 # JAVA_PKG_BSFIX_TARGET_TAGS
292 # ------------------------------------------------------------------------------
293 java-ant_bsfix_one() {
294 debug-print-function ${FUNCNAME} $*
295
296 if [ -z "${1}" ]; then
297 eerror "${FUNCNAME} needs one argument"
298 die "${FUNCNAME} needs one argument"
299 fi
300
301 java-ant_bsfix_files "${1}"
302 }
303
304 # ------------------------------------------------------------------------------
305 # @public java-ant_rewrite-classpath
306 #
307 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
308 # @param $1 - the file to rewrite (defaults to build.xml)
309 # ------------------------------------------------------------------------------
310 java-ant_rewrite-classpath() {
311 debug-print-function ${FUNCNAME} $*
312
313 local file="${1}"
314 [[ -z "${1}" ]] && file=build.xml
315
316 echo "Adding gentoo.classpath to ${file}"
317 debug-print "java-ant_rewrite-classpath: ${file}"
318
319 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
320
321 chmod u+w "${file}"
322
323 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
324
325 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
326 diff -NurbB "${file}.orig" "${file}"
327 fi
328 }
329
330 # ------------------------------------------------------------------------------
331 # @public java-ant_ignore-system-classes
332 #
333 # Makes the available task ignore classes in the system classpath
334 # @param $1 - the file to rewrite (defaults to build.xml)
335 # ------------------------------------------------------------------------------
336 java-ant_ignore-system-classes() {
337 debug-print-function ${FUNCNAME} $*
338 local file="${1}"
339 [[ -z "${1}" ]] && file=build.xml
340 echo "Changing ignoresystemclasses to true for available tasks"
341 java-ant_xml-rewrite -f "${file}" --change \
342 -e available -a ignoresystemclasses -v "true"
343 }
344
345 # ------------------------------------------------------------------------------
346 # @public java-ant_xml-rewrite
347 # Run the right xml-rewrite binary with the given arguments
348 # ------------------------------------------------------------------------------
349 java-ant_xml-rewrite() {
350 local bindir="${ROOT}/usr/bin/"
351 local gen2="${bindir}/xml-rewrite-2.py"
352 local gen1="${bindir}/xml-rewrite.py"
353 if [[ -x "${gen2}" ]]; then
354 ${gen2} "${@}" || die "${gen2} failed"
355 elif [[ -x "${gen1}" ]]; then
356 ${gen1} "${@}" || die "${gen1} failed"
357 else
358 eerror "No binary for rewriting found."
359 eerror "Do you have dev-java/javatoolkit installed?"
360 die "xml-rewrite not found"
361 fi
362 }

  ViewVC Help
Powered by ViewVC 1.1.20