Merge remote-tracking branch 'remotes/github/pr/118'.
[gentoo.git] / eclass / ant-tasks.eclass
1 # Eclass for building dev-java/ant-* packages
2 #
3 # Copyright 1999-2015 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License, v2 or later
5 # Author Vlastimil Babka <caster@gentoo.org>
6 # $Id$
7
8 # @ECLASS: ant-tasks.eclass
9 # @MAINTAINER:
10 # java@gentoo.org
11 # @AUTHOR:
12 # Vlastimil Babka <caster@gentoo.org>
13 # @BLURB: Eclass for building dev-java/ant-* packages
14 # @DESCRIPTION:
15 # This eclass provides functionality and default ebuild variables for building
16 # dev-java/ant-* packages easily.
17
18
19 # we set ant-core dep ourselves, restricted
20 JAVA_ANT_DISABLE_ANT_CORE_DEP=true
21 # rewriting build.xml for are the testcases has no reason atm
22 JAVA_PKG_BSFIX_ALL=no
23 inherit versionator java-pkg-2 java-ant-2
24
25 EXPORT_FUNCTIONS src_unpack src_compile src_install
26
27 # @ECLASS-VARIABLE: ANT_TASK_JDKVER
28 # @DESCRIPTION:
29 # Affects the >=virtual/jdk version set in DEPEND string. Defaults to 1.5, can
30 # be overriden from ebuild BEFORE inheriting this eclass.
31 ANT_TASK_JDKVER=${ANT_TASK_JDKVER-1.5}
32
33 # @ECLASS-VARIABLE: ANT_TASK_JREVER
34 # @DESCRIPTION:
35 # Affects the >=virtual/jre version set in DEPEND string. Defaults to 1.5, can
36 # be overriden from ebuild BEFORE inheriting this eclass.
37 ANT_TASK_JREVER=${ANT_TASK_JREVER-1.5}
38
39 # @ECLASS-VARIABLE: ANT_TASK_NAME
40 # @DESCRIPTION:
41 # The name of this ant task as recognized by ant's build.xml, derived from $PN
42 # by removing the ant- prefix. Read-only.
43 ANT_TASK_NAME="${PN#ant-}"
44
45 # @ECLASS-VARIABLE: ANT_TASK_DEPNAME
46 # @DESCRIPTION:
47 # Specifies JAVA_PKG_NAME (PN{-SLOT} used with java-pkg_jar-from) of the package
48 # that this one depends on. Defaults to the name of ant task, ebuild can
49 # override it before inheriting this eclass.
50 ANT_TASK_DEPNAME=${ANT_TASK_DEPNAME-${ANT_TASK_NAME}}
51
52 # @ECLASS-VARIABLE: ANT_TASK_DISABLE_VM_DEPS
53 # @DEFAULT_UNSET
54 # @DESCRIPTION:
55 # If set, no JDK/JRE deps are added.
56
57 # @VARIABLE: ANT_TASK_PV
58 # @INTERNAL
59 # Version of ant-core this task is intended to register and thus load with.
60 ANT_TASK_PV="${PV}"
61
62 # special care for beta/RC releases
63 if [[ ${PV} == *beta2* ]]; then
64         MY_PV=${PV/_beta2/beta}
65         UPSTREAM_PREFIX="http://people.apache.org/dist/ant/v1.7.1beta2/src"
66         GENTOO_PREFIX="https://dev.gentoo.org/~caster/distfiles"
67         ANT_TASK_PV=$(get_version_component_range 1-3)
68 elif [[ ${PV} == *_rc* ]]; then
69         MY_PV=${PV/_rc/RC}
70         UPSTREAM_PREFIX="https://dev.gentoo.org/~caster/distfiles"
71         GENTOO_PREFIX="https://dev.gentoo.org/~caster/distfiles"
72         ANT_TASK_PV=$(get_version_component_range 1-3)
73 else
74         # default for final releases
75         MY_PV=${PV}
76         UPSTREAM_PREFIX="mirror://apache/ant/source"
77         case ${PV} in
78         1.9.*)
79                 GENTOO_PREFIX="https://dev.gentoo.org/~tomwij/files/dist"
80                 ;;
81         1.8.4)
82                 GENTOO_PREFIX="https://dev.gentoo.org/~sera/distfiles"
83                 ;;
84         *)
85                 GENTOO_PREFIX="https://dev.gentoo.org/~caster/distfiles"
86                 ;;
87         esac
88 fi
89
90 # source/workdir name
91 MY_P="apache-ant-${MY_PV}"
92
93 # Default values for standard ebuild variables, can be overriden from ebuild.
94 DESCRIPTION="Apache Ant's optional tasks depending on ${ANT_TASK_DEPNAME}"
95 HOMEPAGE="http://ant.apache.org/"
96 SRC_URI="${UPSTREAM_PREFIX}/${MY_P}-src.tar.bz2
97         ${GENTOO_PREFIX}/ant-${PV}-gentoo.tar.bz2"
98 LICENSE="Apache-2.0"
99 SLOT="0"
100
101 RDEPEND="~dev-java/ant-core-${PV}:0"
102 DEPEND="${RDEPEND}"
103
104 if [[ -z "${ANT_TASK_DISABLE_VM_DEPS}" ]]; then
105         RDEPEND+=" >=virtual/jre-${ANT_TASK_JREVER}"
106         DEPEND+=" >=virtual/jdk-${ANT_TASK_JDKVER}"
107 fi
108
109 # we need direct blockers with old ant-tasks for file collisions - bug #252324
110 if version_is_at_least 1.7.1 ; then
111         DEPEND+=" !dev-java/ant-tasks"
112 fi
113
114 # Would run the full ant test suite for every ant task
115 RESTRICT="test"
116
117 S="${WORKDIR}/${MY_P}"
118
119 # @FUNCTION: ant-tasks_src_unpack
120 # @USAGE: [ base ] [ jar-dep ] [ all ]
121 # @DESCRIPTION:
122 # The function Is split into two parts, defaults to both of them ('all').
123 #
124 # base: performs the unpack, build.xml replacement and symlinks ant.jar from
125 #       ant-core
126 #
127 # jar-dep: symlinks the jar file(s) from dependency package
128 ant-tasks_src_unpack() {
129         [[ -z "${1}" ]] && ant-tasks_src_unpack all
130
131         while [[ -n "${1}" ]]; do
132                 case ${1} in
133                         base)
134                                 unpack ${A}
135                                 cd "${S}"
136
137                                 # replace build.xml with our modified for split building
138                                 mv -f "${WORKDIR}"/build.xml .
139
140                                 cd lib
141                                 # remove bundled xerces
142                                 rm -f *.jar
143
144                                 # ant.jar to build against
145                                 java-pkg_jar-from --build-only ant-core ant.jar;;
146                         jar-dep)
147                                 # get jar from the dependency package
148                                 if [[ -n "${ANT_TASK_DEPNAME}" ]]; then
149                                         java-pkg_jar-from ${ANT_TASK_DEPNAME}
150                                 fi;;
151                         all)
152                                 ant-tasks_src_unpack base jar-dep;;
153                 esac
154                 shift
155         done
156
157 }
158
159 # @FUNCTION: ant-tasks_src_compile
160 # @DESCRIPTION:
161 # Compiles the jar with installed ant-core.
162 ant-tasks_src_compile() {
163         ANT_TASKS="none" eant -Dbuild.dep=${ANT_TASK_NAME} jar-dep
164 }
165
166 # @FUNCTION: ant-tasks_src_install
167 # @DESCRIPTION:
168 # Installs the jar and registers its presence for the ant launcher script.
169 # Version param ensures it won't get loaded (thus break) when ant-core is
170 # updated to newer version.
171 ant-tasks_src_install() {
172         java-pkg_dojar build/lib/${PN}.jar
173         java-pkg_register-ant-task --version "${ANT_TASK_PV}"
174
175         # create the compatibility symlink
176         if version_is_at_least 1.7.1_beta2; then
177                 dodir /usr/share/ant/lib
178                 dosym /usr/share/${PN}/lib/${PN}.jar /usr/share/ant/lib/${PN}.jar
179         fi
180 }