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