/[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 - (hide annotations) (download)
Sun Jan 28 21:42:24 2007 UTC (7 years, 11 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 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 betelgeuse 1.15 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.14 2007/01/21 01:20:21 caster 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 nichoj 1.2 # 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 betelgeuse 1.15
31 caster 1.14 # add ant-core into DEPEND, unless disabled
32 betelgeuse 1.15 [[ "${JAVA_ANT_DISABLE_ANT_CORE_DEP}" ]] || DEPEND="${DEPEND} dev-java/ant-core"
33    
34 caster 1.14 # 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 nichoj 1.1
44     # ------------------------------------------------------------------------------
45 nichoj 1.7 # @global JAVA_PKG_BSFIX
46 nichoj 1.1 #
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 nichoj 1.7 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
53 nichoj 1.1
54     # ------------------------------------------------------------------------------
55 nichoj 1.7 # @global JAVA_PKG_BSFIX_ALL
56 nichoj 1.1 #
57     # If we're fixing build files, should we try to fix all the ones we can find?
58     #
59     # default: yes
60     # ------------------------------------------------------------------------------
61 nichoj 1.7 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
62 nichoj 1.1
63     # ------------------------------------------------------------------------------
64 nichoj 1.5 # @global JAVA_PKG_BSFIX_NAME
65 nichoj 1.1 #
66     # Filename of build files to fix/search for
67     #
68     # default: build.xml
69     # ------------------------------------------------------------------------------
70 nichoj 1.7 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
71 nichoj 1.1
72     # ------------------------------------------------------------------------------
73 nichoj 1.7 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
74 nichoj 1.1 #
75     # Targets to fix the 'source' attribute in
76     #
77     # default: javac xjavac javac.preset
78     # ------------------------------------------------------------------------------
79 nichoj 1.7 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
80 nichoj 1.1
81     # ------------------------------------------------------------------------------
82 nichoj 1.7 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
83 nichoj 1.1 #
84     # Targets to fix the 'target' attribute in
85     #
86     # default: javacdoc javac xjavac javac.preset
87     # ------------------------------------------------------------------------------
88 nichoj 1.7 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
89 nichoj 1.1
90     # ------------------------------------------------------------------------------
91     # @public java-ant_src_unpack
92     #
93     # Unpacks the source, and attempts to fix build files.
94 betelgeuse 1.13 # variable JAVA_ANT_IGNORE_SYSTEM_CLASSES:
95     # ignore ant classpath in available tasks
96 nichoj 1.1 # ------------------------------------------------------------------------------
97 nichoj 1.2 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 nichoj 1.1 java-ant_bsfix
103 betelgeuse 1.13 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" ]] \
104     && java-ant_ignore-system-classes "${S}/build.xml"
105 nichoj 1.1 }
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 nichoj 1.2 #ant_src_unpack() {
114     # debug-print-function ${FUNCNAME} $*
115     # if [[ -n "${A}" ]]; then
116     # unpack ${A}
117     # fi
118     #}
119 nichoj 1.1
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 nelchael 1.4 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
133     if ! java-pkg_needs-vm; then
134 nichoj 1.1 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
135     fi
136    
137 betelgeuse 1.10 pushd "${S}" >/dev/null
138 nelchael 1.4
139 nichoj 1.7 local find_args=""
140     [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
141 swegener 1.8
142 nichoj 1.7 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
143 nichoj 1.1
144 betelgeuse 1.10 # This voodoo is done for paths with spaces
145     local bsfix_these
146 nichoj 1.1 while read line; do
147     [[ -z ${line} ]] && continue
148 betelgeuse 1.10 bsfix_these="${bsfix_these} '${line}'"
149 swegener 1.8 done <<-EOF
150 flameeyes 1.3 $(find . ${find_args})
151 nichoj 1.1 EOF
152    
153 betelgeuse 1.10 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
154    
155     popd > /dev/null
156 nelchael 1.4 }
157    
158 betelgeuse 1.11 _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 nelchael 1.4 # ------------------------------------------------------------------------------
172 betelgeuse 1.10 # @public java-ant_bsfix_files
173 nelchael 1.4 #
174 betelgeuse 1.10 # Attempts to fix named build files. The following variables will affect its behavior
175 nelchael 1.4 # as listed above:
176     # JAVA_PKG_BSFIX_SOURCE_TAGS
177     # JAVA_PKG_BSFIX_TARGET_TAGS
178 betelgeuse 1.10 #
179     # When changing this function, make sure that it works with paths with spaces in
180     # them.
181 nelchael 1.4 # ------------------------------------------------------------------------------
182 betelgeuse 1.10 java-ant_bsfix_files() {
183 nelchael 1.4 debug-print-function ${FUNCNAME} $*
184    
185 betelgeuse 1.10 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
186 nelchael 1.4
187 nichoj 1.1 local want_source="$(java-pkg_get-source)"
188     local want_target="$(java-pkg_get-target)"
189    
190 betelgeuse 1.10 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
191 nichoj 1.1
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 betelgeuse 1.10 local files
198 nelchael 1.4
199 betelgeuse 1.10 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
200 nelchael 1.4
201 betelgeuse 1.10 for file in "${@}"; do
202     debug-print "${FUNCNAME}: ${file}"
203 nelchael 1.4
204 betelgeuse 1.10 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 betelgeuse 1.11 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 betelgeuse 1.10 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 betelgeuse 1.11 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
233 betelgeuse 1.10
234     vecho "Rewriting target attributes"
235     eval xml-rewrite-2.py ${files} \
236     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
237 betelgeuse 1.11 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
238 betelgeuse 1.10 fi
239 nelchael 1.4
240     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
241 betelgeuse 1.10 for file in "${@}"; do
242     diff -NurbB "${file}.orig" "${file}"
243     done
244 nelchael 1.4 fi
245 nichoj 1.1 fi
246     }
247 nelchael 1.6
248 betelgeuse 1.10
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 nelchael 1.6 # ------------------------------------------------------------------------------
269     # @public java-ant_rewrite-classpath
270     #
271     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
272 betelgeuse 1.12 # @param $1 - the file to rewrite (defaults to build.xml)
273 nelchael 1.6 # ------------------------------------------------------------------------------
274     java-ant_rewrite-classpath() {
275     debug-print-function ${FUNCNAME} $*
276    
277 betelgeuse 1.12 local file="${1}"
278     [[ -z "${1}" ]] && file=build.xml
279 nelchael 1.6
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 betelgeuse 1.12 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
288 nelchael 1.6
289     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
290     diff -NurbB "${file}.orig" "${file}"
291     fi
292     }
293 betelgeuse 1.12
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