/[gentoo-x86]/eclass/java-utils-2.eclass
Gentoo

Diff of /eclass/java-utils-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.150 Revision 1.168
1# Base eclass for Java packages 1# Base eclass for Java packages
2# 2#
3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org> 3# Copyright (c) 2004-2005, Thomas Matthijs <axxo@gentoo.org>
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2011, Gentoo Foundation 5# Copyright (c) 2004-2015, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.150 2012/03/13 10:05:46 sera Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.168 2015/07/31 07:56:17 monsieurp Exp $
10 10
11# ----------------------------------------------------------------------------- 11# @ECLASS: java-utils-2.eclass
12# @eclass-begin 12# @MAINTAINER:
13# @eclass-shortdesc Java Utility eclass 13# java@gentoo.org
14# @eclass-maintainer java@gentoo.org 14# @AUTHOR:
15# 15# Thomas Matthijs <axxo@gentoo.org>, Karl Trygve Kalleberg <karltk@gentoo.org>
16# @BLURB: Base eclass for Java packages
17# @DESCRIPTION:
16# This eclass provides functionality which is used by 18# This eclass provides functionality which is used by java-pkg-2.eclass,
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 19# java-pkg-opt-2.eclass and java-ant-2 eclass, as well as from ebuilds.
18# 20#
19# @warning 21# This eclass should not be inherited this directly from an ebuild. Instead,
20# You probably don't want to inherit this directly from an ebuild. Instead, 22# you should inherit java-pkg-2 for Java packages or java-pkg-opt-2 for packages
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 23# that have optional Java support. In addition you can inherit java-ant-2 for
22# Java packages, or java-pkg-opt for packages that have optional Java support. 24# Ant-based packages.
23#
24# -----------------------------------------------------------------------------
25
26inherit eutils versionator multilib 25inherit eutils versionator multilib
27 26
28IUSE="elibc_FreeBSD" 27IUSE="elibc_FreeBSD"
29
30# -----------------------------------------------------------------------------
31# @section-begin variables
32# @section-title Variables
33#
34# Summary of variables which control the behavior of building Java packges.
35# -----------------------------------------------------------------------------
36 28
37# Make sure we use java-config-2 29# Make sure we use java-config-2
38export WANT_JAVA_CONFIG="2" 30export WANT_JAVA_CONFIG="2"
39 31
40# ----------------------------------------------------------------------------- 32# @VARIABLE: JAVA_PKG_PORTAGE_DEP
41# @variable-external WANT_ANT_TASKS 33# @INTERNAL
42# @variable-default "" 34# @DESCRIPTION:
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was 35# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env 36# portage with phase hooks support but now we use a version with proper env
64# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps. 37# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
65# -----------------------------------------------------------------------------
66has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7" 38has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
67 39
68# ----------------------------------------------------------------------------- 40# @VARIABLE: JAVA_PKG_E_DEPEND
69# @variable-internal JAVA_PKG_E_DEPEND 41# @INTERNAL
70# 42# @DESCRIPTION:
71# This is a convience variable to be used from the other java eclasses. This is 43# This is a convience variable to be used from the other java eclasses. This is
72# the version of java-config we want to use. Usually the latest stable version 44# the version of java-config we want to use. Usually the latest stable version
73# so that ebuilds can use new features without depending on specific versions. 45# so that ebuilds can use new features without depending on specific versions.
74# -----------------------------------------------------------------------------
75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.9-r1 ${JAVA_PKG_PORTAGE_DEP}" 46JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0 ${JAVA_PKG_PORTAGE_DEP}"
76has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )" 47has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
77 48
78# ----------------------------------------------------------------------------- 49# @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
79# @variable-preinherit JAVA_PKG_WANT_BOOTCLASSPATH 50# @DEFAULT_UNSET
80# 51# @DESCRIPTION:
81# The version of bootclasspath the package needs to work. Translates to a proper 52# The version of bootclasspath the package needs to work. Translates to a proper
82# dependency. The bootclasspath has to be obtained by java-ant_rewrite-bootclasspath 53# dependency. The bootclasspath can then be obtained by java-ant_rewrite-bootclasspath
83# -----------------------------------------------------------------------------
84
85if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then 54if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
86 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then 55 if [[ "${JAVA_PKG_WANT_BOOTCLASSPATH}" == "1.5" ]]; then
87 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98" 56 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} >=dev-java/gnu-classpath-0.98-r1:0.98"
88 else 57 else
89 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH" 58 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
90 # since die in global scope doesn't work, this will make repoman fail 59 # since die in global scope doesn't work, this will make repoman fail
91 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH" 60 JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} BAD_JAVA_PKG_WANT_BOOTCLASSPATH"
92 fi 61 fi
93fi 62fi
94 63
95# ----------------------------------------------------------------------------- 64# @ECLASS-VARIABLE: JAVA_PKG_ALLOW_VM_CHANGE
96# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 65# @DESCRIPTION:
97# @variable-default yes
98#
99# Allow this eclass to change the active VM? 66# Allow this eclass to change the active VM?
100# If your system VM isn't sufficient for the package, the build will fail. 67# If your system VM isn't sufficient for the package, the build will fail
101# @note This is useful for testing specific VMs. 68# instead of trying to switch to another VM.
102# ----------------------------------------------------------------------------- 69#
70# Overriding the default can be useful for testing specific VMs locally, but
71# should not be used in the final ebuild.
103JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"} 72JAVA_PKG_ALLOW_VM_CHANGE=${JAVA_PKG_ALLOW_VM_CHANGE:="yes"}
104 73
105# ----------------------------------------------------------------------------- 74# @ECLASS-VARIABLE: JAVA_PKG_FORCE_VM
106# @variable-external JAVA_PKG_FORCE_VM 75# @DEFAULT_UNSET
107# 76# @DESCRIPTION:
108# Explicitly set a particular VM to use. If its not valid, it'll fall back to 77# Explicitly set a particular VM to use. If its not valid, it'll fall back to
109# whatever /etc/java-config-2/build/jdk.conf would elect to use. 78# whatever /etc/java-config-2/build/jdk.conf would elect to use.
110# 79#
111# Should only be used for testing and debugging. 80# Should only be used for testing and debugging.
112# 81#
113# @example Use sun-jdk-1.5 to emerge foo 82# Example: use sun-jdk-1.5 to emerge foo:
83# @CODE
114# JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo 84# JAVA_PKG_FORCE_VM=sun-jdk-1.5 emerge foo
115# 85# @CODE
116# -----------------------------------------------------------------------------
117 86
118# ----------------------------------------------------------------------------- 87# @ECLASS-VARIABLE: JAVA_PKG_WANT_BUILD_VM
119# @variable-external JAVA_PKG_WANT_BUILD_VM 88# @DEFAULT_UNSET
120# 89# @DESCRIPTION:
121# A list of VM handles to choose a build VM from. If the list contains the 90# A list of VM handles to choose a build VM from. If the list contains the
122# currently active VM use that one, otherwise step through the list till a 91# currently active VM use that one, otherwise step through the list till a
123# usable/installed VM is found. 92# usable/installed VM is found.
124# 93#
125# This allows to use an explicit list of JDKs in DEPEND instead of a virtual. 94# This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
126# Users of this variable must make sure at least one of the listed handles is 95# Users of this variable must make sure at least one of the listed handles is
127# covered by DEPEND. 96# covered by DEPEND.
128# Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well. 97# Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
129# -----------------------------------------------------------------------------
130 98
131# ----------------------------------------------------------------------------- 99# @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
132# @variable-external JAVA_PKG_WANT_SOURCE 100# @DEFAULT_UNSET
133# 101# @DESCRIPTION:
134# Specify a specific VM version to compile for to use for -source. 102# Specify a non-standard Java source version for compilation (via javac -source
135# Normally this is determined from DEPEND. 103# parameter or Ant equivalent via build.xml rewriting done by java-ant-2 eclass).
104# Normally this is determined from the jdk version specified in DEPEND.
136# See java-pkg_get-source function below. 105# See java-pkg_get-source function below.
137# 106#
138# Should only be used for testing and debugging. 107# Should generally only be used for testing and debugging.
139# 108#
140# @seealso java-pkg_get-source
141#
142# @example Use 1.4 source to emerge baz 109# Use 1.4 source to emerge baz
110# @CODE
143# JAVA_PKG_WANT_SOURCE=1.4 emerge baz 111# JAVA_PKG_WANT_SOURCE=1.4 emerge baz
144# ----------------------------------------------------------------------------- 112# @CODE
145 113
146# ----------------------------------------------------------------------------- 114# @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
147# @variable-external JAVA_PKG_WANT_TARGET 115# @DEFAULT_UNSET
148# 116# @DESCRIPTION:
149# Same as JAVA_PKG_WANT_SOURCE above but for -target. 117# Same as JAVA_PKG_WANT_SOURCE (see above) but for javac -target parameter,
118# which affects the version of generated bytecode.
119# Normally this is determined from the jre/jdk version specified in RDEPEND.
150# See java-pkg_get-target function below. 120# See java-pkg_get-target function below.
151# 121#
152# Should only be used for testing and debugging. 122# Should generallyonly be used for testing and debugging.
153# 123#
154# @seealso java-pkg_get-target
155#
156# @example emerge bar to be compatible with 1.3 124# emerge bar to be compatible with 1.3
125# @CODE
157# JAVA_PKG_WANT_TARGET=1.3 emerge bar 126# JAVA_PKG_WANT_TARGET=1.3 emerge bar
158# ----------------------------------------------------------------------------- 127# @CODE
159 128
160# ----------------------------------------------------------------------------- 129# @ECLASS-VARIABLE: JAVA_RM_FILES
161# @variable-internal JAVA_PKG_COMPILER_DIR 130# @DEFAULT_UNSET
162# @default /usr/share/java-config-2/compiler 131# @DESCRIPTION:
132# An array containing a list of files to remove. If defined, this array will be
133# automatically handed over to java-pkg_rm_files for processing during the
134# src_prepare phase.
163# 135#
136# @CODE
137# JAVA_RM_FILES=(
138# path/to/File1.java
139# DELETEME.txt
140# )
141# @CODE
142
143# @VARIABLE: JAVA_PKG_COMPILER_DIR
144# @INTERNAL
145# @DESCRIPTION:
164# Directory where compiler settings are saved, without trailing slash. 146# Directory where compiler settings are saved, without trailing slash.
165# Probably shouldn't touch this variable. 147# You probably shouldn't touch this variable except local testing.
166# -----------------------------------------------------------------------------
167JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 148JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
168 149
169 150# @VARIABLE: JAVA_PKG_COMPILERS_CONF
170# ----------------------------------------------------------------------------- 151# @INTERNAL
171# @variable-internal JAVA_PKG_COMPILERS_CONF 152# @DESCRIPTION:
172# @variable-default /etc/java-config-2/build/compilers.conf
173#
174# Path to file containing information about which compiler to use. 153# Path to file containing information about which compiler to use.
175# Can be overloaded, but it should be overloaded for testing. 154# Can be overloaded, but it should be overloaded only for local testing.
176# -----------------------------------------------------------------------------
177JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"} 155JAVA_PKG_COMPILERS_CONF=${JAVA_PKG_COMPILERS_CONF:="/etc/java-config-2/build/compilers.conf"}
178 156
179# ----------------------------------------------------------------------------- 157# @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
180# @variable-external JAVA_PKG_FORCE_COMPILER 158# @INTERNAL
181# 159# @DEFAULT_UNSET
160# @DESCRIPTION:
182# Explicitly set a list of compilers to use. This is normally read from 161# Explicitly set a list of compilers to choose from. This is normally read from
183# JAVA_PKG_COMPILERS_CONF. 162# JAVA_PKG_COMPILERS_CONF.
184# 163#
185# @note This should only be used internally or for testing. 164# Useful for local testing.
165#
186# @example Use jikes and javac, in that order 166# Use jikes and javac, in that order
167# @CODE
187# JAVA_PKG_FORCE_COMPILER="jikes javac" 168# JAVA_PKG_FORCE_COMPILER="jikes javac"
188# ----------------------------------------------------------------------------- 169# @CODE
189 170
190# ----------------------------------------------------------------------------- 171# @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
191# @variable-external JAVA_PKG_FORCE_ANT_TASKS 172# @DEFAULT_UNSET
192# 173# @DESCRIPTION:
193# An $IFS separated list of ant tasks. Can be set in environment before calling 174# An $IFS separated list of ant tasks. Can be set in environment before calling
194# emerge/ebuild to override variables set in ebuild, mainly for testing before 175# emerge/ebuild to override variables set in ebuild, mainly for testing before
195# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in 176# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
196# eant() call, not the dependencies specified in WANT_ANT_TASKS. 177# eant() call, not the dependencies specified in WANT_ANT_TASKS.
197# 178#
179# @CODE
198# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \ 180# JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
199# ebuild foo.ebuild compile 181# ebuild foo.ebuild compile
200# 182# @CODE
201# @seealso WANT_ANT_TASKS
202# -----------------------------------------------------------------------------
203 183
204# TODO document me 184# TODO document me
205JAVA_PKG_QA_VIOLATIONS=0 185JAVA_PKG_QA_VIOLATIONS=0
206 186
207# ----------------------------------------------------------------------------- 187# @FUNCTION: java-pkg_doexamples
208# @section-end variables 188# @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
209# ----------------------------------------------------------------------------- 189# @DESCRIPTION:
210
211
212# -----------------------------------------------------------------------------
213# @section-begin install
214# @section-summary Install functions
215#
216# These are used to install Java-related things, such as jars, Javadocs, JNI
217# libraries, etc.
218# -----------------------------------------------------------------------------
219
220# -----------------------------------------------------------------------------
221# @ebuild-function java-pkg_doexamples
222#
223# Installs given arguments to /usr/share/doc/${PF}/examples 190# Installs given arguments to /usr/share/doc/${PF}/examples
224# If you give it only one parameter and it is a directory it will install 191# If you give it only one parameter and it is a directory it will install
225# everything in that directory to the examples directory. 192# everything in that directory to the examples directory.
226# 193#
194# @CODE
195# Parameters:
196# --subdir - If the examples need a certain directory structure
197# $* - list of files to install
198#
227# @example 199# Examples:
228# java-pkg_doexamples demo 200# java-pkg_doexamples demo
229# java-pkg_doexamples demo/* examples/* 201# java-pkg_doexamples demo/* examples/*
230# 202# @CODE
231# @param --subdir - If the examples need a certain directory structure
232# @param $* - list of files to install
233# ------------------------------------------------------------------------------
234java-pkg_doexamples() { 203java-pkg_doexamples() {
235 debug-print-function ${FUNCNAME} $* 204 debug-print-function ${FUNCNAME} $*
236 205
237 [[ ${#} -lt 1 ]] && die "At least one argument needed" 206 [[ ${#} -lt 1 ]] && die "At least one argument needed"
238 207
239 java-pkg_check-phase install 208 java-pkg_check-phase install
209 java-pkg_init_paths_
240 210
241 local dest=/usr/share/doc/${PF}/examples 211 local dest=/usr/share/doc/${PF}/examples
242 if [[ ${1} == --subdir ]]; then 212 if [[ ${1} == --subdir ]]; then
243 local dest=${dest}/${2} 213 local dest=${dest}/${2}
244 dodir ${dest} 214 dodir ${dest}
259 229
260 # Let's make a symlink to the directory we have everything else under 230 # Let's make a symlink to the directory we have everything else under
261 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die 231 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
262} 232}
263 233
264# ----------------------------------------------------------------------------- 234# @FUNCTION: java-pkg_addres
265# @ebuild-function java-pkg_dojar 235# @USAGE: <jar> <dir> [<find arguments> ...]
236# @DESCRIPTION:
237# Adds resource files to an existing jar.
238# It is important that the directory given is actually the root of the
239# corresponding resource tree. The target directory as well as
240# sources.lst, MANIFEST.MF, *.class, *.jar, and *.java files are
241# automatically excluded. Symlinks are always followed. Additional
242# arguments are passed through to find.
266# 243#
244# @CODE
245# java-pkg_addres ${PN}.jar resources ! -name "*.html"
246# @CODE
247#
248# @param $1 - jar file
249# @param $2 - resource tree directory
250# @param $* - arguments to pass to find
251java-pkg_addres() {
252 debug-print-function ${FUNCNAME} $*
253
254 [[ ${#} -lt 2 ]] && die "at least two arguments needed"
255
256 local jar=$(realpath "$1" || die "realpath $1 failed")
257 local dir="$2"
258 shift 2
259
260 pushd "${dir}" > /dev/null || die "pushd ${dir} failed"
261 find -L -type f ! -path "./target/*" ! -path "./sources.lst" ! -name "MANIFEST.MF" ! -regex ".*\.\(class\|jar\|java\)" "${@}" -print0 | xargs -0 jar uf "${jar}" || die "jar failed"
262 popd > /dev/null || die "popd failed"
263}
264
265# @FUNCTION: java-pkg_rm_files
266# @USAGE: java-pkg_rm_files File1.java File2.java ...
267# @DESCRIPTION:
268# Remove unneeded files in ${S}.
269#
270# Every now and then, you'll run into situations whereby a file needs removing,
271# be it a unit test or a regular java class.
272#
273# You can use this function by either:
274# - calling it yourself in java_prepare() and feeding java-pkg_rm_files with
275# the list of files you wish to remove.
276# - defining an array in the ebuild named JAVA_RM_FILES with the list of files
277# you wish to remove.
278#
279# Both way work and it is left to the developer's preferences. If the
280# JAVA_RM_FILES array is defined, it will be automatically handed over to
281# java-pkg_rm_files during the src_prepare phase.
282#
283# See java-utils-2_src_prepare.
284#
285# @CODE
286# java-pkg_rm_files File1.java File2.java
287# @CODE
288#
289# @param $* - list of files to remove.
290java-pkg_rm_files() {
291 debug-print-function ${FUNCNAME} $*
292 local IFS="\n"
293 for filename in "$@"; do
294 [[ ! -f "${filename}" ]] && die "${filename} is not a regular file. Aborting."
295 einfo "Removing unneeded file ${filename}"
296 rm -f "${S}/${filename}" || die "cannot remove ${filename}"
297 eend $?
298 done
299}
300
301# @FUNCTION: java-pkg_dojar
302# @USAGE: <jar1> [<jar2> ...]
303# @DESCRIPTION:
267# Installs any number of jars. 304# Installs any number of jars.
268# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 305# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
269# You can use java-pkg_jarinto to change this path. 306# You can use java-pkg_jarinto to change this path.
270# You should never install a jar with a package version in the filename. 307# You should never install a jar with a package version in the filename.
271# Instead, use java-pkg_newjar defined below. 308# Instead, use java-pkg_newjar defined below.
272# 309#
273# @example 310# @CODE
274# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 311# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
312# @CODE
275# 313#
276# @param $* - list of jars to install 314# @param $* - list of jars to install
277# ------------------------------------------------------------------------------
278java-pkg_dojar() { 315java-pkg_dojar() {
279 debug-print-function ${FUNCNAME} $* 316 debug-print-function ${FUNCNAME} $*
280 317
281 [[ ${#} -lt 1 ]] && die "At least one argument needed" 318 [[ ${#} -lt 1 ]] && die "At least one argument needed"
282 319
324 done 361 done
325 362
326 java-pkg_do_write_ 363 java-pkg_do_write_
327} 364}
328 365
329# ------------------------------------------------------------------------------ 366# @FUNCTION: java-pkg_regjar
330# @internal-function depend-java-query 367# @USAGE: </path/to/installed/jar>
331# 368# @DESCRIPTION:
332# Wrapper for the depend-java-query binary to enable passing USE in env.
333# Using env variables keeps this eclass working with java-config versions that
334# do not handle use flags.
335# ------------------------------------------------------------------------------
336
337depend-java-query() {
338 # Used to have a which call here but it caused endless loops for some people
339 # that had some weird bashrc voodoo for which.
340 USE="${USE}" /usr/bin/depend-java-query "${@}"
341}
342
343# ------------------------------------------------------------------------------
344# @ebuild-function java-pkg_regjar
345#
346# Records an already installed jar in the package.env 369# Records an already installed (in ${D}) jar in the package.env
347# This would mostly be used if the package has make or a custom script to 370# This would mostly be used if the package has make or a custom script to
348# install things. 371# install things.
349# 372#
350# Example:
351# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
352#
353# WARNING: 373# WARNING:
354# if you want to use shell expansion, you have to use ${D}/... as the for in 374# if you want to use shell expansion, you have to use ${D}/... as the for in
355# this function will not be able to expand the path, here's an example: 375# this function will not be able to expand the path, here's an example:
356# 376#
357# java-pkg_regjar /opt/my-java/lib/*.jar 377# @CODE
358#
359# will not work, because:
360# * the `for jar in "$@"` can't expand the path to jar file names, as they
361# don't exist yet
362# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
363# doesn't exist
364#
365# you have to use it as:
366#
367# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 378# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
379# @CODE
368# 380#
369# @param $@ - jars to record 381
370# ------------------------------------------------------------------------------
371# TODO should we be making sure the jar is present on ${D} or wherever? 382# TODO should we be making sure the jar is present on ${D} or wherever?
372java-pkg_regjar() { 383java-pkg_regjar() {
373 debug-print-function ${FUNCNAME} $* 384 debug-print-function ${FUNCNAME} $*
374 385
375 java-pkg_check-phase install 386 java-pkg_check-phase install
406 done 417 done
407 418
408 java-pkg_do_write_ 419 java-pkg_do_write_
409} 420}
410 421
411# ------------------------------------------------------------------------------ 422# @FUNCTION: java-pkg_newjar
412# @ebuild-function java-pkg_newjar 423# @USAGE: <path/to/oldname.jar> [<newname.jar>]
424# @DESCRIPTION:
425# Installs a jar with a new name (defaults to $PN.jar)
413# 426#
414# Installs a jar with a new name
415#
416# @example: install a versioned jar without the version 427# For example, installs a versioned jar without the version
417# java-pkg_newjar dist/${P}.jar ${PN}.jar
418#
419# @param $1 - jar to install
420# @param $2 - new name for jar - defaults to ${PN}.jar if not specified
421# ------------------------------------------------------------------------------
422java-pkg_newjar() { 428java-pkg_newjar() {
423 debug-print-function ${FUNCNAME} $* 429 debug-print-function ${FUNCNAME} $*
424 430
425 local original_jar="${1}" 431 local original_jar="${1}"
426 local new_jar="${2:-${PN}.jar}" 432 local new_jar="${2:-${PN}.jar}"
434 cp "${original_jar}" "${new_jar_dest}" \ 440 cp "${original_jar}" "${new_jar_dest}" \
435 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 441 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
436 java-pkg_dojar "${new_jar_dest}" 442 java-pkg_dojar "${new_jar_dest}"
437} 443}
438 444
439# ------------------------------------------------------------------------------ 445# @FUNCTION: java-pkg_addcp
440# @ebuild-function java-pkg_addcp 446# @USAGE: <classpath>
441# 447# @DESCRIPTION:
442# Add something to the package's classpath. For jars, you should use dojar, 448# Add something to the package's classpath. For jars, you should use dojar,
443# newjar, or regjar. This is typically used to add directories to the classpath. 449# newjar, or regjar. This is typically used to add directories to the classpath.
444# 450# The parameters of this function are appended to JAVA_PKG_CLASSPATH
445# TODO add example
446# @param $@ - value to append to JAVA_PKG_CLASSPATH
447# ------------------------------------------------------------------------------
448java-pkg_addcp() { 451java-pkg_addcp() {
449 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 452 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
450 java-pkg_do_write_ 453 java-pkg_do_write_
451} 454}
452 455
453# ------------------------------------------------------------------------------ 456# @FUNCTION: java-pkg_doso
454# @ebuild-function java-pkg_doso 457# @USAGE: <path/to/file1.so> [...]
455# 458# @DESCRIPTION:
456# Installs any number of JNI libraries 459# Installs any number of JNI libraries
457# They will be installed into /usr/lib by default, but java-pkg_sointo 460# They will be installed into /usr/lib by default, but java-pkg_sointo
458# can be used change this path 461# can be used change this path
459# 462#
463# @CODE
460# Example: 464# Example:
461# java-pkg_doso *.so 465# java-pkg_doso *.so
462# 466# @CODE
463# @param $@ - JNI libraries to install
464# ------------------------------------------------------------------------------
465java-pkg_doso() { 467java-pkg_doso() {
466 debug-print-function ${FUNCNAME} $* 468 debug-print-function ${FUNCNAME} $*
467 469
468 java-pkg_check-phase install 470 java-pkg_check-phase install
469 471
477 # if the lib exists... 479 # if the lib exists...
478 if [[ -e "${lib}" ]] ; then 480 if [[ -e "${lib}" ]] ; then
479 # install if it isn't a symlink 481 # install if it isn't a symlink
480 if [[ ! -L "${lib}" ]] ; then 482 if [[ ! -L "${lib}" ]] ; then
481 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 483 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
482 INSOPTIONS="${LIBOPTIONS}" \ 484 INSOPTIONS="-m0755" \
483 doins "${lib}" || die "failed to install ${lib}" 485 doins "${lib}" || die "failed to install ${lib}"
484 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 486 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
485 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 487 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
486 # otherwise make a symlink to the symlink's origin 488 # otherwise make a symlink to the symlink's origin
487 else 489 else
495 done 497 done
496 498
497 java-pkg_do_write_ 499 java-pkg_do_write_
498} 500}
499 501
500# ------------------------------------------------------------------------------ 502# @FUNCTION: java-pkg_regso
501# @ebuild-function java-pkg_regso 503# @USAGE: <file1.so> [...]
502# 504# @DESCRIPTION:
503# Registers an already JNI library in package.env. 505# Registers an already installed JNI library in package.env.
506#
507# @CODE
508# Parameters:
509# $@ - JNI libraries to register
504# 510#
505# Example: 511# Example:
506# java-pkg_regso *.so /path/*.so 512# java-pkg_regso *.so /path/*.so
507# 513# @CODE
508# @param $@ - JNI libraries to register
509# ------------------------------------------------------------------------------
510java-pkg_regso() { 514java-pkg_regso() {
511 debug-print-function ${FUNCNAME} $* 515 debug-print-function ${FUNCNAME} $*
512 516
513 java-pkg_check-phase install 517 java-pkg_check-phase install
514 518
532 done 536 done
533 537
534 java-pkg_do_write_ 538 java-pkg_do_write_
535} 539}
536 540
537# ------------------------------------------------------------------------------ 541# @FUNCTION: java-pkg_jarinto
538# @ebuild-function java-pkg_jarinto 542# @USAGE: </path/to/install/jars/into>
539# 543# @DESCRIPTION:
540# Changes the path jars are installed into 544# Changes the path jars are installed into via subsequent java-pkg_dojar calls.
541#
542# @param $1 - new location to install jars into.
543# -----------------------------------------------------------------------------
544java-pkg_jarinto() { 545java-pkg_jarinto() {
545 debug-print-function ${FUNCNAME} $* 546 debug-print-function ${FUNCNAME} $*
546 547
547 JAVA_PKG_JARDEST="${1}" 548 JAVA_PKG_JARDEST="${1}"
548} 549}
549 550
550# ------------------------------------------------------------------------------ 551# @FUNCTION: java-pkg_sointo
551# @ebuild-function java-pkg_sointo 552# @USAGE: </path/to/install/sofiles/into>
552# 553# @DESCRIPTION:
553# Changes the path that JNI libraries are installed into. 554# Changes the path that JNI libraries are installed into via subsequent
554# 555# java-pkg_doso calls.
555# @param $1 - new location to install JNI libraries into.
556# ------------------------------------------------------------------------------
557java-pkg_sointo() { 556java-pkg_sointo() {
558 debug-print-function ${FUNCNAME} $* 557 debug-print-function ${FUNCNAME} $*
559 558
560 JAVA_PKG_LIBDEST="${1}" 559 JAVA_PKG_LIBDEST="${1}"
561} 560}
562 561
563# ------------------------------------------------------------------------------ 562# @FUNCTION: java-pkg_dohtml
564# @ebuild-function java-pkg_dohtml 563# @USAGE: <path/to/javadoc/documentation> [...]
564# @DESCRIPTION:
565# Install Javadoc HTML documentation. Usage of java-pkg_dojavadoc is preferred.
565# 566#
566# Install Javadoc HTML documentation 567# @CODE
567#
568# @example
569# java-pkg_dohtml dist/docs/ 568# java-pkg_dohtml dist/docs/
570# 569# @CODE
571# ------------------------------------------------------------------------------
572java-pkg_dohtml() { 570java-pkg_dohtml() {
573 debug-print-function ${FUNCNAME} $* 571 debug-print-function ${FUNCNAME} $*
574 572
575 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 573 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
576 574
582 # a reasonable way to catch # docs for all of the 580 # a reasonable way to catch # docs for all of the
583 # old ebuilds. 581 # old ebuilds.
584 java-pkg_recordjavadoc 582 java-pkg_recordjavadoc
585} 583}
586 584
587# ------------------------------------------------------------------------------ 585# @FUNCTION: java-pkg_dojavadoc
588# @ebuild-function java-pkg_dojavadoc 586# @USAGE: [--symlink destination] <path/to/javadocs/root>
589# 587# @DESCRIPTION:
590# Installs javadoc documentation. This should be controlled by the doc use flag. 588# Installs javadoc documentation. This should be controlled by the doc use flag.
591# 589#
590# @CODE
591# Parameters:
592# @param $1: optional --symlink creates to symlink like this for html 592# $1: optional --symlink creates to symlink like this for html
593# documentation bundles. 593# documentation bundles.
594# @param $2: - The javadoc root directory. 594# $2: - The javadoc root directory.
595# 595#
596# @example: 596# Examples:
597# java-pkg_dojavadoc docs/api 597# java-pkg_dojavadoc docs/api
598# java-pkg_dojavadoc --symlink apidocs docs/api 598# java-pkg_dojavadoc --symlink apidocs docs/api
599# 599# @CODE
600# ------------------------------------------------------------------------------
601java-pkg_dojavadoc() { 600java-pkg_dojavadoc() {
602 debug-print-function ${FUNCNAME} $* 601 debug-print-function ${FUNCNAME} $*
603 602
604 # For html documentation bundles that link to Javadoc 603 # For html documentation bundles that link to Javadoc
605 local symlink 604 local symlink
612 local dest=/usr/share/doc/${PF}/html 611 local dest=/usr/share/doc/${PF}/html
613 612
614 # QA checks 613 # QA checks
615 614
616 java-pkg_check-phase install 615 java-pkg_check-phase install
616 java-pkg_init_paths_
617 617
618 [[ -z "${dir}" ]] && die "Must specify a directory!" 618 [[ -z "${dir}" ]] && die "Must specify a directory!"
619 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 619 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
620 if [[ ! -e "${dir}/index.html" ]]; then 620 if [[ ! -e "${dir}/index.html" ]]; then
621 local msg="No index.html in javadoc directory" 621 local msg="No index.html in javadoc directory"
648 debug-print "symlinking ${dest}/{api,${symlink}}" 648 debug-print "symlinking ${dest}/{api,${symlink}}"
649 dosym ${dest}/{api,${symlink}} || die 649 dosym ${dest}/{api,${symlink}} || die
650 fi 650 fi
651} 651}
652 652
653# ------------------------------------------------------------------------------ 653# @FUNCTION: java-pkg_dosrc
654# @ebuild-function java-pkg_dosrc 654# @USAGE: <path/to/sources> [...]
655# 655# @DESCRIPTION:
656# Installs a zip containing the source for a package, so it can used in 656# Installs a zip containing the source for a package, so it can used in
657# from IDEs like eclipse and netbeans. 657# from IDEs like eclipse and netbeans.
658# Ebuild needs to DEPEND on app-arch/zip to use this. It also should be controlled by USE=source.
658# 659#
659# Ebuild needs to DEPEND on app-arch/zip to use this. 660# @CODE
660#
661# It also should be controlled by USE=source.
662#
663# @example: 661# Example:
664# java-pkg_dosrc src/* 662# java-pkg_dosrc src/*
665# 663# @CODE
666# ------------------------------------------------------------------------------ 664
667# TODO change so it the arguments it takes are the base directories containing 665# TODO change so it the arguments it takes are the base directories containing
668# source -nichoj 666# source -nichoj
667#
669# TODO should we be able to handle multiple calls to dosrc? -nichoj 668# TODO should we be able to handle multiple calls to dosrc? -nichoj
669#
670# TODO maybe we can take an existing zip/jar? -nichoj 670# TODO maybe we can take an existing zip/jar? -nichoj
671#
671# FIXME apparently this fails if you give it an empty directories 672# FIXME apparently this fails if you give it an empty directories
672java-pkg_dosrc() { 673java-pkg_dosrc() {
673 debug-print-function ${FUNCNAME} $* 674 debug-print-function ${FUNCNAME} $*
674 675
675 [ ${#} -lt 1 ] && die "At least one argument needed" 676 [ ${#} -lt 1 ] && die "At least one argument needed"
707 708
708 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}" 709 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
709 java-pkg_do_write_ 710 java-pkg_do_write_
710} 711}
711 712
712# ------------------------------------------------------------------------------ 713# @FUNCTION: java-pkg_dolauncher
713# @ebuild-function java-pkg_dolauncher 714# @USAGE: <filename> [options]
714# 715# @DESCRIPTION:
715# Make a wrapper script to lauch/start this package 716# Make a wrapper script to lauch/start this package
716# If necessary, the wrapper will switch to the appropriate VM. 717# If necessary, the wrapper will switch to the appropriate VM.
717# 718#
718# Can be called without parameters if the package installs only one jar 719# Can be called without parameters if the package installs only one jar
719# that has the Main-class attribute set. The wrapper will be named ${PN}. 720# that has the Main-class attribute set. The wrapper will be named ${PN}.
720# 721#
722# @CODE
723# Parameters:
721# @param $1 - filename of launcher to create 724# $1 - filename of launcher to create
722# @param $2 - options, as follows: 725# $2 - options, as follows:
723# --main the.main.class.too.start 726# --main the.main.class.to.start
724# --jar /the/jar/too/launch.jar or just <name>.jar 727# --jar /the/jar/too/launch.jar or just <name>.jar
725# --java_args 'Extra arguments to pass to java' 728# --java_args 'Extra arguments to pass to java'
726# --pkg_args 'Extra arguments to pass to the package' 729# --pkg_args 'Extra arguments to pass to the package'
727# --pwd Directory the launcher changes to before executing java 730# --pwd Directory the launcher changes to before executing java
728# -into Directory to install the launcher to, instead of /usr/bin 731# -into Directory to install the launcher to, instead of /usr/bin
729# -pre Prepend contents of this file to the launcher 732# -pre Prepend contents of this file to the launcher
730# ------------------------------------------------------------------------------ 733# @CODE
731java-pkg_dolauncher() { 734java-pkg_dolauncher() {
732 debug-print-function ${FUNCNAME} $* 735 debug-print-function ${FUNCNAME} $*
733 736
734 java-pkg_check-phase install 737 java-pkg_check-phase install
735 java-pkg_init_paths_ 738 java-pkg_init_paths_
796 else 799 else
797 dobin "${target}" 800 dobin "${target}"
798 fi 801 fi
799} 802}
800 803
801# ------------------------------------------------------------------------------ 804# @FUNCTION: java-pkg_dowar
805# @DESCRIPTION:
802# Install war files. 806# Install war files.
803# TODO document 807# TODO document
804# ------------------------------------------------------------------------------
805java-pkg_dowar() { 808java-pkg_dowar() {
806 debug-print-function ${FUNCNAME} $* 809 debug-print-function ${FUNCNAME} $*
807 810
808 # Check for arguments 811 # Check for arguments
809 [[ ${#} -lt 1 ]] && die "At least one argument needed" 812 [[ ${#} -lt 1 ]] && die "At least one argument needed"
833 INSDESTTREE=${JAVA_PKG_WARDEST} \ 836 INSDESTTREE=${JAVA_PKG_WARDEST} \
834 doins ${warpath} 837 doins ${warpath}
835 done 838 done
836} 839}
837 840
838# ------------------------------------------------------------------------------ 841# @FUNCTION: java-pkg_recordjavadoc
839# @internal-function java-pkg_recordjavadoc 842# @INTERNAL
843# @DESCRIPTION:
840# Scan for JavaDocs, and record their existence in the package.env file 844# Scan for JavaDocs, and record their existence in the package.env file
841# 845
842# TODO make sure this in the proper section 846# TODO make sure this in the proper section
843# ------------------------------------------------------------------------------
844java-pkg_recordjavadoc() 847java-pkg_recordjavadoc()
845{ 848{
846 debug-print-function ${FUNCNAME} $* 849 debug-print-function ${FUNCNAME} $*
847 # the find statement is important 850 # the find statement is important
848 # as some packages include multiple trees of javadoc 851 # as some packages include multiple trees of javadoc
855 else 858 else
856 debug-print "No javadocs found" 859 debug-print "No javadocs found"
857 fi 860 fi
858} 861}
859 862
860# ------------------------------------------------------------------------------
861# @section-end install
862# ------------------------------------------------------------------------------
863 863
864# ------------------------------------------------------------------------------ 864# @FUNCTION: java-pkg_jar-from
865# @begin-section query 865# @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
866# Use these to build the classpath for building a package. 866# @DESCRIPTION:
867# ------------------------------------------------------------------------------
868
869# ------------------------------------------------------------------------------
870# @ebuild-function java-pkg_jar-from
871#
872# Makes a symlink to a jar from a certain package 867# Makes a symlink to a jar from a certain package
873# A lot of java packages include dependencies in a lib/ directory 868# A lot of java packages include dependencies in a lib/ directory
874# You can use this function to replace these bundled dependencies. 869# You can use this function to replace these bundled dependencies.
875# The dependency is recorded into package.env DEPEND line, unless "--build-only" 870# The dependency is recorded into package.env DEPEND line, unless "--build-only"
876# is passed as the very first argument, for jars that have to be present only 871# is passed as the very first argument, for jars that have to be present only
877# at build time and are not needed on runtime (junit testing etc). 872# at build time and are not needed on runtime (junit testing etc).
878# 873#
874# @CODE
879# Example: get all jars from xerces slot 2 875# Example: get all jars from xerces slot 2
880# java-pkg_jar-from xerces-2 876# java-pkg_jar-from xerces-2
877#
881# Example: get a specific jar from xerces slot 2 878# Example: get a specific jar from xerces slot 2
882# java-pkg_jar-from xerces-2 xml-apis.jar 879# java-pkg_jar-from xerces-2 xml-apis.jar
880#
883# Example: get a specific jar from xerces slot 2, and name it diffrently 881# Example: get a specific jar from xerces slot 2, and name it diffrently
884# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 882# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
883#
885# Example: get junit.jar which is needed only for building 884# Example: get junit.jar which is needed only for building
886# java-pkg_jar-from --build-only junit junit.jar 885# java-pkg_jar-from --build-only junit junit.jar
886# @CODE
887# 887#
888# @param $opt 888# @CODE
889# Parameters
889# --build-only - makes the jar(s) not added into package.env DEPEND line. 890# --build-only - makes the jar(s) not added into package.env DEPEND line.
890# (assumed automatically when called inside src_test) 891# (assumed automatically when called inside src_test)
891# --with-dependencies - get jars also from requested package's dependencies 892# --with-dependencies - get jars also from requested package's dependencies
892# transitively. 893# transitively.
893# --virtual - Packages passed to this function are to be handled as virtuals 894# --virtual - Packages passed to this function are to be handled as virtuals
894# and will not have individual jar dependencies recorded. 895# and will not have individual jar dependencies recorded.
895# --into $dir - symlink jar(s) into $dir (must exist) instead of . 896# --into $dir - symlink jar(s) into $dir (must exist) instead of .
896# @param $1 - Package to get jars from, or comma-separated list of packages in 897# $1 - Package to get jars from, or comma-separated list of packages in
897# case other parameters are not used. 898# case other parameters are not used.
898# @param $2 - jar from package. If not specified, all jars will be used. 899# $2 - jar from package. If not specified, all jars will be used.
899# @param $3 - When a single jar is specified, destination filename of the 900# $3 - When a single jar is specified, destination filename of the
900# symlink. Defaults to the name of the jar. 901# symlink. Defaults to the name of the jar.
901# ------------------------------------------------------------------------------ 902# @CODE
903
902# TODO could probably be cleaned up a little 904# TODO could probably be cleaned up a little
903java-pkg_jar-from() { 905java-pkg_jar-from() {
904 debug-print-function ${FUNCNAME} $* 906 debug-print-function ${FUNCNAME} $*
905 907
906 local build_only="" 908 local build_only=""
985 java-pkg_record-jar_ "${target_pkg}" "${jar}" 987 java-pkg_record-jar_ "${target_pkg}" "${jar}"
986 else 988 else
987 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}" 989 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
988 fi 990 fi
989 fi 991 fi
990 # otherwise, if the current jar is the target jar, link it 992 # otherwise, if the current jar is the target jar, link it
991 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 993 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
992 [[ -f "${destjar}" ]] && rm "${destjar}" 994 [[ -f "${destjar}" ]] && rm "${destjar}"
993 ln -snf "${jar}" "${destjar}" \ 995 ln -snf "${jar}" "${destjar}" \
994 || die "Failed to make symlink from ${jar} to ${destjar}" 996 || die "Failed to make symlink from ${jar} to ${destjar}"
995 if [[ -z "${record_jar}" ]]; then 997 if [[ -z "${record_jar}" ]]; then
996 if [[ -z "${build_only}" ]]; then 998 if [[ -z "${build_only}" ]]; then
997 java-pkg_record-jar_ "${target_pkg}" "${jar}" 999 java-pkg_record-jar_ "${target_pkg}" "${jar}"
998 else 1000 else
999 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}" 1001 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
1000 fi 1002 fi
1001 fi 1003 fi
1002 popd > /dev/null 1004 popd > /dev/null
1003 return 0 1005 return 0
1004 fi 1006 fi
1011 else 1013 else
1012 die "Failed to find ${target_jar:-jar} in ${target_pkg}" 1014 die "Failed to find ${target_jar:-jar} in ${target_pkg}"
1013 fi 1015 fi
1014} 1016}
1015 1017
1016# ------------------------------------------------------------------------------ 1018# @FUNCTION: java-pkg_jarfrom
1017# @ebuild-function java-pkg_jarfrom 1019# @DESCRIPTION:
1018#
1019# See java-pkg_jar-from 1020# See java-pkg_jar-from
1020# ------------------------------------------------------------------------------
1021java-pkg_jarfrom() { 1021java-pkg_jarfrom() {
1022 java-pkg_jar-from "$@" 1022 java-pkg_jar-from "$@"
1023} 1023}
1024 1024
1025# ------------------------------------------------------------------------------ 1025# @FUNCTION: java-pkg_getjars
1026# @ebuild-function java-pkg_getjars 1026# @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
1027# 1027# @DESCRIPTION:
1028# Get the classpath provided by any number of packages 1028# Get the classpath provided by any number of packages
1029# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 1029# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
1030# The providing packages are recorded as dependencies into package.env DEPEND 1030# The providing packages are recorded as dependencies into package.env DEPEND
1031# line, unless "--build-only" is passed as the very first argument, for jars 1031# line, unless "--build-only" is passed as the very first argument, for jars
1032# that have to be present only at build time and are not needed on runtime 1032# that have to be present only at build time and are not needed on runtime
1033# (junit testing etc). 1033# (junit testing etc).
1034# 1034#
1035# @CODE
1035# Example: Get the classpath for xerces-2 and xalan, 1036# Example: Get the classpath for xerces-2 and xalan,
1036# java-pkg_getjars xerces-2,xalan 1037# java-pkg_getjars xerces-2,xalan
1038#
1037# Example Return: 1039# Example Return:
1038# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 1040# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
1039# 1041#
1040# @param $opt 1042#
1043# Parameters:
1041# --build-only - makes the jar(s) not added into package.env DEPEND line. 1044# --build-only - makes the jar(s) not added into package.env DEPEND line.
1042# (assumed automatically when called inside src_test) 1045# (assumed automatically when called inside src_test)
1043# --with-dependencies - get jars also from requested package's dependencies 1046# --with-dependencies - get jars also from requested package's dependencies
1044# transitively. 1047# transitively.
1045# @param $1 - list of packages to get jars from 1048# $1 - list of packages to get jars from
1046# (passed to java-config --classpath) 1049# (passed to java-config --classpath)
1047# ------------------------------------------------------------------------------ 1050# @CODE
1048java-pkg_getjars() { 1051java-pkg_getjars() {
1049 debug-print-function ${FUNCNAME} $* 1052 debug-print-function ${FUNCNAME} $*
1050 1053
1051 local build_only="" 1054 local build_only=""
1052 local deep="" 1055 local deep=""
1090 done 1093 done
1091 1094
1092 echo "${jars}" 1095 echo "${jars}"
1093} 1096}
1094 1097
1095# ------------------------------------------------------------------------------ 1098# @FUNCTION: java-pkg_getjar
1096# @ebuild-function java-pkg_getjar 1099# @USAGE: [--build-only] [--virtual] <package> <jarfile>
1097# 1100# @DESCRIPTION:
1098# Get the filename of a single jar from a package 1101# Get the complete path of a single jar from a package
1099# The providing package is recorded as runtime dependency into package.env 1102# The providing package is recorded as runtime dependency into package.env
1100# DEPEND line, unless "--build-only" is passed as the very first argument, for 1103# DEPEND line, unless "--build-only" is passed as the very first argument, for
1101# jars that have to be present only at build time and are not needed on runtime 1104# jars that have to be present only at build time and are not needed on runtime
1102# (junit testing etc). 1105# (junit testing etc).
1103# 1106#
1107# @CODE
1104# @example 1108# Example:
1105# java-pkg_getjar xerces-2 xml-apis.jar 1109# java-pkg_getjar xerces-2 xml-apis.jar
1106# @example-return 1110# returns
1107# /usr/share/xerces-2/lib/xml-apis.jar 1111# /usr/share/xerces-2/lib/xml-apis.jar
1108# 1112#
1109# @param $opt 1113# Parameters:
1110# --build-only - makes the jar not added into package.env DEPEND line. 1114# --build-only - makes the jar not added into package.env DEPEND line.
1111# --virtual - Packages passed to this function are to be handled as virtuals 1115# --virtual - Packages passed to this function are to be handled as virtuals
1112# and will not have individual jar dependencies recorded. 1116# and will not have individual jar dependencies recorded.
1113# @param $1 - package to use 1117# $1 - package to use
1114# @param $2 - jar to get 1118# $2 - jar to get
1115# ------------------------------------------------------------------------------ 1119# @CODE
1116java-pkg_getjar() { 1120java-pkg_getjar() {
1117 debug-print-function ${FUNCNAME} $* 1121 debug-print-function ${FUNCNAME} $*
1118 1122
1119 local build_only="" 1123 local build_only=""
1120 local virtual="" 1124 local virtual=""
1183 1187
1184 die "Could not find ${target_jar} in ${pkg}" 1188 die "Could not find ${target_jar} in ${pkg}"
1185 return 1 1189 return 1
1186} 1190}
1187 1191
1188# ------------------------------------------------------------------------------ 1192# @FUNCTION: java-pkg_register-dependency
1189# @ebuild-function java-pkg_register-dependency 1193# @USAGE: <package>[,<package2>...] [<jarfile>]
1190# 1194# @DESCRIPTION:
1191# Registers runtime dependency on a package, list of packages, or a single jar 1195# Registers runtime dependency on a package, list of packages, or a single jar
1192# from a package, into package.env DEPEND line. Can only be called in 1196# from a package, into package.env DEPEND line. Can only be called in
1193# src_install phase. 1197# src_install phase.
1194# Intended for binary packages where you don't need to symlink the jars or get 1198# Intended for binary packages where you don't need to symlink the jars or get
1195# their classpath during build. As such, the dependencies only need to be 1199# their classpath during build. As such, the dependencies only need to be
1196# specified in ebuild's RDEPEND, and should be omitted in DEPEND. 1200# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1197# 1201#
1202# @CODE
1203# Parameters:
1198# @param $1 - comma-separated list of packages, or a single package 1204# $1 - comma-separated list of packages, or a single package
1199# @param $2 - if param $1 is a single package, optionally specify the jar 1205# $2 - if param $1 is a single package, optionally specify the jar
1200# to depend on 1206# to depend on
1201# 1207#
1208# Examples:
1202# Example: Record the dependency on whole xerces-2 and xalan, 1209# Record the dependency on whole xerces-2 and xalan,
1203# java-pkg_register-dependency xerces-2,xalan 1210# java-pkg_register-dependency xerces-2,xalan
1211#
1204# Example: Record the dependency on ant.jar from ant-core 1212# Record the dependency on ant.jar from ant-core
1205# java-pkg_register-dependency ant-core ant.jar 1213# java-pkg_register-dependency ant-core ant.jar
1214# @CODE
1206# 1215#
1207# Note: Passing both list of packages as the first parameter AND specifying the 1216# Note: Passing both list of packages as the first parameter AND specifying the
1208# jar as the second is not allowed and will cause the function to die. We assume 1217# jar as the second is not allowed and will cause the function to die. We assume
1209# that there's more chance one passes such combination as a mistake, than that 1218# that there's more chance one passes such combination as a mistake, than that
1210# there are more packages providing identically named jar without class 1219# there are more packages providing identically named jar without class
1211# collisions. 1220# collisions.
1212# ------------------------------------------------------------------------------
1213java-pkg_register-dependency() { 1221java-pkg_register-dependency() {
1214 debug-print-function ${FUNCNAME} $* 1222 debug-print-function ${FUNCNAME} $*
1215 1223
1216 java-pkg_check-phase install 1224 java-pkg_check-phase install
1217 1225
1239 fi 1247 fi
1240 1248
1241 java-pkg_do_write_ 1249 java-pkg_do_write_
1242} 1250}
1243 1251
1244# ------------------------------------------------------------------------------
1245# @ebuild-function java-pkg_register-optional-dependency 1252# @FUNCTION: java-pkg_register-optional-dependency
1246# 1253# @USAGE: <package>[,<package2>...] [<jarfile>]
1254# @DESCRIPTION:
1247# Registers optional runtime dependency on a package, list of packages, or a 1255# Registers optional runtime dependency on a package, list of packages, or a
1248# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be 1256# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1249# called in src_install phase. 1257# called in src_install phase.
1250# Intended for packages that can use other packages when those are in classpath. 1258# Intended for packages that can use other packages when those are in classpath.
1251# Will be put on classpath by launcher if they are installed. Typical case is 1259# Will be put on classpath by launcher if they are installed. Typical case is
1252# JDBC implementations for various databases. It's better than having USE flag 1260# JDBC implementations for various databases. It's better than having USE flag
1253# for each implementation triggering hard dependency. 1261# for each implementation triggering hard dependency.
1254# 1262#
1263# @CODE
1264# Parameters:
1255# @param $1 - comma-separated list of packages, or a single package 1265# $1 - comma-separated list of packages, or a single package
1256# @param $2 - if param $1 is a single package, optionally specify the jar 1266# $2 - if param $1 is a single package, optionally specify the jar to depend on
1257# to depend on
1258# 1267#
1268# Example:
1259# Example: Record the optional dependency on some jdbc providers 1269# Record the optional dependency on some jdbc providers
1260# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql 1270# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1271# @CODE
1261# 1272#
1262# Note: Passing both list of packages as the first parameter AND specifying the 1273# Note: Passing both list of packages as the first parameter AND specifying the
1263# jar as the second is not allowed and will cause the function to die. We assume 1274# jar as the second is not allowed and will cause the function to die. We assume
1264# that there's more chance one passes such combination as a mistake, than that 1275# that there's more chance one passes such combination as a mistake, than that
1265# there are more packages providing identically named jar without class 1276# there are more packages providing identically named jar without class
1266# collisions. 1277# collisions.
1267# ------------------------------------------------------------------------------
1268java-pkg_register-optional-dependency() { 1278java-pkg_register-optional-dependency() {
1269 debug-print-function ${FUNCNAME} $* 1279 debug-print-function ${FUNCNAME} $*
1270 1280
1271 java-pkg_check-phase install 1281 java-pkg_check-phase install
1272 1282
1292 fi 1302 fi
1293 1303
1294 java-pkg_do_write_ 1304 java-pkg_do_write_
1295} 1305}
1296 1306
1297# ------------------------------------------------------------------------------
1298# @ebuild-function java-pkg_register-environment-variable 1307# @FUNCTION: java-pkg_register-environment-variable
1299# 1308# @USAGE: <name> <value>
1309# @DESCRIPTION:
1300# Register an arbitrary environment variable into package.env. The gjl launcher 1310# Register an arbitrary environment variable into package.env. The gjl launcher
1301# for this package or any package depending on this will export it into 1311# for this package or any package depending on this will export it into
1302# environement before executing java command. 1312# environement before executing java command.
1303# Must only be called in src_install phase. 1313# Must only be called in src_install phase.
1304#
1305# @param $1 - variable name
1306# @param $2 - variable value
1307# ------------------------------------------------------------------------------
1308JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env" 1314JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1309JAVA_PKG_EXTRA_ENV_VARS="" 1315JAVA_PKG_EXTRA_ENV_VARS=""
1310java-pkg_register-environment-variable() { 1316java-pkg_register-environment-variable() {
1311 debug-print-function ${FUNCNAME} $* 1317 debug-print-function ${FUNCNAME} $*
1312 1318
1318 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}" 1324 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1319 1325
1320 java-pkg_do_write_ 1326 java-pkg_do_write_
1321} 1327}
1322 1328
1323# ------------------------------------------------------------------------------ 1329# @FUNCTION: java-pkg_get-bootclasspath
1324# @ebuild-function java-pkg_get-bootclasspath 1330# @USAGE: <version>
1325# 1331# @DESCRIPTION:
1326# Returns classpath of a given bootclasspath-providing package version. 1332# Returns classpath of a given bootclasspath-providing package version.
1327# 1333#
1328# @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath 1334# @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1329# of the current JDK 1335# of the current JDK
1330# ------------------------------------------------------------------------------
1331
1332java-pkg_get-bootclasspath() { 1336java-pkg_get-bootclasspath() {
1333 local version="${1}" 1337 local version="${1}"
1334 1338
1335 local bcp 1339 local bcp
1336 case "${version}" in 1340 case "${version}" in
1384# 1388#
1385# read line 1389# read line
1386# done 1390# done
1387#} 1391#}
1388 1392
1389# ------------------------------------------------------------------------------ 1393# @FUNCTION: java-pkg_find-normal-jars
1390# @section-end query 1394# @USAGE: [<path/to/directory>]
1391# ------------------------------------------------------------------------------ 1395# @DESCRIPTION:
1392
1393# ------------------------------------------------------------------------------
1394# @section-begin helper
1395# @section-summary Helper functions
1396#
1397# Various other functions to use from an ebuild
1398# ------------------------------------------------------------------------------
1399
1400# ------------------------------------------------------------------------------
1401# @ebuild-function java-pkg_find-normal-jars
1402#
1403# Find the files with suffix .jar file in the given directory or $WORKDIR 1396# Find the files with suffix .jar file in the given directory (default: $WORKDIR)
1404#
1405# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1406# ------------------------------------------------------------------------------
1407java-pkg_find-normal-jars() { 1397java-pkg_find-normal-jars() {
1408 local dir=$1 1398 local dir=$1
1409 [[ "${dir}" ]] || dir="${WORKDIR}" 1399 [[ "${dir}" ]] || dir="${WORKDIR}"
1410 local found 1400 local found
1411 for jar in $(find "${dir}" -name "*.jar" -type f); do 1401 for jar in $(find "${dir}" -name "*.jar" -type f); do
1414 done 1404 done
1415 [[ "${found}" ]] 1405 [[ "${found}" ]]
1416 return $? 1406 return $?
1417} 1407}
1418 1408
1419# ------------------------------------------------------------------------------ 1409# @FUNCTION: java-pkg_ensure-no-bundled-jars
1420# @ebuild-function java-pkg_ensure-no-bundled-jars 1410# @DESCRIPTION:
1421#
1422# Try to locate bundled jar files in ${WORKDIR} and die if found. 1411# Try to locate bundled jar files in ${WORKDIR} and die if found.
1423# This function should be called after WORKDIR has been populated with symlink 1412# This function should be called after WORKDIR has been populated with symlink
1424# to system jar files or bundled jars removed. 1413# to system jar files or bundled jars removed.
1425# ------------------------------------------------------------------------------
1426java-pkg_ensure-no-bundled-jars() { 1414java-pkg_ensure-no-bundled-jars() {
1427 debug-print-function ${FUNCNAME} $* 1415 debug-print-function ${FUNCNAME} $*
1428 1416
1429 local bundled_jars=$(java-pkg_find-normal-jars) 1417 local bundled_jars=$(java-pkg_find-normal-jars)
1430 if [[ -n ${bundled_jars} ]]; then 1418 if [[ -n ${bundled_jars} ]]; then
1435 done 1423 done
1436 die "Bundled jars found!" 1424 die "Bundled jars found!"
1437 fi 1425 fi
1438} 1426}
1439 1427
1440# ------------------------------------------------------------------------------
1441# @internal-function java-pkg_ensure-vm-version-sufficient 1428# @FUNCTION: java-pkg_ensure-vm-version-sufficient
1442# 1429# @INTERNAL
1430# @DESCRIPTION:
1443# Checks if we have a sufficient VM and dies if we don't. 1431# Checks if we have a sufficient VM and dies if we don't.
1444#
1445# ------------------------------------------------------------------------------
1446java-pkg_ensure-vm-version-sufficient() { 1432java-pkg_ensure-vm-version-sufficient() {
1447 debug-print-function ${FUNCNAME} $* 1433 debug-print-function ${FUNCNAME} $*
1448 1434
1449 if ! java-pkg_is-vm-version-sufficient; then 1435 if ! java-pkg_is-vm-version-sufficient; then
1450 debug-print "VM is not suffient" 1436 debug-print "VM is not suffient"
1452 einfo "Please use java-config -S to set the correct one" 1438 einfo "Please use java-config -S to set the correct one"
1453 die "Active Java VM cannot build this package" 1439 die "Active Java VM cannot build this package"
1454 fi 1440 fi
1455} 1441}
1456 1442
1457# ------------------------------------------------------------------------------ 1443# @FUNCTION: java-pkg_is-vm-version-sufficient
1458# @internal-function java-pkg_is-vm-version-sufficient 1444# @INTERNAL
1459# 1445# @DESCRIPTION:
1460# @return zero - VM is sufficient 1446# @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
1461# @return non-zero - VM is not sufficient
1462# ------------------------------------------------------------------------------
1463java-pkg_is-vm-version-sufficient() { 1447java-pkg_is-vm-version-sufficient() {
1464 debug-print-function ${FUNCNAME} $* 1448 debug-print-function ${FUNCNAME} $*
1465 1449
1466 depend-java-query --is-sufficient "${DEPEND}" > /dev/null 1450 depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1467 return $? 1451 return $?
1468} 1452}
1469 1453
1470# ------------------------------------------------------------------------------ 1454# @FUNCTION: java-pkg_ensure-vm-version-eq
1471# @internal-function java-pkg_ensure-vm-version-eq 1455# @INTERNAL
1472# 1456# @DESCRIPTION:
1473# Die if the current VM is not equal to the argument passed. 1457# Die if the current VM is not equal to the argument passed.
1474# 1458#
1475# @param $@ - Desired VM version to ensure 1459# @param $@ - Desired VM version to ensure
1476# ------------------------------------------------------------------------------
1477java-pkg_ensure-vm-version-eq() { 1460java-pkg_ensure-vm-version-eq() {
1478 debug-print-function ${FUNCNAME} $* 1461 debug-print-function ${FUNCNAME} $*
1479 1462
1480 if ! java-pkg_is-vm-version-eq $@ ; then 1463 if ! java-pkg_is-vm-version-eq $@ ; then
1481 debug-print "VM is not suffient" 1464 debug-print "VM is not suffient"
1483 einfo "Please use java-config -S to set the correct one" 1466 einfo "Please use java-config -S to set the correct one"
1484 die "Active Java VM too old" 1467 die "Active Java VM too old"
1485 fi 1468 fi
1486} 1469}
1487 1470
1488# ------------------------------------------------------------------------------ 1471# @FUNCTION: java-pkg_is-vm-version-eq
1489# @internal-function java-pkg_is-vm-version-eq 1472# @USAGE: <version>
1490# 1473# @INTERNAL
1491# @param $@ - VM version to compare current VM to 1474# @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
1492# @return zero - VM versions are equal
1493# @return non-zero - VM version are not equal
1494# ------------------------------------------------------------------------------
1495java-pkg_is-vm-version-eq() { 1475java-pkg_is-vm-version-eq() {
1496 debug-print-function ${FUNCNAME} $* 1476 debug-print-function ${FUNCNAME} $*
1497 1477
1498 local needed_version="$@" 1478 local needed_version="$@"
1499 1479
1516 return 1 1496 return 1
1517 fi 1497 fi
1518 fi 1498 fi
1519} 1499}
1520 1500
1521# ------------------------------------------------------------------------------ 1501# @FUNCTION: java-pkg_ensure-vm-version-ge
1522# @internal-function java-pkg_ensure-vm-version-ge 1502# @INTERNAL
1523# 1503# @DESCRIPTION:
1524# Die if the current VM is not greater than the desired version 1504# Die if the current VM is not greater than the desired version
1525# 1505#
1526# @param $@ - VM version to compare current to 1506# @param $@ - VM version to compare current to
1527# ------------------------------------------------------------------------------
1528java-pkg_ensure-vm-version-ge() { 1507java-pkg_ensure-vm-version-ge() {
1529 debug-print-function ${FUNCNAME} $* 1508 debug-print-function ${FUNCNAME} $*
1530 1509
1531 if ! java-pkg_is-vm-version-ge "$@" ; then 1510 if ! java-pkg_is-vm-version-ge "$@" ; then
1532 debug-print "vm is not suffient" 1511 debug-print "vm is not suffient"
1534 einfo "Please use java-config -S to set the correct one" 1513 einfo "Please use java-config -S to set the correct one"
1535 die "Active Java VM too old" 1514 die "Active Java VM too old"
1536 fi 1515 fi
1537} 1516}
1538 1517
1539# ------------------------------------------------------------------------------ 1518# @FUNCTION: java-pkg_is-vm-version-ge
1540# @internal-function java-pkg_is-vm-version-ge 1519# @INTERNAL
1541# 1520# @DESCRIPTION:
1521# @CODE
1522# Parameters:
1542# @param $@ - VM version to compare current VM to 1523# $@ - VM version to compare current VM to
1524# @CODE
1543# @return zero - current VM version is greater than checked version 1525# @RETURN: zero - current VM version is greater than checked version;
1544# @return non-zero - current VM version is not greater than checked version 1526# non-zero - current VM version is not greater than checked version
1545# ------------------------------------------------------------------------------
1546java-pkg_is-vm-version-ge() { 1527java-pkg_is-vm-version-ge() {
1547 debug-print-function ${FUNCNAME} $* 1528 debug-print-function ${FUNCNAME} $*
1548 1529
1549 local needed_version=$@ 1530 local needed_version=$@
1550 local vm_version=$(java-pkg_get-vm-version) 1531 local vm_version=$(java-pkg_get-vm-version)
1573java-pkg_current-vm-matches() { 1554java-pkg_current-vm-matches() {
1574 has $(java-pkg_get-current-vm) ${@} 1555 has $(java-pkg_get-current-vm) ${@}
1575 return $? 1556 return $?
1576} 1557}
1577 1558
1578# ------------------------------------------------------------------------------ 1559# @FUNCTION: java-pkg_get-source
1579# @ebuild-function java-pkg_get-source 1560# @DESCRIPTION:
1580#
1581# Determines what source version should be used, for passing to -source. 1561# Determines what source version should be used, for passing to -source.
1582# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1562# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1583# 1563#
1584# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1564# @RETURN: string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1585# ------------------------------------------------------------------------------
1586java-pkg_get-source() { 1565java-pkg_get-source() {
1587 echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")} 1566 echo ${JAVA_PKG_WANT_SOURCE:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1588} 1567}
1589 1568
1590# ------------------------------------------------------------------------------ 1569# @FUNCTION: java-pkg_get-target
1591# @ebuild-function java-pkg_get-target 1570# @DESCRIPTION:
1592#
1593# Determines what target version should be used, for passing to -target. 1571# Determines what target version should be used, for passing to -target.
1594# If you don't care about lower versions, you can set _WANT_TARGET to the 1572# If you don't care about lower versions, you can set _WANT_TARGET to the
1595# version of your JDK. 1573# version of your JDK.
1596# 1574#
1597# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1575# @RETURN: string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1598# ------------------------------------------------------------------------------
1599java-pkg_get-target() { 1576java-pkg_get-target() {
1600 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")} 1577 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1601} 1578}
1602 1579
1580# @FUNCTION: java-pkg_get-javac
1581# @DESCRIPTION:
1582# Returns the compiler executable
1603java-pkg_get-javac() { 1583java-pkg_get-javac() {
1604 debug-print-function ${FUNCNAME} $* 1584 debug-print-function ${FUNCNAME} $*
1605 1585
1606 1586
1607 local compiler="${GENTOO_COMPILER}" 1587 local compiler="${GENTOO_COMPILER}"
1637 fi 1617 fi
1638 fi 1618 fi
1639 echo ${compiler_executable} 1619 echo ${compiler_executable}
1640} 1620}
1641 1621
1642# ------------------------------------------------------------------------------ 1622# @FUNCTION: java-pkg_javac-args
1643# @ebuild-function java-pkg_javac-args 1623# @DESCRIPTION:
1644#
1645# If an ebuild uses javac directly, instead of using ejavac, it should call this 1624# If an ebuild uses javac directly, instead of using ejavac, it should call this
1646# to know what -source/-target to use. 1625# to know what -source/-target to use.
1647# 1626#
1648# @return string - arguments to pass to javac, complete with -target and -source 1627# @RETURN: string - arguments to pass to javac, complete with -target and -source
1649# ------------------------------------------------------------------------------
1650java-pkg_javac-args() { 1628java-pkg_javac-args() {
1651 debug-print-function ${FUNCNAME} $* 1629 debug-print-function ${FUNCNAME} $*
1652 1630
1653 local want_source="$(java-pkg_get-source)" 1631 local want_source="$(java-pkg_get-source)"
1654 local want_target="$(java-pkg_get-target)" 1632 local want_target="$(java-pkg_get-target)"
1662 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1640 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1663 debug-print "could not find valid -source/-target values for javac" 1641 debug-print "could not find valid -source/-target values for javac"
1664 echo "Could not find valid -source/-target values for javac" 1642 echo "Could not find valid -source/-target values for javac"
1665 return 1 1643 return 1
1666 else 1644 else
1667 if java-pkg_is-vm-version-ge "1.4"; then
1668 echo "${source_str} ${target_str}" 1645 echo "${source_str} ${target_str}"
1669 else
1670 echo "${target_str}"
1671 fi 1646 fi
1672 fi
1673} 1647}
1674 1648
1675# TODO document 1649# @FUNCTION: java-pkg_get-jni-cflags
1650# @DESCRIPTION:
1651# Echos the CFLAGS for JNI compilations
1676java-pkg_get-jni-cflags() { 1652java-pkg_get-jni-cflags() {
1677 local flags="-I${JAVA_HOME}/include" 1653 local flags="-I${JAVA_HOME}/include"
1678 1654
1679 local platform="linux" 1655 local platform="linux"
1680 use elibc_FreeBSD && platform="freebsd" 1656 use elibc_FreeBSD && platform="freebsd"
1684 1660
1685 echo ${flags} 1661 echo ${flags}
1686} 1662}
1687 1663
1688java-pkg_ensure-gcj() { 1664java-pkg_ensure-gcj() {
1689 if ! built_with_use sys-devel/gcc gcj ; then 1665 # was enforcing sys-devel/gcc[gcj]
1690 ewarn 1666 die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
1691 ewarn "You must build gcc with the gcj support to build with gcj"
1692 ewarn
1693 ebeep 5
1694 die "No GCJ support found!"
1695 fi
1696} 1667}
1697 1668
1698java-pkg_ensure-test() { 1669java-pkg_ensure-test() {
1699 if has test ${FEATURES} && ! has -test ${FEATURES} \ 1670 # was enforcing USE=test if FEATURES=test
1700 && has test ${IUSE} && ! use test; 1671 die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
1701 then
1702 eerror "You specified FEATURES=test, but USE=test is needed"
1703 eerror "to pull in the additional dependencies for testing"
1704 die "Need USE=test enabled"
1705 fi
1706} 1672}
1707 1673
1708# ------------------------------------------------------------------------------ 1674# @FUNCTION: java-pkg_register-ant-task
1709# @ebuild-function java-pkg_register-ant-task 1675# @USAGE: [--version x.y] [<name>]
1710# 1676# @DESCRIPTION:
1711# Register this package as ant task, so that ant will load it when no specific 1677# Register this package as ant task, so that ant will load it when no specific
1712# ANT_TASKS are specified. Note that even without this registering, all packages 1678# ANT_TASKS are specified. Note that even without this registering, all packages
1713# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks 1679# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1714# packages, but can be also used by other ebuilds that used to symlink their 1680# packages, but can be also used by other ebuilds that used to symlink their
1715# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards 1681# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1716# compatibility. 1682# compatibility.
1717# 1683#
1684# @CODE
1685# Parameters
1718# @param --version x.y Register only for ant version x.y (otherwise for any ant 1686# --version x.y Register only for ant version x.y (otherwise for any ant
1719# version). Used by the ant-* packages to prevent loading of mismatched 1687# version). Used by the ant-* packages to prevent loading of mismatched
1720# ant-core ant tasks after core was updated, before the tasks are updated, 1688# ant-core ant tasks after core was updated, before the tasks are updated,
1721# without a need for blockers. 1689# without a need for blockers.
1722# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT]) 1690# $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1723# ------------------------------------------------------------------------------ 1691# @CODE
1724java-pkg_register-ant-task() { 1692java-pkg_register-ant-task() {
1725 local TASKS_DIR="tasks" 1693 local TASKS_DIR="tasks"
1726 1694
1727 # check for --version x.y parameters 1695 # check for --version x.y parameters
1728 while [[ -n "${1}" && -n "${2}" ]]; do 1696 while [[ -n "${1}" && -n "${2}" ]]; do
1740 1708
1741 dodir /usr/share/ant/${TASKS_DIR} 1709 dodir /usr/share/ant/${TASKS_DIR}
1742 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}" 1710 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1743} 1711}
1744 1712
1745# ------------------------------------------------------------------------------ 1713# @FUNCTION: java-pkg_ant-tasks-depend
1746# @internal-function java-pkg_ant-tasks-depend 1714# @INTERNAL
1747# 1715# @DESCRIPTION:
1748# Translates the WANT_ANT_TASKS variable into valid dependencies. 1716# Translates the WANT_ANT_TASKS variable into valid dependencies.
1749# ------------------------------------------------------------------------------
1750java-pkg_ant-tasks-depend() { 1717java-pkg_ant-tasks-depend() {
1751 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS} 1718 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1752 1719
1753 if [[ -n "${WANT_ANT_TASKS}" ]]; then 1720 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1754 local DEP="" 1721 local DEP=""
1769 return 0 1736 return 0
1770 fi 1737 fi
1771} 1738}
1772 1739
1773 1740
1774# ------------------------------------------------------------------------------ 1741# @FUNCTION: ejunit_
1775# @internal-function ejunit_ 1742# @INTERNAL
1776# 1743# @DESCRIPTION:
1777# Internal Junit wrapper function. Makes it easier to run the tests and checks for 1744# Internal Junit wrapper function. Makes it easier to run the tests and checks for
1778# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner. 1745# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1779# 1746# @CODE
1747# Parameters:
1780# @param $1 - junit package (junit or junit-4) 1748# $1 - junit package (junit or junit-4)
1781# @param $2 - -cp or -classpath 1749# $2 - -cp or -classpath
1782# @param $3 - classpath; junit and recorded dependencies get appended 1750# $3 - classpath; junit and recorded dependencies get appended
1783# @param $@ - the rest of the parameters are passed to java 1751# $@ - the rest of the parameters are passed to java
1752# @CODE
1784ejunit_() { 1753ejunit_() {
1785 debug-print-function ${FUNCNAME} $* 1754 debug-print-function ${FUNCNAME} $*
1786 1755
1787 local pkgs 1756 local pkgs
1788 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then 1757 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1808 fi 1777 fi
1809 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}" 1778 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1810 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed" 1779 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1811} 1780}
1812 1781
1813# ------------------------------------------------------------------------------ 1782# @FUNCTION: ejunit
1814# @ebuild-function ejunit 1783# @DESCRIPTION:
1815#
1816# Junit wrapper function. Makes it easier to run the tests and checks for 1784# Junit wrapper function. Makes it easier to run the tests and checks for
1817# dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore. 1785# dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1786#
1787# @CODE
1788# Parameters:
1789# $1 - -cp or -classpath
1790# $2 - classpath; junit and recorded dependencies get appended
1791# $@ - the rest of the parameters are passed to java
1818# 1792#
1819# Examples: 1793# Examples:
1820# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests 1794# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1821# ejunit org.blinkenlights.jid3.test.AllTests 1795# ejunit org.blinkenlights.jid3.test.AllTests
1822# ejunit org.blinkenlights.jid3.test.FirstTest \ 1796# ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
1823# org.blinkenlights.jid3.test.SecondTest 1797# @CODE
1824#
1825# @param $1 - -cp or -classpath
1826# @param $2 - classpath; junit and recorded dependencies get appended
1827# @param $@ - the rest of the parameters are passed to java
1828# ------------------------------------------------------------------------------
1829ejunit() { 1798ejunit() {
1830 debug-print-function ${FUNCNAME} $* 1799 debug-print-function ${FUNCNAME} $*
1831 1800
1832 ejunit_ "junit" "${@}" 1801 ejunit_ "junit" "${@}"
1833} 1802}
1834 1803
1835# ------------------------------------------------------------------------------ 1804# @FUNCTION: ejunit4
1836# @ebuild-function ejunit4 1805# @DESCRIPTION:
1837#
1838# Junit4 wrapper function. Makes it easier to run the tests and checks for 1806# Junit4 wrapper function. Makes it easier to run the tests and checks for
1839# dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner. 1807# dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1808#
1809# @CODE
1810# Parameters:
1811# $1 - -cp or -classpath
1812# $2 - classpath; junit and recorded dependencies get appended
1813# $@ - the rest of the parameters are passed to java
1840# 1814#
1841# Examples: 1815# Examples:
1842# ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests 1816# ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1843# ejunit4 org.blinkenlights.jid3.test.AllTests 1817# ejunit4 org.blinkenlights.jid3.test.AllTests
1844# ejunit4 org.blinkenlights.jid3.test.FirstTest \ 1818# ejunit4 org.blinkenlights.jid3.test.FirstTest \
1845# org.blinkenlights.jid3.test.SecondTest 1819# org.blinkenlights.jid3.test.SecondTest
1846# 1820# @CODE
1847# @param $1 - -cp or -classpath
1848# @param $2 - classpath; junit and recorded dependencies get appended
1849# @param $@ - the rest of the parameters are passed to java
1850# ------------------------------------------------------------------------------
1851ejunit4() { 1821ejunit4() {
1852 debug-print-function ${FUNCNAME} $* 1822 debug-print-function ${FUNCNAME} $*
1853 1823
1854 ejunit_ "junit-4" "${@}" 1824 ejunit_ "junit-4" "${@}"
1855} 1825}
1856 1826
1857# ------------------------------------------------------------------------------ 1827# @FUNCTION: java-utils-2_src_prepare
1858# @section-end helper 1828# @DESCRIPTION:
1859# ------------------------------------------------------------------------------
1860
1861# ------------------------------------------------------------------------------
1862# @eclass-src_prepare
1863#
1864# src_prepare Searches for bundled jars 1829# src_prepare Searches for bundled jars
1865# Don't call directly, but via java-pkg-2_src_prepare! 1830# Don't call directly, but via java-pkg-2_src_prepare!
1866# ------------------------------------------------------------------------------
1867
1868java-utils-2_src_prepare() { 1831java-utils-2_src_prepare() {
1869 [[ ${EBUILD_PHASE} == prepare ]] &&
1870 java-pkg_func-exists java_prepare && java_prepare 1832 java-pkg_func-exists java_prepare && java_prepare
1871 1833
1872 # Remember that eant will call this unless called via Portage 1834 # Check for files in JAVA_RM_FILES array.
1873 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then 1835 if [[ ${JAVA_RM_FILES[@]} ]]; then
1836 debug-print "$FUNCNAME: removing unneeded files"
1837 java-pkg_rm_files "${JAVA_RM_FILES[@]}"
1838 fi
1839
1840 if is-java-strict; then
1874 echo "Searching for bundled jars:" 1841 echo "Searching for bundled jars:"
1875 java-pkg_find-normal-jars || echo "None found." 1842 java-pkg_find-normal-jars || echo "None found."
1876 echo "Searching for bundled classes (no output if none found):" 1843 echo "Searching for bundled classes (no output if none found):"
1877 find "${WORKDIR}" -name "*.class" 1844 find "${WORKDIR}" -name "*.class"
1878 echo "Search done." 1845 echo "Search done."
1879 fi 1846 fi
1880 touch "${T}/java-utils-2_src_prepare-run"
1881} 1847}
1882 1848
1883# ------------------------------------------------------------------------------ 1849# @FUNCTION: java-utils-2_pkg_preinst
1884# @eclass-pkg_preinst 1850# @DESCRIPTION:
1885#
1886# pkg_preinst Searches for missing and unneeded dependencies 1851# pkg_preinst Searches for missing and unneeded dependencies
1887# Don't call directly, but via java-pkg-2_pkg_preinst! 1852# Don't call directly, but via java-pkg-2_pkg_preinst!
1888# ------------------------------------------------------------------------------
1889
1890java-utils-2_pkg_preinst() { 1853java-utils-2_pkg_preinst() {
1891 if is-java-strict; then 1854 if is-java-strict; then
1855 if [[ ! -e "${JAVA_PKG_ENV}" ]] || has ant-tasks ${INHERITED}; then
1856 return
1857 fi
1858
1892 if has_version dev-java/java-dep-check; then 1859 if has_version dev-java/java-dep-check; then
1893 [[ -e "${JAVA_PKG_ENV}" ]] || return
1894 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}") 1860 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1895 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then 1861 [[ ${output} ]] && ewarn "${output}"
1896 ewarn "Possibly unneeded dependencies found in package.env:"
1897 for dep in ${output}; do
1898 ewarn "\t${dep}"
1899 done
1900 fi
1901 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1902 ewarn "${output}"
1903 fi
1904 else 1862 else
1905 eerror "Install dev-java/java-dep-check for dependency checking" 1863 eerror "Install dev-java/java-dep-check for dependency checking"
1906 fi 1864 fi
1907 fi 1865 fi
1908} 1866}
1909 1867
1910# ------------------------------------------------------------------------------ 1868# @FUNCTION: eant
1911# @section-begin build 1869# @USAGE: <ant_build_target(s)>
1912# @section-summary Build functions 1870# @DESCRIPTION:
1913#
1914# These are some functions for building a package. In particular, it consists of
1915# wrappers for javac and ant.
1916# ------------------------------------------------------------------------------
1917
1918# ------------------------------------------------------------------------------
1919# @ebuild-function eant
1920#
1921# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1871# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1922# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS, 1872# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1923# variables: 1873# variables:
1874#
1875# @CODE
1876# Variables:
1924# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the 1877# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1925# gentoo.classpath property. Be sure to call 1878# gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
1926# java-ant_rewrite-classpath in src_unpack.
1927# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used 1879# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1928# for build-time purposes, the dependency is not recorded to 1880# for build-time purposes, the dependency is not recorded to
1929# package.env! 1881# package.env!
1930# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. 1882# ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1931# ------------------------------------------------------------------------------ 1883# @CODE
1932eant() { 1884eant() {
1933 debug-print-function ${FUNCNAME} $* 1885 debug-print-function ${FUNCNAME} $*
1934 1886
1935 if [[ ${EBUILD_PHASE} = compile ]]; then 1887 if [[ ${EBUILD_PHASE} = compile ]]; then
1936 java-ant-2_src_configure 1888 java-ant-2_src_configure
1937 java-utils-2_src_prepare
1938 fi 1889 fi
1939 1890
1940 if ! has java-ant-2 ${INHERITED}; then 1891 if ! has java-ant-2 ${INHERITED}; then
1941 local msg="You should inherit java-ant-2 when using eant" 1892 local msg="You should inherit java-ant-2 when using eant"
1942 java-pkg_announce-qa-violation "${msg}" 1893 java-pkg_announce-qa-violation "${msg}"
2018 local gcp="${EANT_GENTOO_CLASSPATH}" 1969 local gcp="${EANT_GENTOO_CLASSPATH}"
2019 local getjarsarg="" 1970 local getjarsarg=""
2020 1971
2021 if [[ ${EBUILD_PHASE} = "test" ]]; then 1972 if [[ ${EBUILD_PHASE} = "test" ]]; then
2022 antflags="${antflags} -DJunit.present=true" 1973 antflags="${antflags} -DJunit.present=true"
2023 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
2024 getjarsarg="--with-dependencies" 1974 getjarsarg="--with-dependencies"
1975
1976 local re="\bant-junit4?([-:]\S+)?\b"
1977 [[ ${ANT_TASKS} =~ ${re} ]] && gcp+=" ${BASH_REMATCH[0]}"
2025 else 1978 else
2026 antflags="${antflags} -Dmaven.test.skip=true" 1979 antflags="${antflags} -Dmaven.test.skip=true"
2027 fi 1980 fi
2028 1981
2029 local cp 1982 local cp
2030 1983
2031 for atom in ${gcp}; do 1984 for atom in ${gcp}; do
2032 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})" 1985 cp+=":$(java-pkg_getjars ${getjarsarg} ${atom})"
2033 done 1986 done
2034 1987
2035 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)" 1988 [[ ${EANT_NEEDS_TOOLS} ]] && cp+=":$(java-config --tools)"
1989 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && cp+=":${EANT_GENTOO_CLASSPATH_EXTRA}"
2036 1990
2037 if [[ ${cp} ]]; then 1991 if [[ ${cp#:} ]]; then
2038 # It seems ant does not like single quotes around ${cp} 1992 # It seems ant does not like single quotes around ${cp}
2039 cp=${cp#:}
2040 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
2041 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
2042 antflags="${antflags} -Dgentoo.classpath=\"${cp}\"" 1993 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
2043 fi 1994 fi
2044 1995
2045 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1996 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
2046 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}" 1997 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
2047 ant ${antflags} "${@}" || die "eant failed" 1998 ant ${antflags} "${@}" || die "eant failed"
2048} 1999}
2049 2000
2050# ------------------------------------------------------------------------------ 2001# @FUNCTION: ejavac
2051# @ebuild-function ejavac 2002# @USAGE: <javac_arguments>
2052# 2003# @DESCRIPTION:
2053# Javac wrapper function. Will use the appropriate compiler, based on 2004# Javac wrapper function. Will use the appropriate compiler, based on
2054# /etc/java-config/compilers.conf 2005# /etc/java-config/compilers.conf
2055#
2056# @param $@ - Arguments to be passed to the compiler
2057# ------------------------------------------------------------------------------
2058ejavac() { 2006ejavac() {
2059 debug-print-function ${FUNCNAME} $* 2007 debug-print-function ${FUNCNAME} $*
2060 2008
2061 java-pkg_init-compiler_ 2009 java-pkg_init-compiler_
2062 2010
2076 2024
2077 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}" 2025 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
2078 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed" 2026 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
2079} 2027}
2080 2028
2081# ------------------------------------------------------------------------------ 2029# @FUNCTION: ejavadoc
2082# @ebuild-function java-pkg_filter-compiler 2030# @USAGE: <javadoc_arguments>
2083# 2031# @DESCRIPTION:
2032# javadoc wrapper function. Will set some flags based on the VM version
2033# due to strict javadoc rules in 1.8.
2034ejavadoc() {
2035 debug-print-function ${FUNCNAME} $*
2036
2037 local javadoc_args=""
2038
2039 if java-pkg_is-vm-version-ge "1.8" ; then
2040 javadoc_args="-Xdoclint:none"
2041 fi
2042
2043 javadoc ${javadoc_args} "${@}" || die "ejavadoc failed"
2044}
2045
2046# @FUNCTION: java-pkg_filter-compiler
2047# @USAGE: <compiler(s)_to_filter>
2048# @DESCRIPTION:
2084# Used to prevent the use of some compilers. Should be used in src_compile. 2049# Used to prevent the use of some compilers. Should be used in src_compile.
2085# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 2050# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
2086#
2087# @param $@ - compilers to filter
2088# ------------------------------------------------------------------------------
2089java-pkg_filter-compiler() { 2051java-pkg_filter-compiler() {
2090 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 2052 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
2091} 2053}
2092 2054
2093# ------------------------------------------------------------------------------ 2055# @FUNCTION: java-pkg_force-compiler
2094# @ebuild-function java-pkg_force-compiler 2056# @USAGE: <compiler(s)_to_force>
2095# 2057# @DESCRIPTION:
2096# Used to force the use of particular compilers. Should be used in src_compile. 2058# Used to force the use of particular compilers. Should be used in src_compile.
2097# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid 2059# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
2098# OutOfMemoryErrors that may come up. 2060# OutOfMemoryErrors that may come up.
2099#
2100# @param $@ - compilers to force
2101# ------------------------------------------------------------------------------
2102java-pkg_force-compiler() { 2061java-pkg_force-compiler() {
2103 JAVA_PKG_FORCE_COMPILER="$@" 2062 JAVA_PKG_FORCE_COMPILER="$@"
2104} 2063}
2105 2064
2106# ------------------------------------------------------------------------------ 2065# @FUNCTION: use_doc
2107# @ebuild-function use_doc 2066# @DESCRIPTION:
2108# 2067#
2109# Helper function for getting ant to build javadocs. If the user has USE=doc, 2068# Helper function for getting ant to build javadocs. If the user has USE=doc,
2110# then 'javadoc' or the argument are returned. Otherwise, there is no return. 2069# then 'javadoc' or the argument are returned. Otherwise, there is no return.
2111# 2070#
2112# The output of this should be passed to ant. 2071# The output of this should be passed to ant.
2072# @CODE
2073# Parameters:
2074# $@ - Option value to return. Defaults to 'javadoc'
2113# 2075#
2076# Examples:
2114# Example: build javadocs by calling 'javadoc' target 2077# build javadocs by calling 'javadoc' target
2115# eant $(use_doc) 2078# eant $(use_doc)
2079#
2116# Example: build javadocs by calling 'apidoc' target 2080# build javadocs by calling 'apidoc' target
2117# eant $(use_doc apidoc) 2081# eant $(use_doc apidoc)
2118# 2082# @CODE
2119# @param $@ - Option value to return. Defaults to 'javadoc'
2120# @return string - Name of the target to create javadocs 2083# @RETURN string - Name of the target to create javadocs
2121# ------------------------------------------------------------------------------
2122use_doc() { 2084use_doc() {
2123 use doc && echo ${@:-javadoc} 2085 use doc && echo ${@:-javadoc}
2124} 2086}
2125 2087
2126 2088
2127# ------------------------------------------------------------------------------ 2089# @FUNCTION: java-pkg_init
2128# @section-end build 2090# @INTERNAL
2129# ------------------------------------------------------------------------------ 2091# @DESCRIPTION:
2130
2131# ------------------------------------------------------------------------------
2132# @section-begin internal
2133# @section-summary Internal functions
2134#
2135# Do __NOT__ use any of these from an ebuild! These are only to be used from
2136# within the java eclasses.
2137# ------------------------------------------------------------------------------
2138
2139# -----------------------------------------------------------------------------
2140# @function-internal java-pkg_init
2141#
2142# The purpose of this function, as the name might imply, is to initialize the 2092# The purpose of this function, as the name might imply, is to initialize the
2143# Java environment. It ensures that that there aren't any environment variables 2093# Java environment. It ensures that that there aren't any environment variables
2144# that'll muss things up. It initializes some variables, which are used 2094# that'll muss things up. It initializes some variables, which are used
2145# internally. And most importantly, it'll switch the VM if necessary. 2095# internally. And most importantly, it'll switch the VM if necessary.
2146# 2096#
2147# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2097# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
2148# call it during each of the phases of the merge process. 2098# call it during each of the phases of the merge process.
2149#
2150# -----------------------------------------------------------------------------
2151java-pkg_init() { 2099java-pkg_init() {
2152 debug-print-function ${FUNCNAME} $* 2100 debug-print-function ${FUNCNAME} $*
2153 2101
2154 # Don't set up build environment if installing from binary. #206024 #258423 2102 # Don't set up build environment if installing from binary. #206024 #258423
2155 [[ "${MERGE_TYPE}" == "binary" ]] && return 2103 [[ "${MERGE_TYPE}" == "binary" ]] && return
2191 2139
2192 if java-pkg_func-exists ant_src_unpack; then 2140 if java-pkg_func-exists ant_src_unpack; then
2193 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack" 2141 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2194 fi 2142 fi
2195 2143
2196 java-pkg_init_paths_
2197 java-pkg_switch-vm 2144 java-pkg_switch-vm
2198 PATH=${JAVA_HOME}/bin:${PATH} 2145 PATH=${JAVA_HOME}/bin:${PATH}
2199 2146
2200 # TODO we will probably want to set JAVAC and JAVACFLAGS 2147 # TODO we will probably want to set JAVAC and JAVACFLAGS
2201 2148
2215 export ANT_TASKS= 2162 export ANT_TASKS=
2216 export ANT_OPTS= 2163 export ANT_OPTS=
2217 export ANT_RESPECT_JAVA_HOME= 2164 export ANT_RESPECT_JAVA_HOME=
2218} 2165}
2219 2166
2220# ------------------------------------------------------------------------------ 2167# @FUNCTION: java-pkg-init-compiler_
2221# @function-internal java-pkg-init-compiler_ 2168# @INTERNAL
2222# 2169# @DESCRIPTION:
2223# This function attempts to figure out what compiler should be used. It does 2170# This function attempts to figure out what compiler should be used. It does
2224# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2171# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
2225# COMPILERS variable defined there. 2172# COMPILERS variable defined there.
2226# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2173# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
2227# 2174#
2238# If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no 2185# If the user doesn't defined anything in JAVA_PKG_COMPILERS_CONF, or no
2239# suitable compiler was found there, then the default is to use javac provided 2186# suitable compiler was found there, then the default is to use javac provided
2240# by the current VM. 2187# by the current VM.
2241# 2188#
2242# 2189#
2243# @return name of the compiler to use 2190# @RETURN name of the compiler to use
2244# ------------------------------------------------------------------------------
2245java-pkg_init-compiler_() { 2191java-pkg_init-compiler_() {
2246 debug-print-function ${FUNCNAME} $* 2192 debug-print-function ${FUNCNAME} $*
2247 2193
2248 if [[ -n ${GENTOO_COMPILER} ]]; then 2194 if [[ -n ${GENTOO_COMPILER} ]]; then
2249 debug-print "GENTOO_COMPILER already set" 2195 debug-print "GENTOO_COMPILER already set"
2290 if ! has ${desired_target} ${supported_target}; then 2236 if ! has ${desired_target} ${supported_target}; then
2291 ewarn "${compiler} does not support -target ${desired_target}, skipping" 2237 ewarn "${compiler} does not support -target ${desired_target}, skipping"
2292 continue 2238 continue
2293 fi 2239 fi
2294 2240
2295 # -source was introduced in 1.3, so only check 1.3 and on
2296 if version_is_at_least "${desired_soure}" "1.3"; then
2297 # Verify that the compiler supports source 2241 # Verify that the compiler supports source
2298 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE}) 2242 local supported_source=$(source ${compiler_env} 1>/dev/null 2>&1; echo ${SUPPORTED_SOURCE})
2299 if ! has ${desired_source} ${supported_source}; then 2243 if ! has ${desired_source} ${supported_source}; then
2300 ewarn "${compiler} does not support -source ${desired_source}, skipping" 2244 ewarn "${compiler} does not support -source ${desired_source}, skipping"
2301 continue 2245 continue
2302 fi
2303 fi 2246 fi
2304 2247
2305 # if you get here, then the compiler should be good to go 2248 # if you get here, then the compiler should be good to go
2306 export GENTOO_COMPILER="${compiler}" 2249 export GENTOO_COMPILER="${compiler}"
2307 break 2250 break
2329 einfo "Using ${GENTOO_COMPILER} for compilation" 2272 einfo "Using ${GENTOO_COMPILER} for compilation"
2330 fi 2273 fi
2331 2274
2332} 2275}
2333 2276
2334# ------------------------------------------------------------------------------ 2277# @FUNCTION: init_paths_
2335# @internal-function init_paths_ 2278# @INTERNAL
2336# 2279# @DESCRIPTION:
2337# Initializes some variables that will be used. These variables are mostly used 2280# Initializes some variables that will be used. These variables are mostly used
2338# to determine where things will eventually get installed. 2281# to determine where things will eventually get installed.
2339# ------------------------------------------------------------------------------
2340java-pkg_init_paths_() { 2282java-pkg_init_paths_() {
2341 debug-print-function ${FUNCNAME} $* 2283 debug-print-function ${FUNCNAME} $*
2342 2284
2343 local pkg_name 2285 local pkg_name
2344 if [[ "$SLOT" == "0" ]] ; then 2286 if [[ "${SLOT%/*}" == "0" ]] ; then
2345 JAVA_PKG_NAME="${PN}" 2287 JAVA_PKG_NAME="${PN}"
2346 else 2288 else
2347 JAVA_PKG_NAME="${PN}-${SLOT}" 2289 JAVA_PKG_NAME="${PN}-${SLOT%/*}"
2348 fi 2290 fi
2349 2291
2350 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2292 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
2351 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2293 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
2352 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2294 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2354 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}" 2296 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
2355 2297
2356 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2298 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
2357 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2299 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
2358 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2300 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
2359
2360 2301
2361 # TODO maybe only print once? 2302 # TODO maybe only print once?
2362 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}" 2303 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
2363 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}" 2304 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
2364 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}" 2305 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
2365 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}" 2306 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
2366 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}" 2307 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
2367} 2308}
2368 2309
2369# ------------------------------------------------------------------------------ 2310# @FUNCTION: java-pkg_do_write_
2370# @internal-function java-pkg_do_write_ 2311# @INTERNAL
2371# 2312# @DESCRIPTION:
2372# Writes the package.env out to disk. 2313# Writes the package.env out to disk.
2373# 2314#
2374# ------------------------------------------------------------------------------
2375# TODO change to do-write, to match everything else 2315# TODO change to do-write, to match everything else
2376java-pkg_do_write_() { 2316java-pkg_do_write_() {
2377 debug-print-function ${FUNCNAME} $* 2317 debug-print-function ${FUNCNAME} $*
2378 java-pkg_init_paths_ 2318 java-pkg_init_paths_
2379 # Create directory for package.env 2319 # Create directory for package.env
2434 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't" 2374 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2435 debug-print "write package.env." 2375 debug-print "write package.env."
2436 fi 2376 fi
2437} 2377}
2438 2378
2439# ------------------------------------------------------------------------------ 2379# @FUNCTION: java-pkg_record-jar_
2440# @internal-function java-pkg_record-jar_ 2380# @INTERNAL
2441# 2381# @DESCRIPTION:
2442# Record an (optional) dependency to the package.env 2382# Record an (optional) dependency to the package.env
2383# @CODE
2384# Parameters:
2443# @param --optional - record dependency as optional 2385# --optional - record dependency as optional
2444# @param --build - record dependency as build_only 2386# --build - record dependency as build_only
2445# @param $1 - package to record 2387# $1 - package to record
2446# @param $2 - (optional) jar of package to record 2388# $2 - (optional) jar of package to record
2447# ------------------------------------------------------------------------------ 2389# @CODE
2448JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend" 2390JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2449JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend" 2391JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2450JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend" 2392JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
2451 2393
2452java-pkg_record-jar_() { 2394java-pkg_record-jar_() {
2466 fi 2408 fi
2467 2409
2468 echo "${append}" >> "${depend_file}" 2410 echo "${append}" >> "${depend_file}"
2469} 2411}
2470 2412
2471# ------------------------------------------------------------------------------ 2413# @FUNCTION: java-pkg_append_
2472# @internal-function java-pkg_append_ 2414# @INTERNAL
2473# 2415# @DESCRIPTION:
2474# Appends a value to a variable 2416# Appends a value to a variable
2475# 2417#
2476# Example: java-pkg_append_ CLASSPATH foo.jar 2418# @CODE
2419# Parameters:
2477# @param $1 variable name to modify 2420# $1 variable name to modify
2478# @param $2 value to append 2421# $2 value to append
2479# ------------------------------------------------------------------------------ 2422#
2423# Examples:
2424# java-pkg_append_ CLASSPATH foo.jar
2425# @CODE
2480java-pkg_append_() { 2426java-pkg_append_() {
2481 debug-print-function ${FUNCNAME} $* 2427 debug-print-function ${FUNCNAME} $*
2482 2428
2483 local var="${1}" value="${2}" 2429 local var="${1}" value="${2}"
2484 if [[ -z "${!var}" ]] ; then 2430 if [[ -z "${!var}" ]] ; then
2495 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}" 2441 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
2496 IFS=${oldIFS} 2442 IFS=${oldIFS}
2497 fi 2443 fi
2498} 2444}
2499 2445
2500# ------------------------------------------------------------------------------ 2446# @FUNCTION: java-pkg_expand_dir_
2501# @internal-function java-pkg_expand_dir_ 2447# @INTERNAL
2502# 2448# @DESCRIPTION:
2503# Gets the full path of the file/directory's parent. 2449# Gets the full path of the file/directory's parent.
2450# @CODE
2451# Parameters:
2504# @param $1 - file/directory to find parent directory for 2452# $1 - file/directory to find parent directory for
2453# @CODE
2505# @return - path to $1's parent directory 2454# @RETURN: path to $1's parent directory
2506# ------------------------------------------------------------------------------
2507java-pkg_expand_dir_() { 2455java-pkg_expand_dir_() {
2508 pushd "$(dirname "${1}")" >/dev/null 2>&1 2456 pushd "$(dirname "${1}")" >/dev/null 2>&1
2509 pwd 2457 pwd
2510 popd >/dev/null 2>&1 2458 popd >/dev/null 2>&1
2511} 2459}
2512 2460
2513# ------------------------------------------------------------------------------ 2461# @FUNCTION: java-pkg_func-exists
2514# @internal-function java-pkg_func-exists 2462# @INTERNAL
2515# 2463# @DESCRIPTION:
2516# Does the indicated function exist? 2464# Does the indicated function exist?
2517# 2465# @RETURN: 0 - function is declared, 1 - function is undeclared
2518# @return 0 - function is declared
2519# @return 1 - function is undeclared
2520# ------------------------------------------------------------------------------
2521java-pkg_func-exists() { 2466java-pkg_func-exists() {
2522 declare -F ${1} > /dev/null 2467 declare -F ${1} > /dev/null
2523} 2468}
2524 2469
2525# ------------------------------------------------------------------------------ 2470# @FUNCTION: java-pkg_setup-vm
2526# @internal-function java-pkg_setup-vm 2471# @INTERNAL
2527# 2472# @DESCRIPTION:
2528# Sets up the environment for a specific VM 2473# Sets up the environment for a specific VM
2529#
2530# ------------------------------------------------------------------------------
2531java-pkg_setup-vm() { 2474java-pkg_setup-vm() {
2532 debug-print-function ${FUNCNAME} $* 2475 debug-print-function ${FUNCNAME} $*
2533 2476
2534 local vendor="$(java-pkg_get-vm-vendor)" 2477 local vendor="$(java-pkg_get-vm-vendor)"
2535 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2478 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2547 elif [[ "${vendor}" == "jrockit" ]]; then 2490 elif [[ "${vendor}" == "jrockit" ]]; then
2548 addpredict "/proc/cpuinfo" 2491 addpredict "/proc/cpuinfo"
2549 fi 2492 fi
2550} 2493}
2551 2494
2552# ------------------------------------------------------------------------------ 2495# @FUNCTION: java-pkg_needs-vm
2553# @internal-function java-pkg_needs-vm 2496# @INTERNAL
2554# 2497# @DESCRIPTION:
2555# Does the current package depend on virtual/jdk or does it set 2498# Does the current package depend on virtual/jdk or does it set
2556# JAVA_PKG_WANT_BUILD_VM? 2499# JAVA_PKG_WANT_BUILD_VM?
2557# 2500#
2558# @return 0 - Package depends on virtual/jdk 2501# @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
2559# @return 1 - Package does not depend on virtual/jdk
2560# ------------------------------------------------------------------------------
2561java-pkg_needs-vm() { 2502java-pkg_needs-vm() {
2562 debug-print-function ${FUNCNAME} $* 2503 debug-print-function ${FUNCNAME} $*
2563 2504
2564 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then 2505 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
2565 return 0 2506 return 0
2568 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0 2509 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
2569 2510
2570 return 1 2511 return 1
2571} 2512}
2572 2513
2573# ------------------------------------------------------------------------------ 2514# @FUNCTION: java-pkg_get-current-vm
2574# @internal-function java-pkg_get-current-vm 2515# @INTERNAL
2575#
2576# @return - The current VM being used 2516# @RETURN - The current VM being used
2577# ------------------------------------------------------------------------------
2578java-pkg_get-current-vm() { 2517java-pkg_get-current-vm() {
2579 java-config -f 2518 java-config -f
2580} 2519}
2581 2520
2582# ------------------------------------------------------------------------------ 2521# @FUNCTION: java-pkg_get-vm-vendor
2583# @internal-function java-pkg_get-vm-vendor 2522# @INTERNAL
2584#
2585# @return - The vendor of the current VM 2523# @RETURN - The vendor of the current VM
2586# ------------------------------------------------------------------------------
2587java-pkg_get-vm-vendor() { 2524java-pkg_get-vm-vendor() {
2588 debug-print-function ${FUNCNAME} $* 2525 debug-print-function ${FUNCNAME} $*
2589 2526
2590 local vm="$(java-pkg_get-current-vm)" 2527 local vm="$(java-pkg_get-current-vm)"
2591 vm="${vm/-*/}" 2528 vm="${vm/-*/}"
2592 echo "${vm}" 2529 echo "${vm}"
2593} 2530}
2594 2531
2595# ------------------------------------------------------------------------------ 2532# @FUNCTION: java-pkg_get-vm-version
2596# @internal-function java-pkg_get-vm-version 2533# @INTERNAL
2597#
2598# @return - The version of the current VM 2534# @RETURN - The version of the current VM
2599# ------------------------------------------------------------------------------
2600java-pkg_get-vm-version() { 2535java-pkg_get-vm-version() {
2601 debug-print-function ${FUNCNAME} $* 2536 debug-print-function ${FUNCNAME} $*
2602 2537
2603 java-config -g PROVIDES_VERSION 2538 java-config -g PROVIDES_VERSION
2604} 2539}
2605 2540
2606# ------------------------------------------------------------------------------ 2541# @FUNCTION: java-pkg_build-vm-from-handle
2607# @internal-function java-pkg_build-vm-from-handle 2542# @INTERNAL
2608# 2543# @DESCRIPTION:
2609# Selects a build vm from a list of vm handles. First checks for the system-vm 2544# Selects a build vm from a list of vm handles. First checks for the system-vm
2610# beeing usable, then steps through the listed handles till a suitable vm is 2545# beeing usable, then steps through the listed handles till a suitable vm is
2611# found. 2546# found.
2612# 2547#
2613# @return - VM handle of an available JDK 2548# @RETURN - VM handle of an available JDK
2614# ------------------------------------------------------------------------------
2615java-pkg_build-vm-from-handle() { 2549java-pkg_build-vm-from-handle() {
2616 debug-print-function ${FUNCNAME} "$*" 2550 debug-print-function ${FUNCNAME} "$*"
2617 2551
2618 local vm 2552 local vm
2619 vm=$(java-pkg_get-current-vm) 2553 vm=$(java-pkg_get-current-vm 2>/dev/null)
2620 if [[ $? != 0 ]]; then 2554 if [[ $? -eq 0 ]]; then
2621 eerror "${FUNCNAME}: Failed to get active vm"
2622 return 1
2623 fi
2624
2625 if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then 2555 if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
2626 echo ${vm} 2556 echo ${vm}
2627 return 0 2557 return 0
2558 fi
2628 fi 2559 fi
2629 2560
2630 for vm in ${JAVA_PKG_WANT_BUILD_VM}; do 2561 for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
2631 if java-config-2 --select-vm=${vm} 2>/dev/null; then 2562 if java-config-2 --select-vm=${vm} 2>/dev/null; then
2632 echo ${vm} 2563 echo ${vm}
2636 2567
2637 eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}" 2568 eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2638 return 1 2569 return 1
2639} 2570}
2640 2571
2641# ------------------------------------------------------------------------------ 2572# @FUNCTION: java-pkg_switch-vm
2642# @internal-function java-pkg_switch-vm 2573# @INTERNAL
2643# 2574# @DESCRIPTION:
2644# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2575# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
2645# verify that the current VM is sufficient. 2576# verify that the current VM is sufficient.
2646# Setup the environment for the VM being used. 2577# Setup the environment for the VM being used.
2647# ------------------------------------------------------------------------------
2648java-pkg_switch-vm() { 2578java-pkg_switch-vm() {
2649 debug-print-function ${FUNCNAME} $* 2579 debug-print-function ${FUNCNAME} $*
2650 2580
2651 if java-pkg_needs-vm; then 2581 if java-pkg_needs-vm; then
2652 # Use the VM specified by JAVA_PKG_FORCE_VM 2582 # Use the VM specified by JAVA_PKG_FORCE_VM
2720 else 2650 else
2721 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2651 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2722 fi 2652 fi
2723} 2653}
2724 2654
2725# ------------------------------------------------------------------------------ 2655# @FUNCTION: java-pkg_die
2726# @internal-function java-pkg_die 2656# @INTERNAL
2727# 2657# @DESCRIPTION:
2728# Enhanced die for Java packages, which displays some information that may be 2658# Enhanced die for Java packages, which displays some information that may be
2729# useful for debugging bugs on bugzilla. 2659# useful for debugging bugs on bugzilla.
2730# ------------------------------------------------------------------------------
2731#register_die_hook java-pkg_die 2660#register_die_hook java-pkg_die
2732if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then 2661if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
2733 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die" 2662 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
2734fi 2663fi
2735 2664
2736java-pkg_die() { 2665java-pkg_die() {
2737 echo "!!! When you file a bug report, please include the following information:" >&2 2666 echo "!!! When you file a bug report, please include the following information:" >&2
2738 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 2667 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
2739 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2668 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
2740 echo "and of course, the output of emerge --info" >&2 2669 echo "and of course, the output of emerge --info =${P}" >&2
2741} 2670}
2742 2671
2743 2672
2744# TODO document 2673# TODO document
2745# List jars in the source directory, ${S} 2674# List jars in the source directory, ${S}
2752 einfo "Classes" 2681 einfo "Classes"
2753 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2682 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2754 fi 2683 fi
2755} 2684}
2756 2685
2757# ------------------------------------------------------------------------------ 2686# @FUNCTION: java-pkg_verify-classes
2758# @internal-function java-pkg_verify-classes 2687# @INTERNAL
2759# 2688# @DESCRIPTION:
2760# Verify that the classes were compiled for the right source / target. Dies if 2689# Verify that the classes were compiled for the right source / target. Dies if
2761# not. 2690# not.
2691# @CODE
2762# @param $1 (optional) - the file to check, otherwise checks whole ${D} 2692# $1 (optional) - the file to check, otherwise checks whole ${D}
2763# ------------------------------------------------------------------------------ 2693# @CODE
2764java-pkg_verify-classes() { 2694java-pkg_verify-classes() {
2765 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2695 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2766 2696
2767 local version_verify="/usr/bin/class-version-verify.py" 2697 local version_verify="/usr/bin/class-version-verify.py"
2768 2698
2796 eerror "See ${log} for more details." 2726 eerror "See ${log} for more details."
2797 die "Incorrect bytecode found" 2727 die "Incorrect bytecode found"
2798 fi 2728 fi
2799} 2729}
2800 2730
2801# ---------------------------------------------------------------------------- 2731# @FUNCTION: java-pkg_ensure-dep
2802# @internal-function java-pkg_ensure-dep 2732# @INTERNAL
2733# @DESCRIPTION:
2803# Check that a package being used in jarfrom, getjars and getjar is contained 2734# Check that a package being used in jarfrom, getjars and getjar is contained
2804# within DEPEND or RDEPEND. 2735# within DEPEND or RDEPEND with the correct SLOT. See this mail for details:
2736# https://archives.gentoo.org/gentoo-dev/message/dcb644f89520f4bbb61cc7bbe45fdf6e
2737# @CODE
2738# Parameters:
2805# @param $1 - empty - check both vars; "runtime" or "build" - check only 2739# $1 - empty - check both vars; "runtime" or "build" - check only
2806# RDEPEND, resp. DEPEND 2740# RDEPEND, resp. DEPEND
2807# @param $2 - Package name and slot. 2741# $2 - Package name and slot.
2808 2742# @CODE
2809java-pkg_ensure-dep() { 2743java-pkg_ensure-dep() {
2810 debug-print-function ${FUNCNAME} $* 2744 debug-print-function ${FUNCNAME} $*
2811 2745
2812 local limit_to="${1}" 2746 local limit_to="${1}"
2813 local target_pkg="${2}" 2747 local target_pkg="${2}"
2814 local dev_error="" 2748 local dev_error=""
2815 2749
2816 # remove the version specification, which may include globbing (* and [123]) 2750 # Transform into a regular expression to look for a matching package
2817 local stripped_pkg=$(echo "${target_pkg}" | sed \ 2751 # and SLOT. SLOTs don't have to be numeric so foo-bar could either
2818 's/-\([0-9*]*\(\[[0-9]*\]\)*\)*\(\.\([0-9*]*\(\[[0-9]*\]\)*\)*\)*$//') 2752 # mean foo-bar:0 or foo:bar. So you want to get your head around the
2753 # line below?
2754 #
2755 # * The target package first has any dots escaped, e.g. foo-1.2
2756 # becomes foo-1\.2.
2757 #
2758 # * sed then looks at the component following the last - or :
2759 # character, or the whole string if there is no - or :
2760 # character. It uses this to build a new regexp with two
2761 # significant branches.
2762 #
2763 # * The first checks for the whole target package string, optionally
2764 # followed by a version number, and then :0.
2765 #
2766 # * The second checks for the first part of the target package
2767 # string, optionally followed by a version number, followed by the
2768 # aforementioned component, treating that as a SLOT.
2769 #
2770 local stripped_pkg=/$(sed -r 's/[-:]?([^-:]+)$/(\0(-[^:]+)?:0|(-[^:]+)?:\1)/' <<< "${target_pkg//./\\.}")\\b
2819 2771
2820 debug-print "Matching against: ${stripped_pkg}" 2772 debug-print "Matching against: ${stripped_pkg}"
2821 2773
2774 # Uncomment the lines below once we've dealt with more of these
2775 # otherwise we'll be tempted to turn JAVA_PKG_STRICT off while
2776 # getting hit with a wave of bug reports. :(
2777
2822 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then 2778 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ $stripped_pkg ) ]]; then
2823 dev_error="The ebuild is attempting to use ${target_pkg} that is not" 2779 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2824 dev_error="${dev_error} declared in DEPEND." 2780 dev_error+="declared with a SLOT in DEPEND."
2825 if is-java-strict; then 2781# if is-java-strict; then
2826 eerror "${dev_error}"
2827 die "${dev_error}" 2782# die "${dev_error}"
2828 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2783# else
2829 eerror "${dev_error}" 2784 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2830 elog "Because you have this package installed the package will" 2785# eerror "Because you have ${target_pkg} installed,"
2831 elog "build without problems, but please report this to" 2786# eerror "the package will build without problems, but please"
2832 elog "http://bugs.gentoo.org" 2787# eerror "report this to http://bugs.gentoo.org."
2833 fi 2788# fi
2834 fi 2789 elif [[ ${limit_to} != build && ! ( "${RDEPEND}${PDEPEND}" =~ ${stripped_pkg} ) ]]; then
2835
2836 if [[ ${limit_to} != build ]]; then
2837 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2838 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2839 dev_error="The ebuild is attempting to use ${target_pkg}," 2790 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2840 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND" 2791 dev_error+="declared with a SLOT in [RP]DEPEND and --build-only wasn't given."
2841 dev_error="${dev_error} or PDEPEND."
2842 if is-java-strict; then 2792# if is-java-strict; then
2843 eerror "${dev_error}"
2844 die "${dev_error}" 2793# die "${dev_error}"
2845 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2794# else
2846 eerror "${dev_error}" 2795 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2847 elog "The package will build without problems, but may fail to run" 2796# eerror "The package will build without problems, but may fail to run"
2848 elog "if you don't have ${target_pkg} installed, so please report" 2797# eerror "if you don't have ${target_pkg} installed,"
2849 elog "this to http://bugs.gentoo.org" 2798# eerror "so please report this to http://bugs.gentoo.org."
2850 fi
2851 fi
2852 fi 2799# fi
2853 fi 2800 fi
2854} 2801}
2855
2856# ------------------------------------------------------------------------------
2857# @section-end internal
2858# ------------------------------------------------------------------------------
2859 2802
2860java-pkg_check-phase() { 2803java-pkg_check-phase() {
2861 local phase=${1} 2804 local phase=${1}
2862 local funcname=${FUNCNAME[1]} 2805 local funcname=${FUNCNAME[1]}
2863 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2806 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2898 2841
2899is-java-strict() { 2842is-java-strict() {
2900 [[ -n ${JAVA_PKG_STRICT} ]] 2843 [[ -n ${JAVA_PKG_STRICT} ]]
2901 return $? 2844 return $?
2902} 2845}
2903
2904
2905# ------------------------------------------------------------------------------
2906# @eclass-end
2907# ------------------------------------------------------------------------------

Legend:
Removed from v.1.150  
changed lines
  Added in v.1.168

  ViewVC Help
Powered by ViewVC 1.1.20