/[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.6 - (hide annotations) (download)
Sun Aug 6 17:03:26 2006 UTC (8 years, 2 months ago) by nelchael
Branch: MAIN
Changes since 1.5: +28 -0 lines
New function to rewrite build.xml: adds classpath.

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    
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 nichoj 1.2 # 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 nichoj 1.1
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 nichoj 1.5 # @global JAVA_PKG_BSFIX_NAME
39 nichoj 1.1 #
40     # Filename of build files to fix/search for
41     #
42     # default: build.xml
43     # ------------------------------------------------------------------------------
44 nichoj 1.5 JAVA_PKG_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:="build.xml"}
45 nichoj 1.1
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 nichoj 1.2 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 nichoj 1.1 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 nichoj 1.2 #ant_src_unpack() {
84     # debug-print-function ${FUNCNAME} $*
85     # if [[ -n "${A}" ]]; then
86     # unpack ${A}
87     # fi
88     #}
89 nichoj 1.1
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 nelchael 1.4 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
103     if ! java-pkg_needs-vm; then
104 nichoj 1.1 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
105     fi
106    
107     cd "${S}"
108 nelchael 1.4
109 nichoj 1.1 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 flameeyes 1.3 $(find . ${find_args})
124 nichoj 1.1 EOF
125    
126 nelchael 1.4 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 nichoj 1.1 local want_source="$(java-pkg_get-source)"
149     local want_target="$(java-pkg_get-target)"
150    
151 nelchael 1.4 debug-print "bsfix_one: target: ${want_target} source: ${want_source}"
152 nichoj 1.1
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 nelchael 1.4 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 nichoj 1.1 fi
173     }
174 nelchael 1.6
175     # ------------------------------------------------------------------------------
176     # @public java-ant_rewrite-classpath
177     #
178     # Adds 'classpath="${gentoo.classpath}"' to specified build file.
179     # ------------------------------------------------------------------------------
180     java-ant_rewrite-classpath() {
181     debug-print-function ${FUNCNAME} $*
182    
183     if [ -z "${1}" ]; then
184     eerror "java-ant_rewrite-classpath needs one argument"
185     die "java-ant_rewrite-classpath needs one argument"
186     fi
187    
188     local file="${1}"
189     echo "Adding gentoo.classpath to ${file}"
190     debug-print "java-ant_rewrite-classpath: ${file}"
191    
192     cp "${file}" "${file}.orig" || die "failed to copy ${file}"
193    
194     chmod u+w "${file}"
195    
196     xml-rewrite.py -f "${file}" --change -e javac -e xjavac -a classpath -v '${gentoo.classpath}' || die "xml-rewrite failed: ${file}"
197    
198     if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
199     diff -NurbB "${file}.orig" "${file}"
200     fi
201     }

  ViewVC Help
Powered by ViewVC 1.1.20