/[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.1 - (show annotations) (download)
Sat Jun 24 18:36:59 2006 UTC (8 years, 5 months ago) by nichoj
Branch: MAIN
Adding new Java eclasses, and updating old ones.

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 # Only exports src_unpack
16 EXPORT_FUNCTIONS src_unpack
17
18 # We need some tools from java-toolkit
19 DEPEND=">=dev-java/javatoolkit-0.1.5"
20
21 # ------------------------------------------------------------------------------
22 # @global JAVA_ANT_BSFIX
23 #
24 # Should we attempt to 'fix' ant build files to include the source/target
25 # attributes when calling javac?
26 #
27 # default: on
28 # ------------------------------------------------------------------------------
29 JAVA_ANT_BSFIX=${JAVA_PKG_BSFIX:="on"}
30
31 # ------------------------------------------------------------------------------
32 # @global JAVA_ANT_BSFIX_ALL
33 #
34 # If we're fixing build files, should we try to fix all the ones we can find?
35 #
36 # default: yes
37 # ------------------------------------------------------------------------------
38 JAVA_ANT_BSFIX_ALL=${JAVA_PKG_BSFIX_ALL:="yes"}
39
40 # ------------------------------------------------------------------------------
41 # @global JAVA_ANT_BSFIX_NAME
42 #
43 # Filename of build files to fix/search for
44 #
45 # default: build.xml
46 # ------------------------------------------------------------------------------
47 JAVA_ANT_BSFIX_NAME=${JAVA_PKG_BSFIX_NAME:="build.xml"}
48
49 # ------------------------------------------------------------------------------
50 # @global JAVA_ANT_BSFIX_TARGETS_TAGS
51 #
52 # Targets to fix the 'source' attribute in
53 #
54 # default: javac xjavac javac.preset
55 # ------------------------------------------------------------------------------
56 JAVA_ANT_BSFIX_TARGET_TAGS=${JAVA_PKG_BSFIX_TARGET_TAGS:="javac xjavac javac.preset"}
57
58 # ------------------------------------------------------------------------------
59 # @global JAVA_ANT_BSFIX_SOURCE_TAGS
60 #
61 # Targets to fix the 'target' attribute in
62 #
63 # default: javacdoc javac xjavac javac.preset
64 # ------------------------------------------------------------------------------
65 JAVA_ANT_BSFIX_SOURCE_TAGS=${JAVA_PKG_BSFIX_SOURCE_TAGS:="javadoc javac xjavac javac.preset"}
66
67 # ------------------------------------------------------------------------------
68 # @public java-ant_src_unpack
69 #
70 # Unpacks the source, and attempts to fix build files.
71 # ------------------------------------------------------------------------------
72 java-ant-2_src_unpack() {
73 ant_src_unpack
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 # JAVA_PKG_BSFIX_SOURCE_TAGS
99 # JAVA_PKG_BSFIX_TARGET_TAGS)
100 # ------------------------------------------------------------------------------
101 java-ant_bsfix() {
102 debug-print-function ${FUNCNAME} $*
103
104 [[ "${JAVA_PKG_BSFIX}" != "on" ]] && return
105 if ! java-pkg_needs-vm; then
106 echo "QA Notice: Package is using java-ant, but doesn't depend on a Java VM"
107 fi
108
109 cd "${S}"
110
111 local find_args="-type f"
112 if [[ "${JAVA_PKG_BSFIX_ALL}" == "yes" ]]; then
113 find_args="${find_args} -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
118 local i=0
119 local -a bsfix_these
120 while read line; do
121 [[ -z ${line} ]] && continue
122 bsfix_these[${i}]="${line}"
123 let i+=1
124 done <<-EOF
125 $(find ${find_args})
126 EOF
127
128 local want_source="$(java-pkg_get-source)"
129 local want_target="$(java-pkg_get-target)"
130
131 debug-print "bsfix: target: ${want_target} source: ${want_source}"
132
133 if [ -z "${want_source}" -o -z "${want_target}" ]; then
134 eerror "Could not find valid -source/-target values"
135 eerror "Please file a bug about this on bugs.gentoo.org"
136 die "Could not find valid -source/-target values"
137 else
138 for (( i = 0 ; i < ${#bsfix_these[@]} ; i++ )); do
139 local file="${bsfix_these[${i}]}"
140 echo "Rewriting ${file}"
141 debug-print "bsfix: ${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
150 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
151 diff -NurbB "${file}.orig" "${file}"
152 fi
153 done
154 fi
155 }

  ViewVC Help
Powered by ViewVC 1.1.20