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

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