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