/[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.9 - (hide annotations) (download)
Sun Dec 3 13:05:06 2006 UTC (7 years, 7 months ago) by betelgeuse
Branch: MAIN
Changes since 1.8: +1 -0 lines
Added CVS Headers after a request from grobian.

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

  ViewVC Help
Powered by ViewVC 1.1.20