/[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.18 - (hide annotations) (download)
Thu Mar 1 14:01:02 2007 UTC (7 years, 9 months ago) by betelgeuse
Branch: MAIN
Changes since 1.17: +8 -5 lines
Don't use Portage internals to make the eclass quieter without first checking that quiet_mode exists. Makes this eclass play nicer with paludis.

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.18 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.17 2007/01/30 21:51:15 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 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 betelgeuse 1.18 echo "Rewriting $file (using xml-rewrite.py)"
250 betelgeuse 1.10 # 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 betelgeuse 1.18 # Play nice with paludis
263     if [[ $(type -t quiet_mode) = function ]] && quiet_mode; then
264     local output=">/dev/null"
265     fi
266     eval echo "Rewriting source attributes" ${output}
267 betelgeuse 1.10 eval xml-rewrite-2.py ${files} \
268     -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
269 betelgeuse 1.11 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
270 betelgeuse 1.10
271 betelgeuse 1.18 eval echo "Rewriting target attributes" ${output}
272 betelgeuse 1.10 eval xml-rewrite-2.py ${files} \
273     -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
274 betelgeuse 1.11 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
275 betelgeuse 1.10 fi
276 nelchael 1.4
277     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
278 betelgeuse 1.10 for file in "${@}"; do
279     diff -NurbB "${file}.orig" "${file}"
280     done
281 nelchael 1.4 fi
282 nichoj 1.1 fi
283     }
284 nelchael 1.6
285 betelgeuse 1.10
286     # ------------------------------------------------------------------------------
287     # @public java-ant_bsfix_one
288     #
289     # Attempts to fix named build file. The following variables will affect its behavior
290     # as listed above:
291     # JAVA_PKG_BSFIX_SOURCE_TAGS
292     # JAVA_PKG_BSFIX_TARGET_TAGS
293     # ------------------------------------------------------------------------------
294     java-ant_bsfix_one() {
295     debug-print-function ${FUNCNAME} $*
296    
297     if [ -z "${1}" ]; then
298     eerror "${FUNCNAME} needs one argument"
299     die "${FUNCNAME} needs one argument"
300     fi
301    
302     java-ant_bsfix_files "${1}"
303     }
304    
305 nelchael 1.6 # ------------------------------------------------------------------------------
306     # @public java-ant_rewrite-classpath
307     #
308     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
309 betelgeuse 1.12 # @param $1 - the file to rewrite (defaults to build.xml)
310 nelchael 1.6 # ------------------------------------------------------------------------------
311     java-ant_rewrite-classpath() {
312     debug-print-function ${FUNCNAME} $*
313    
314 betelgeuse 1.12 local file="${1}"
315     [[ -z "${1}" ]] && file=build.xml
316 nelchael 1.6
317     echo "Adding gentoo.classpath to ${file}"
318     debug-print "java-ant_rewrite-classpath: ${file}"
319    
320     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
321    
322     chmod u+w "${file}"
323    
324 betelgeuse 1.12 java-ant_xml-rewrite -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}'
325 nelchael 1.6
326     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
327     diff -NurbB "${file}.orig" "${file}"
328     fi
329     }
330 betelgeuse 1.12
331     # ------------------------------------------------------------------------------
332     # @public java-ant_ignore-system-classes
333     #
334     # Makes the available task ignore classes in the system classpath
335     # @param $1 - the file to rewrite (defaults to build.xml)
336     # ------------------------------------------------------------------------------
337     java-ant_ignore-system-classes() {
338     debug-print-function ${FUNCNAME} $*
339     local file="${1}"
340     [[ -z "${1}" ]] && file=build.xml
341     echo "Changing ignoresystemclasses to true for available tasks"
342     java-ant_xml-rewrite -f "${file}" --change \
343     -e available -a ignoresystemclasses -v "true"
344     }
345    
346     # ------------------------------------------------------------------------------
347     # @public java-ant_xml-rewrite
348     # Run the right xml-rewrite binary with the given arguments
349     # ------------------------------------------------------------------------------
350     java-ant_xml-rewrite() {
351     local bindir="${ROOT}/usr/bin/"
352     local gen2="${bindir}/xml-rewrite-2.py"
353     local gen1="${bindir}/xml-rewrite.py"
354     if [[ -x "${gen2}" ]]; then
355     ${gen2} "${@}" || die "${gen2} failed"
356     elif [[ -x "${gen1}" ]]; then
357     ${gen1} "${@}" || die "${gen1} failed"
358     else
359     eerror "No binary for rewriting found."
360     eerror "Do you have dev-java/javatoolkit installed?"
361     die "xml-rewrite not found"
362     fi
363     }

  ViewVC Help
Powered by ViewVC 1.1.20