/[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.5 - (show annotations) (download)
Tue Aug 1 01:53:20 2006 UTC (8 years, 2 months ago) by nichoj
Branch: MAIN
Changes since 1.4: +2 -2 lines
Fixed typo of eclass variable names

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_ANT_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_ANT_BSFIX=${JAVA_PKG_BSFIX:="on"}
27
28 # ------------------------------------------------------------------------------
29 # @global JAVA_ANT_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_ANT_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_ANT_BSFIX_TARGETS_TAGS
48 #
49 # Targets to fix the 'source' attribute in
50 #
51 # default: javac xjavac javac.preset
52 # ------------------------------------------------------------------------------
53 JAVA_ANT_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:="javac xjavac javac.preset"}
54
55 # ------------------------------------------------------------------------------
56 # @global JAVA_ANT_BSFIX_SOURCE_TAGS
57 #
58 # Targets to fix the 'target' attribute in
59 #
60 # default: javacdoc javac xjavac javac.preset
61 # ------------------------------------------------------------------------------
62 JAVA_ANT_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="-type f"
110 if [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]]; then
111 find_args="${find_args} -name ${JAVA_PKG_BSFIX_NAME// / -o -name }"
112 else
113 find_args="${find_args} -maxdepth 1 -name ${JAVA_PKG_BSFIX_NAME// / -o -name } "
114 fi
115
116 local i=0
117 local -a bsfix_these
118 while read line; do
119 [[ -z ${line} ]] && continue
120 bsfix_these[${i}]="${line}"
121 let i+=1
122 done <<-EOF
123 $(find . ${find_args})
124 EOF
125
126 for (( i = 0 ; i < ${#bsfix_these[@]} ; i++ )); do
127 local file="${bsfix_these[${i}]}"
128 java-ant_bsfix_one "${file}"
129 done
130 }
131
132 # ------------------------------------------------------------------------------
133 # @public java-ant_bsfix_one
134 #
135 # Attempts to fix named build file. The following variables will affect its behavior
136 # as listed above:
137 # JAVA_PKG_BSFIX_SOURCE_TAGS
138 # JAVA_PKG_BSFIX_TARGET_TAGS
139 # ------------------------------------------------------------------------------
140 java-ant_bsfix_one() {
141 debug-print-function ${FUNCNAME} $*
142
143 if [ -z "${1}" ]; then
144 eerror "java-ant_bsfix_one needs one argument"
145 die "java-ant_bsfix_one needs one argument"
146 fi
147
148 local want_source="$(java-pkg_get-source)"
149 local want_target="$(java-pkg_get-target)"
150
151 debug-print "bsfix_one: target: ${want_target} source: ${want_source}"
152
153 if [ -z "${want_source}" -o -z "${want_target}" ]; then
154 eerror "Could not find valid -source/-target values"
155 eerror "Please file a bug about this on bugs.gentoo.org"
156 die "Could not find valid -source/-target values"
157 else
158 local file="${1}"
159 echo "Rewriting ${file}"
160 debug-print "bsfix: ${file}"
161
162 cp "${file}" "${file}.orig" || die "failed to copy ${file}"
163
164 chmod u+w "${file}"
165
166 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_SOURCE_TAGS// / -e } -a source -v ${want_source} || die "xml-rewrite failed: ${file}"
167 xml-rewrite.py -f "${file}" -c -e ${JAVA_PKG_BSFIX_TARGET_TAGS// / -e } -a target -v ${want_target} || die "xml-rewrite failed: ${file}"
168
169 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
170 diff -NurbB "${file}.orig" "${file}"
171 fi
172 fi
173 }

  ViewVC Help
Powered by ViewVC 1.1.20