/[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.15 - (show annotations) (download)
Sun Jan 28 21:42:24 2007 UTC (7 years, 8 months ago) by betelgeuse
Branch: MAIN
Changes since 1.14: +4 -2 lines
Use WANT_ANT_TASKS if EANT_ANT_TASKS is not defined. Fixes bug #164315.

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.14 2007/01/21 01:20:21 caster 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 # We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
29 DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}"
30
31 # add ant-core into DEPEND, unless disabled
32 [[ "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]] || DEPEND="${DEPEND} dev-java/ant-core"
33
34 # add ant tasks specified in WANT_ANT_TASKS to DEPEND
35 local ANT_TASKS_DEPEND;
36 ANT_TASKS_DEPEND="$(java-pkg_ant-tasks-depend)"
37 # check that java-pkg_ant-tasks-depend didn't fail
38 if [[ $? != 0 ]]; then
39 eerror "${ANT_TASKS_DEPEND}"
40 die "java-pkg_ant-tasks-depend() failed"
41 fi
42 DEPEND="${DEPEND} ${ANT_TASKS_DEPEND}"
43
44 # ------------------------------------------------------------------------------
45 # @global JAVA_PKG_BSFIX
46 #
47 # Should we attempt to 'fix' ant build files to include the source/target
48 # attributes when calling javac?
49 #
50 # default: on
51 # ------------------------------------------------------------------------------
52 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
53
54 # ------------------------------------------------------------------------------
55 # @global JAVA_PKG_BSFIX_ALL
56 #
57 # If we're fixing build files, should we try to fix all the ones we can find?
58 #
59 # default: yes
60 # ------------------------------------------------------------------------------
61 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
62
63 # ------------------------------------------------------------------------------
64 # @global JAVA_PKG_BSFIX_NAME
65 #
66 # Filename of build files to fix/search for
67 #
68 # default: build.xml
69 # ------------------------------------------------------------------------------
70 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
71
72 # ------------------------------------------------------------------------------
73 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
74 #
75 # Targets to fix the 'source' attribute in
76 #
77 # default: javac xjavac javac.preset
78 # ------------------------------------------------------------------------------
79 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
80
81 # ------------------------------------------------------------------------------
82 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
83 #
84 # Targets to fix the 'target' attribute in
85 #
86 # default: javacdoc javac xjavac javac.preset
87 # ------------------------------------------------------------------------------
88 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
89
90 # ------------------------------------------------------------------------------
91 # @public java-ant_src_unpack
92 #
93 # Unpacks the source, and attempts to fix build files.
94 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
95 # ignore ant classpath in available tasks
96 # ------------------------------------------------------------------------------
97 post_src_unpack() {
98 if java-pkg_func-exists ant_src_unpack; then
99 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
100 ant_src_unpack
101 fi
102 java-ant_bsfix
103 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
104 && java-ant_ignore-system-classes "${S}/build.xml"
105 }
106
107 # ------------------------------------------------------------------------------
108 # @private ant_src_unpack
109 #
110 # Helper function which does the actual unpacking
111 # ------------------------------------------------------------------------------
112 # TODO maybe use base.eclass for some patching love?
113 #ant_src_unpack() {
114 # debug-print-function ${FUNCNAME} $*
115 # if [[ -n "${A}" ]]; then
116 # unpack ${A}
117 # fi
118 #}
119
120 # ------------------------------------------------------------------------------
121 # @private java-ant_bsfix
122 #
123 # Attempts to fix build files. The following variables will affect its behavior
124 # as listed above:
125 # JAVA_PKG_BSFIX
126 # JAVA_PKG_BSFIX_ALL
127 # JAVA_PKG_BSFIX_NAME,
128 # ------------------------------------------------------------------------------
129 java-ant_bsfix() {
130 debug-print-function ${FUNCNAME} $*
131
132 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
133 if ! java-pkg_needs-vm; then
134 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
135 fi
136
137 pushd "${S}" >/dev/null
138
139 local find_args=""
140 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
141
142 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
143
144 # This voodoo is done for paths with spaces
145 local bsfix_these
146 while read line; do
147 [[ -z ${line} ]] && continue
148 bsfix_these="${bsfix_these} '${line}'"
149 done <<-EOF
150 $(find . ${find_args})
151 EOF
152
153 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
154
155 popd > /dev/null
156 }
157
158 _bsfix_die() {
159 if has_version dev-python/pyxml; then
160 eerror "If the output above contains:"
161 eerror "ImportError:"
162 eerror "/usr/lib/python2.4/site-packages/_xmlplus/parsers/pyexpat.so:"
163 eerror "undefined symbol: PyUnicodeUCS2_DecodeUTF8"
164 eerror "Try re-emerging dev-python/pyxml"
165 die ${1} " Look at the eerror message above"
166 else
167 die ${1}
168 fi
169 }
170
171 # ------------------------------------------------------------------------------
172 # @public java-ant_bsfix_files
173 #
174 # Attempts to fix named build files. The following variables will affect its behavior
175 # as listed above:
176 # JAVA_PKG_BSFIX_SOURCE_TAGS
177 # JAVA_PKG_BSFIX_TARGET_TAGS
178 #
179 # When changing this function, make sure that it works with paths with spaces in
180 # them.
181 # ------------------------------------------------------------------------------
182 java-ant_bsfix_files() {
183 debug-print-function ${FUNCNAME} $*
184
185 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
186
187 local want_source="$(java-pkg_get-source)"
188 local want_target="$(java-pkg_get-target)"
189
190 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
191
192 if [ -z "${want_source}" -o -z "${want_target}" ]; then
193 eerror "Could not find valid -source/-target values"
194 eerror "Please file a bug about this on bugs.gentoo.org"
195 die "Could not find valid -source/-target values"
196 else
197 local files
198
199 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
200
201 for file in "${@}"; do
202 debug-print "${FUNCNAME}: ${file}"
203
204 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
205 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
206 fi
207
208 if [[ ! -w "${file}" ]]; then
209 chmod u+w "${file}" || die "chmod u+w ${file} failed"
210 fi
211
212 files="${files} -f '${file}'"
213
214 if [[ -z "${using_new}" ]]; then
215 vecho "Rewriting $file (using xml-rewrite.py)"
216 # Doing this twice because otherwise the source attributes would
217 # get added to target tags too and javadoc does not like target
218 xml-rewrite.py -f "${file}" \
219 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
220 -a source -v ${want_source} || _bsfix_die "xml-rewrite failed: ${file}"
221 xml-rewrite.py -f "${file}" \
222 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
223 -a target -v ${want_target} || _bsfix_die "xml-rewrite failed: ${file}"
224 fi
225 done
226
227 if [[ "${using_new}" ]]; then
228 quiet_mode && local output=">/dev/null"
229 vecho "Rewriting source attributes"
230 eval xml-rewrite-2.py ${files} \
231 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
232 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
233
234 vecho "Rewriting target attributes"
235 eval xml-rewrite-2.py ${files} \
236 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
237 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
238 fi
239
240 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
241 for file in "${@}"; do
242 diff -NurbB "${file}.orig" "${file}"
243 done
244 fi
245 fi
246 }
247
248
249 # ------------------------------------------------------------------------------
250 # @public java-ant_bsfix_one
251 #
252 # Attempts to fix named build file. The following variables will affect its behavior
253 # as listed above:
254 # JAVA_PKG_BSFIX_SOURCE_TAGS
255 # JAVA_PKG_BSFIX_TARGET_TAGS
256 # ------------------------------------------------------------------------------
257 java-ant_bsfix_one() {
258 debug-print-function ${FUNCNAME} $*
259
260 if [ -z "${1}" ]; then
261 eerror "${FUNCNAME} needs one argument"
262 die "${FUNCNAME} needs one argument"
263 fi
264
265 java-ant_bsfix_files "${1}"
266 }
267
268 # ------------------------------------------------------------------------------
269 # @public java-ant_rewrite-classpath
270 #
271 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
272 # @param $1 - the file to rewrite (defaults to build.xml)
273 # ------------------------------------------------------------------------------
274 java-ant_rewrite-classpath() {
275 debug-print-function ${FUNCNAME} $*
276
277 local file="${1}"
278 [[ -z "${1}" ]] && file=build.xml
279
280 echo "Adding gentoo.classpath to ${file}"
281 debug-print "java-ant_rewrite-classpath: ${file}"
282
283 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
284
285 chmod u+w "${file}"
286
287 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
288
289 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
290 diff -NurbB "${file}.orig" "${file}"
291 fi
292 }
293
294 # ------------------------------------------------------------------------------
295 # @public java-ant_ignore-system-classes
296 #
297 # Makes the available task ignore classes in the system classpath
298 # @param $1 - the file to rewrite (defaults to build.xml)
299 # ------------------------------------------------------------------------------
300 java-ant_ignore-system-classes() {
301 debug-print-function ${FUNCNAME} $*
302 local file="${1}"
303 [[ -z "${1}" ]] && file=build.xml
304 echo "Changing ignoresystemclasses to true for available tasks"
305 java-ant_xml-rewrite -f "${file}" --change \
306 -e available -a ignoresystemclasses -v "true"
307 }
308
309 # ------------------------------------------------------------------------------
310 # @public java-ant_xml-rewrite
311 # Run the right xml-rewrite binary with the given arguments
312 # ------------------------------------------------------------------------------
313 java-ant_xml-rewrite() {
314 local bindir="${ROOT}/usr/bin/"
315 local gen2="${bindir}/xml-rewrite-2.py"
316 local gen1="${bindir}/xml-rewrite.py"
317 if [[ -x "${gen2}" ]]; then
318 ${gen2} "${@}" || die "${gen2} failed"
319 elif [[ -x "${gen1}" ]]; then
320 ${gen1} "${@}" || die "${gen1} failed"
321 else
322 eerror "No binary for rewriting found."
323 eerror "Do you have dev-java/javatoolkit installed?"
324 die "xml-rewrite not found"
325 fi
326 }

  ViewVC Help
Powered by ViewVC 1.1.20