/[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.7 - (show annotations) (download)
Mon Sep 11 04:37:57 2006 UTC (7 years, 10 months ago) by nichoj
Branch: MAIN
Changes since 1.6: +13 -15 lines
Fixes variable names. Also cleans up building of find_args. Courtesy of Caster, bug #146479.

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 #
6 # Licensed under the GNU General Public License, v2
7 #
8
9 inherit java-utils-2
10
11 # 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
13 # they use the appropriate 'target' and 'source' attributes.
14
15 # We need some tools from javatoolkit. We also need portage 2.1 for phase hooks
16 DEPEND=">=dev-java/javatoolkit-0.1.5 ${JAVA_PKG_PORTAGE_DEP}"
17
18 # ------------------------------------------------------------------------------
19 # @global JAVA_PKG_BSFIX
20 #
21 # Should we attempt to 'fix' ant build files to include the source/target
22 # attributes when calling javac?
23 #
24 # default: on
25 # ------------------------------------------------------------------------------
26 JAVA_PKG_BSFIX=${JAVA_PKG_BSFIX:-"on"}
27
28 # ------------------------------------------------------------------------------
29 # @global JAVA_PKG_BSFIX_ALL
30 #
31 # If we're fixing build files, should we try to fix all the ones we can find?
32 #
33 # default: yes
34 # ------------------------------------------------------------------------------
35 JAVA_PKG_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:-"yes"}
36
37 # ------------------------------------------------------------------------------
38 # @global JAVA_PKG_BSFIX_NAME
39 #
40 # Filename of build files to fix/search for
41 #
42 # default: build.xml
43 # ------------------------------------------------------------------------------
44 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:-"build.xml"}
45
46 # ------------------------------------------------------------------------------
47 # @global JAVA_PKG_BSFIX_TARGETS_TAGS
48 #
49 # Targets to fix the 'source' attribute in
50 #
51 # default: javac xjavac javac.preset
52 # ------------------------------------------------------------------------------
53 JAVA_PKG_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:-"javac xjavac javac.preset"}
54
55 # ------------------------------------------------------------------------------
56 # @global JAVA_PKG_BSFIX_SOURCE_TAGS
57 #
58 # Targets to fix the 'target' attribute in
59 #
60 # default: javacdoc javac xjavac javac.preset
61 # ------------------------------------------------------------------------------
62 JAVA_PKG_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:-"javadoc javac xjavac javac.preset"}
63
64 # ------------------------------------------------------------------------------
65 # @public java-ant_src_unpack
66 #
67 # Unpacks the source, and attempts to fix build files.
68 # ------------------------------------------------------------------------------
69 post_src_unpack() {
70 if java-pkg_func-exists ant_src_unpack; then
71 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
72 ant_src_unpack
73 fi
74 java-ant_bsfix
75 }
76
77 # ------------------------------------------------------------------------------
78 # @private ant_src_unpack
79 #
80 # Helper function which does the actual unpacking
81 # ------------------------------------------------------------------------------
82 # TODO maybe use base.eclass for some patching love?
83 #ant_src_unpack() {
84 # debug-print-function ${FUNCNAME} $*
85 # if [[ -n "${A}" ]]; then
86 # unpack ${A}
87 # fi
88 #}
89
90 # ------------------------------------------------------------------------------
91 # @private java-ant_bsfix
92 #
93 # Attempts to fix build files. The following variables will affect its behavior
94 # as listed above:
95 # JAVA_PKG_BSFIX
96 # JAVA_PKG_BSFIX_ALL
97 # JAVA_PKG_BSFIX_NAME,
98 # ------------------------------------------------------------------------------
99 java-ant_bsfix() {
100 debug-print-function ${FUNCNAME} $*
101
102 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
103 if ! java-pkg_needs-vm; then
104 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
105 fi
106
107 cd "${S}"
108
109 local find_args=""
110 [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]] || find_args="-maxdepth 1"
111
112 find_args="${find_args} -type f -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
113
114 local i=0
115 local -a bsfix_these
116 while read line; do
117 [[ -z ${line} ]] && continue
118 bsfix_these[${i}]="${line}"
119 let i+=1
120 done <<-EOF
121 $(find . ${find_args})
122 EOF
123
124 for (( i = 0 ; i < ${#bsfix_these[@]} ; i++ )); do
125 local file="${bsfix_these[${i}]}"
126 java-ant_bsfix_one "${file}"
127 done
128 }
129
130 # ------------------------------------------------------------------------------
131 # @public java-ant_bsfix_one
132 #
133 # Attempts to fix named build file. The following variables will affect its behavior
134 # as listed above:
135 # JAVA_PKG_BSFIX_SOURCE_TAGS
136 # JAVA_PKG_BSFIX_TARGET_TAGS
137 # ------------------------------------------------------------------------------
138 java-ant_bsfix_one() {
139 debug-print-function ${FUNCNAME} $*
140
141 if [ -z "${1}" ]; then
142 eerror "java-ant_bsfix_one needs one argument"
143 die "java-ant_bsfix_one needs one argument"
144 fi
145
146 local want_source="$(java-pkg_get-source)"
147 local want_target="$(java-pkg_get-target)"
148
149 debug-print "bsfix_one: target: ${want_target} source: ${want_source}"
150
151 if [ -z "${want_source}" -o -z "${want_target}" ]; then
152 eerror "Could not find valid -source/-target values"
153 eerror "Please file a bug about this on bugs.gentoo.org"
154 die "Could not find valid -source/-target values"
155 else
156 local file="${1}"
157 echo "Rewriting ${file}"
158 debug-print "bsfix: ${file}"
159
160 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
161
162 chmod u+w "${file}"
163
164 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } -a source -v ${want_source} || die "xml-rewrite failed: ${file}"
165 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } -a target -v ${want_target} || die "xml-rewrite failed: ${file}"
166
167 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
168 diff -NurbB "${file}.orig" "${file}"
169 fi
170 fi
171 }
172
173 # ------------------------------------------------------------------------------
174 # @public java-ant_rewrite-classpath
175 #
176 # Adds 'classpath="${gentoo.classpath}"' to specified build file.
177 # ------------------------------------------------------------------------------
178 java-ant_rewrite-classpath() {
179 debug-print-function ${FUNCNAME} $*
180
181 if [ -z "${1}" ]; then
182 eerror "java-ant_rewrite-classpath needs one argument"
183 die "java-ant_rewrite-classpath needs one argument"
184 fi
185
186 local file="${1}"
187 echo "Adding gentoo.classpath to ${file}"
188 debug-print "java-ant_rewrite-classpath: ${file}"
189
190 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
191
192 chmod u+w "${file}"
193
194 xml-rewrite.py -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}' || die "xml-rewrite failed: ${file}"
195
196 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
197 diff -NurbB "${file}.orig" "${file}"
198 fi
199 }

  ViewVC Help
Powered by ViewVC 1.1.20