/[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.133 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-2005, 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.133 2010/03/24 12:11:05 betelgeuse 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# -----------------------------------------------------------------------------
66hasq "${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}"
76hasq 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_SOURCE 88# @DEFAULT_UNSET
89# @DESCRIPTION:
90# A list of VM handles to choose a build VM from. If the list contains the
91# currently active VM use that one, otherwise step through the list till a
92# usable/installed VM is found.
120# 93#
121# Specify a specific VM version to compile for to use for -source. 94# This allows to use an explicit list of JDKs in DEPEND instead of a virtual.
122# Normally this is determined from DEPEND. 95# Users of this variable must make sure at least one of the listed handles is
96# covered by DEPEND.
97# Requires JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET to be set as well.
98
99# @ECLASS-VARIABLE: JAVA_PKG_WANT_SOURCE
100# @DEFAULT_UNSET
101# @DESCRIPTION:
102# Specify a non-standard Java source version for compilation (via javac -source
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.
123# See java-pkg_get-source function below. 105# See java-pkg_get-source function below.
124# 106#
125# Should only be used for testing and debugging. 107# Should generally only be used for testing and debugging.
126# 108#
127# @seealso java-pkg_get-source
128#
129# @example Use 1.4 source to emerge baz 109# Use 1.4 source to emerge baz
110# @CODE
130# JAVA_PKG_WANT_SOURCE=1.4 emerge baz 111# JAVA_PKG_WANT_SOURCE=1.4 emerge baz
131# ----------------------------------------------------------------------------- 112# @CODE
132 113
133# ----------------------------------------------------------------------------- 114# @ECLASS-VARIABLE: JAVA_PKG_WANT_TARGET
134# @variable-external JAVA_PKG_WANT_TARGET 115# @DEFAULT_UNSET
135# 116# @DESCRIPTION:
136# 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.
137# See java-pkg_get-target function below. 120# See java-pkg_get-target function below.
138# 121#
139# Should only be used for testing and debugging. 122# Should generallyonly be used for testing and debugging.
140# 123#
141# @seealso java-pkg_get-target
142#
143# @example emerge bar to be compatible with 1.3 124# emerge bar to be compatible with 1.3
125# @CODE
144# JAVA_PKG_WANT_TARGET=1.3 emerge bar 126# JAVA_PKG_WANT_TARGET=1.3 emerge bar
145# ----------------------------------------------------------------------------- 127# @CODE
146 128
147# ----------------------------------------------------------------------------- 129# @ECLASS-VARIABLE: JAVA_RM_FILES
148# @variable-internal JAVA_PKG_COMPILER_DIR 130# @DEFAULT_UNSET
149# @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.
150# 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:
151# Directory where compiler settings are saved, without trailing slash. 146# Directory where compiler settings are saved, without trailing slash.
152# Probably shouldn't touch this variable. 147# You probably shouldn't touch this variable except local testing.
153# -----------------------------------------------------------------------------
154JAVA_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"}
155 149
156 150# @VARIABLE: JAVA_PKG_COMPILERS_CONF
157# ----------------------------------------------------------------------------- 151# @INTERNAL
158# @variable-internal JAVA_PKG_COMPILERS_CONF 152# @DESCRIPTION:
159# @variable-default /etc/java-config-2/build/compilers.conf
160#
161# Path to file containing information about which compiler to use. 153# Path to file containing information about which compiler to use.
162# Can be overloaded, but it should be overloaded for testing. 154# Can be overloaded, but it should be overloaded only for local testing.
163# -----------------------------------------------------------------------------
164JAVA_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"}
165 156
166# ----------------------------------------------------------------------------- 157# @ECLASS-VARIABLE: JAVA_PKG_FORCE_COMPILER
167# @variable-external JAVA_PKG_FORCE_COMPILER 158# @INTERNAL
168# 159# @DEFAULT_UNSET
160# @DESCRIPTION:
169# 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
170# JAVA_PKG_COMPILERS_CONF. 162# JAVA_PKG_COMPILERS_CONF.
171# 163#
172# @note This should only be used internally or for testing. 164# Useful for local testing.
165#
173# @example Use jikes and javac, in that order 166# Use jikes and javac, in that order
167# @CODE
174# JAVA_PKG_FORCE_COMPILER="jikes javac" 168# JAVA_PKG_FORCE_COMPILER="jikes javac"
175# ----------------------------------------------------------------------------- 169# @CODE
176 170
177# ----------------------------------------------------------------------------- 171# @ECLASS-VARIABLE: JAVA_PKG_FORCE_ANT_TASKS
178# @variable-external JAVA_PKG_FORCE_ANT_TASKS 172# @DEFAULT_UNSET
179# 173# @DESCRIPTION:
180# 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
181# 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
182# 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
183# eant() call, not the dependencies specified in WANT_ANT_TASKS. 177# eant() call, not the dependencies specified in WANT_ANT_TASKS.
184# 178#
179# @CODE
185# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \ 180# JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
186# ebuild foo.ebuild compile 181# ebuild foo.ebuild compile
187# 182# @CODE
188# @seealso WANT_ANT_TASKS
189# -----------------------------------------------------------------------------
190 183
191# TODO document me 184# TODO document me
192JAVA_PKG_QA_VIOLATIONS=0 185JAVA_PKG_QA_VIOLATIONS=0
193 186
194# ----------------------------------------------------------------------------- 187# @FUNCTION: java-pkg_doexamples
195# @section-end variables 188# @USAGE: [--subdir <subdir>] <file1/dir1> [<file2> ...]
196# ----------------------------------------------------------------------------- 189# @DESCRIPTION:
197
198
199# -----------------------------------------------------------------------------
200# @section-begin install
201# @section-summary Install functions
202#
203# These are used to install Java-related things, such as jars, Javadocs, JNI
204# libraries, etc.
205# -----------------------------------------------------------------------------
206
207# -----------------------------------------------------------------------------
208# @ebuild-function java-pkg_doexamples
209#
210# Installs given arguments to /usr/share/doc/${PF}/examples 190# Installs given arguments to /usr/share/doc/${PF}/examples
211# 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
212# everything in that directory to the examples directory. 192# everything in that directory to the examples directory.
213# 193#
194# @CODE
195# Parameters:
196# --subdir - If the examples need a certain directory structure
197# $* - list of files to install
198#
214# @example 199# Examples:
215# java-pkg_doexamples demo 200# java-pkg_doexamples demo
216# java-pkg_doexamples demo/* examples/* 201# java-pkg_doexamples demo/* examples/*
217# 202# @CODE
218# @param --subdir - If the examples need a certain directory structure
219# @param $* - list of files to install
220# ------------------------------------------------------------------------------
221java-pkg_doexamples() { 203java-pkg_doexamples() {
222 debug-print-function ${FUNCNAME} $* 204 debug-print-function ${FUNCNAME} $*
223 205
224 [[ ${#} -lt 1 ]] && die "At least one argument needed" 206 [[ ${#} -lt 1 ]] && die "At least one argument needed"
225 207
226 java-pkg_check-phase install 208 java-pkg_check-phase install
209 java-pkg_init_paths_
227 210
228 local dest=/usr/share/doc/${PF}/examples 211 local dest=/usr/share/doc/${PF}/examples
229 if [[ ${1} == --subdir ]]; then 212 if [[ ${1} == --subdir ]]; then
230 local dest=${dest}/${2} 213 local dest=${dest}/${2}
231 dodir ${dest} 214 dodir ${dest}
241 ( # dont want to pollute calling env 224 ( # dont want to pollute calling env
242 insinto "${dest}" 225 insinto "${dest}"
243 doins -r "$@" 226 doins -r "$@"
244 ) || die "Installing examples failed" 227 ) || die "Installing examples failed"
245 fi 228 fi
246}
247 229
248# ----------------------------------------------------------------------------- 230 # Let's make a symlink to the directory we have everything else under
249# @ebuild-function java-pkg_dojar 231 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
232}
233
234# @FUNCTION: java-pkg_addres
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.
250# 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:
251# Installs any number of jars. 304# Installs any number of jars.
252# 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.
253# You can use java-pkg_jarinto to change this path. 306# You can use java-pkg_jarinto to change this path.
254# 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.
255# Instead, use java-pkg_newjar defined below. 308# Instead, use java-pkg_newjar defined below.
256# 309#
257# @example 310# @CODE
258# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 311# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
312# @CODE
259# 313#
260# @param $* - list of jars to install 314# @param $* - list of jars to install
261# ------------------------------------------------------------------------------
262java-pkg_dojar() { 315java-pkg_dojar() {
263 debug-print-function ${FUNCNAME} $* 316 debug-print-function ${FUNCNAME} $*
264 317
265 [[ ${#} -lt 1 ]] && die "At least one argument needed" 318 [[ ${#} -lt 1 ]] && die "At least one argument needed"
266 319
308 done 361 done
309 362
310 java-pkg_do_write_ 363 java-pkg_do_write_
311} 364}
312 365
313# ------------------------------------------------------------------------------ 366# @FUNCTION: java-pkg_regjar
314# @internal-function depend-java-query 367# @USAGE: </path/to/installed/jar>
315# 368# @DESCRIPTION:
316# Wrapper for the depend-java-query binary to enable passing USE in env.
317# Using env variables keeps this eclass working with java-config versions that
318# do not handle use flags.
319# ------------------------------------------------------------------------------
320
321depend-java-query() {
322 # Used to have a which call here but it caused endless loops for some people
323 # that had some weird bashrc voodoo for which.
324 USE="${USE}" /usr/bin/depend-java-query "${@}"
325}
326
327# ------------------------------------------------------------------------------
328# @ebuild-function java-pkg_regjar
329#
330# Records an already installed jar in the package.env 369# Records an already installed (in ${D}) jar in the package.env
331# 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
332# install things. 371# install things.
333# 372#
334# Example:
335# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
336#
337# WARNING: 373# WARNING:
338# 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
339# 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:
340# 376#
341# java-pkg_regjar /opt/my-java/lib/*.jar 377# @CODE
342#
343# will not work, because:
344# * the `for jar in "$@"` can't expand the path to jar file names, as they
345# don't exist yet
346# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
347# doesn't exist
348#
349# you have to use it as:
350#
351# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 378# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
379# @CODE
352# 380#
353# @param $@ - jars to record 381
354# ------------------------------------------------------------------------------
355# 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?
356java-pkg_regjar() { 383java-pkg_regjar() {
357 debug-print-function ${FUNCNAME} $* 384 debug-print-function ${FUNCNAME} $*
358 385
359 java-pkg_check-phase install 386 java-pkg_check-phase install
390 done 417 done
391 418
392 java-pkg_do_write_ 419 java-pkg_do_write_
393} 420}
394 421
395# ------------------------------------------------------------------------------ 422# @FUNCTION: java-pkg_newjar
396# @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)
397# 426#
398# Installs a jar with a new name
399#
400# @example: install a versioned jar without the version 427# For example, installs a versioned jar without the version
401# java-pkg_newjar dist/${P}.jar ${PN}.jar
402#
403# @param $1 - jar to install
404# @param $2 - new name for jar - defaults to ${PN}.jar if not specified
405# ------------------------------------------------------------------------------
406java-pkg_newjar() { 428java-pkg_newjar() {
407 debug-print-function ${FUNCNAME} $* 429 debug-print-function ${FUNCNAME} $*
408 430
409 local original_jar="${1}" 431 local original_jar="${1}"
410 local new_jar="${2:-${PN}.jar}" 432 local new_jar="${2:-${PN}.jar}"
418 cp "${original_jar}" "${new_jar_dest}" \ 440 cp "${original_jar}" "${new_jar_dest}" \
419 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 441 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
420 java-pkg_dojar "${new_jar_dest}" 442 java-pkg_dojar "${new_jar_dest}"
421} 443}
422 444
423# ------------------------------------------------------------------------------ 445# @FUNCTION: java-pkg_addcp
424# @ebuild-function java-pkg_addcp 446# @USAGE: <classpath>
425# 447# @DESCRIPTION:
426# 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,
427# 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.
428# 450# The parameters of this function are appended to JAVA_PKG_CLASSPATH
429# TODO add example
430# @param $@ - value to append to JAVA_PKG_CLASSPATH
431# ------------------------------------------------------------------------------
432java-pkg_addcp() { 451java-pkg_addcp() {
433 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 452 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
434 java-pkg_do_write_ 453 java-pkg_do_write_
435} 454}
436 455
437# ------------------------------------------------------------------------------ 456# @FUNCTION: java-pkg_doso
438# @ebuild-function java-pkg_doso 457# @USAGE: <path/to/file1.so> [...]
439# 458# @DESCRIPTION:
440# Installs any number of JNI libraries 459# Installs any number of JNI libraries
441# 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
442# can be used change this path 461# can be used change this path
443# 462#
463# @CODE
444# Example: 464# Example:
445# java-pkg_doso *.so 465# java-pkg_doso *.so
446# 466# @CODE
447# @param $@ - JNI libraries to install
448# ------------------------------------------------------------------------------
449java-pkg_doso() { 467java-pkg_doso() {
450 debug-print-function ${FUNCNAME} $* 468 debug-print-function ${FUNCNAME} $*
451 469
452 java-pkg_check-phase install 470 java-pkg_check-phase install
453 471
461 # if the lib exists... 479 # if the lib exists...
462 if [[ -e "${lib}" ]] ; then 480 if [[ -e "${lib}" ]] ; then
463 # install if it isn't a symlink 481 # install if it isn't a symlink
464 if [[ ! -L "${lib}" ]] ; then 482 if [[ ! -L "${lib}" ]] ; then
465 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 483 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
466 INSOPTIONS="${LIBOPTIONS}" \ 484 INSOPTIONS="-m0755" \
467 doins "${lib}" || die "failed to install ${lib}" 485 doins "${lib}" || die "failed to install ${lib}"
468 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 486 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
469 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 487 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
470 # otherwise make a symlink to the symlink's origin 488 # otherwise make a symlink to the symlink's origin
471 else 489 else
479 done 497 done
480 498
481 java-pkg_do_write_ 499 java-pkg_do_write_
482} 500}
483 501
484# ------------------------------------------------------------------------------ 502# @FUNCTION: java-pkg_regso
485# @ebuild-function java-pkg_regso 503# @USAGE: <file1.so> [...]
486# 504# @DESCRIPTION:
487# 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
488# 510#
489# Example: 511# Example:
490# java-pkg_regso *.so /path/*.so 512# java-pkg_regso *.so /path/*.so
491# 513# @CODE
492# @param $@ - JNI libraries to register
493# ------------------------------------------------------------------------------
494java-pkg_regso() { 514java-pkg_regso() {
495 debug-print-function ${FUNCNAME} $* 515 debug-print-function ${FUNCNAME} $*
496 516
497 java-pkg_check-phase install 517 java-pkg_check-phase install
498 518
516 done 536 done
517 537
518 java-pkg_do_write_ 538 java-pkg_do_write_
519} 539}
520 540
521# ------------------------------------------------------------------------------ 541# @FUNCTION: java-pkg_jarinto
522# @ebuild-function java-pkg_jarinto 542# @USAGE: </path/to/install/jars/into>
523# 543# @DESCRIPTION:
524# Changes the path jars are installed into 544# Changes the path jars are installed into via subsequent java-pkg_dojar calls.
525#
526# @param $1 - new location to install jars into.
527# -----------------------------------------------------------------------------
528java-pkg_jarinto() { 545java-pkg_jarinto() {
529 debug-print-function ${FUNCNAME} $* 546 debug-print-function ${FUNCNAME} $*
530 547
531 JAVA_PKG_JARDEST="${1}" 548 JAVA_PKG_JARDEST="${1}"
532} 549}
533 550
534# ------------------------------------------------------------------------------ 551# @FUNCTION: java-pkg_sointo
535# @ebuild-function java-pkg_sointo 552# @USAGE: </path/to/install/sofiles/into>
536# 553# @DESCRIPTION:
537# Changes the path that JNI libraries are installed into. 554# Changes the path that JNI libraries are installed into via subsequent
538# 555# java-pkg_doso calls.
539# @param $1 - new location to install JNI libraries into.
540# ------------------------------------------------------------------------------
541java-pkg_sointo() { 556java-pkg_sointo() {
542 debug-print-function ${FUNCNAME} $* 557 debug-print-function ${FUNCNAME} $*
543 558
544 JAVA_PKG_LIBDEST="${1}" 559 JAVA_PKG_LIBDEST="${1}"
545} 560}
546 561
547# ------------------------------------------------------------------------------ 562# @FUNCTION: java-pkg_dohtml
548# @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.
549# 566#
550# Install Javadoc HTML documentation 567# @CODE
551#
552# @example
553# java-pkg_dohtml dist/docs/ 568# java-pkg_dohtml dist/docs/
554# 569# @CODE
555# ------------------------------------------------------------------------------
556java-pkg_dohtml() { 570java-pkg_dohtml() {
557 debug-print-function ${FUNCNAME} $* 571 debug-print-function ${FUNCNAME} $*
558 572
559 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 573 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
560 574
566 # a reasonable way to catch # docs for all of the 580 # a reasonable way to catch # docs for all of the
567 # old ebuilds. 581 # old ebuilds.
568 java-pkg_recordjavadoc 582 java-pkg_recordjavadoc
569} 583}
570 584
571# ------------------------------------------------------------------------------ 585# @FUNCTION: java-pkg_dojavadoc
572# @ebuild-function java-pkg_dojavadoc 586# @USAGE: [--symlink destination] <path/to/javadocs/root>
573# 587# @DESCRIPTION:
574# 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.
575# 589#
590# @CODE
591# Parameters:
576# @param $1: optional --symlink creates to symlink like this for html 592# $1: optional --symlink creates to symlink like this for html
577# documentation bundles. 593# documentation bundles.
578# @param $2: - The javadoc root directory. 594# $2: - The javadoc root directory.
579# 595#
580# @example: 596# Examples:
581# java-pkg_dojavadoc docs/api 597# java-pkg_dojavadoc docs/api
582# java-pkg_dojavadoc --symlink apidocs docs/api 598# java-pkg_dojavadoc --symlink apidocs docs/api
583# 599# @CODE
584# ------------------------------------------------------------------------------
585java-pkg_dojavadoc() { 600java-pkg_dojavadoc() {
586 debug-print-function ${FUNCNAME} $* 601 debug-print-function ${FUNCNAME} $*
587 602
588 # For html documentation bundles that link to Javadoc 603 # For html documentation bundles that link to Javadoc
589 local symlink 604 local symlink
596 local dest=/usr/share/doc/${PF}/html 611 local dest=/usr/share/doc/${PF}/html
597 612
598 # QA checks 613 # QA checks
599 614
600 java-pkg_check-phase install 615 java-pkg_check-phase install
616 java-pkg_init_paths_
601 617
602 [[ -z "${dir}" ]] && die "Must specify a directory!" 618 [[ -z "${dir}" ]] && die "Must specify a directory!"
603 [[ ! -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!"
604 if [[ ! -e "${dir}/index.html" ]]; then 620 if [[ ! -e "${dir}/index.html" ]]; then
605 local msg="No index.html in javadoc directory" 621 local msg="No index.html in javadoc directory"
632 debug-print "symlinking ${dest}/{api,${symlink}}" 648 debug-print "symlinking ${dest}/{api,${symlink}}"
633 dosym ${dest}/{api,${symlink}} || die 649 dosym ${dest}/{api,${symlink}} || die
634 fi 650 fi
635} 651}
636 652
637# ------------------------------------------------------------------------------ 653# @FUNCTION: java-pkg_dosrc
638# @ebuild-function java-pkg_dosrc 654# @USAGE: <path/to/sources> [...]
639# 655# @DESCRIPTION:
640# 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
641# 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.
642# 659#
643# Ebuild needs to DEPEND on app-arch/zip to use this. 660# @CODE
644#
645# It also should be controlled by USE=source.
646#
647# @example: 661# Example:
648# java-pkg_dosrc src/* 662# java-pkg_dosrc src/*
649# 663# @CODE
650# ------------------------------------------------------------------------------ 664
651# 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
652# source -nichoj 666# source -nichoj
667#
653# 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#
654# TODO maybe we can take an existing zip/jar? -nichoj 670# TODO maybe we can take an existing zip/jar? -nichoj
671#
655# FIXME apparently this fails if you give it an empty directories 672# FIXME apparently this fails if you give it an empty directories
656java-pkg_dosrc() { 673java-pkg_dosrc() {
657 debug-print-function ${FUNCNAME} $* 674 debug-print-function ${FUNCNAME} $*
658 675
659 [ ${#} -lt 1 ] && die "At least one argument needed" 676 [ ${#} -lt 1 ] && die "At least one argument needed"
691 708
692 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}" 709 JAVA_SOURCES="${JAVA_PKG_SOURCESPATH}/${zip_name}"
693 java-pkg_do_write_ 710 java-pkg_do_write_
694} 711}
695 712
696# ------------------------------------------------------------------------------ 713# @FUNCTION: java-pkg_dolauncher
697# @ebuild-function java-pkg_dolauncher 714# @USAGE: <filename> [options]
698# 715# @DESCRIPTION:
699# Make a wrapper script to lauch/start this package 716# Make a wrapper script to lauch/start this package
700# If necessary, the wrapper will switch to the appropriate VM. 717# If necessary, the wrapper will switch to the appropriate VM.
701# 718#
702# 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
703# 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}.
704# 721#
722# @CODE
723# Parameters:
705# @param $1 - filename of launcher to create 724# $1 - filename of launcher to create
706# @param $2 - options, as follows: 725# $2 - options, as follows:
707# --main the.main.class.too.start 726# --main the.main.class.to.start
708# --jar /the/jar/too/launch.jar or just <name>.jar 727# --jar /the/jar/too/launch.jar or just <name>.jar
709# --java_args 'Extra arguments to pass to java' 728# --java_args 'Extra arguments to pass to java'
710# --pkg_args 'Extra arguments to pass to the package' 729# --pkg_args 'Extra arguments to pass to the package'
711# --pwd Directory the launcher changes to before executing java 730# --pwd Directory the launcher changes to before executing java
712# -into Directory to install the launcher to, instead of /usr/bin 731# -into Directory to install the launcher to, instead of /usr/bin
713# -pre Prepend contents of this file to the launcher 732# -pre Prepend contents of this file to the launcher
714# ------------------------------------------------------------------------------ 733# @CODE
715java-pkg_dolauncher() { 734java-pkg_dolauncher() {
716 debug-print-function ${FUNCNAME} $* 735 debug-print-function ${FUNCNAME} $*
717 736
718 java-pkg_check-phase install 737 java-pkg_check-phase install
719 java-pkg_init_paths_ 738 java-pkg_init_paths_
780 else 799 else
781 dobin "${target}" 800 dobin "${target}"
782 fi 801 fi
783} 802}
784 803
785# ------------------------------------------------------------------------------ 804# @FUNCTION: java-pkg_dowar
805# @DESCRIPTION:
786# Install war files. 806# Install war files.
787# TODO document 807# TODO document
788# ------------------------------------------------------------------------------
789java-pkg_dowar() { 808java-pkg_dowar() {
790 debug-print-function ${FUNCNAME} $* 809 debug-print-function ${FUNCNAME} $*
791 810
792 # Check for arguments 811 # Check for arguments
793 [[ ${#} -lt 1 ]] && die "At least one argument needed" 812 [[ ${#} -lt 1 ]] && die "At least one argument needed"
817 INSDESTTREE=${JAVA_PKG_WARDEST} \ 836 INSDESTTREE=${JAVA_PKG_WARDEST} \
818 doins ${warpath} 837 doins ${warpath}
819 done 838 done
820} 839}
821 840
822# ------------------------------------------------------------------------------ 841# @FUNCTION: java-pkg_recordjavadoc
823# @internal-function java-pkg_recordjavadoc 842# @INTERNAL
843# @DESCRIPTION:
824# 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
825# 845
826# TODO make sure this in the proper section 846# TODO make sure this in the proper section
827# ------------------------------------------------------------------------------
828java-pkg_recordjavadoc() 847java-pkg_recordjavadoc()
829{ 848{
830 debug-print-function ${FUNCNAME} $* 849 debug-print-function ${FUNCNAME} $*
831 # the find statement is important 850 # the find statement is important
832 # as some packages include multiple trees of javadoc 851 # as some packages include multiple trees of javadoc
839 else 858 else
840 debug-print "No javadocs found" 859 debug-print "No javadocs found"
841 fi 860 fi
842} 861}
843 862
844# ------------------------------------------------------------------------------
845# @section-end install
846# ------------------------------------------------------------------------------
847 863
848# ------------------------------------------------------------------------------ 864# @FUNCTION: java-pkg_jar-from
849# @begin-section query 865# @USAGE: [--build-only] [--with-dependencies] [--virtual] [--into dir] <package> [<package.jar>] [<destination.jar>]
850# Use these to build the classpath for building a package. 866# @DESCRIPTION:
851# ------------------------------------------------------------------------------
852
853# ------------------------------------------------------------------------------
854# @ebuild-function java-pkg_jar-from
855#
856# Makes a symlink to a jar from a certain package 867# Makes a symlink to a jar from a certain package
857# A lot of java packages include dependencies in a lib/ directory 868# A lot of java packages include dependencies in a lib/ directory
858# You can use this function to replace these bundled dependencies. 869# You can use this function to replace these bundled dependencies.
859# 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"
860# 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
861# 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).
862# 873#
874# @CODE
863# Example: get all jars from xerces slot 2 875# Example: get all jars from xerces slot 2
864# java-pkg_jar-from xerces-2 876# java-pkg_jar-from xerces-2
877#
865# Example: get a specific jar from xerces slot 2 878# Example: get a specific jar from xerces slot 2
866# java-pkg_jar-from xerces-2 xml-apis.jar 879# java-pkg_jar-from xerces-2 xml-apis.jar
880#
867# 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
868# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 882# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
883#
869# Example: get junit.jar which is needed only for building 884# Example: get junit.jar which is needed only for building
870# java-pkg_jar-from --build-only junit junit.jar 885# java-pkg_jar-from --build-only junit junit.jar
886# @CODE
871# 887#
872# @param $opt 888# @CODE
889# Parameters
873# --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.
874# (assumed automatically when called inside src_test) 891# (assumed automatically when called inside src_test)
875# --with-dependencies - get jars also from requested package's dependencies 892# --with-dependencies - get jars also from requested package's dependencies
876# transitively. 893# transitively.
877# --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
878# and will not have individual jar dependencies recorded. 895# and will not have individual jar dependencies recorded.
879# --into $dir - symlink jar(s) into $dir (must exist) instead of . 896# --into $dir - symlink jar(s) into $dir (must exist) instead of .
880# @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
881# case other parameters are not used. 898# case other parameters are not used.
882# @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.
883# @param $3 - When a single jar is specified, destination filename of the 900# $3 - When a single jar is specified, destination filename of the
884# symlink. Defaults to the name of the jar. 901# symlink. Defaults to the name of the jar.
885# ------------------------------------------------------------------------------ 902# @CODE
903
886# TODO could probably be cleaned up a little 904# TODO could probably be cleaned up a little
887java-pkg_jar-from() { 905java-pkg_jar-from() {
888 debug-print-function ${FUNCNAME} $* 906 debug-print-function ${FUNCNAME} $*
889 907
890 local build_only="" 908 local build_only=""
969 java-pkg_record-jar_ "${target_pkg}" "${jar}" 987 java-pkg_record-jar_ "${target_pkg}" "${jar}"
970 else 988 else
971 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}" 989 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
972 fi 990 fi
973 fi 991 fi
974 # otherwise, if the current jar is the target jar, link it 992 # otherwise, if the current jar is the target jar, link it
975 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 993 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
976 [[ -f "${destjar}" ]] && rm "${destjar}" 994 [[ -f "${destjar}" ]] && rm "${destjar}"
977 ln -snf "${jar}" "${destjar}" \ 995 ln -snf "${jar}" "${destjar}" \
978 || die "Failed to make symlink from ${jar} to ${destjar}" 996 || die "Failed to make symlink from ${jar} to ${destjar}"
979 if [[ -z "${record_jar}" ]]; then 997 if [[ -z "${record_jar}" ]]; then
980 if [[ -z "${build_only}" ]]; then 998 if [[ -z "${build_only}" ]]; then
981 java-pkg_record-jar_ "${target_pkg}" "${jar}" 999 java-pkg_record-jar_ "${target_pkg}" "${jar}"
982 else 1000 else
983 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}" 1001 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
984 fi 1002 fi
985 fi 1003 fi
986 popd > /dev/null 1004 popd > /dev/null
987 return 0 1005 return 0
988 fi 1006 fi
995 else 1013 else
996 die "Failed to find ${target_jar:-jar} in ${target_pkg}" 1014 die "Failed to find ${target_jar:-jar} in ${target_pkg}"
997 fi 1015 fi
998} 1016}
999 1017
1000# ------------------------------------------------------------------------------ 1018# @FUNCTION: java-pkg_jarfrom
1001# @ebuild-function java-pkg_jarfrom 1019# @DESCRIPTION:
1002#
1003# See java-pkg_jar-from 1020# See java-pkg_jar-from
1004# ------------------------------------------------------------------------------
1005java-pkg_jarfrom() { 1021java-pkg_jarfrom() {
1006 java-pkg_jar-from "$@" 1022 java-pkg_jar-from "$@"
1007} 1023}
1008 1024
1009# ------------------------------------------------------------------------------ 1025# @FUNCTION: java-pkg_getjars
1010# @ebuild-function java-pkg_getjars 1026# @USAGE: [--build-only] [--with-dependencies] <package1>[,<package2>...]
1011# 1027# @DESCRIPTION:
1012# Get the classpath provided by any number of packages 1028# Get the classpath provided by any number of packages
1013# 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'.
1014# The providing packages are recorded as dependencies into package.env DEPEND 1030# The providing packages are recorded as dependencies into package.env DEPEND
1015# 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
1016# 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
1017# (junit testing etc). 1033# (junit testing etc).
1018# 1034#
1035# @CODE
1019# Example: Get the classpath for xerces-2 and xalan, 1036# Example: Get the classpath for xerces-2 and xalan,
1020# java-pkg_getjars xerces-2,xalan 1037# java-pkg_getjars xerces-2,xalan
1038#
1021# Example Return: 1039# Example Return:
1022# /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
1023# 1041#
1024# @param $opt 1042#
1043# Parameters:
1025# --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.
1026# (assumed automatically when called inside src_test) 1045# (assumed automatically when called inside src_test)
1027# --with-dependencies - get jars also from requested package's dependencies 1046# --with-dependencies - get jars also from requested package's dependencies
1028# transitively. 1047# transitively.
1029# @param $1 - list of packages to get jars from 1048# $1 - list of packages to get jars from
1030# (passed to java-config --classpath) 1049# (passed to java-config --classpath)
1031# ------------------------------------------------------------------------------ 1050# @CODE
1032java-pkg_getjars() { 1051java-pkg_getjars() {
1033 debug-print-function ${FUNCNAME} $* 1052 debug-print-function ${FUNCNAME} $*
1034 1053
1035 local build_only="" 1054 local build_only=""
1036 local deep="" 1055 local deep=""
1074 done 1093 done
1075 1094
1076 echo "${jars}" 1095 echo "${jars}"
1077} 1096}
1078 1097
1079# ------------------------------------------------------------------------------ 1098# @FUNCTION: java-pkg_getjar
1080# @ebuild-function java-pkg_getjar 1099# @USAGE: [--build-only] [--virtual] <package> <jarfile>
1081# 1100# @DESCRIPTION:
1082# Get the filename of a single jar from a package 1101# Get the complete path of a single jar from a package
1083# The providing package is recorded as runtime dependency into package.env 1102# The providing package is recorded as runtime dependency into package.env
1084# 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
1085# 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
1086# (junit testing etc). 1105# (junit testing etc).
1087# 1106#
1107# @CODE
1088# @example 1108# Example:
1089# java-pkg_getjar xerces-2 xml-apis.jar 1109# java-pkg_getjar xerces-2 xml-apis.jar
1090# @example-return 1110# returns
1091# /usr/share/xerces-2/lib/xml-apis.jar 1111# /usr/share/xerces-2/lib/xml-apis.jar
1092# 1112#
1093# @param $opt 1113# Parameters:
1094# --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.
1095# --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
1096# and will not have individual jar dependencies recorded. 1116# and will not have individual jar dependencies recorded.
1097# @param $1 - package to use 1117# $1 - package to use
1098# @param $2 - jar to get 1118# $2 - jar to get
1099# ------------------------------------------------------------------------------ 1119# @CODE
1100java-pkg_getjar() { 1120java-pkg_getjar() {
1101 debug-print-function ${FUNCNAME} $* 1121 debug-print-function ${FUNCNAME} $*
1102 1122
1103 local build_only="" 1123 local build_only=""
1104 local virtual="" 1124 local virtual=""
1167 1187
1168 die "Could not find ${target_jar} in ${pkg}" 1188 die "Could not find ${target_jar} in ${pkg}"
1169 return 1 1189 return 1
1170} 1190}
1171 1191
1172# ------------------------------------------------------------------------------ 1192# @FUNCTION: java-pkg_register-dependency
1173# @ebuild-function java-pkg_register-dependency 1193# @USAGE: <package>[,<package2>...] [<jarfile>]
1174# 1194# @DESCRIPTION:
1175# 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
1176# 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
1177# src_install phase. 1197# src_install phase.
1178# 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
1179# 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
1180# specified in ebuild's RDEPEND, and should be omitted in DEPEND. 1200# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1181# 1201#
1202# @CODE
1203# Parameters:
1182# @param $1 - comma-separated list of packages, or a single package 1204# $1 - comma-separated list of packages, or a single package
1183# @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
1184# to depend on 1206# to depend on
1185# 1207#
1208# Examples:
1186# Example: Record the dependency on whole xerces-2 and xalan, 1209# Record the dependency on whole xerces-2 and xalan,
1187# java-pkg_register-dependency xerces-2,xalan 1210# java-pkg_register-dependency xerces-2,xalan
1211#
1188# Example: Record the dependency on ant.jar from ant-core 1212# Record the dependency on ant.jar from ant-core
1189# java-pkg_register-dependency ant-core ant.jar 1213# java-pkg_register-dependency ant-core ant.jar
1214# @CODE
1190# 1215#
1191# 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
1192# 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
1193# 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
1194# there are more packages providing identically named jar without class 1219# there are more packages providing identically named jar without class
1195# collisions. 1220# collisions.
1196# ------------------------------------------------------------------------------
1197java-pkg_register-dependency() { 1221java-pkg_register-dependency() {
1198 debug-print-function ${FUNCNAME} $* 1222 debug-print-function ${FUNCNAME} $*
1199 1223
1200 java-pkg_check-phase install 1224 java-pkg_check-phase install
1201 1225
1223 fi 1247 fi
1224 1248
1225 java-pkg_do_write_ 1249 java-pkg_do_write_
1226} 1250}
1227 1251
1228# ------------------------------------------------------------------------------
1229# @ebuild-function java-pkg_register-optional-dependency 1252# @FUNCTION: java-pkg_register-optional-dependency
1230# 1253# @USAGE: <package>[,<package2>...] [<jarfile>]
1254# @DESCRIPTION:
1231# 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
1232# 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
1233# called in src_install phase. 1257# called in src_install phase.
1234# 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.
1235# 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
1236# 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
1237# for each implementation triggering hard dependency. 1261# for each implementation triggering hard dependency.
1238# 1262#
1263# @CODE
1264# Parameters:
1239# @param $1 - comma-separated list of packages, or a single package 1265# $1 - comma-separated list of packages, or a single package
1240# @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
1241# to depend on
1242# 1267#
1268# Example:
1243# Example: Record the optional dependency on some jdbc providers 1269# Record the optional dependency on some jdbc providers
1244# 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
1245# 1272#
1246# 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
1247# 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
1248# 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
1249# there are more packages providing identically named jar without class 1276# there are more packages providing identically named jar without class
1250# collisions. 1277# collisions.
1251# ------------------------------------------------------------------------------
1252java-pkg_register-optional-dependency() { 1278java-pkg_register-optional-dependency() {
1253 debug-print-function ${FUNCNAME} $* 1279 debug-print-function ${FUNCNAME} $*
1254 1280
1255 java-pkg_check-phase install 1281 java-pkg_check-phase install
1256 1282
1276 fi 1302 fi
1277 1303
1278 java-pkg_do_write_ 1304 java-pkg_do_write_
1279} 1305}
1280 1306
1281# ------------------------------------------------------------------------------
1282# @ebuild-function java-pkg_register-environment-variable 1307# @FUNCTION: java-pkg_register-environment-variable
1283# 1308# @USAGE: <name> <value>
1309# @DESCRIPTION:
1284# Register an arbitrary environment variable into package.env. The gjl launcher 1310# Register an arbitrary environment variable into package.env. The gjl launcher
1285# 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
1286# environement before executing java command. 1312# environement before executing java command.
1287# Must only be called in src_install phase. 1313# Must only be called in src_install phase.
1288#
1289# @param $1 - variable name
1290# @param $2 - variable value
1291# ------------------------------------------------------------------------------
1292JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env" 1314JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1293JAVA_PKG_EXTRA_ENV_VARS="" 1315JAVA_PKG_EXTRA_ENV_VARS=""
1294java-pkg_register-environment-variable() { 1316java-pkg_register-environment-variable() {
1295 debug-print-function ${FUNCNAME} $* 1317 debug-print-function ${FUNCNAME} $*
1296 1318
1302 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}" 1324 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1303 1325
1304 java-pkg_do_write_ 1326 java-pkg_do_write_
1305} 1327}
1306 1328
1307# ------------------------------------------------------------------------------ 1329# @FUNCTION: java-pkg_get-bootclasspath
1308# @ebuild-function java-pkg_get-bootclasspath 1330# @USAGE: <version>
1309# 1331# @DESCRIPTION:
1310# Returns classpath of a given bootclasspath-providing package version. 1332# Returns classpath of a given bootclasspath-providing package version.
1311# 1333#
1312# @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
1313# of the current JDK 1335# of the current JDK
1314# ------------------------------------------------------------------------------
1315
1316java-pkg_get-bootclasspath() { 1336java-pkg_get-bootclasspath() {
1317 local version="${1}" 1337 local version="${1}"
1318 1338
1319 local bcp 1339 local bcp
1320 case "${version}" in 1340 case "${version}" in
1321 auto) 1341 auto)
1322 bcp="$(java-config -g BOOTCLASSPATH)" 1342 bcp="$(java-config -g BOOTCLASSPATH)"
1323 ;; 1343 ;;
1324 1.5) 1344 1.5)
1325 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)" 1345 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1368# 1388#
1369# read line 1389# read line
1370# done 1390# done
1371#} 1391#}
1372 1392
1373# ------------------------------------------------------------------------------ 1393# @FUNCTION: java-pkg_find-normal-jars
1374# @section-end query 1394# @USAGE: [<path/to/directory>]
1375# ------------------------------------------------------------------------------ 1395# @DESCRIPTION:
1376
1377# ------------------------------------------------------------------------------
1378# @section-begin helper
1379# @section-summary Helper functions
1380#
1381# Various other functions to use from an ebuild
1382# ------------------------------------------------------------------------------
1383
1384# ------------------------------------------------------------------------------
1385# @ebuild-function java-pkg_find-normal-jars
1386#
1387# 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)
1388#
1389# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1390# ------------------------------------------------------------------------------
1391java-pkg_find-normal-jars() { 1397java-pkg_find-normal-jars() {
1392 local dir=$1 1398 local dir=$1
1393 [[ "${dir}" ]] || dir="${WORKDIR}" 1399 [[ "${dir}" ]] || dir="${WORKDIR}"
1394 local found 1400 local found
1395 for jar in $(find "${dir}" -name "*.jar" -type f); do 1401 for jar in $(find "${dir}" -name "*.jar" -type f); do
1398 done 1404 done
1399 [[ "${found}" ]] 1405 [[ "${found}" ]]
1400 return $? 1406 return $?
1401} 1407}
1402 1408
1403# ------------------------------------------------------------------------------ 1409# @FUNCTION: java-pkg_ensure-no-bundled-jars
1404# @ebuild-function java-pkg_ensure-no-bundled-jars 1410# @DESCRIPTION:
1405#
1406# 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.
1407# 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
1408# to system jar files or bundled jars removed. 1413# to system jar files or bundled jars removed.
1409# ------------------------------------------------------------------------------
1410java-pkg_ensure-no-bundled-jars() { 1414java-pkg_ensure-no-bundled-jars() {
1411 debug-print-function ${FUNCNAME} $* 1415 debug-print-function ${FUNCNAME} $*
1412 1416
1413 local bundled_jars=$(java-pkg_find-normal-jars) 1417 local bundled_jars=$(java-pkg_find-normal-jars)
1414 if [[ -n ${bundled_jars} ]]; then 1418 if [[ -n ${bundled_jars} ]]; then
1419 done 1423 done
1420 die "Bundled jars found!" 1424 die "Bundled jars found!"
1421 fi 1425 fi
1422} 1426}
1423 1427
1424# ------------------------------------------------------------------------------
1425# @internal-function java-pkg_ensure-vm-version-sufficient 1428# @FUNCTION: java-pkg_ensure-vm-version-sufficient
1426# 1429# @INTERNAL
1430# @DESCRIPTION:
1427# 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.
1428#
1429# ------------------------------------------------------------------------------
1430java-pkg_ensure-vm-version-sufficient() { 1432java-pkg_ensure-vm-version-sufficient() {
1431 debug-print-function ${FUNCNAME} $* 1433 debug-print-function ${FUNCNAME} $*
1432 1434
1433 if ! java-pkg_is-vm-version-sufficient; then 1435 if ! java-pkg_is-vm-version-sufficient; then
1434 debug-print "VM is not suffient" 1436 debug-print "VM is not suffient"
1436 einfo "Please use java-config -S to set the correct one" 1438 einfo "Please use java-config -S to set the correct one"
1437 die "Active Java VM cannot build this package" 1439 die "Active Java VM cannot build this package"
1438 fi 1440 fi
1439} 1441}
1440 1442
1441# ------------------------------------------------------------------------------ 1443# @FUNCTION: java-pkg_is-vm-version-sufficient
1442# @internal-function java-pkg_is-vm-version-sufficient 1444# @INTERNAL
1443# 1445# @DESCRIPTION:
1444# @return zero - VM is sufficient 1446# @RETURN: zero - VM is sufficient; non-zero - VM is not sufficient
1445# @return non-zero - VM is not sufficient
1446# ------------------------------------------------------------------------------
1447java-pkg_is-vm-version-sufficient() { 1447java-pkg_is-vm-version-sufficient() {
1448 debug-print-function ${FUNCNAME} $* 1448 debug-print-function ${FUNCNAME} $*
1449 1449
1450 depend-java-query --is-sufficient "${DEPEND}" > /dev/null 1450 depend-java-query --is-sufficient "${DEPEND}" > /dev/null
1451 return $? 1451 return $?
1452} 1452}
1453 1453
1454# ------------------------------------------------------------------------------ 1454# @FUNCTION: java-pkg_ensure-vm-version-eq
1455# @internal-function java-pkg_ensure-vm-version-eq 1455# @INTERNAL
1456# 1456# @DESCRIPTION:
1457# 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.
1458# 1458#
1459# @param $@ - Desired VM version to ensure 1459# @param $@ - Desired VM version to ensure
1460# ------------------------------------------------------------------------------
1461java-pkg_ensure-vm-version-eq() { 1460java-pkg_ensure-vm-version-eq() {
1462 debug-print-function ${FUNCNAME} $* 1461 debug-print-function ${FUNCNAME} $*
1463 1462
1464 if ! java-pkg_is-vm-version-eq $@ ; then 1463 if ! java-pkg_is-vm-version-eq $@ ; then
1465 debug-print "VM is not suffient" 1464 debug-print "VM is not suffient"
1467 einfo "Please use java-config -S to set the correct one" 1466 einfo "Please use java-config -S to set the correct one"
1468 die "Active Java VM too old" 1467 die "Active Java VM too old"
1469 fi 1468 fi
1470} 1469}
1471 1470
1472# ------------------------------------------------------------------------------ 1471# @FUNCTION: java-pkg_is-vm-version-eq
1473# @internal-function java-pkg_is-vm-version-eq 1472# @USAGE: <version>
1474# 1473# @INTERNAL
1475# @param $@ - VM version to compare current VM to 1474# @RETURN: zero - VM versions are equal; non-zero - VM version are not equal
1476# @return zero - VM versions are equal
1477# @return non-zero - VM version are not equal
1478# ------------------------------------------------------------------------------
1479java-pkg_is-vm-version-eq() { 1475java-pkg_is-vm-version-eq() {
1480 debug-print-function ${FUNCNAME} $* 1476 debug-print-function ${FUNCNAME} $*
1481 1477
1482 local needed_version="$@" 1478 local needed_version="$@"
1483 1479
1500 return 1 1496 return 1
1501 fi 1497 fi
1502 fi 1498 fi
1503} 1499}
1504 1500
1505# ------------------------------------------------------------------------------ 1501# @FUNCTION: java-pkg_ensure-vm-version-ge
1506# @internal-function java-pkg_ensure-vm-version-ge 1502# @INTERNAL
1507# 1503# @DESCRIPTION:
1508# 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
1509# 1505#
1510# @param $@ - VM version to compare current to 1506# @param $@ - VM version to compare current to
1511# ------------------------------------------------------------------------------
1512java-pkg_ensure-vm-version-ge() { 1507java-pkg_ensure-vm-version-ge() {
1513 debug-print-function ${FUNCNAME} $* 1508 debug-print-function ${FUNCNAME} $*
1514 1509
1515 if ! java-pkg_is-vm-version-ge "$@" ; then 1510 if ! java-pkg_is-vm-version-ge "$@" ; then
1516 debug-print "vm is not suffient" 1511 debug-print "vm is not suffient"
1518 einfo "Please use java-config -S to set the correct one" 1513 einfo "Please use java-config -S to set the correct one"
1519 die "Active Java VM too old" 1514 die "Active Java VM too old"
1520 fi 1515 fi
1521} 1516}
1522 1517
1523# ------------------------------------------------------------------------------ 1518# @FUNCTION: java-pkg_is-vm-version-ge
1524# @internal-function java-pkg_is-vm-version-ge 1519# @INTERNAL
1525# 1520# @DESCRIPTION:
1521# @CODE
1522# Parameters:
1526# @param $@ - VM version to compare current VM to 1523# $@ - VM version to compare current VM to
1524# @CODE
1527# @return zero - current VM version is greater than checked version 1525# @RETURN: zero - current VM version is greater than checked version;
1528# @return non-zero - current VM version is not greater than checked version 1526# non-zero - current VM version is not greater than checked version
1529# ------------------------------------------------------------------------------
1530java-pkg_is-vm-version-ge() { 1527java-pkg_is-vm-version-ge() {
1531 debug-print-function ${FUNCNAME} $* 1528 debug-print-function ${FUNCNAME} $*
1532 1529
1533 local needed_version=$@ 1530 local needed_version=$@
1534 local vm_version=$(java-pkg_get-vm-version) 1531 local vm_version=$(java-pkg_get-vm-version)
1553java-pkg_get-current-vm() { 1550java-pkg_get-current-vm() {
1554 echo ${GENTOO_VM} 1551 echo ${GENTOO_VM}
1555} 1552}
1556 1553
1557java-pkg_current-vm-matches() { 1554java-pkg_current-vm-matches() {
1558 hasq $(java-pkg_get-current-vm) ${@} 1555 has $(java-pkg_get-current-vm) ${@}
1559 return $? 1556 return $?
1560} 1557}
1561 1558
1562# ------------------------------------------------------------------------------ 1559# @FUNCTION: java-pkg_get-source
1563# @ebuild-function java-pkg_get-source 1560# @DESCRIPTION:
1564#
1565# Determines what source version should be used, for passing to -source. 1561# Determines what source version should be used, for passing to -source.
1566# 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
1567# 1563#
1568# @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
1569# ------------------------------------------------------------------------------
1570java-pkg_get-source() { 1565java-pkg_get-source() {
1571 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}")}
1572} 1567}
1573 1568
1574# ------------------------------------------------------------------------------ 1569# @FUNCTION: java-pkg_get-target
1575# @ebuild-function java-pkg_get-target 1570# @DESCRIPTION:
1576#
1577# Determines what target version should be used, for passing to -target. 1571# Determines what target version should be used, for passing to -target.
1578# 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
1579# version of your JDK. 1573# version of your JDK.
1580# 1574#
1581# @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
1582# ------------------------------------------------------------------------------
1583java-pkg_get-target() { 1576java-pkg_get-target() {
1584 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}")}
1585} 1578}
1586 1579
1580# @FUNCTION: java-pkg_get-javac
1581# @DESCRIPTION:
1582# Returns the compiler executable
1587java-pkg_get-javac() { 1583java-pkg_get-javac() {
1588 debug-print-function ${FUNCNAME} $* 1584 debug-print-function ${FUNCNAME} $*
1589 1585
1590 1586
1591 local compiler="${GENTOO_COMPILER}" 1587 local compiler="${GENTOO_COMPILER}"
1621 fi 1617 fi
1622 fi 1618 fi
1623 echo ${compiler_executable} 1619 echo ${compiler_executable}
1624} 1620}
1625 1621
1626# ------------------------------------------------------------------------------ 1622# @FUNCTION: java-pkg_javac-args
1627# @ebuild-function java-pkg_javac-args 1623# @DESCRIPTION:
1628#
1629# 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
1630# to know what -source/-target to use. 1625# to know what -source/-target to use.
1631# 1626#
1632# @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
1633# ------------------------------------------------------------------------------
1634java-pkg_javac-args() { 1628java-pkg_javac-args() {
1635 debug-print-function ${FUNCNAME} $* 1629 debug-print-function ${FUNCNAME} $*
1636 1630
1637 local want_source="$(java-pkg_get-source)" 1631 local want_source="$(java-pkg_get-source)"
1638 local want_target="$(java-pkg_get-target)" 1632 local want_target="$(java-pkg_get-target)"
1646 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1640 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1647 debug-print "could not find valid -source/-target values for javac" 1641 debug-print "could not find valid -source/-target values for javac"
1648 echo "Could not find valid -source/-target values for javac" 1642 echo "Could not find valid -source/-target values for javac"
1649 return 1 1643 return 1
1650 else 1644 else
1651 if java-pkg_is-vm-version-ge "1.4"; then
1652 echo "${source_str} ${target_str}" 1645 echo "${source_str} ${target_str}"
1653 else
1654 echo "${target_str}"
1655 fi 1646 fi
1656 fi
1657} 1647}
1658 1648
1659# TODO document 1649# @FUNCTION: java-pkg_get-jni-cflags
1650# @DESCRIPTION:
1651# Echos the CFLAGS for JNI compilations
1660java-pkg_get-jni-cflags() { 1652java-pkg_get-jni-cflags() {
1661 local flags="-I${JAVA_HOME}/include" 1653 local flags="-I${JAVA_HOME}/include"
1662 1654
1663 local platform="linux" 1655 local platform="linux"
1664 use elibc_FreeBSD && platform="freebsd" 1656 use elibc_FreeBSD && platform="freebsd"
1668 1660
1669 echo ${flags} 1661 echo ${flags}
1670} 1662}
1671 1663
1672java-pkg_ensure-gcj() { 1664java-pkg_ensure-gcj() {
1673 if ! built_with_use sys-devel/gcc gcj ; then 1665 # was enforcing sys-devel/gcc[gcj]
1674 ewarn 1666 die "${FUNCNAME} was removed. Use use-deps available as of EAPI 2 instead. #261562"
1675 ewarn "You must build gcc with the gcj support to build with gcj"
1676 ewarn
1677 ebeep 5
1678 die "No GCJ support found!"
1679 fi
1680} 1667}
1681 1668
1682java-pkg_ensure-test() { 1669java-pkg_ensure-test() {
1683 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \ 1670 # was enforcing USE=test if FEATURES=test
1684 && hasq test ${IUSE} && ! use test; 1671 die "${FUNCNAME} was removed. Package mangers handle this already. #278965"
1685 then
1686 eerror "You specified FEATURES=test, but USE=test is needed"
1687 eerror "to pull in the additional dependencies for testing"
1688 die "Need USE=test enabled"
1689 fi
1690} 1672}
1691 1673
1692# ------------------------------------------------------------------------------ 1674# @FUNCTION: java-pkg_register-ant-task
1693# @ebuild-function java-pkg_register-ant-task 1675# @USAGE: [--version x.y] [<name>]
1694# 1676# @DESCRIPTION:
1695# 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
1696# 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
1697# 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
1698# 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
1699# .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
1700# compatibility. 1682# compatibility.
1701# 1683#
1684# @CODE
1685# Parameters
1702# @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
1703# version). Used by the ant-* packages to prevent loading of mismatched 1687# version). Used by the ant-* packages to prevent loading of mismatched
1704# 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,
1705# without a need for blockers. 1689# without a need for blockers.
1706# @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])
1707# ------------------------------------------------------------------------------ 1691# @CODE
1708java-pkg_register-ant-task() { 1692java-pkg_register-ant-task() {
1709 local TASKS_DIR="tasks" 1693 local TASKS_DIR="tasks"
1710 1694
1711 # check for --version x.y parameters 1695 # check for --version x.y parameters
1712 while [[ -n "${1}" && -n "${2}" ]]; do 1696 while [[ -n "${1}" && -n "${2}" ]]; do
1724 1708
1725 dodir /usr/share/ant/${TASKS_DIR} 1709 dodir /usr/share/ant/${TASKS_DIR}
1726 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}" 1710 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1727} 1711}
1728 1712
1729# ------------------------------------------------------------------------------ 1713# @FUNCTION: java-pkg_ant-tasks-depend
1730# @internal-function java-pkg_ant-tasks-depend 1714# @INTERNAL
1731# 1715# @DESCRIPTION:
1732# Translates the WANT_ANT_TASKS variable into valid dependencies. 1716# Translates the WANT_ANT_TASKS variable into valid dependencies.
1733# ------------------------------------------------------------------------------
1734java-pkg_ant-tasks-depend() { 1717java-pkg_ant-tasks-depend() {
1735 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS} 1718 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1736 1719
1737 if [[ -n "${WANT_ANT_TASKS}" ]]; then 1720 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1738 local DEP="" 1721 local DEP=""
1752 else 1735 else
1753 return 0 1736 return 0
1754 fi 1737 fi
1755} 1738}
1756 1739
1757# ------------------------------------------------------------------------------ 1740
1758# @ebuild-function ejunit 1741# @FUNCTION: ejunit_
1759# 1742# @INTERNAL
1743# @DESCRIPTION:
1760# 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
1761# 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.
1762# 1746# @CODE
1763# Examples: 1747# Parameters:
1764# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests 1748# $1 - junit package (junit or junit-4)
1765# ejunit org.blinkenlights.jid3.test.AllTests
1766#
1767# @param $1 - -cp or -classpath 1749# $2 - -cp or -classpath
1768# @param $2 - classpath; junit and recorded dependencies get appended 1750# $3 - classpath; junit and recorded dependencies get appended
1769# @param $@ - the rest of the parameters are passed to java 1751# $@ - the rest of the parameters are passed to java
1770# ------------------------------------------------------------------------------ 1752# @CODE
1771ejunit() { 1753ejunit_() {
1772 debug-print-function ${FUNCNAME} $* 1754 debug-print-function ${FUNCNAME} $*
1773 1755
1774 local pkgs 1756 local pkgs
1775 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then 1757 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1776 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do 1758 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1777 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//") 1759 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1778 done 1760 done
1779 fi 1761 fi
1780 1762
1763 local junit=${1}
1764 shift 1
1765
1781 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs}) 1766 local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1782 if [[ ${1} = -cp || ${1} = -classpath ]]; then 1767 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1783 cp="${2}:${cp}" 1768 cp="${2}:${cp}"
1784 shift 2 1769 shift 2
1785 else 1770 else
1786 cp=".:${cp}" 1771 cp=".:${cp}"
1787 fi 1772 fi
1788 1773
1789 local runner=junit.textui.TestRunner 1774 local runner=junit.textui.TestRunner
1775 if [[ "${junit}" == "junit-4" ]] ; then
1776 runner=org.junit.runner.JUnitCore
1777 fi
1790 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}" 1778 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1791 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"
1792} 1780}
1793 1781
1794# ------------------------------------------------------------------------------ 1782# @FUNCTION: ejunit
1795# @section-end helper 1783# @DESCRIPTION:
1796# ------------------------------------------------------------------------------ 1784# Junit wrapper function. Makes it easier to run the tests and checks for
1797 1785# dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1798# ------------------------------------------------------------------------------
1799# @eclass-src_prepare
1800# 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
1792#
1793# Examples:
1794# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1795# ejunit org.blinkenlights.jid3.test.AllTests
1796# ejunit org.blinkenlights.jid3.test.FirstTest org.blinkenlights.jid3.test.SecondTest
1797# @CODE
1798ejunit() {
1799 debug-print-function ${FUNCNAME} $*
1800
1801 ejunit_ "junit" "${@}"
1802}
1803
1804# @FUNCTION: ejunit4
1805# @DESCRIPTION:
1806# Junit4 wrapper function. Makes it easier to run the tests and checks for
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
1814#
1815# Examples:
1816# ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1817# ejunit4 org.blinkenlights.jid3.test.AllTests
1818# ejunit4 org.blinkenlights.jid3.test.FirstTest \
1819# org.blinkenlights.jid3.test.SecondTest
1820# @CODE
1821ejunit4() {
1822 debug-print-function ${FUNCNAME} $*
1823
1824 ejunit_ "junit-4" "${@}"
1825}
1826
1827# @FUNCTION: java-utils-2_src_prepare
1828# @DESCRIPTION:
1801# src_prepare Searches for bundled jars 1829# src_prepare Searches for bundled jars
1802# Don't call directly, but via java-pkg-2_src_prepare! 1830# Don't call directly, but via java-pkg-2_src_prepare!
1803# ------------------------------------------------------------------------------
1804
1805java-utils-2_src_prepare() { 1831java-utils-2_src_prepare() {
1806 [[ ${EBUILD_PHASE} == prepare ]] &&
1807 java-pkg_func-exists java_prepare && java_prepare 1832 java-pkg_func-exists java_prepare && java_prepare
1808 1833
1809 # Remember that eant will call this unless called via Portage 1834 # Check for files in JAVA_RM_FILES array.
1810 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
1811 echo "Searching for bundled jars:" 1841 echo "Searching for bundled jars:"
1812 java-pkg_find-normal-jars || echo "None found." 1842 java-pkg_find-normal-jars || echo "None found."
1813 echo "Searching for bundled classes (no output if none found):" 1843 echo "Searching for bundled classes (no output if none found):"
1814 find "${WORKDIR}" -name "*.class" 1844 find "${WORKDIR}" -name "*.class"
1815 echo "Search done." 1845 echo "Search done."
1816 fi 1846 fi
1817 touch "${T}/java-utils-2_src_prepare-run"
1818} 1847}
1819 1848
1820# ------------------------------------------------------------------------------ 1849# @FUNCTION: java-utils-2_pkg_preinst
1821# @eclass-pkg_preinst 1850# @DESCRIPTION:
1822#
1823# pkg_preinst Searches for missing and unneeded dependencies 1851# pkg_preinst Searches for missing and unneeded dependencies
1824# Don't call directly, but via java-pkg-2_pkg_preinst! 1852# Don't call directly, but via java-pkg-2_pkg_preinst!
1825# ------------------------------------------------------------------------------
1826
1827java-utils-2_pkg_preinst() { 1853java-utils-2_pkg_preinst() {
1828 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
1829 if has_version dev-java/java-dep-check; then 1859 if has_version dev-java/java-dep-check; then
1830 [[ -e "${JAVA_PKG_ENV}" ]] || return
1831 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}")
1832 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then 1861 [[ ${output} ]] && ewarn "${output}"
1833 ewarn "Possibly unneeded dependencies found in package.env:"
1834 for dep in ${output}; do
1835 ewarn "\t${dep}"
1836 done
1837 fi
1838 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1839 ewarn "${output}"
1840 fi
1841 else 1862 else
1842 eerror "Install dev-java/java-dep-check for dependency checking" 1863 eerror "Install dev-java/java-dep-check for dependency checking"
1843 fi 1864 fi
1844 fi 1865 fi
1845} 1866}
1846 1867
1847# ------------------------------------------------------------------------------ 1868# @FUNCTION: eant
1848# @section-begin build 1869# @USAGE: <ant_build_target(s)>
1849# @section-summary Build functions 1870# @DESCRIPTION:
1850#
1851# These are some functions for building a package. In particular, it consists of
1852# wrappers for javac and ant.
1853# ------------------------------------------------------------------------------
1854
1855# ------------------------------------------------------------------------------
1856# @ebuild-function eant
1857#
1858# 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
1859# 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,
1860# variables: 1873# variables:
1874#
1875# @CODE
1876# Variables:
1861# 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
1862# gentoo.classpath property. Be sure to call 1878# gentoo.classpath property. Be sure to call java-ant_rewrite-classpath in src_unpack.
1863# java-ant_rewrite-classpath in src_unpack.
1864# 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
1865# for build-time purposes, the dependency is not recorded to 1880# for build-time purposes, the dependency is not recorded to
1866# package.env! 1881# package.env!
1867# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1868# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. 1882# ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1869# ------------------------------------------------------------------------------ 1883# @CODE
1870eant() { 1884eant() {
1871 debug-print-function ${FUNCNAME} $* 1885 debug-print-function ${FUNCNAME} $*
1872 1886
1873 if [[ ${EBUILD_PHASE} = compile ]]; then 1887 if [[ ${EBUILD_PHASE} = compile ]]; then
1874 java-ant-2_src_configure 1888 java-ant-2_src_configure
1875 java-utils-2_src_prepare
1876 fi 1889 fi
1877 1890
1878 if ! hasq java-ant-2 ${INHERITED}; then 1891 if ! has java-ant-2 ${INHERITED}; then
1879 local msg="You should inherit java-ant-2 when using eant" 1892 local msg="You should inherit java-ant-2 when using eant"
1880 java-pkg_announce-qa-violation "${msg}" 1893 java-pkg_announce-qa-violation "${msg}"
1881 fi 1894 fi
1882 1895
1883 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore" 1896 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1956 local gcp="${EANT_GENTOO_CLASSPATH}" 1969 local gcp="${EANT_GENTOO_CLASSPATH}"
1957 local getjarsarg="" 1970 local getjarsarg=""
1958 1971
1959 if [[ ${EBUILD_PHASE} = "test" ]]; then 1972 if [[ ${EBUILD_PHASE} = "test" ]]; then
1960 antflags="${antflags} -DJunit.present=true" 1973 antflags="${antflags} -DJunit.present=true"
1961 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1962 getjarsarg="--with-dependencies" 1974 getjarsarg="--with-dependencies"
1975
1976 local re="\bant-junit4?([-:]\S+)?\b"
1977 [[ ${ANT_TASKS} =~ ${re} ]] && gcp+=" ${BASH_REMATCH[0]}"
1978 else
1979 antflags="${antflags} -Dmaven.test.skip=true"
1963 fi 1980 fi
1964 1981
1965 local cp 1982 local cp
1966 1983
1967 for atom in ${gcp}; do 1984 for atom in ${gcp}; do
1968 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})" 1985 cp+=":$(java-pkg_getjars ${getjarsarg} ${atom})"
1969 done 1986 done
1970 1987
1971 [[ -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}"
1972 1990
1973 if [[ ${cp} ]]; then 1991 if [[ ${cp#:} ]]; then
1974 # It seems ant does not like single quotes around ${cp} 1992 # It seems ant does not like single quotes around ${cp}
1975 cp=${cp#:}
1976 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1977 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1978 antflags="${antflags} -Dgentoo.classpath=\"${cp}\"" 1993 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1979 fi 1994 fi
1980 1995
1981 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1996 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1982 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}" 1997 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1983 ant ${antflags} "${@}" || die "eant failed" 1998 ant ${antflags} "${@}" || die "eant failed"
1984} 1999}
1985 2000
1986# ------------------------------------------------------------------------------ 2001# @FUNCTION: ejavac
1987# @ebuild-function ejavac 2002# @USAGE: <javac_arguments>
1988# 2003# @DESCRIPTION:
1989# Javac wrapper function. Will use the appropriate compiler, based on 2004# Javac wrapper function. Will use the appropriate compiler, based on
1990# /etc/java-config/compilers.conf 2005# /etc/java-config/compilers.conf
1991#
1992# @param $@ - Arguments to be passed to the compiler
1993# ------------------------------------------------------------------------------
1994ejavac() { 2006ejavac() {
1995 debug-print-function ${FUNCNAME} $* 2007 debug-print-function ${FUNCNAME} $*
1996 2008
1997 java-pkg_init-compiler_ 2009 java-pkg_init-compiler_
1998 2010
2012 2024
2013 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}" 2025 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
2014 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed" 2026 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
2015} 2027}
2016 2028
2017# ------------------------------------------------------------------------------ 2029# @FUNCTION: ejavadoc
2018# @ebuild-function java-pkg_filter-compiler 2030# @USAGE: <javadoc_arguments>
2019# 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:
2020# 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.
2021# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 2050# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
2022#
2023# @param $@ - compilers to filter
2024# ------------------------------------------------------------------------------
2025java-pkg_filter-compiler() { 2051java-pkg_filter-compiler() {
2026 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 2052 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
2027} 2053}
2028 2054
2029# ------------------------------------------------------------------------------ 2055# @FUNCTION: java-pkg_force-compiler
2030# @ebuild-function java-pkg_force-compiler 2056# @USAGE: <compiler(s)_to_force>
2031# 2057# @DESCRIPTION:
2032# 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.
2033# 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
2034# OutOfMemoryErrors that may come up. 2060# OutOfMemoryErrors that may come up.
2035#
2036# @param $@ - compilers to force
2037# ------------------------------------------------------------------------------
2038java-pkg_force-compiler() { 2061java-pkg_force-compiler() {
2039 JAVA_PKG_FORCE_COMPILER="$@" 2062 JAVA_PKG_FORCE_COMPILER="$@"
2040} 2063}
2041 2064
2042# ------------------------------------------------------------------------------ 2065# @FUNCTION: use_doc
2043# @ebuild-function use_doc 2066# @DESCRIPTION:
2044# 2067#
2045# 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,
2046# 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.
2047# 2070#
2048# 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'
2049# 2075#
2076# Examples:
2050# Example: build javadocs by calling 'javadoc' target 2077# build javadocs by calling 'javadoc' target
2051# eant $(use_doc) 2078# eant $(use_doc)
2079#
2052# Example: build javadocs by calling 'apidoc' target 2080# build javadocs by calling 'apidoc' target
2053# eant $(use_doc apidoc) 2081# eant $(use_doc apidoc)
2054# 2082# @CODE
2055# @param $@ - Option value to return. Defaults to 'javadoc'
2056# @return string - Name of the target to create javadocs 2083# @RETURN string - Name of the target to create javadocs
2057# ------------------------------------------------------------------------------
2058use_doc() { 2084use_doc() {
2059 use doc && echo ${@:-javadoc} 2085 use doc && echo ${@:-javadoc}
2060} 2086}
2061 2087
2062 2088
2063# ------------------------------------------------------------------------------ 2089# @FUNCTION: java-pkg_init
2064# @section-end build 2090# @INTERNAL
2065# ------------------------------------------------------------------------------ 2091# @DESCRIPTION:
2066
2067# ------------------------------------------------------------------------------
2068# @section-begin internal
2069# @section-summary Internal functions
2070#
2071# Do __NOT__ use any of these from an ebuild! These are only to be used from
2072# within the java eclasses.
2073# ------------------------------------------------------------------------------
2074
2075# -----------------------------------------------------------------------------
2076# @function-internal java-pkg_init
2077#
2078# 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
2079# 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
2080# 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
2081# internally. And most importantly, it'll switch the VM if necessary. 2095# internally. And most importantly, it'll switch the VM if necessary.
2082# 2096#
2083# 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
2084# call it during each of the phases of the merge process. 2098# call it during each of the phases of the merge process.
2085#
2086# -----------------------------------------------------------------------------
2087java-pkg_init() { 2099java-pkg_init() {
2088 debug-print-function ${FUNCNAME} $* 2100 debug-print-function ${FUNCNAME} $*
2101
2102 # Don't set up build environment if installing from binary. #206024 #258423
2103 [[ "${MERGE_TYPE}" == "binary" ]] && return
2104 # Also try Portage's nonstandard EMERGE_FROM for old EAPIs, if it doesn't
2105 # work nothing is lost.
2106 has ${EAPI:-0} 0 1 2 3 && [[ "${EMERGE_FROM}" == "binary" ]] && return
2107
2089 unset JAVAC 2108 unset JAVAC
2090 unset JAVA_HOME 2109 unset JAVA_HOME
2091 2110
2092 java-config --help >/dev/null || { 2111 java-config --help >/dev/null || {
2093 eerror "" 2112 eerror ""
2120 2139
2121 if java-pkg_func-exists ant_src_unpack; then 2140 if java-pkg_func-exists ant_src_unpack; then
2122 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"
2123 fi 2142 fi
2124 2143
2125 java-pkg_init_paths_
2126 java-pkg_switch-vm 2144 java-pkg_switch-vm
2127 PATH=${JAVA_HOME}/bin:${PATH} 2145 PATH=${JAVA_HOME}/bin:${PATH}
2128 2146
2129 # TODO we will probably want to set JAVAC and JAVACFLAGS 2147 # TODO we will probably want to set JAVAC and JAVACFLAGS
2130 2148
2144 export ANT_TASKS= 2162 export ANT_TASKS=
2145 export ANT_OPTS= 2163 export ANT_OPTS=
2146 export ANT_RESPECT_JAVA_HOME= 2164 export ANT_RESPECT_JAVA_HOME=
2147} 2165}
2148 2166
2149# ------------------------------------------------------------------------------ 2167# @FUNCTION: java-pkg-init-compiler_
2150# @function-internal java-pkg-init-compiler_ 2168# @INTERNAL
2151# 2169# @DESCRIPTION:
2152# 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
2153# 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
2154# COMPILERS variable defined there. 2172# COMPILERS variable defined there.
2155# 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
2156# 2174#
2167# 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
2168# 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
2169# by the current VM. 2187# by the current VM.
2170# 2188#
2171# 2189#
2172# @return name of the compiler to use 2190# @RETURN name of the compiler to use
2173# ------------------------------------------------------------------------------
2174java-pkg_init-compiler_() { 2191java-pkg_init-compiler_() {
2175 debug-print-function ${FUNCNAME} $* 2192 debug-print-function ${FUNCNAME} $*
2176 2193
2177 if [[ -n ${GENTOO_COMPILER} ]]; then 2194 if [[ -n ${GENTOO_COMPILER} ]]; then
2178 debug-print "GENTOO_COMPILER already set" 2195 debug-print "GENTOO_COMPILER already set"
2219 if ! has ${desired_target} ${supported_target}; then 2236 if ! has ${desired_target} ${supported_target}; then
2220 ewarn "${compiler} does not support -target ${desired_target}, skipping" 2237 ewarn "${compiler} does not support -target ${desired_target}, skipping"
2221 continue 2238 continue
2222 fi 2239 fi
2223 2240
2224 # -source was introduced in 1.3, so only check 1.3 and on
2225 if version_is_at_least "${desired_soure}" "1.3"; then
2226 # Verify that the compiler supports source 2241 # Verify that the compiler supports source
2227 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})
2228 if ! has ${desired_source} ${supported_source}; then 2243 if ! has ${desired_source} ${supported_source}; then
2229 ewarn "${compiler} does not support -source ${desired_source}, skipping" 2244 ewarn "${compiler} does not support -source ${desired_source}, skipping"
2230 continue 2245 continue
2231 fi
2232 fi 2246 fi
2233 2247
2234 # 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
2235 export GENTOO_COMPILER="${compiler}" 2249 export GENTOO_COMPILER="${compiler}"
2236 break 2250 break
2258 einfo "Using ${GENTOO_COMPILER} for compilation" 2272 einfo "Using ${GENTOO_COMPILER} for compilation"
2259 fi 2273 fi
2260 2274
2261} 2275}
2262 2276
2263# ------------------------------------------------------------------------------ 2277# @FUNCTION: init_paths_
2264# @internal-function init_paths_ 2278# @INTERNAL
2265# 2279# @DESCRIPTION:
2266# 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
2267# to determine where things will eventually get installed. 2281# to determine where things will eventually get installed.
2268# ------------------------------------------------------------------------------
2269java-pkg_init_paths_() { 2282java-pkg_init_paths_() {
2270 debug-print-function ${FUNCNAME} $* 2283 debug-print-function ${FUNCNAME} $*
2271 2284
2272 local pkg_name 2285 local pkg_name
2273 if [[ "$SLOT" == "0" ]] ; then 2286 if [[ "${SLOT%/*}" == "0" ]] ; then
2274 JAVA_PKG_NAME="${PN}" 2287 JAVA_PKG_NAME="${PN}"
2275 else 2288 else
2276 JAVA_PKG_NAME="${PN}-${SLOT}" 2289 JAVA_PKG_NAME="${PN}-${SLOT%/*}"
2277 fi 2290 fi
2278 2291
2279 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2292 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
2280 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2293 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
2281 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2294 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2283 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}"
2284 2297
2285 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2298 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
2286 [[ -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}"
2287 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2300 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
2288
2289 2301
2290 # TODO maybe only print once? 2302 # TODO maybe only print once?
2291 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}" 2303 debug-print "JAVA_PKG_SHAREPATH: ${JAVA_PKG_SHAREPATH}"
2292 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}" 2304 debug-print "JAVA_PKG_ENV: ${JAVA_PKG_ENV}"
2293 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}" 2305 debug-print "JAVA_PKG_JARDEST: ${JAVA_PKG_JARDEST}"
2294 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}" 2306 debug-print "JAVA_PKG_LIBDEST: ${JAVA_PKG_LIBDEST}"
2295 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}" 2307 debug-print "JAVA_PKG_WARDEST: ${JAVA_PKG_WARDEST}"
2296} 2308}
2297 2309
2298# ------------------------------------------------------------------------------ 2310# @FUNCTION: java-pkg_do_write_
2299# @internal-function java-pkg_do_write_ 2311# @INTERNAL
2300# 2312# @DESCRIPTION:
2301# Writes the package.env out to disk. 2313# Writes the package.env out to disk.
2302# 2314#
2303# ------------------------------------------------------------------------------
2304# TODO change to do-write, to match everything else 2315# TODO change to do-write, to match everything else
2305java-pkg_do_write_() { 2316java-pkg_do_write_() {
2306 debug-print-function ${FUNCNAME} $* 2317 debug-print-function ${FUNCNAME} $*
2307 java-pkg_init_paths_ 2318 java-pkg_init_paths_
2308 # Create directory for package.env 2319 # Create directory for package.env
2363 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"
2364 debug-print "write package.env." 2375 debug-print "write package.env."
2365 fi 2376 fi
2366} 2377}
2367 2378
2368# ------------------------------------------------------------------------------ 2379# @FUNCTION: java-pkg_record-jar_
2369# @internal-function java-pkg_record-jar_ 2380# @INTERNAL
2370# 2381# @DESCRIPTION:
2371# Record an (optional) dependency to the package.env 2382# Record an (optional) dependency to the package.env
2383# @CODE
2384# Parameters:
2372# @param --optional - record dependency as optional 2385# --optional - record dependency as optional
2373# @param --build - record dependency as build_only 2386# --build - record dependency as build_only
2374# @param $1 - package to record 2387# $1 - package to record
2375# @param $2 - (optional) jar of package to record 2388# $2 - (optional) jar of package to record
2376# ------------------------------------------------------------------------------ 2389# @CODE
2377JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend" 2390JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2378JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend" 2391JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2379JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend" 2392JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
2380 2393
2381java-pkg_record-jar_() { 2394java-pkg_record-jar_() {
2395 fi 2408 fi
2396 2409
2397 echo "${append}" >> "${depend_file}" 2410 echo "${append}" >> "${depend_file}"
2398} 2411}
2399 2412
2400# ------------------------------------------------------------------------------ 2413# @FUNCTION: java-pkg_append_
2401# @internal-function java-pkg_append_ 2414# @INTERNAL
2402# 2415# @DESCRIPTION:
2403# Appends a value to a variable 2416# Appends a value to a variable
2404# 2417#
2405# Example: java-pkg_append_ CLASSPATH foo.jar 2418# @CODE
2419# Parameters:
2406# @param $1 variable name to modify 2420# $1 variable name to modify
2407# @param $2 value to append 2421# $2 value to append
2408# ------------------------------------------------------------------------------ 2422#
2423# Examples:
2424# java-pkg_append_ CLASSPATH foo.jar
2425# @CODE
2409java-pkg_append_() { 2426java-pkg_append_() {
2410 debug-print-function ${FUNCNAME} $* 2427 debug-print-function ${FUNCNAME} $*
2411 2428
2412 local var="${1}" value="${2}" 2429 local var="${1}" value="${2}"
2413 if [[ -z "${!var}" ]] ; then 2430 if [[ -z "${!var}" ]] ; then
2424 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}" 2441 [[ -z ${haveit} ]] && export ${var}="${!var}:${value}"
2425 IFS=${oldIFS} 2442 IFS=${oldIFS}
2426 fi 2443 fi
2427} 2444}
2428 2445
2429# ------------------------------------------------------------------------------ 2446# @FUNCTION: java-pkg_expand_dir_
2430# @internal-function java-pkg_expand_dir_ 2447# @INTERNAL
2431# 2448# @DESCRIPTION:
2432# 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:
2433# @param $1 - file/directory to find parent directory for 2452# $1 - file/directory to find parent directory for
2453# @CODE
2434# @return - path to $1's parent directory 2454# @RETURN: path to $1's parent directory
2435# ------------------------------------------------------------------------------
2436java-pkg_expand_dir_() { 2455java-pkg_expand_dir_() {
2437 pushd "$(dirname "${1}")" >/dev/null 2>&1 2456 pushd "$(dirname "${1}")" >/dev/null 2>&1
2438 pwd 2457 pwd
2439 popd >/dev/null 2>&1 2458 popd >/dev/null 2>&1
2440} 2459}
2441 2460
2442# ------------------------------------------------------------------------------ 2461# @FUNCTION: java-pkg_func-exists
2443# @internal-function java-pkg_func-exists 2462# @INTERNAL
2444# 2463# @DESCRIPTION:
2445# Does the indicated function exist? 2464# Does the indicated function exist?
2446# 2465# @RETURN: 0 - function is declared, 1 - function is undeclared
2447# @return 0 - function is declared
2448# @return 1 - function is undeclared
2449# ------------------------------------------------------------------------------
2450java-pkg_func-exists() { 2466java-pkg_func-exists() {
2451 declare -F ${1} > /dev/null 2467 declare -F ${1} > /dev/null
2452} 2468}
2453 2469
2454# ------------------------------------------------------------------------------ 2470# @FUNCTION: java-pkg_setup-vm
2455# @internal-function java-pkg_setup-vm 2471# @INTERNAL
2456# 2472# @DESCRIPTION:
2457# Sets up the environment for a specific VM 2473# Sets up the environment for a specific VM
2458#
2459# ------------------------------------------------------------------------------
2460java-pkg_setup-vm() { 2474java-pkg_setup-vm() {
2461 debug-print-function ${FUNCNAME} $* 2475 debug-print-function ${FUNCNAME} $*
2462
2463 export LANG="C" LC_ALL="C"
2464 2476
2465 local vendor="$(java-pkg_get-vm-vendor)" 2477 local vendor="$(java-pkg_get-vm-vendor)"
2466 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
2467 addpredict "/dev/random" 2479 addpredict "/dev/random"
2468 elif [[ "${vendor}" == "ibm" ]]; then 2480 elif [[ "${vendor}" == "ibm" ]]; then
2469 addpredict "/proc/self/maps" 2481 addpredict "/proc/self/maps"
2470 addpredict "/proc/cpuinfo" 2482 addpredict "/proc/cpuinfo"
2483 addpredict "/proc/self/coredump_filter"
2484 elif [[ "${vendor}" == "oracle" ]]; then
2485 addpredict "/dev/random"
2486 addpredict "/proc/self/coredump_filter"
2487 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2488 addpredict "/dev/random"
2489 addpredict "/proc/self/coredump_filter"
2471 elif [[ "${vendor}" == "jrockit" ]]; then 2490 elif [[ "${vendor}" == "jrockit" ]]; then
2472 addpredict "/proc/cpuinfo" 2491 addpredict "/proc/cpuinfo"
2473 fi 2492 fi
2474} 2493}
2475 2494
2476# ------------------------------------------------------------------------------ 2495# @FUNCTION: java-pkg_needs-vm
2477# @internal-function java-pkg_needs-vm 2496# @INTERNAL
2478# 2497# @DESCRIPTION:
2479# Does the current package depend on virtual/jdk? 2498# Does the current package depend on virtual/jdk or does it set
2499# JAVA_PKG_WANT_BUILD_VM?
2480# 2500#
2481# @return 0 - Package depends on virtual/jdk 2501# @RETURN: 0 - Package depends on virtual/jdk; 1 - Package does not depend on virtual/jdk
2482# @return 1 - Package does not depend on virtual/jdk
2483# ------------------------------------------------------------------------------
2484java-pkg_needs-vm() { 2502java-pkg_needs-vm() {
2485 debug-print-function ${FUNCNAME} $* 2503 debug-print-function ${FUNCNAME} $*
2486 2504
2487 if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then 2505 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
2488 return 0 2506 return 0
2489 fi 2507 fi
2490 2508
2509 [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]] && return 0
2510
2491 return 1 2511 return 1
2492} 2512}
2493 2513
2494# ------------------------------------------------------------------------------ 2514# @FUNCTION: java-pkg_get-current-vm
2495# @internal-function java-pkg_get-current-vm 2515# @INTERNAL
2496#
2497# @return - The current VM being used 2516# @RETURN - The current VM being used
2498# ------------------------------------------------------------------------------
2499java-pkg_get-current-vm() { 2517java-pkg_get-current-vm() {
2500 java-config -f 2518 java-config -f
2501} 2519}
2502 2520
2503# ------------------------------------------------------------------------------ 2521# @FUNCTION: java-pkg_get-vm-vendor
2504# @internal-function java-pkg_get-vm-vendor 2522# @INTERNAL
2505#
2506# @return - The vendor of the current VM 2523# @RETURN - The vendor of the current VM
2507# ------------------------------------------------------------------------------
2508java-pkg_get-vm-vendor() { 2524java-pkg_get-vm-vendor() {
2509 debug-print-function ${FUNCNAME} $* 2525 debug-print-function ${FUNCNAME} $*
2510 2526
2511 local vm="$(java-pkg_get-current-vm)" 2527 local vm="$(java-pkg_get-current-vm)"
2512 vm="${vm/-*/}" 2528 vm="${vm/-*/}"
2513 echo "${vm}" 2529 echo "${vm}"
2514} 2530}
2515 2531
2516# ------------------------------------------------------------------------------ 2532# @FUNCTION: java-pkg_get-vm-version
2517# @internal-function java-pkg_get-vm-version 2533# @INTERNAL
2518#
2519# @return - The version of the current VM 2534# @RETURN - The version of the current VM
2520# ------------------------------------------------------------------------------
2521java-pkg_get-vm-version() { 2535java-pkg_get-vm-version() {
2522 debug-print-function ${FUNCNAME} $* 2536 debug-print-function ${FUNCNAME} $*
2523 2537
2524 java-config -g PROVIDES_VERSION 2538 java-config -g PROVIDES_VERSION
2525} 2539}
2526 2540
2527# ------------------------------------------------------------------------------ 2541# @FUNCTION: java-pkg_build-vm-from-handle
2528# @internal-function java-pkg_switch-vm 2542# @INTERNAL
2543# @DESCRIPTION:
2544# Selects a build vm from a list of vm handles. First checks for the system-vm
2545# beeing usable, then steps through the listed handles till a suitable vm is
2546# found.
2529# 2547#
2548# @RETURN - VM handle of an available JDK
2549java-pkg_build-vm-from-handle() {
2550 debug-print-function ${FUNCNAME} "$*"
2551
2552 local vm
2553 vm=$(java-pkg_get-current-vm 2>/dev/null)
2554 if [[ $? -eq 0 ]]; then
2555 if has ${vm} ${JAVA_PKG_WANT_BUILD_VM}; then
2556 echo ${vm}
2557 return 0
2558 fi
2559 fi
2560
2561 for vm in ${JAVA_PKG_WANT_BUILD_VM}; do
2562 if java-config-2 --select-vm=${vm} 2>/dev/null; then
2563 echo ${vm}
2564 return 0
2565 fi
2566 done
2567
2568 eerror "${FUNCNAME}: No vm found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2569 return 1
2570}
2571
2572# @FUNCTION: java-pkg_switch-vm
2573# @INTERNAL
2574# @DESCRIPTION:
2530# 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
2531# verify that the current VM is sufficient. 2576# verify that the current VM is sufficient.
2532# Setup the environment for the VM being used. 2577# Setup the environment for the VM being used.
2533# ------------------------------------------------------------------------------
2534java-pkg_switch-vm() { 2578java-pkg_switch-vm() {
2535 debug-print-function ${FUNCNAME} $* 2579 debug-print-function ${FUNCNAME} $*
2536 2580
2537 if java-pkg_needs-vm; then 2581 if java-pkg_needs-vm; then
2538 # Use the VM specified by JAVA_PKG_FORCE_VM 2582 # Use the VM specified by JAVA_PKG_FORCE_VM
2540 # If you're forcing the VM, I hope you know what your doing... 2584 # If you're forcing the VM, I hope you know what your doing...
2541 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}" 2585 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
2542 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2586 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
2543 # if we're allowed to switch the vm... 2587 # if we're allowed to switch the vm...
2544 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2588 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
2545 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}" 2589 # if there is an explicit list of handles to choose from
2546 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2590 if [[ -n "${JAVA_PKG_WANT_BUILD_VM}" ]]; then
2547 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then 2591 debug-print "JAVA_PKG_WANT_BUILD_VM used: ${JAVA_PKG_WANT_BUILD_VM}"
2548 eerror "Unable to determine VM for building from dependencies:" 2592 GENTOO_VM=$(java-pkg_build-vm-from-handle)
2549 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}" 2593 if [[ $? != 0 ]]; then
2594 eerror "${FUNCNAME}: No VM found for handles: ${JAVA_PKG_WANT_BUILD_VM}"
2550 die "Failed to determine VM for building." 2595 die "${FUNCNAME}: Failed to determine VM for building"
2596 fi
2597 # JAVA_PKG_WANT_SOURCE and JAVA_PKG_WANT_TARGET are required as
2598 # they can't be deduced from handles.
2599 if [[ -z "${JAVA_PKG_WANT_SOURCE}" ]]; then
2600 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_SOURCE"
2601 die "Specify JAVA_PKG_WANT_SOURCE"
2602 fi
2603 if [[ -z "${JAVA_PKG_WANT_TARGET}" ]]; then
2604 eerror "JAVA_PKG_WANT_BUILD_VM specified but not JAVA_PKG_WANT_TARGET"
2605 die "Specify JAVA_PKG_WANT_TARGET"
2606 fi
2607 # otherwise determine a vm from dep string
2551 else 2608 else
2552 export GENTOO_VM 2609 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2610 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2611 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2612 eerror "Unable to determine VM for building from dependencies:"
2613 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2614 die "Failed to determine VM for building."
2615 fi
2553 fi 2616 fi
2617 export GENTOO_VM
2554 # otherwise just make sure the current VM is sufficient 2618 # otherwise just make sure the current VM is sufficient
2555 else 2619 else
2556 java-pkg_ensure-vm-version-sufficient 2620 java-pkg_ensure-vm-version-sufficient
2557 fi 2621 fi
2558 debug-print "Using: $(java-config -f)" 2622 debug-print "Using: $(java-config -f)"
2586 else 2650 else
2587 [[ -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!!!"
2588 fi 2652 fi
2589} 2653}
2590 2654
2591# ------------------------------------------------------------------------------ 2655# @FUNCTION: java-pkg_die
2592# @internal-function java-pkg_die 2656# @INTERNAL
2593# 2657# @DESCRIPTION:
2594# 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
2595# useful for debugging bugs on bugzilla. 2659# useful for debugging bugs on bugzilla.
2596# ------------------------------------------------------------------------------
2597#register_die_hook java-pkg_die 2660#register_die_hook java-pkg_die
2598if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then 2661if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
2599 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die" 2662 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
2600fi 2663fi
2601 2664
2602java-pkg_die() { 2665java-pkg_die() {
2603 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
2604 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
2605 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 2668 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
2606 echo "and of course, the output of emerge --info" >&2 2669 echo "and of course, the output of emerge --info =${P}" >&2
2607} 2670}
2608 2671
2609 2672
2610# TODO document 2673# TODO document
2611# List jars in the source directory, ${S} 2674# List jars in the source directory, ${S}
2618 einfo "Classes" 2681 einfo "Classes"
2619 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},"
2620 fi 2683 fi
2621} 2684}
2622 2685
2623# ------------------------------------------------------------------------------ 2686# @FUNCTION: java-pkg_verify-classes
2624# @internal-function java-pkg_verify-classes 2687# @INTERNAL
2625# 2688# @DESCRIPTION:
2626# 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
2627# not. 2690# not.
2691# @CODE
2628# @param $1 (optional) - the file to check, otherwise checks whole ${D} 2692# $1 (optional) - the file to check, otherwise checks whole ${D}
2629# ------------------------------------------------------------------------------ 2693# @CODE
2630java-pkg_verify-classes() { 2694java-pkg_verify-classes() {
2631 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2695 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2632 2696
2633 local version_verify="/usr/bin/class-version-verify.py" 2697 local version_verify="/usr/bin/class-version-verify.py"
2634 2698
2662 eerror "See ${log} for more details." 2726 eerror "See ${log} for more details."
2663 die "Incorrect bytecode found" 2727 die "Incorrect bytecode found"
2664 fi 2728 fi
2665} 2729}
2666 2730
2667# ---------------------------------------------------------------------------- 2731# @FUNCTION: java-pkg_ensure-dep
2668# @internal-function java-pkg_ensure-dep 2732# @INTERNAL
2733# @DESCRIPTION:
2669# 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
2670# 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:
2671# @param $1 - empty - check both vars; "runtime" or "build" - check only 2739# $1 - empty - check both vars; "runtime" or "build" - check only
2672# RDEPEND, resp. DEPEND 2740# RDEPEND, resp. DEPEND
2673# @param $2 - Package name and slot. 2741# $2 - Package name and slot.
2674 2742# @CODE
2675java-pkg_ensure-dep() { 2743java-pkg_ensure-dep() {
2676 debug-print-function ${FUNCNAME} $* 2744 debug-print-function ${FUNCNAME} $*
2677 2745
2678 local limit_to="${1}" 2746 local limit_to="${1}"
2679 local target_pkg="${2}" 2747 local target_pkg="${2}"
2680 local dev_error="" 2748 local dev_error=""
2681 2749
2682 local stripped_pkg=$(echo "${target_pkg}" | sed \ 2750 # Transform into a regular expression to look for a matching package
2683 's/-[0-9]*\(\.[0-9]\)*$//') 2751 # and SLOT. SLOTs don't have to be numeric so foo-bar could either
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
2684 2771
2685 debug-print "Matching against: ${stripped_pkg}" 2772 debug-print "Matching against: ${stripped_pkg}"
2686 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
2687 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then 2778 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ $stripped_pkg ) ]]; then
2688 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 "
2689 dev_error="${dev_error} declared in DEPEND." 2780 dev_error+="declared with a SLOT in DEPEND."
2690 if is-java-strict; then 2781# if is-java-strict; then
2691 eerror "${dev_error}"
2692 die "${dev_error}" 2782# die "${dev_error}"
2693 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2783# else
2694 eerror "${dev_error}" 2784 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2695 elog "Because you have this package installed the package will" 2785# eerror "Because you have ${target_pkg} installed,"
2696 elog "build without problems, but please report this to" 2786# eerror "the package will build without problems, but please"
2697 elog "http://bugs.gentoo.org" 2787# eerror "report this to http://bugs.gentoo.org."
2698 fi 2788# fi
2699 fi 2789 elif [[ ${limit_to} != build && ! ( "${RDEPEND}${PDEPEND}" =~ ${stripped_pkg} ) ]]; then
2700
2701 if [[ ${limit_to} != build ]]; then
2702 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2703 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2704 dev_error="The ebuild is attempting to use ${target_pkg}," 2790 dev_error="The ebuild is attempting to use ${target_pkg}, which is not "
2705 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."
2706 dev_error="${dev_error} or PDEPEND."
2707 if is-java-strict; then 2792# if is-java-strict; then
2708 eerror "${dev_error}"
2709 die "${dev_error}" 2793# die "${dev_error}"
2710 elif [[ ${BASH_SUBSHELL} = 0 ]]; then 2794# else
2711 eerror "${dev_error}" 2795 eqawarn "java-pkg_ensure-dep: ${dev_error}"
2712 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"
2713 elog "if you don't have ${target_pkg} installed, so please report" 2797# eerror "if you don't have ${target_pkg} installed,"
2714 elog "this to http://bugs.gentoo.org" 2798# eerror "so please report this to http://bugs.gentoo.org."
2715 fi
2716 fi
2717 fi 2799# fi
2718 fi 2800 fi
2719} 2801}
2720
2721# ------------------------------------------------------------------------------
2722# @section-end internal
2723# ------------------------------------------------------------------------------
2724 2802
2725java-pkg_check-phase() { 2803java-pkg_check-phase() {
2726 local phase=${1} 2804 local phase=${1}
2727 local funcname=${FUNCNAME[1]} 2805 local funcname=${FUNCNAME[1]}
2728 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 2806 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2738 java-pkg_announce-qa-violation "installing versioned jar '${jar}'" 2816 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
2739 fi 2817 fi
2740} 2818}
2741 2819
2742java-pkg_check-jikes() { 2820java-pkg_check-jikes() {
2743 if hasq jikes ${IUSE}; then 2821 if has jikes ${IUSE}; then
2744 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2822 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2745 fi 2823 fi
2746} 2824}
2747 2825
2748java-pkg_announce-qa-violation() { 2826java-pkg_announce-qa-violation() {
2763 2841
2764is-java-strict() { 2842is-java-strict() {
2765 [[ -n ${JAVA_PKG_STRICT} ]] 2843 [[ -n ${JAVA_PKG_STRICT} ]]
2766 return $? 2844 return $?
2767} 2845}
2768
2769
2770# ------------------------------------------------------------------------------
2771# @eclass-end
2772# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20