/[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.17 - (hide annotations) (download)
Tue Jan 30 21:51:15 2007 UTC (7 years, 7 months ago) by caster
Branch: MAIN
Changes since 1.16: +40 -6 lines
Put ant-core to DEPEND unless disabled. WANT_SPLIT_ANT restricts the dep to proper version. These
depends are mandatory for java-pkg-2, and triggered by USE flag for java-pkg-opt-2 (WANT_ANT_TASKS
depends. Because of that, java-ant-2 can only by inherited AFTER one of those eclasss.
too)

1 nichoj 1.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 betelgeuse 1.10 # 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 nichoj 1.1 #
11     # Licensed under the GNU General Public License, v2
12     #
13 caster 1.17 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.16 2007/01/28 21:45:38 betelgeuse Exp $
14 nichoj 1.1
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 caster 1.14 # -----------------------------------------------------------------------------
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 caster 1.17 # -----------------------------------------------------------------------------
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 betelgeuse 1.15
45 caster 1.17 # 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 betelgeuse 1.15
56 caster 1.14 # 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 caster 1.17 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.1.5 ${JAVA_PKG_PORTAGE_DEP} ${JAVA_ANT_E_DEPEND}"
77 nichoj 1.1
78     # ------------------------------------------------------------------------------
79 nichoj 1.7 # @global JAVA_PKG_BSFIX
80 nichoj 1.1 #
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 nichoj 1.7 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
87 nichoj 1.1
88     # ------------------------------------------------------------------------------
89 nichoj 1.7 # @global JAVA_PKG_BSFIX_ALL
90 nichoj 1.1 #
91     # If we're fixing build files, should we try to fix all the ones we can find?
92     #
93     # default: yes
94     # ------------------------------------------------------------------------------
95 nichoj 1.7 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
96 nichoj 1.1
97     # ------------------------------------------------------------------------------
98 nichoj 1.5 # @global JAVA_PKG_BSFIX_NAME
99 nichoj 1.1 #
100     # Filename of build files to fix/search for
101     #
102     # default: build.xml
103     # ------------------------------------------------------------------------------
104 nichoj 1.7 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
105 nichoj 1.1
106     # ------------------------------------------------------------------------------
107 nichoj 1.7 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
108 nichoj 1.1 #
109     # Targets to fix the 'source' attribute in
110     #
111     # default: javac xjavac javac.preset
112     # ------------------------------------------------------------------------------
113 nichoj 1.7 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
114 nichoj 1.1
115     # ------------------------------------------------------------------------------
116 nichoj 1.7 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
117 nichoj 1.1 #
118     # Targets to fix the 'target' attribute in
119     #
120     # default: javacdoc javac xjavac javac.preset
121     # ------------------------------------------------------------------------------
122 nichoj 1.7 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
123 nichoj 1.1
124     # ------------------------------------------------------------------------------
125     # @public java-ant_src_unpack
126     #
127     # Unpacks the source, and attempts to fix build files.
128 betelgeuse 1.13 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
129     # ignore ant classpath in available tasks
130 nichoj 1.1 # ------------------------------------------------------------------------------
131 nichoj 1.2 post_src_unpack() {
132     if java-pkg_func-exists ant_src_unpack; then
133     java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
134     ant_src_unpack
135     fi
136 nichoj 1.1 java-ant_bsfix
137 betelgeuse 1.13 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
138     && java-ant_ignore-system-classes "${S}/build.xml"
139 nichoj 1.1 }
140    
141     # ------------------------------------------------------------------------------
142     # @private ant_src_unpack
143     #
144     # Helper function which does the actual unpacking
145     # ------------------------------------------------------------------------------
146     # TODO maybe use base.eclass for some patching love?
147 nichoj 1.2 #ant_src_unpack() {
148     # debug-print-function ${FUNCNAME} $*
149     # if [[ -n "${A}" ]]; then
150     # unpack ${A}
151     # fi
152     #}
153 nichoj 1.1
154     # ------------------------------------------------------------------------------
155     # @private java-ant_bsfix
156     #
157     # Attempts to fix build files. The following variables will affect its behavior
158     # as listed above:
159     # JAVA_PKG_BSFIX
160     # JAVA_PKG_BSFIX_ALL
161     # JAVA_PKG_BSFIX_NAME,
162     # ------------------------------------------------------------------------------
163     java-ant_bsfix() {
164     debug-print-function ${FUNCNAME} $*
165    
166 nelchael 1.4 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
167     if ! java-pkg_needs-vm; then
168 nichoj 1.1 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
169     fi
170    
171 betelgeuse 1.10 pushd "${S}" >/dev/null
172 nelchael 1.4
173 nichoj 1.7 local find_args=""
174     [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
175 swegener 1.8
176 nichoj 1.7 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
177 nichoj 1.1
178 betelgeuse 1.10 # This voodoo is done for paths with spaces
179     local bsfix_these
180 nichoj 1.1 while read line; do
181     [[ -z ${line} ]] && continue
182 betelgeuse 1.10 bsfix_these="${bsfix_these} '${line}'"
183 swegener 1.8 done <<-EOF
184 flameeyes 1.3 $(find . ${find_args})
185 nichoj 1.1 EOF
186    
187 betelgeuse 1.10 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
188    
189     popd > /dev/null
190 nelchael 1.4 }
191    
192 betelgeuse 1.11 _bsfix_die() {
193     if has_version dev-python/pyxml; then
194     eerror "If the output above contains:"
195     eerror "ImportError:"
196     eerror "/usr/lib/python2.4/site-packages/_xmlplus/parsers/pyexpat.so:"
197     eerror "undefined symbol: PyUnicodeUCS2_DecodeUTF8"
198     eerror "Try re-emerging dev-python/pyxml"
199     die ${1} " Look at the eerror message above"
200     else
201     die ${1}
202     fi
203     }
204    
205 nelchael 1.4 # ------------------------------------------------------------------------------
206 betelgeuse 1.10 # @public java-ant_bsfix_files
207 nelchael 1.4 #
208 betelgeuse 1.10 # Attempts to fix named build files. The following variables will affect its behavior
209 nelchael 1.4 # as listed above:
210     # JAVA_PKG_BSFIX_SOURCE_TAGS
211     # JAVA_PKG_BSFIX_TARGET_TAGS
212 betelgeuse 1.10 #
213     # When changing this function, make sure that it works with paths with spaces in
214     # them.
215 nelchael 1.4 # ------------------------------------------------------------------------------
216 betelgeuse 1.10 java-ant_bsfix_files() {
217 nelchael 1.4 debug-print-function ${FUNCNAME} $*
218    
219 betelgeuse 1.10 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
220 nelchael 1.4
221 nichoj 1.1 local want_source="$(java-pkg_get-source)"
222     local want_target="$(java-pkg_get-target)"
223    
224 betelgeuse 1.10 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
225 nichoj 1.1
226     if [ -z "${want_source}" -o -z "${want_target}" ]; then
227     eerror "Could not find valid -source/-target values"
228     eerror "Please file a bug about this on bugs.gentoo.org"
229     die "Could not find valid -source/-target values"
230     else
231 betelgeuse 1.10 local files
232 nelchael 1.4
233 betelgeuse 1.10 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
234 nelchael 1.4
235 betelgeuse 1.10 for file in "${@}"; do
236     debug-print "${FUNCNAME}: ${file}"
237 nelchael 1.4
238 betelgeuse 1.10 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
239     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
240     fi
241    
242     if [[ ! -w "${file}" ]]; then
243     chmod u+w "${file}" || die "chmod u+w ${file} failed"
244     fi
245    
246     files="${files} -f '${file}'"
247    
248     if [[ -z "${using_new}" ]]; then
249     vecho "Rewriting $file (using xml-rewrite.py)"
250     # Doing this twice because otherwise the source attributes would
251     # get added to target tags too and javadoc does not like target
252 betelgeuse 1.11 xml-rewrite.py -f "${file}" \
253     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
254     -a source -v ${want_source} || _bsfix_die "xml-rewrite failed: ${file}"
255     xml-rewrite.py -f "${file}" \
256     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
257     -a target -v ${want_target} || _bsfix_die "xml-rewrite failed: ${file}"
258 betelgeuse 1.10 fi
259     done
260    
261     if [[ "${using_new}" ]]; then
262     quiet_mode && local output=">/dev/null"
263     vecho "Rewriting source attributes"
264     eval xml-rewrite-2.py ${files} \
265     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
266 betelgeuse 1.11 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
267 betelgeuse 1.10
268     vecho "Rewriting target attributes"
269     eval xml-rewrite-2.py ${files} \
270     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
271 betelgeuse 1.11 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
272 betelgeuse 1.10 fi
273 nelchael 1.4
274     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
275 betelgeuse 1.10 for file in "${@}"; do
276     diff -NurbB "${file}.orig" "${file}"
277     done
278 nelchael 1.4 fi
279 nichoj 1.1 fi
280     }
281 nelchael 1.6
282 betelgeuse 1.10
283     # ------------------------------------------------------------------------------
284     # @public java-ant_bsfix_one
285     #
286     # Attempts to fix named build file. The following variables will affect its behavior
287     # as listed above:
288     # JAVA_PKG_BSFIX_SOURCE_TAGS
289     # JAVA_PKG_BSFIX_TARGET_TAGS
290     # ------------------------------------------------------------------------------
291     java-ant_bsfix_one() {
292     debug-print-function ${FUNCNAME} $*
293    
294     if [ -z "${1}" ]; then
295     eerror "${FUNCNAME} needs one argument"
296     die "${FUNCNAME} needs one argument"
297     fi
298    
299     java-ant_bsfix_files "${1}"
300     }
301    
302 nelchael 1.6 # ------------------------------------------------------------------------------
303     # @public java-ant_rewrite-classpath
304     #
305     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
306 betelgeuse 1.12 # @param $1 - the file to rewrite (defaults to build.xml)
307 nelchael 1.6 # ------------------------------------------------------------------------------
308     java-ant_rewrite-classpath() {
309     debug-print-function ${FUNCNAME} $*
310    
311 betelgeuse 1.12 local file="${1}"
312     [[ -z "${1}" ]] && file=build.xml
313 nelchael 1.6
314     echo "Adding gentoo.classpath to ${file}"
315     debug-print "java-ant_rewrite-classpath: ${file}"
316    
317     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
318    
319     chmod u+w "${file}"
320    
321 betelgeuse 1.12 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
322 nelchael 1.6
323     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
324     diff -NurbB "${file}.orig" "${file}"
325     fi
326     }
327 betelgeuse 1.12
328     # ------------------------------------------------------------------------------
329     # @public java-ant_ignore-system-classes
330     #
331     # Makes the available task ignore classes in the system classpath
332     # @param $1 - the file to rewrite (defaults to build.xml)
333     # ------------------------------------------------------------------------------
334     java-ant_ignore-system-classes() {
335     debug-print-function ${FUNCNAME} $*
336     local file="${1}"
337     [[ -z "${1}" ]] && file=build.xml
338     echo "Changing ignoresystemclasses to true for available tasks"
339     java-ant_xml-rewrite -f "${file}" --change \
340     -e available -a ignoresystemclasses -v "true"
341     }
342    
343     # ------------------------------------------------------------------------------
344     # @public java-ant_xml-rewrite
345     # Run the right xml-rewrite binary with the given arguments
346     # ------------------------------------------------------------------------------
347     java-ant_xml-rewrite() {
348     local bindir="${ROOT}/usr/bin/"
349     local gen2="${bindir}/xml-rewrite-2.py"
350     local gen1="${bindir}/xml-rewrite.py"
351     if [[ -x "${gen2}" ]]; then
352     ${gen2} "${@}" || die "${gen2} failed"
353     elif [[ -x "${gen1}" ]]; then
354     ${gen1} "${@}" || die "${gen1} failed"
355     else
356     eerror "No binary for rewriting found."
357     eerror "Do you have dev-java/javatoolkit installed?"
358     die "xml-rewrite not found"
359     fi
360     }

  ViewVC Help
Powered by ViewVC 1.1.20