/[gentoo-x86]/eclass/java-ant-2.eclass
Gentoo

Diff of /eclass/java-ant-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.11
1# eclass for ant based Java packages 1# eclass for ant based Java packages
2# 2#
3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org> 3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org>
4# Copyright (c) 2004-2005, Gentoo Foundation 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)
5# 10#
6# Licensed under the GNU General Public License, v2 11# Licensed under the GNU General Public License, v2
7# 12#
13# $Header: /var/cvsroot/gentoo-x86/eclass/java-ant-2.eclass,v 1.11 2007/01/06 19:45:27 betelgeuse Exp $
8 14
9inherit java-utils-2 15inherit java-utils-2
10 16
11# This eclass provides functionality for Java packages which use 17# This eclass provides functionality for Java packages which use
12# ant to build. In particular, it will attempt to fix build.xml files, so that 18# ant to build. In particular, it will attempt to fix build.xml files, so that
14 20
15# We need some tools from javatoolkit. We also need portage 2.1 for phase hooks 21# We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
16DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}" 22DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}"
17 23
18# ------------------------------------------------------------------------------ 24# ------------------------------------------------------------------------------
19# @global JAVA_ANT_BSFIX 25# @global JAVA_PKG_BSFIX
20# 26#
21# Should we attempt to 'fix' ant build files to include the source/target 27# Should we attempt to 'fix' ant build files to include the source/target
22# attributes when calling javac? 28# attributes when calling javac?
23# 29#
24# default: on 30# default: on
25# ------------------------------------------------------------------------------ 31# ------------------------------------------------------------------------------
26JAVA_ANT_BSFIX=${JAVA_PKG_BSFIX:="on"} 32JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
27 33
28# ------------------------------------------------------------------------------ 34# ------------------------------------------------------------------------------
29# @global JAVA_ANT_BSFIX_ALL 35# @global JAVA_PKG_BSFIX_ALL
30# 36#
31# If we're fixing build files, should we try to fix all the ones we can find? 37# If we're fixing build files, should we try to fix all the ones we can find?
32# 38#
33# default: yes 39# default: yes
34# ------------------------------------------------------------------------------ 40# ------------------------------------------------------------------------------
35JAVA_ANT_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:="yes"} 41JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
36 42
37# ------------------------------------------------------------------------------ 43# ------------------------------------------------------------------------------
38# @global JAVA_ANT_BSFIX_NAME 44# @global JAVA_PKG_BSFIX_NAME
39# 45#
40# Filename of build files to fix/search for 46# Filename of build files to fix/search for
41# 47#
42# default: build.xml 48# default: build.xml
43# ------------------------------------------------------------------------------ 49# ------------------------------------------------------------------------------
44JAVA_ANT_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:="build.xml"} 50JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
45 51
46# ------------------------------------------------------------------------------ 52# ------------------------------------------------------------------------------
47# @global JAVA_ANT_BSFIX_TARGETS_TAGS 53# @global JAVA_PKG_BSFIX_TARGETS_TAGS
48# 54#
49# Targets to fix the 'source' attribute in 55# Targets to fix the 'source' attribute in
50# 56#
51# default: javac xjavac javac.preset 57# default: javac xjavac javac.preset
52# ------------------------------------------------------------------------------ 58# ------------------------------------------------------------------------------
53JAVA_ANT_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:="javac xjavac javac.preset"} 59JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
54 60
55# ------------------------------------------------------------------------------ 61# ------------------------------------------------------------------------------
56# @global JAVA_ANT_BSFIX_SOURCE_TAGS 62# @global JAVA_PKG_BSFIX_SOURCE_TAGS
57# 63#
58# Targets to fix the 'target' attribute in 64# Targets to fix the 'target' attribute in
59# 65#
60# default: javacdoc javac xjavac javac.preset 66# default: javacdoc javac xjavac javac.preset
61# ------------------------------------------------------------------------------ 67# ------------------------------------------------------------------------------
62JAVA_ANT_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:="javadoc javac xjavac javac.preset"} 68JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
63 69
64# ------------------------------------------------------------------------------ 70# ------------------------------------------------------------------------------
65# @public java-ant_src_unpack 71# @public java-ant_src_unpack
66# 72#
67# Unpacks the source, and attempts to fix build files. 73# Unpacks the source, and attempts to fix build files.
93# Attempts to fix build files. The following variables will affect its behavior 99# Attempts to fix build files. The following variables will affect its behavior
94# as listed above: 100# as listed above:
95# JAVA_PKG_BSFIX 101# JAVA_PKG_BSFIX
96# JAVA_PKG_BSFIX_ALL 102# JAVA_PKG_BSFIX_ALL
97# JAVA_PKG_BSFIX_NAME, 103# JAVA_PKG_BSFIX_NAME,
98# JAVA_PKG_BSFIX_SOURCE_TAGS
99# JAVA_PKG_BSFIX_TARGET_TAGS)
100# ------------------------------------------------------------------------------ 104# ------------------------------------------------------------------------------
101java-ant_bsfix() { 105java-ant_bsfix() {
102 debug-print-function ${FUNCNAME} $* 106 debug-print-function ${FUNCNAME} $*
103 107
104 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return 108 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
105 if ! java-pkg_needs-vm; then 109 if ! java-pkg_needs-vm; then
106 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM" 110 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
107 fi 111 fi
108 112
109 cd "${S}" 113 pushd "${S}" >/dev/null
110 114
111 local find_args="-type f" 115 local find_args=""
112 if [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]]; then 116 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
117
113 find_args="${find_args} -name ${JAVA_PKG_BSFIX_NAME// / -o -name }" 118 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
114 else
115 find_args="${find_args} -maxdepth 1 -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
116 fi
117 119
118 local i=0 120 # This voodoo is done for paths with spaces
119 local -a bsfix_these 121 local bsfix_these
120 while read line; do 122 while read line; do
121 [[ -z ${line} ]] && continue 123 [[ -z ${line} ]] && continue
122 bsfix_these[${i}]="${line}" 124 bsfix_these="${bsfix_these} '${line}'"
123 let i+=1
124 done <<-EOF 125 done <<-EOF
125 $(find ${find_args}) 126 $(find . ${find_args})
126 EOF 127 EOF
128
129 [[ "${bsfix_these// /}" ]] && eval java-ant_bsfix_files ${bsfix_these}
130
131 popd > /dev/null
132}
133
134_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# ------------------------------------------------------------------------------
148# @public java-ant_bsfix_files
149#
150# Attempts to fix named build files. The following variables will affect its behavior
151# as listed above:
152# JAVA_PKG_BSFIX_SOURCE_TAGS
153# JAVA_PKG_BSFIX_TARGET_TAGS
154#
155# When changing this function, make sure that it works with paths with spaces in
156# them.
157# ------------------------------------------------------------------------------
158java-ant_bsfix_files() {
159 debug-print-function ${FUNCNAME} $*
160
161 [[ ${#} = 0 ]] && die "${FUNCNAME} called without arguments"
127 162
128 local want_source="$(java-pkg_get-source)" 163 local want_source="$(java-pkg_get-source)"
129 local want_target="$(java-pkg_get-target)" 164 local want_target="$(java-pkg_get-target)"
130 165
131 debug-print "bsfix: target: ${want_target} source: ${want_source}" 166 debug-print "${FUNCNAME}: target: ${want_target} source: ${want_source}"
132 167
133 if [ -z "${want_source}" -o -z "${want_target}" ]; then 168 if [ -z "${want_source}" -o -z "${want_target}" ]; then
134 eerror "Could not find valid -source/-target values" 169 eerror "Could not find valid -source/-target values"
135 eerror "Please file a bug about this on bugs.gentoo.org" 170 eerror "Please file a bug about this on bugs.gentoo.org"
136 die "Could not find valid -source/-target values" 171 die "Could not find valid -source/-target values"
137 else 172 else
138 for (( i = 0 ; i < ${#bsfix_these[@]} ; i++ )); do 173 local files
139 local file="${bsfix_these[${i}]}" 174
140 echo "Rewriting ${file}" 175 [[ -x "/usr/bin/xml-rewrite-2.py" ]] && local using_new="true"
176
177 for file in "${@}"; do
141 debug-print "bsfix: ${file}" 178 debug-print "${FUNCNAME}: ${file}"
142
143 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
144
145 chmod u+w "${file}"
146
147 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } -a source -v ${want_source} || die "xml-rewrite failed: ${file}"
148 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } -a target -v ${want_target} || die "xml-rewrite failed: ${file}"
149 179
150 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then 180 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
151 diff -NurbB "${file}.orig" "${file}" 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 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}"
152 fi 200 fi
153 done 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 -a source -v ${want_source} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
209
210 vecho "Rewriting target attributes"
211 eval xml-rewrite-2.py ${files} \
212 -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } \
213 -a target -v ${want_target} ${output} || _bsfix_die "xml-rewrite2 failed: ${file}"
154 fi 214 fi
215
216 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
217 for file in "${@}"; do
218 diff -NurbB "${file}.orig" "${file}"
219 done
220 fi
221 fi
155} 222}
223
224
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# ------------------------------------------------------------------------------
233java-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# ------------------------------------------------------------------------------
245# @public java-ant_rewrite-classpath
246#
247# Adds 'classpath="${gentoo.classpath}"' to specified build file.
248# ------------------------------------------------------------------------------
249java-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}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.20