/[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.13 - (show annotations) (download)
Sat Jan 20 22:27:34 2007 UTC (7 years, 11 months ago) by betelgeuse
Branch: MAIN
Changes since 1.12: +6 -1 lines
Add support for JAVA_ANT_IGNORE_SYSTEM_CLASSES.

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

  ViewVC Help
Powered by ViewVC 1.1.20