/[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.11 - (hide annotations) (download)
Sat Jan 6 19:45:27 2007 UTC (7 years, 3 months ago) by betelgeuse
Branch: MAIN
Changes since 1.10: +22 -5 lines
Added instructions for re-emerging dev-python/pyxml when there are undefined symbols in pyexpat.so

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

  ViewVC Help
Powered by ViewVC 1.1.20