/[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.28 - (show annotations) (download)
Sun Jan 27 03:37:49 2008 UTC (6 years, 11 months ago) by betelgeuse
Branch: MAIN
Changes since 1.27: +77 -95 lines
Remove generation 1 write support from the eclass to make it simpler. The eclass has for a while required javatoolkit version with a second generation rewriter.

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.26 2008/01/22 21:57:03 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.2.0-r1 ${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_IGNORE_SYSTEM_CLASSES
116 #
117 # Rewrites available tasks to ignore ant classpath.
118 #
119 # default: off
120 # ------------------------------------------------------------------------------
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 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
135 if ! java-pkg_needs-vm; then
136 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
137 fi
138
139 pushd "${S}" >/dev/null
140
141 local find_args=""
142 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
143
144 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
145
146 # This voodoo is done for paths with spaces
147 local bsfix_these
148 while read line; do
149 [[ -z ${line} ]] && continue
150 bsfix_these="${bsfix_these} '${line}'"
151 done <<-EOF
152 $(find . ${find_args})
153 EOF
154
155 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
156
157 popd > /dev/null
158 }
159
160 _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 # ------------------------------------------------------------------------------
174 # @public java-ant_bsfix_files
175 #
176 # Attempts to fix named build files. The following variables will affect its behavior
177 # as listed above:
178 # JAVA_PKG_BSFIX_SOURCE_TAGS
179 # JAVA_PKG_BSFIX_TARGET_TAGS
180 # 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 # When changing this function, make sure that it works with paths with spaces in
194 # them.
195 # ------------------------------------------------------------------------------
196 java-ant_bsfix_files() {
197 debug-print-function ${FUNCNAME} $*
198
199 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
200
201 local want_source="$(java-pkg_get-source)"
202 local want_target="$(java-pkg_get-target)"
203
204 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
205
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 local files
212
213 for file in "${@}"; do
214 debug-print "${FUNCNAME}: ${file}"
215
216 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
217 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
218 fi
219
220 if [[ ! -w "${file}" ]]; then
221 chmod u+w "${file}" || die "chmod u+w ${file} failed"
222 fi
223
224 files="${files} -f '${file}'"
225 done
226
227 # Play nice with paludis
228 if [[ $(type -t quiet_mode) = function ]] && quiet_mode; then
229 local output=">/dev/null"
230 fi
231
232 # for javadoc target and all in one pass, we need the new rewriter.
233 local rewriter3="/usr/share/javatoolkit/xml-rewrite-3.py"
234 if [[ ! -f ${rewriter3} ]]; then
235 debug-print "Using second generation rewriter"
236 eval echo "Rewriting source attributes" ${output}
237 eval xml-rewrite-2.py ${files} \
238 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
239 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
240
241 eval echo "Rewriting target attributes" ${output}
242 eval xml-rewrite-2.py ${files} \
243 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
244 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
245
246 eval echo "Rewriting nowarn attributes" ${output}
247 eval xml-rewrite-2.py ${files} \
248 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
249 -a nowarn -v yes ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
250
251 if [[ ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
252 eval echo "Adding gentoo.classpath to javac tasks" ${output}
253 eval xml-rewrite-2.py ${files} \
254 -c -e javac -e xjavac -a classpath -v \
255 '\${gentoo.classpath}' \
256 || _bsfix_die "xml-rewrite2 failed"
257 fi
258 else
259 debug-print "Using third generation rewriter"
260 eval echo "Rewriting attributes" ${output}
261 local bsfix_extra_args=""
262 # WARNING KEEP THE ORDER, ESPECIALLY FOR CHANGED ATTRIBUTES!
263 if [[ -n ${JAVA_ANT_REWRITE_CLASSPATH} ]]; then
264 bsfix_extra_args="${bsfix_extra_args} -g -e javac -e xjavac "
265 bsfix_extra_args="${bsfix_extra_args} -a classpath -v '\${gentoo.classpath}'"
266 fi
267 if [[ -n ${JAVA_ANT_JAVADOC_INPUT_DIRS} ]]; then
268 if [[ -n ${JAVA_ANT_JAVADOC_OUTPUT_DIR} ]]; then
269 die "Do not define JAVA_ANT_JAVADOC_OUTPUT_DIR!"
270 fi
271 # Where will our generated javadoc go.
272 readonly JAVA_ANT_JAVADOC_OUTPUT_DIR=${WORKDIR}/gentoo_javadoc
273 mkdir -p "${JAVA_ANT_JAVADOC_OUTPUT_DIR}" || die
274
275 if hasq doc ${IUSE}; then
276 if use doc; then
277 if [[ -z ${EANT_DOC_TARGET} ]]; then
278 EANT_DOC_TARGET="gentoojavadoc"
279 else
280 die "You can't use javadoc adding and set EANT_DOC_TARGET too."
281 fi
282
283 for dir in ${JAVA_ANT_JAVADOC_INPUT_DIRS};do
284 if [[ ! -d ${dir} ]]; then
285 eerror "This dir: ${dir} doesnt' exists"
286 die "You must specify directories for javadoc input/output dirs."
287 fi
288 done
289 bsfix_extra_args="${bsfix_extra_args} --javadoc --source-directory "
290 # filter third/double spaces
291 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
292 JAVA_ANT_JAVADOC_INPUT_DIRS=${JAVA_ANT_JAVADOC_INPUT_DIRS// /}
293 bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_JAVADOC_INPUT_DIRS// / --source-directory }"
294 bsfix_extra_args="${bsfix_extra_args} --output-directory ${JAVA_ANT_JAVADOC_OUTPUT_DIR}"
295 fi
296 else
297 die "You need to have doc in IUSE when using JAVA_ANT_JAVADOC_INPUT_DIRS"
298 fi
299 fi
300
301 [[ -n ${JAVA_ANT_BSFIX_EXTRA_ARGS} ]] \
302 && bsfix_extra_args="${bsfix_extra_args} ${JAVA_ANT_BSFIX_EXTRA_ARGS}"
303
304 eval ${rewriter3} ${files} \
305 -c --source-element ${JAVA_PKG_BSFIX_SOURCE_TAGS// / --source-element } \
306 --source-attribute source --source-value ${want_source} \
307 --target-element ${JAVA_PKG_BSFIX_TARGET_TAGS// / --target-element } \
308 --target-attribute target --target-value ${want_target} \
309 --target-attribute nowarn --target-value yes \
310 ${bsfix_extra_args} \
311 ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
312 fi
313
314 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
315 for file in "${@}"; do
316 diff -NurbB "${file}.orig" "${file}"
317 done
318 fi
319 fi
320 return 0 # so that the 1 for diff doesn't get reported
321 }
322
323
324 # ------------------------------------------------------------------------------
325 # @public java-ant_bsfix_one
326 #
327 # Attempts to fix named build file. The following variables will affect its behavior
328 # as listed above:
329 # JAVA_PKG_BSFIX_SOURCE_TAGS
330 # JAVA_PKG_BSFIX_TARGET_TAGS
331 # ------------------------------------------------------------------------------
332 java-ant_bsfix_one() {
333 debug-print-function ${FUNCNAME} $*
334
335 if [ -z "${1}" ]; then
336 eerror "${FUNCNAME} needs one argument"
337 die "${FUNCNAME} needs one argument"
338 fi
339
340 java-ant_bsfix_files "${1}"
341 }
342
343 # ------------------------------------------------------------------------------
344 # @public java-ant_rewrite-classpath
345 #
346 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
347 # @param $1 - the file to rewrite (defaults to build.xml)
348 # ------------------------------------------------------------------------------
349 java-ant_rewrite-classpath() {
350 debug-print-function ${FUNCNAME} $*
351
352 local file="${1}"
353 [[ -z "${1}" ]] && file=build.xml
354 [[ ${#} -gt 1 ]] && die "${FUNCNAME} currently can only rewrite one file."
355
356 echo "Adding gentoo.classpath to ${file}"
357 debug-print "java-ant_rewrite-classpath: ${file}"
358
359 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
360
361 chmod u+w "${file}"
362
363 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
364
365 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
366 diff -NurbB "${file}.orig" "${file}"
367 fi
368 }
369
370 # ------------------------------------------------------------------------------
371 # @public java-ant_ignore-system-classes
372 #
373 # Makes the available task ignore classes in the system classpath
374 # @param $1 - the file to rewrite (defaults to build.xml)
375 # ------------------------------------------------------------------------------
376 java-ant_ignore-system-classes() {
377 debug-print-function ${FUNCNAME} $*
378 local file="${1}"
379 [[ -z "${1}" ]] && file=build.xml
380 echo "Changing ignoresystemclasses to true for available tasks"
381 java-ant_xml-rewrite -f "${file}" --change \
382 -e available -a ignoresystemclasses -v "true"
383 }
384
385 # ------------------------------------------------------------------------------
386 # @public java-ant_xml-rewrite
387 # Run the right xml-rewrite binary with the given arguments
388 # ------------------------------------------------------------------------------
389 java-ant_xml-rewrite() {
390 local bindir="${ROOT}/usr/bin/"
391 local gen2="${bindir}/xml-rewrite-2.py"
392 # gen1 is deprecated
393 if [[ -x "${gen2}" ]]; then
394 ${gen2} "${@}" || die "${gen2} failed"
395 else
396 eerror "No binary for rewriting found."
397 eerror "Do you have dev-java/javatoolkit installed?"
398 die "xml-rewrite not found"
399 fi
400 }

  ViewVC Help
Powered by ViewVC 1.1.20