/[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.14 - (show annotations) (download)
Sun Jan 21 01:20:21 2007 UTC (7 years, 10 months ago) by caster
Branch: MAIN
Changes since 1.13: +18 -1 lines
Add split-ant functionality to relevant eclasses.
----------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20