/[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.10 - (show annotations) (download)
Wed Dec 27 18:46:01 2006 UTC (7 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.9: +79 -26 lines
Reworked the eclass to work with xml-rewrite-2.py that is way faster.

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 # 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 #
11 # Licensed under the GNU General Public License, v2
12 #
13 # $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.9 2006/12/03 13:05:06 betelgeuse Exp $
14
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 # 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
24 # ------------------------------------------------------------------------------
25 # @global JAVA_PKG_BSFIX
26 #
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 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
33
34 # ------------------------------------------------------------------------------
35 # @global JAVA_PKG_BSFIX_ALL
36 #
37 # If we're fixing build files, should we try to fix all the ones we can find?
38 #
39 # default: yes
40 # ------------------------------------------------------------------------------
41 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
42
43 # ------------------------------------------------------------------------------
44 # @global JAVA_PKG_BSFIX_NAME
45 #
46 # Filename of build files to fix/search for
47 #
48 # default: build.xml
49 # ------------------------------------------------------------------------------
50 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
51
52 # ------------------------------------------------------------------------------
53 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
54 #
55 # Targets to fix the 'source' attribute in
56 #
57 # default: javac xjavac javac.preset
58 # ------------------------------------------------------------------------------
59 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
60
61 # ------------------------------------------------------------------------------
62 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
63 #
64 # Targets to fix the 'target' attribute in
65 #
66 # default: javacdoc javac xjavac javac.preset
67 # ------------------------------------------------------------------------------
68 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
69
70 # ------------------------------------------------------------------------------
71 # @public java-ant_src_unpack
72 #
73 # Unpacks the source, and attempts to fix build files.
74 # ------------------------------------------------------------------------------
75 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 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 #ant_src_unpack() {
90 # debug-print-function ${FUNCNAME} $*
91 # if [[ -n "${A}" ]]; then
92 # unpack ${A}
93 # fi
94 #}
95
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 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
109 if ! java-pkg_needs-vm; then
110 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
111 fi
112
113 pushd "${S}" >/dev/null
114
115 local find_args=""
116 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
117
118 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
119
120 # This voodoo is done for paths with spaces
121 local bsfix_these
122 while read line; do
123 [[ -z ${line} ]] && continue
124 bsfix_these="${bsfix_these} '${line}'"
125 done <<-EOF
126 $(find . ${find_args})
127 EOF
128
129 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
130
131 popd > /dev/null
132 }
133
134 # ------------------------------------------------------------------------------
135 # @public java-ant_bsfix_files
136 #
137 # Attempts to fix named build files. The following variables will affect its behavior
138 # as listed above:
139 # JAVA_PKG_BSFIX_SOURCE_TAGS
140 # JAVA_PKG_BSFIX_TARGET_TAGS
141 #
142 # When changing this function, make sure that it works with paths with spaces in
143 # them.
144 # ------------------------------------------------------------------------------
145 java-ant_bsfix_files() {
146 debug-print-function ${FUNCNAME} $*
147
148 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
149
150 local want_source="$(java-pkg_get-source)"
151 local want_target="$(java-pkg_get-target)"
152
153 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
154
155 if [ -z "${want_source}" -o -z "${want_target}" ]; then
156 eerror "Could not find valid -source/-target values"
157 eerror "Please file a bug about this on bugs.gentoo.org"
158 die "Could not find valid -source/-target values"
159 else
160 local files
161
162 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
163
164 for file in "${@}"; do
165 debug-print "${FUNCNAME}: ${file}"
166
167 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
168 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
169 fi
170
171 if [[ ! -w "${file}" ]]; then
172 chmod u+w "${file}" || die "chmod u+w ${file} failed"
173 fi
174
175 files="${files} -f '${file}'"
176
177 if [[ -z "${using_new}" ]]; then
178 vecho "Rewriting $file (using xml-rewrite.py)"
179 # Doing this twice because otherwise the source attributes would
180 # get added to target tags too and javadoc does not like target
181 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } -a source -v ${want_source} || die "xml-rewrite failed: ${file}"
182 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } -a target -v ${want_target} || die "xml-rewrite failed: ${file}"
183 fi
184 done
185
186 if [[ "${using_new}" ]]; then
187 quiet_mode && local output=">/dev/null"
188 vecho "Rewriting source attributes"
189 eval xml-rewrite-2.py ${files} \
190 -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } \
191 -a source -v ${want_source} ${output} || die "xml-rewrite2 failed: ${file}"
192
193 vecho "Rewriting target attributes"
194 eval xml-rewrite-2.py ${files} \
195 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
196 -a target -v ${want_target} ${output} || die "xml-rewrite2 failed: ${file}"
197 fi
198
199 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
200 for file in "${@}"; do
201 diff -NurbB "${file}.orig" "${file}"
202 done
203 fi
204 fi
205 }
206
207
208 # ------------------------------------------------------------------------------
209 # @public java-ant_bsfix_one
210 #
211 # Attempts to fix named build file. The following variables will affect its behavior
212 # as listed above:
213 # JAVA_PKG_BSFIX_SOURCE_TAGS
214 # JAVA_PKG_BSFIX_TARGET_TAGS
215 # ------------------------------------------------------------------------------
216 java-ant_bsfix_one() {
217 debug-print-function ${FUNCNAME} $*
218
219 if [ -z "${1}" ]; then
220 eerror "${FUNCNAME} needs one argument"
221 die "${FUNCNAME} needs one argument"
222 fi
223
224 java-ant_bsfix_files "${1}"
225 }
226
227 # ------------------------------------------------------------------------------
228 # @public java-ant_rewrite-classpath
229 #
230 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
231 # ------------------------------------------------------------------------------
232 java-ant_rewrite-classpath() {
233 debug-print-function ${FUNCNAME} $*
234
235 if [ -z "${1}" ]; then
236 eerror "java-ant_rewrite-classpath needs one argument"
237 die "java-ant_rewrite-classpath needs one argument"
238 fi
239
240 local file="${1}"
241 echo "Adding gentoo.classpath to ${file}"
242 debug-print "java-ant_rewrite-classpath: ${file}"
243
244 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
245
246 chmod u+w "${file}"
247
248 xml-rewrite.py -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}' || die "xml-rewrite failed: ${file}"
249
250 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
251 diff -NurbB "${file}.orig" "${file}"
252 fi
253 }

  ViewVC Help
Powered by ViewVC 1.1.20