/[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.10 Revision 1.147
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-2005, 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 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.147 2011/10/29 14:05:48 caster Exp $
10 10
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27
28IUSE="elibc_FreeBSD"
27 29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
33# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
34 36
35# Make sure we use java-config-2 37# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
37 39
38# TODO document 40# -----------------------------------------------------------------------------
41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
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
63# 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.
65# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
40 67
41# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
43# 70#
44# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
45# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
46# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
47# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.1.9-r1 ${JAVA_PKG_PORTAGE_DEP}"
76has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
77
78# -----------------------------------------------------------------------------
79# @variable-preinherit JAVA_PKG_WANT_BOOTCLASSPATH
80#
81# 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
83# -----------------------------------------------------------------------------
84
85if [[ -n "${JAVA_PKG_WANT_BOOTCLASSPATH}" ]]; then
86 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"
88 else
89 eerror "Unknown value of JAVA_PKG_WANT_BOOTCLASSPATH"
90 # 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"
92 fi
93fi
49 94
50# ----------------------------------------------------------------------------- 95# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 96# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 97# @variable-default yes
53# 98#
100# ----------------------------------------------------------------------------- 145# -----------------------------------------------------------------------------
101 146
102# ----------------------------------------------------------------------------- 147# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 148# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 149# @default /usr/share/java-config-2/compiler
105# 150#
106# Directory where compiler settings are saved, without trailing slash. 151# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 152# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 153# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 154JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 155
120 165
121# ----------------------------------------------------------------------------- 166# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 167# @variable-external JAVA_PKG_FORCE_COMPILER
123# 168#
124# Explicitly set a list of compilers to use. This is normally read from 169# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 170# JAVA_PKG_COMPILERS_CONF.
126# 171#
127# @note This should only be used internally or for testing. 172# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 173# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 174# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
131 176
177# -----------------------------------------------------------------------------
178# @variable-external JAVA_PKG_FORCE_ANT_TASKS
179#
180# 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
182# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
183# eant() call, not the dependencies specified in WANT_ANT_TASKS.
184#
185# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
186# ebuild foo.ebuild compile
187#
188# @seealso WANT_ANT_TASKS
189# -----------------------------------------------------------------------------
190
132# TODO document me 191# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 192JAVA_PKG_QA_VIOLATIONS=0
134 193
135# ----------------------------------------------------------------------------- 194# -----------------------------------------------------------------------------
136# @section-end variables 195# @section-end variables
143# 202#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 203# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 204# libraries, etc.
146# ----------------------------------------------------------------------------- 205# -----------------------------------------------------------------------------
147 206
207# -----------------------------------------------------------------------------
208# @ebuild-function java-pkg_doexamples
209#
210# 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
212# everything in that directory to the examples directory.
213#
214# @example
215# java-pkg_doexamples demo
216# java-pkg_doexamples demo/* examples/*
217#
218# @param --subdir - If the examples need a certain directory structure
219# @param $* - list of files to install
220# ------------------------------------------------------------------------------
221java-pkg_doexamples() {
222 debug-print-function ${FUNCNAME} $*
223
224 [[ ${#} -lt 1 ]] && die "At least one argument needed"
225
226 java-pkg_check-phase install
227
228 local dest=/usr/share/doc/${PF}/examples
229 if [[ ${1} == --subdir ]]; then
230 local dest=${dest}/${2}
231 dodir ${dest}
232 shift 2
233 fi
234
235 if [[ ${#} = 1 && -d ${1} ]]; then
236 ( # dont want to pollute calling env
237 insinto "${dest}"
238 doins -r ${1}/*
239 ) || die "Installing examples failed"
240 else
241 ( # dont want to pollute calling env
242 insinto "${dest}"
243 doins -r "$@"
244 ) || die "Installing examples failed"
245 fi
246
247 # Let's make a symlink to the directory we have everything else under
248 dosym "${dest}" "${JAVA_PKG_SHAREPATH}/examples" || die
249}
148 250
149# ----------------------------------------------------------------------------- 251# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 252# @ebuild-function java-pkg_dojar
151# 253#
152# Installs any number of jars. 254# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 255# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 256# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 257# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 258# Instead, use java-pkg_newjar defined below.
157# 259#
158# @example 260# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 261# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 262#
171 # Create JARDEST if it doesn't exist 273 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 274 dodir ${JAVA_PKG_JARDEST}
173 275
174 local jar 276 local jar
175 # for each jar 277 # for each jar
176 for jar in "$@"; do 278 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 279 local jar_basename=$(basename "${jar}")
178 280
179 java-pkg_check-versioned-jar ${jar_basename} 281 java-pkg_check-versioned-jar ${jar_basename}
180 282
181 # check if it exists 283 # check if it exists
182 if [[ -e "${jar}" ]] ; then 284 if [[ -e "${jar}" ]] ; then
285 # Don't overwrite if jar has already been installed with the same
286 # name
287 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
288 if [[ -e "${dest}" ]]; then
289 ewarn "Overwriting ${dest}"
290 fi
291
183 # install it into JARDEST if it's a non-symlink 292 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 293 if [[ ! -L "${jar}" ]] ; then
294 #but first check class version when in strict mode.
295 is-java-strict && java-pkg_verify-classes "${jar}"
296
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 297 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 298 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 299 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 300 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 301 # make a symlink to the original jar if it's symlink
199 done 311 done
200 312
201 java-pkg_do_write_ 313 java-pkg_do_write_
202} 314}
203 315
316# ------------------------------------------------------------------------------
317# @internal-function depend-java-query
318#
319# Wrapper for the depend-java-query binary to enable passing USE in env.
320# Using env variables keeps this eclass working with java-config versions that
321# do not handle use flags.
322# ------------------------------------------------------------------------------
204 323
324depend-java-query() {
325 # Used to have a which call here but it caused endless loops for some people
326 # that had some weird bashrc voodoo for which.
327 USE="${USE}" /usr/bin/depend-java-query "${@}"
328}
205 329
206# ------------------------------------------------------------------------------ 330# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 331# @ebuild-function java-pkg_regjar
208# 332#
209# Records an already installed jar in the package.env 333# Records an already installed jar in the package.env
222# will not work, because: 346# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 347# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 348# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 349# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 350# doesn't exist
227# 351#
228# you have to use it as: 352# you have to use it as:
229# 353#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 354# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 355#
232# @param $@ - jars to record 356# @param $@ - jars to record
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 364 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 365
242 java-pkg_init_paths_ 366 java-pkg_init_paths_
243 367
244 local jar jar_dir jar_file 368 local jar jar_dir jar_file
245 for jar in "$@"; do 369 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 370 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 371 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
372 [[ -d "${jar}" || -d "${D}${jar}" ]] \
373 && die "Called ${FUNCNAME} on a directory $*"
374
375 #check that class version correct when in strict mode
376 is-java-strict && java-pkg_verify-classes "${jar}"
377
248 # nelchael: we should strip ${D} in this case too, here's why: 378 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 379 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 380 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 381 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 382 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 383 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
254 elif [[ -e "${D}${jar}" ]]; then
255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
256 else 384 else
385 if [[ ${jar} = *\** ]]; then
386 eerror "The argument ${jar} to ${FUNCNAME}"
387 eerror "has * in it. If you want it to glob in"
388 eerror '${D} add ${D} to the argument.'
389 fi
390 debug-print "${jar} or ${D}${jar} not found"
257 die "${jar} does not exist" 391 die "${jar} does not exist"
258 fi 392 fi
259 done 393 done
260 394
261 java-pkg_do_write_ 395 java-pkg_do_write_
262} 396}
263
264 397
265# ------------------------------------------------------------------------------ 398# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 399# @ebuild-function java-pkg_newjar
267# 400#
268# Installs a jar with a new name 401# Installs a jar with a new name
279 local original_jar="${1}" 412 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 413 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 414 local new_jar_dest="${T}/${new_jar}"
282 415
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 416 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 417 [[ ! -f ${original_jar} ]] \
418 && die "${original_jar} does not exist or is not a file!"
285 419
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 420 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 421 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 422 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 423 java-pkg_dojar "${new_jar_dest}"
290} 424}
291 425
292
293# ------------------------------------------------------------------------------ 426# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 427# @ebuild-function java-pkg_addcp
295# 428#
296# Add something to the package's classpath. For jars, you should use dojar, 429# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 430# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 435java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 436 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 437 java-pkg_do_write_
305} 438}
306 439
307
308# ------------------------------------------------------------------------------ 440# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 441# @ebuild-function java-pkg_doso
310# 442#
311# Installs any number of JNI libraries 443# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 444# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 445# can be used change this path
314# 446#
315# Example: 447# Example:
318# @param $@ - JNI libraries to install 450# @param $@ - JNI libraries to install
319# ------------------------------------------------------------------------------ 451# ------------------------------------------------------------------------------
320java-pkg_doso() { 452java-pkg_doso() {
321 debug-print-function ${FUNCNAME} $* 453 debug-print-function ${FUNCNAME} $*
322 454
323 [[ ${#} -lt 1 ]] && "At least one argument required for ${FUNCNAME}"
324 java-pkg_check-phase install 455 java-pkg_check-phase install
325 456
326 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 457 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
327 458
328 java-pkg_init_paths_ 459 java-pkg_init_paths_
329 460
330 local lib 461 local lib
331 # for each lib 462 # for each lib
334 if [[ -e "${lib}" ]] ; then 465 if [[ -e "${lib}" ]] ; then
335 # install if it isn't a symlink 466 # install if it isn't a symlink
336 if [[ ! -L "${lib}" ]] ; then 467 if [[ ! -L "${lib}" ]] ; then
337 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 468 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
338 INSOPTIONS="${LIBOPTIONS}" \ 469 INSOPTIONS="${LIBOPTIONS}" \
339 doins "${lib}" || "failed to install ${lib}" 470 doins "${lib}" || die "failed to install ${lib}"
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 471 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 472 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 473 # otherwise make a symlink to the symlink's origin
343 else 474 else
344 # TODO use dosym
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 475 dosym "$(readlink "${lib}")" "${JAVA_PKG_LIBDEST}/${lib##*/}"
346 debug-print "${lib} is a symlink, linking accordanly" 476 debug-print "${lib} is a symlink, linking accordantly"
347 fi 477 fi
348 # otherwise die 478 # otherwise die
349 else 479 else
350 die "${lib} does not exist" 480 die "${lib} does not exist"
351 fi 481 fi
367java-pkg_regso() { 497java-pkg_regso() {
368 debug-print-function ${FUNCNAME} $* 498 debug-print-function ${FUNCNAME} $*
369 499
370 java-pkg_check-phase install 500 java-pkg_check-phase install
371 501
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 502 [[ ${#} -lt 1 ]] && die "${FUNCNAME} requires at least one argument"
373 503
374 java-pkg_init_paths_ 504 java-pkg_init_paths_
375 505
376 local lib target_dir 506 local lib target_dir
377 for lib in "$@" ; do 507 for lib in "$@" ; do
378 # Check the absolute path of the lib 508 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 509 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 510 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 558# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 559java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 560 debug-print-function ${FUNCNAME} $*
431 561
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 562 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 563
564 # from /usr/lib/portage/bin/dohtml -h
565 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 566 dohtml -f package-list "$@"
567
435 # this probably shouldn't be here but it provides 568 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 569 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 570 # old ebuilds.
438 java-pkg_recordjavadoc 571 java-pkg_recordjavadoc
439} 572}
440 573
441# TODO document 574# ------------------------------------------------------------------------------
575# @ebuild-function java-pkg_dojavadoc
576#
577# Installs javadoc documentation. This should be controlled by the doc use flag.
578#
579# @param $1: optional --symlink creates to symlink like this for html
580# documentation bundles.
581# @param $2: - The javadoc root directory.
582#
583# @example:
584# java-pkg_dojavadoc docs/api
585# java-pkg_dojavadoc --symlink apidocs docs/api
586#
587# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 588java-pkg_dojavadoc() {
589 debug-print-function ${FUNCNAME} $*
590
591 # For html documentation bundles that link to Javadoc
592 local symlink
593 if [[ ${1} = --symlink ]]; then
594 symlink=${2}
595 shift 2
596 fi
597
443 local dir="$1" 598 local dir="$1"
599 local dest=/usr/share/doc/${PF}/html
600
601 # QA checks
444 602
445 java-pkg_check-phase install 603 java-pkg_check-phase install
446 604
447 [[ -z "${dir}" ]] && die "Must specify a directory!" 605 [[ -z "${dir}" ]] && die "Must specify a directory!"
448 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 606 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
607 if [[ ! -e "${dir}/index.html" ]]; then
608 local msg="No index.html in javadoc directory"
609 ewarn "${msg}"
610 is-java-strict && die "${msg}"
611 fi
612
613 if [[ -e ${D}/${dest}/api ]]; then
614 eerror "${dest} already exists. Will not overwrite."
615 die "${dest}"
616 fi
617
618 # Renaming to match our directory layout
449 619
450 local dir_to_install="${dir}" 620 local dir_to_install="${dir}"
451 if [[ "$(basename "${dir}")" != "api" ]]; then 621 if [[ "$(basename "${dir}")" != "api" ]]; then
452 dir_to_install="${T}/api" 622 dir_to_install="${T}/api"
453 # TODO use doins 623 # TODO use doins
454 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 624 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
455 fi 625 fi
456 626
627 # Actual installation
628
457 java-pkg_dohtml -r ${dir_to_install} 629 java-pkg_dohtml -r "${dir_to_install}"
630
631 # Let's make a symlink to the directory we have everything else under
632 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
633
634 if [[ ${symlink} ]]; then
635 debug-print "symlinking ${dest}/{api,${symlink}}"
636 dosym ${dest}/{api,${symlink}} || die
637 fi
458} 638}
459 639
460# ------------------------------------------------------------------------------ 640# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 641# @ebuild-function java-pkg_dosrc
462# 642#
463# Installs a zip containing the source for a package, so it can used in 643# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 644# from IDEs like eclipse and netbeans.
465# 645#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 646# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 647#
468# It also should be controlled by USE=source. 648# It also should be controlled by USE=source.
469# 649#
470# @example: 650# @example:
471# java-pkg_dosrc src/* 651# java-pkg_dosrc src/*
472# 652#
473# ------------------------------------------------------------------------------ 653# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 654# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 655# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 656# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 657# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 658# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 659java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 660 debug-print-function ${FUNCNAME} $*
481 661
482 [ ${#} -lt 1 ] && die "At least one argument needed" 662 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi
486 663
487 java-pkg_check-phase install 664 java-pkg_check-phase install
488 665
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 666 [[ ${#} -lt 1 ]] && die "At least one argument needed"
667
668 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
669 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
670 java-pkg_announce-qa-violation ${msg}
671 fi
490 672
491 java-pkg_init_paths_ 673 java-pkg_init_paths_
492 674
493 local zip_name="${PN}-src.zip" 675 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 676 local zip_path="${T}/${zip_name}"
495 local dir 677 local dir
496 for dir in ${@}; do 678 for dir in "${@}"; do
497 local dir_parent=$(dirname "${dir}") 679 local dir_parent=$(dirname "${dir}")
498 local dir_name=$(basename "${dir}") 680 local dir_name=$(basename "${dir}")
499 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 681 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
500 zip -q -r ${zip_path} ${dir_name} -i '*.java' 682 zip -q -r ${zip_path} ${dir_name} -i '*.java'
501 local result=$? 683 local result=$?
518# @ebuild-function java-pkg_dolauncher 700# @ebuild-function java-pkg_dolauncher
519# 701#
520# Make a wrapper script to lauch/start this package 702# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 703# If necessary, the wrapper will switch to the appropriate VM.
522# 704#
705# Can be called without parameters if the package installs only one jar
706# that has the Main-class attribute set. The wrapper will be named ${PN}.
707#
523# @param $1 - filename of launcher to create 708# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 709# @param $2 - options, as follows:
525# --main the.main.class.too.start 710# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 711# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 712# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 713# --pkg_args 'Extra arguments to pass to the package'
529# --pwd 714# --pwd Directory the launcher changes to before executing java
530# -into 715# -into Directory to install the launcher to, instead of /usr/bin
531# -pre 716# -pre Prepend contents of this file to the launcher
532# ------------------------------------------------------------------------------ 717# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 718java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 719 debug-print-function ${FUNCNAME} $*
535 720
536 java-pkg_check-phase install 721 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 722 java-pkg_init_paths_
541 723
724 if [[ ${#} = 0 ]]; then
725 local name="${PN}"
726 else
542 local name="${1}" 727 local name="${1}"
728 shift
729 fi
730
543 # TODO rename to launcher 731 # TODO rename to launcher
544 local target="${T}/${name}" 732 local target="${T}/${name}"
733 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 734 local target_dir pre
546 shift
547 735
548 echo "#!/bin/bash" > "${target}" 736 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 737 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 738 local var="${1}" value="${2}"
551 if [[ "${var:0:2}" == "--" ]]; then 739 if [[ "${var:0:2}" == "--" ]]; then
740 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 741 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
742 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 743 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 744 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 745 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 746 pre="${value}"
557 fi 747 fi
558 shift 2 748 shift 2
559 done 749 done
750
751 # Test if no --jar and --main arguments were given and
752 # in that case check if the package only installs one jar
753 # and use that jar.
754 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
755 local cp="${JAVA_PKG_CLASSPATH}"
756 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
757 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
758 else
759 local msg="Not enough information to create a launcher given."
760 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
761 die "${msg}"
762 fi
763 fi
764
765 # Write the actual script
766 echo "#!/bin/bash" > "${target}"
767 if [[ -n "${pre}" ]]; then
768 if [[ -f "${pre}" ]]; then
769 cat "${pre}" >> "${target}"
770 else
771 die "-pre specified file '${pre}' does not exist"
772 fi
773 fi
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 774 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 775 cat "${var_tmp}" >> "${target}"
776 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 777 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 778
564 if [[ -n "${into}" ]]; then 779 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 780 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 781 local ret=$?
567 return ${ret} 782 return ${ret}
568 else 783 else
569 dobin "${target}" 784 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 812 echo "dowar: warning, skipping directory ${war}"
598 continue 813 continue
599 else 814 else
600 warpath="${war}" 815 warpath="${war}"
601 fi 816 fi
602 817
603 # Install those files like you mean it 818 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 819 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 820 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 821 doins ${warpath}
607 done 822 done
642# @ebuild-function java-pkg_jar-from 857# @ebuild-function java-pkg_jar-from
643# 858#
644# Makes a symlink to a jar from a certain package 859# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 860# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 861# You can use this function to replace these bundled dependencies.
862# The dependency is recorded into package.env DEPEND line, unless "--build-only"
863# is passed as the very first argument, for jars that have to be present only
864# at build time and are not needed on runtime (junit testing etc).
647# 865#
648# Example: get all jars from xerces slot 2 866# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 867# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 868# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 869# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 870# Example: get a specific jar from xerces slot 2, and name it diffrently
653# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 871# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
872# Example: get junit.jar which is needed only for building
873# java-pkg_jar-from --build-only junit junit.jar
654# 874#
655# @param $1 - Package to get jars from. 875# @param $opt
876# --build-only - makes the jar(s) not added into package.env DEPEND line.
877# (assumed automatically when called inside src_test)
878# --with-dependencies - get jars also from requested package's dependencies
879# transitively.
880# --virtual - Packages passed to this function are to be handled as virtuals
881# and will not have individual jar dependencies recorded.
882# --into $dir - symlink jar(s) into $dir (must exist) instead of .
883# @param $1 - Package to get jars from, or comma-separated list of packages in
884# case other parameters are not used.
656# @param $2 - jar from package. If not specified, all jars will be used. 885# @param $2 - jar from package. If not specified, all jars will be used.
657# @param $3 - When a single jar is specified, destination filename of the 886# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 887# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 888# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 889# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 890java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 891 debug-print-function ${FUNCNAME} $*
663 892
893 local build_only=""
894 local destdir="."
895 local deep=""
896 local virtual=""
897 local record_jar=""
898
899 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
900
901 while [[ "${1}" == --* ]]; do
902 if [[ "${1}" = "--build-only" ]]; then
903 build_only="build"
904 elif [[ "${1}" = "--with-dependencies" ]]; then
905 deep="--with-dependencies"
906 elif [[ "${1}" = "--virtual" ]]; then
907 virtual="true"
908 elif [[ "${1}" = "--into" ]]; then
909 destdir="${2}"
910 shift
911 else
912 die "java-pkg_jar-from called with unknown parameter: ${1}"
913 fi
914 shift
915 done
916
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 917 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 918
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 919 [[ -z ${target_pkg} ]] && die "Must specify a package"
920
921 if [[ "${EAPI}" == "1" ]]; then
922 target_pkg="${target_pkg//:/-}"
923 fi
667 924
668 # default destjar to the target jar 925 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 926 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 927
928 local error_msg="There was a problem getting the classpath for ${target_pkg}."
929 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 930 classpath="$(java-config ${deep} --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 931 [[ $? != 0 ]] && die ${error_msg}
932
933 # When we have commas this functions is called to bring jars from multiple
934 # packages. This affects recording of dependencencies performed later
935 # which expects one package only, so we do it here.
936 if [[ ${target_pkg} = *,* ]]; then
937 for pkg in ${target_pkg//,/ }; do
938 java-pkg_ensure-dep "${build_only}" "${pkg}"
939 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
940 done
941 # setting this disables further record-jar_ calls later
942 record_jar="true"
943 else
944 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
945 fi
946
947 # Record the entire virtual as a dependency so that
948 # no jars are missed.
949 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
950 java-pkg_record-jar_ "${target_pkg}"
951 # setting this disables further record-jars_ calls later
952 record_jar="true"
953 fi
954
955 pushd ${destdir} > /dev/null \
956 || die "failed to change directory to ${destdir}"
673 957
674 local jar 958 local jar
675 for jar in ${classpath//:/ }; do 959 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 960 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 961 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 965 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 966 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 967 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 968 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 969 || die "Failed to make symlink from ${jar} to ${jar_name}"
970 if [[ -z "${record_jar}" ]]; then
971 if [[ -z "${build_only}" ]]; then
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 972 java-pkg_record-jar_ "${target_pkg}" "${jar}"
973 else
974 java-pkg_record-jar_ --build-only "${target_pkg}" "${jar}"
975 fi
976 fi
687 # otherwise, if the current jar is the target jar, link it 977 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 978 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 979 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 980 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 981 || die "Failed to make symlink from ${jar} to ${destjar}"
982 if [[ -z "${record_jar}" ]]; then
983 if [[ -z "${build_only}" ]]; then
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 984 java-pkg_record-jar_ "${target_pkg}" "${jar}"
985 else
986 java-pkg_record-jar_ --build-only "${target_jar}" "${jar}"
987 fi
988 fi
989 popd > /dev/null
693 return 0 990 return 0
694 fi 991 fi
695 done 992 done
993 popd > /dev/null
696 # if no target was specified, we're ok 994 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 995 if [[ -z "${target_jar}" ]] ; then
698 return 0 996 return 0
699 # otherwise, die bitterly 997 # otherwise, die bitterly
700 else 998 else
714# ------------------------------------------------------------------------------ 1012# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 1013# @ebuild-function java-pkg_getjars
716# 1014#
717# Get the classpath provided by any number of packages 1015# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 1016# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
1017# The providing packages are recorded as dependencies into package.env DEPEND
1018# line, unless "--build-only" is passed as the very first argument, for jars
1019# that have to be present only at build time and are not needed on runtime
1020# (junit testing etc).
719# 1021#
720# Example: Get the classpath for xerces-2, 1022# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 1023# java-pkg_getjars xerces-2,xalan
722# Example Return: 1024# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 1025# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 1026#
1027# @param $opt
1028# --build-only - makes the jar(s) not added into package.env DEPEND line.
1029# (assumed automatically when called inside src_test)
1030# --with-dependencies - get jars also from requested package's dependencies
1031# transitively.
725# @param $@ - list of packages to get jars from 1032# @param $1 - list of packages to get jars from
1033# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 1034# ------------------------------------------------------------------------------
727java-pkg_getjars() { 1035java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 1036 debug-print-function ${FUNCNAME} $*
729 1037
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 1038 local build_only=""
1039 local deep=""
731 1040
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 1041 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
733 local classpath pkg 1042
734 for pkg in ${@//,/ }; do 1043 while [[ "${1}" == --* ]]; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 1044 if [[ "${1}" = "--build-only" ]]; then
736 jars="$(java-config --classpath=${pkg})" 1045 build_only="build"
737 debug-print "${pkg}:${jars}" 1046 elif [[ "${1}" = "--with-dependencies" ]]; then
738 # TODO should we ensure jars exist? 1047 deep="--with-dependencies"
739 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}"
741 else 1048 else
742 classpath="${classpath}:${jars}" 1049 die "java-pkg_jar-from called with unknown parameter: ${1}"
743 fi 1050 fi
744 java-pkg_record-jar_ "${pkg}" 1051 shift
745 done 1052 done
746 echo "${classpath}" 1053
1054 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1055
1056
1057 local pkgs="${1}"
1058
1059 if [[ "${EAPI}" == "1" ]]; then
1060 pkgs="${pkgs//:/-}"
1061 fi
1062
1063 jars="$(java-config ${deep} --classpath=${pkgs})"
1064 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1065 debug-print "${pkgs}:${jars}"
1066
1067 for pkg in ${pkgs//,/ }; do
1068 java-pkg_ensure-dep "${build_only}" "${pkg}"
1069 done
1070
1071 for pkg in ${pkgs//,/ }; do
1072 if [[ -z "${build_only}" ]]; then
1073 java-pkg_record-jar_ "${pkg}"
1074 else
1075 java-pkg_record-jar_ --build-only "${pkg}"
1076 fi
1077 done
1078
1079 echo "${jars}"
747} 1080}
748 1081
749# ------------------------------------------------------------------------------ 1082# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 1083# @ebuild-function java-pkg_getjar
751# 1084#
752# Get the filename of a single jar from a package 1085# Get the filename of a single jar from a package
1086# The providing package is recorded as runtime dependency into package.env
1087# DEPEND line, unless "--build-only" is passed as the very first argument, for
1088# jars that have to be present only at build time and are not needed on runtime
1089# (junit testing etc).
753# 1090#
754# @example 1091# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 1092# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 1093# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 1094# /usr/share/xerces-2/lib/xml-apis.jar
758# 1095#
1096# @param $opt
1097# --build-only - makes the jar not added into package.env DEPEND line.
1098# --virtual - Packages passed to this function are to be handled as virtuals
1099# and will not have individual jar dependencies recorded.
759# @param $1 - package to use 1100# @param $1 - package to use
760# @param $2 - jar to get 1101# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 1102# ------------------------------------------------------------------------------
762java-pkg_getjar() { 1103java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 1104 debug-print-function ${FUNCNAME} $*
764 1105
1106 local build_only=""
1107 local virtual=""
1108 local record_jar=""
1109
1110 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1111
1112 while [[ "${1}" == --* ]]; do
1113 if [[ "${1}" = "--build-only" ]]; then
1114 build_only="build"
1115 elif [[ "${1}" == "--virtual" ]]; then
1116 virtual="true"
1117 else
1118 die "java-pkg_getjar called with unknown parameter: ${1}"
1119 fi
1120 shift
1121 done
1122
1123 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
1124
765 local pkg="${1}" target_jar="${2}" jar 1125 local pkg="${1}" target_jar="${2}" jar
1126
1127 if [[ "${EAPI}" == "1" ]]; then
1128 pkg="${pkg//:/-}"
1129 fi
1130
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1131 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1132 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 1133
769 # TODO check that package is actually installed 1134 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
1135 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 1136 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 1137 [[ $? != 0 ]] && die ${error_msg}
1138
1139 java-pkg_ensure-dep "${build_only}" "${pkg}"
1140
1141 # Record the package(Virtual) as a dependency and then set build_only
1142 # So that individual jars are not recorded.
1143 if [[ -n "${virtual}" ]]; then
1144 if [[ -z "${build_only}" ]]; then
1145 java-pkg_record-jar_ "${pkg}"
1146 else
1147 java-pkg_record-jar_ --build-only "${pkg}"
1148 fi
1149 record_jar="true"
1150 fi
1151
772 for jar in ${classpath//:/ }; do 1152 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 1153 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 1154 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 1155 fi
776 1156
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 1157 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
1158 # Only record jars that aren't build-only
1159 if [[ -z "${record_jar}" ]]; then
1160 if [[ -z "${build_only}" ]]; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 1161 java-pkg_record-jar_ "${pkg}" "${jar}"
1162 else
1163 java-pkg_record-jar_ --build-only "${pkg}" "${jar}"
1164 fi
1165 fi
779 echo "${jar}" 1166 echo "${jar}"
780 return 0 1167 return 0
781 fi 1168 fi
782 done 1169 done
783 1170
784 die "Could not find ${target_jar} in ${pkg}" 1171 die "Could not find ${target_jar} in ${pkg}"
785 return 1 1172 return 1
786} 1173}
1174
1175# ------------------------------------------------------------------------------
1176# @ebuild-function java-pkg_register-dependency
1177#
1178# Registers runtime dependency on a package, list of packages, or a single jar
1179# from a package, into package.env DEPEND line. Can only be called in
1180# src_install phase.
1181# Intended for binary packages where you don't need to symlink the jars or get
1182# their classpath during build. As such, the dependencies only need to be
1183# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1184#
1185# @param $1 - comma-separated list of packages, or a single package
1186# @param $2 - if param $1 is a single package, optionally specify the jar
1187# to depend on
1188#
1189# Example: Record the dependency on whole xerces-2 and xalan,
1190# java-pkg_register-dependency xerces-2,xalan
1191# Example: Record the dependency on ant.jar from ant-core
1192# java-pkg_register-dependency ant-core ant.jar
1193#
1194# Note: Passing both list of packages as the first parameter AND specifying the
1195# jar as the second is not allowed and will cause the function to die. We assume
1196# that there's more chance one passes such combination as a mistake, than that
1197# there are more packages providing identically named jar without class
1198# collisions.
1199# ------------------------------------------------------------------------------
1200java-pkg_register-dependency() {
1201 debug-print-function ${FUNCNAME} $*
1202
1203 java-pkg_check-phase install
1204
1205 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1206
1207 local pkgs="${1}"
1208 local jar="${2}"
1209
1210 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1211
1212 if [[ "${EAPI}" == "1" ]]; then
1213 pkgs="${pkgs//:/-}"
1214 fi
1215
1216 if [[ -z "${jar}" ]]; then
1217 for pkg in ${pkgs//,/ }; do
1218 java-pkg_ensure-dep runtime "${pkg}"
1219 java-pkg_record-jar_ "${pkg}"
1220 done
1221 else
1222 [[ ${pkgs} == *,* ]] && \
1223 die "${FUNCNAME} called with both package list and jar name"
1224 java-pkg_ensure-dep runtime "${pkgs}"
1225 java-pkg_record-jar_ "${pkgs}" "${jar}"
1226 fi
1227
1228 java-pkg_do_write_
1229}
1230
1231# ------------------------------------------------------------------------------
1232# @ebuild-function java-pkg_register-optional-dependency
1233#
1234# Registers optional runtime dependency on a package, list of packages, or a
1235# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1236# called in src_install phase.
1237# Intended for packages that can use other packages when those are in classpath.
1238# Will be put on classpath by launcher if they are installed. Typical case is
1239# JDBC implementations for various databases. It's better than having USE flag
1240# for each implementation triggering hard dependency.
1241#
1242# @param $1 - comma-separated list of packages, or a single package
1243# @param $2 - if param $1 is a single package, optionally specify the jar
1244# to depend on
1245#
1246# Example: Record the optional dependency on some jdbc providers
1247# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1248#
1249# Note: Passing both list of packages as the first parameter AND specifying the
1250# jar as the second is not allowed and will cause the function to die. We assume
1251# that there's more chance one passes such combination as a mistake, than that
1252# there are more packages providing identically named jar without class
1253# collisions.
1254# ------------------------------------------------------------------------------
1255java-pkg_register-optional-dependency() {
1256 debug-print-function ${FUNCNAME} $*
1257
1258 java-pkg_check-phase install
1259
1260 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1261
1262 local pkgs="${1}"
1263 local jar="${2}"
1264
1265 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1266
1267 if [[ "${EAPI}" == "1" ]]; then
1268 pkgs="${pkgs//:/-}"
1269 fi
1270
1271 if [[ -z "${jar}" ]]; then
1272 for pkg in ${pkgs//,/ }; do
1273 java-pkg_record-jar_ --optional "${pkg}"
1274 done
1275 else
1276 [[ ${pkgs} == *,* ]] && \
1277 die "${FUNCNAME} called with both package list and jar name"
1278 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1279 fi
1280
1281 java-pkg_do_write_
1282}
1283
1284# ------------------------------------------------------------------------------
1285# @ebuild-function java-pkg_register-environment-variable
1286#
1287# Register an arbitrary environment variable into package.env. The gjl launcher
1288# for this package or any package depending on this will export it into
1289# environement before executing java command.
1290# Must only be called in src_install phase.
1291#
1292# @param $1 - variable name
1293# @param $2 - variable value
1294# ------------------------------------------------------------------------------
1295JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1296JAVA_PKG_EXTRA_ENV_VARS=""
1297java-pkg_register-environment-variable() {
1298 debug-print-function ${FUNCNAME} $*
1299
1300 java-pkg_check-phase install
1301
1302 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1303
1304 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1305 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1306
1307 java-pkg_do_write_
1308}
1309
1310# ------------------------------------------------------------------------------
1311# @ebuild-function java-pkg_get-bootclasspath
1312#
1313# Returns classpath of a given bootclasspath-providing package version.
1314#
1315# @param $1 - the version of bootclasspath (e.g. 1.5), 'auto' for bootclasspath
1316# of the current JDK
1317# ------------------------------------------------------------------------------
1318
1319java-pkg_get-bootclasspath() {
1320 local version="${1}"
1321
1322 local bcp
1323 case "${version}" in
1324 auto)
1325 bcp="$(java-config -g BOOTCLASSPATH)"
1326 ;;
1327 1.5)
1328 bcp="$(java-pkg_getjars --build-only gnu-classpath-0.98)"
1329 ;;
1330 *)
1331 eerror "unknown parameter of java-pkg_get-bootclasspath"
1332 die "unknown parameter of java-pkg_get-bootclasspath"
1333 ;;
1334 esac
1335
1336 echo "${bcp}"
1337}
1338
787 1339
788# This function reads stdin, and based on that input, figures out how to 1340# This function reads stdin, and based on that input, figures out how to
789# populate jars from the filesystem. 1341# populate jars from the filesystem.
790# Need to figure out a good way of making use of this, ie be able to use a 1342# Need to figure out a good way of making use of this, ie be able to use a
791# string that was built instead of stdin 1343# string that was built instead of stdin
802# line="${line// /}" 1354# line="${line// /}"
803# 1355#
804# # format: path=jarinfo 1356# # format: path=jarinfo
805# local path=${line%%=*} 1357# local path=${line%%=*}
806# local jarinfo=${line##*=} 1358# local jarinfo=${line##*=}
807# 1359#
808# # format: jar@package 1360# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 1361# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 1362# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 1363# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 1364# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 1377# @section-end query
826# ------------------------------------------------------------------------------ 1378# ------------------------------------------------------------------------------
827 1379
828# ------------------------------------------------------------------------------ 1380# ------------------------------------------------------------------------------
829# @section-begin helper 1381# @section-begin helper
830# @section-summary Helper functions 1382# @section-summary Helper functions
831# 1383#
832# Various other functions to use from an ebuild 1384# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 1385# ------------------------------------------------------------------------------
834 1386
835# ------------------------------------------------------------------------------ 1387# ------------------------------------------------------------------------------
836# @ebuild-function java-pkg_need 1388# @ebuild-function java-pkg_find-normal-jars
837# 1389#
838# Adds virtual dependencies, which can optionally be controlled by a USE flag. 1390# Find the files with suffix .jar file in the given directory or $WORKDIR
839# Currently supported virtuals are:
840# javamail
841# jdbc-stdext
842# jaf
843# jdbc-rowset
844# jms
845# 1391#
846# @param $1 - Optionally indicate that the dependencies are controlled by 1392# @param $1 - The directory to search for jar files (default: ${WORKDIR})
847# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 1393# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 1394java-pkg_find-normal-jars() {
852#java-pkg_need() { 1395 local dir=$1
853# debug-print-function ${FUNCNAME} $* 1396 [[ "${dir}" ]] || dir="${WORKDIR}"
854# local useflag 1397 local found
855# if [[ ${1} == "--use" ]]; then 1398 for jar in $(find "${dir}" -name "*.jar" -type f); do
856# useflag="${2}" 1399 echo "${jar}"
857# shift 2 1400 found="true"
858# fi
859#
860# if [[ -z ${1} ]]; then
861# die "Must specify at least one virtual package."
862# fi
863#
864# local depstr newdepstr
865#
866# for virtual in ${@}; do
867# if has ${virtual} ${JAVA_PKG_VNEED}; then
868# debug-print "Already registered virtual ${virtual}"
869# continue
870# fi
871# case ${virtual} in
872# javamail)
873# debug-print "java-pkg_need: adding javamail dependencies"
874# newdepstr="|| ( dev-java/gnu-javamail dev-java/sun-javamail-bin )"
875# ;;
876# jdbc-stdext)
877# debug-print "java-pkg_need: adding jdbc-stdext dependencies"
878# newdepstr="|| ( >=virtual/jdk-1.4 dev-java/jdbc2-stdext )"
879# ;;
880# jaf)
881# debug-print "java-pkg_need: adding jaf dependencies"
882# newdepstr="|| ( dev-java/gnu-jaf dev-java/sun-jaf-bin )"
883# ;;
884# jdbc-rowset)
885# debug-print "java-pkg_need: adding jdbc-rowset dependencies"
886# newdepstr="|| ( >=virtual/jdk-1.5 dev-java/sun-jdbc-rowset )"
887# ;;
888# jms)
889# debug-print "java-pkg_need: adding jms dependencies"
890# newdepstr="|| ( dev-java/sun-jms dev-java/openjms )"
891# ;;
892# *)
893# die "Invalid virtual: ${virtual}"
894# esac
895#
896# export JAVA_PKG_VNEED="${JAVA_PKG_VNEED} ${virtual}"
897#
898# if [[ -n ${useflag} ]]; then
899# depstr="${depstr} ${useflag}? ( ${newdepstr} )"
900# else
901# depstr="${depstr} ${newdepstr}"
902# fi
903# done 1401 done
904# 1402 [[ "${found}" ]]
905# [[ -z ${JAVA_PKG_NV_DEPEND} ]] && export JAVA_PKG_NV_DEPEND="${DEPEND}" 1403 return $?
906# [[ -z ${JAVA_PKG_NV_RDEPEND} ]] && export JAVA_PKG_NV_RDEPEND="${RDEPEND}" 1404}
907#
908# export DEPEND="${DEPEND} ${depstr}"
909# export RDEPEND="${RDEPEND} ${depstr}"
910#}
911 1405
1406# ------------------------------------------------------------------------------
1407# @ebuild-function java-pkg_ensure-no-bundled-jars
1408#
1409# Try to locate bundled jar files in ${WORKDIR} and die if found.
912# This should be used after S has been populated with symlinks to jars 1410# This function should be called after WORKDIR has been populated with symlink
913# TODO document 1411# to system jar files or bundled jars removed.
1412# ------------------------------------------------------------------------------
914java-pkg_ensure-no-bundled-jars() { 1413java-pkg_ensure-no-bundled-jars() {
915 debug-print-function ${FUNCNAME} $* 1414 debug-print-function ${FUNCNAME} $*
916 pushd ${WORKDIR} >/dev/null 2>/dev/null
917 1415
918 local bundled_jars=$(find . -name "*.jar" -type f) 1416 local bundled_jars=$(java-pkg_find-normal-jars)
919 if [[ -n ${bundled_jars} ]]; then 1417 if [[ -n ${bundled_jars} ]]; then
920 echo "Bundled jars found:" 1418 echo "Bundled jars found:"
921 local jar 1419 local jar
922 for jar in ${bundled_jars}; do 1420 for jar in ${bundled_jars}; do
923 echo $(pwd)${jar/./} 1421 echo $(pwd)${jar/./}
924 done 1422 done
925 die "Bundled jars found!" 1423 die "Bundled jars found!"
926
927 fi 1424 fi
928 popd >/dev/null 2>/dev/null
929} 1425}
930 1426
931# ------------------------------------------------------------------------------ 1427# ------------------------------------------------------------------------------
932# @internal-function java-pkg_ensure-vm-version-sufficient 1428# @internal-function java-pkg_ensure-vm-version-sufficient
933# 1429#
945 fi 1441 fi
946} 1442}
947 1443
948# ------------------------------------------------------------------------------ 1444# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1445# @internal-function java-pkg_is-vm-version-sufficient
950# 1446#
951# @return zero - VM is sufficient 1447# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1448# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1449# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1450java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1451 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1471 die "Active Java VM too old"
976 fi 1472 fi
977} 1473}
978 1474
979# ------------------------------------------------------------------------------ 1475# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1476# @internal-function java-pkg_is-vm-version-eq
981# 1477#
982# @param $@ - VM version to compare current VM to 1478# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1479# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1480# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1481# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1482java-pkg_is-vm-version-eq() {
1016# 1512#
1017# @param $@ - VM version to compare current to 1513# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1514# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1515java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1516 debug-print-function ${FUNCNAME} $*
1021 1517
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1518 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1519 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1520 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1521 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1522 die "Active Java VM too old"
1027 fi 1523 fi
1028} 1524}
1029 1525
1030# ------------------------------------------------------------------------------ 1526# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1527# @internal-function java-pkg_is-vm-version-ge
1032# 1528#
1033# @param $@ - VM version to compare current VM to 1529# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1530# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1531# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1532# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1533java-pkg_is-vm-version-ge() {
1051 return 1 1547 return 1
1052 fi 1548 fi
1053 fi 1549 fi
1054} 1550}
1055 1551
1552java-pkg_set-current-vm() {
1553 export GENTOO_VM=${1}
1554}
1555
1556java-pkg_get-current-vm() {
1557 echo ${GENTOO_VM}
1558}
1559
1560java-pkg_current-vm-matches() {
1561 has $(java-pkg_get-current-vm) ${@}
1562 return $?
1563}
1564
1056# ------------------------------------------------------------------------------ 1565# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1566# @ebuild-function java-pkg_get-source
1058# 1567#
1059# Determines what source version should be used, for passing to -source. 1568# Determines what source version should be used, for passing to -source.
1060# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1569# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1570#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1571# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1572# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1577# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1578# @ebuild-function java-pkg_get-target
1070# 1579#
1071# Determines what target version should be used, for passing to -target. 1580# Determines what target version should be used, for passing to -target.
1072# If you don't care about lower versions, you can set _WANT_TARGET to the 1581# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1582# version of your JDK.
1074# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm.
1077# 1583#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1584# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1585# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1586java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1084 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1085 echo ${JAVA_PKG_WANT_TARGET}
1086 else
1087 echo ${min}
1088 fi
1089 else
1090 echo ${min}
1091 fi
1092
1093 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1587 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1094} 1588}
1095 1589
1096java-pkg_get-javac() { 1590java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1591 debug-print-function ${FUNCNAME} $*
1098 1592
1099 java-pkg_init-compiler_ 1593
1100 local compiler="${GENTOO_COMPILER}" 1594 local compiler="${GENTOO_COMPILER}"
1101 1595
1102 local compiler_executable 1596 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1597 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1598 # nothing fancy needs to be done for javac
1112 unset JAVAC 1606 unset JAVAC
1113 # try to get value of JAVAC 1607 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1608 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1609 export JAVAC=${old_javac}
1116 1610
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1611 if [[ -z ${compiler_executable} ]]; then
1118 1612 echo "JAVAC is empty or undefined in ${compiler_env}"
1613 return 1
1614 fi
1615
1119 # check that it's executable 1616 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1617 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1618 echo "${compiler_executable} doesn't exist, or isn't executable"
1619 return 1
1123 fi 1620 fi
1124 else 1621 else
1125 eerror "Could not find environment file for ${compiler}" 1622 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1623 return 1
1127 fi 1624 fi
1128 fi 1625 fi
1129 echo ${compiler_executable} 1626 echo ${compiler_executable}
1130} 1627}
1131 1628
1132# ------------------------------------------------------------------------------ 1629# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1630# @ebuild-function java-pkg_javac-args
1134# 1631#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1632# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1633# to know what -source/-target to use.
1137# 1634#
1138# @return string - arguments to pass to javac, complete with -target and -source 1635# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1638 debug-print-function ${FUNCNAME} $*
1142 1639
1143 local want_source="$(java-pkg_get-source)" 1640 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1641 local want_target="$(java-pkg_get-target)"
1145 1642
1146 local source_str="-source ${want_source}" 1643 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1644 local target_str="-target ${want_target}"
1148 1645
1149 debug-print "want source: ${want_source}" 1646 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1647 debug-print "want target: ${want_target}"
1151 1648
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1649 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1650 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1651 echo "Could not find valid -source/-target values for javac"
1652 return 1
1155 else 1653 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1654 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1655 echo "${source_str} ${target_str}"
1158 else 1656 else
1159 echo "${target_str}" 1657 echo "${target_str}"
1163 1661
1164# TODO document 1662# TODO document
1165java-pkg_get-jni-cflags() { 1663java-pkg_get-jni-cflags() {
1166 local flags="-I${JAVA_HOME}/include" 1664 local flags="-I${JAVA_HOME}/include"
1167 1665
1666 local platform="linux"
1667 use elibc_FreeBSD && platform="freebsd"
1668
1168 # TODO do a check that the directories are valid 1669 # TODO do a check that the directories are valid
1169 # TODO figure out how to cope with other things than linux...
1170 flags="${flags} -I${JAVA_HOME}/include/linux" 1670 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1171 1671
1172 echo ${flags} 1672 echo ${flags}
1173} 1673}
1174 1674
1175java-pkg_ensure-gcj() { 1675java-pkg_ensure-gcj() {
1180 ebeep 5 1680 ebeep 5
1181 die "No GCJ support found!" 1681 die "No GCJ support found!"
1182 fi 1682 fi
1183} 1683}
1184 1684
1685java-pkg_ensure-test() {
1686 if has test ${FEATURES} && ! has -test ${FEATURES} \
1687 && has test ${IUSE} && ! use test;
1688 then
1689 eerror "You specified FEATURES=test, but USE=test is needed"
1690 eerror "to pull in the additional dependencies for testing"
1691 die "Need USE=test enabled"
1692 fi
1693}
1694
1695# ------------------------------------------------------------------------------
1696# @ebuild-function java-pkg_register-ant-task
1697#
1698# Register this package as ant task, so that ant will load it when no specific
1699# ANT_TASKS are specified. Note that even without this registering, all packages
1700# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1701# packages, but can be also used by other ebuilds that used to symlink their
1702# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1703# compatibility.
1704#
1705# @param --version x.y Register only for ant version x.y (otherwise for any ant
1706# version). Used by the ant-* packages to prevent loading of mismatched
1707# ant-core ant tasks after core was updated, before the tasks are updated,
1708# without a need for blockers.
1709# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1710# ------------------------------------------------------------------------------
1711java-pkg_register-ant-task() {
1712 local TASKS_DIR="tasks"
1713
1714 # check for --version x.y parameters
1715 while [[ -n "${1}" && -n "${2}" ]]; do
1716 local var="${1#--}"
1717 local val="${2}"
1718 if [[ "${var}" == "version" ]]; then
1719 TASKS_DIR="tasks-${val}"
1720 else
1721 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1722 fi
1723 shift 2
1724 done
1725
1726 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1727
1728 dodir /usr/share/ant/${TASKS_DIR}
1729 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1730}
1731
1732# ------------------------------------------------------------------------------
1733# @internal-function java-pkg_ant-tasks-depend
1734#
1735# Translates the WANT_ANT_TASKS variable into valid dependencies.
1736# ------------------------------------------------------------------------------
1737java-pkg_ant-tasks-depend() {
1738 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1739
1740 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1741 local DEP=""
1742 for i in ${WANT_ANT_TASKS}
1743 do
1744 if [[ ${i} = ant-* ]]; then
1745 DEP="${DEP}dev-java/${i} "
1746 elif [[ ${i} = */*:* ]]; then
1747 DEP="${DEP}${i} "
1748 else
1749 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1750 return 1
1751 fi
1752 done
1753 echo ${DEP}
1754 return 0
1755 else
1756 return 0
1757 fi
1758}
1759
1760
1761# ------------------------------------------------------------------------------
1762# @internal-function ejunit_
1763#
1764# Internal Junit wrapper function. Makes it easier to run the tests and checks for
1765# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1766#
1767# @param $1 - junit package (junit or junit-4)
1768# @param $2 - -cp or -classpath
1769# @param $3 - classpath; junit and recorded dependencies get appended
1770# @param $@ - the rest of the parameters are passed to java
1771ejunit_() {
1772 debug-print-function ${FUNCNAME} $*
1773
1774 local pkgs
1775 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1776 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1777 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1778 done
1779 fi
1780
1781 local junit=${1}
1782 shift 1
1783
1784 local cp=$(java-pkg_getjars --with-dependencies ${junit}${pkgs})
1785 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1786 cp="${2}:${cp}"
1787 shift 2
1788 else
1789 cp=".:${cp}"
1790 fi
1791
1792 local runner=junit.textui.TestRunner
1793 if [[ "${junit}" == "junit-4" ]] ; then
1794 runner=org.junit.runner.JUnitCore
1795 fi
1796 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1797 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1798}
1799
1800# ------------------------------------------------------------------------------
1801# @ebuild-function ejunit
1802#
1803# Junit wrapper function. Makes it easier to run the tests and checks for
1804# dev-java/junit in DEPEND. Launches the tests using org.junit.runner.JUnitCore.
1805#
1806# Examples:
1807# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1808# ejunit org.blinkenlights.jid3.test.AllTests
1809# ejunit org.blinkenlights.jid3.test.FirstTest \
1810# org.blinkenlights.jid3.test.SecondTest
1811#
1812# @param $1 - -cp or -classpath
1813# @param $2 - classpath; junit and recorded dependencies get appended
1814# @param $@ - the rest of the parameters are passed to java
1815# ------------------------------------------------------------------------------
1816ejunit() {
1817 debug-print-function ${FUNCNAME} $*
1818
1819 ejunit_ "junit" "${@}"
1820}
1821
1822# ------------------------------------------------------------------------------
1823# @ebuild-function ejunit4
1824#
1825# Junit4 wrapper function. Makes it easier to run the tests and checks for
1826# dev-java/junit:4 in DEPEND. Launches the tests using junit.textui.TestRunner.
1827#
1828# Examples:
1829# ejunit4 -cp build/classes org.blinkenlights.jid3.test.AllTests
1830# ejunit4 org.blinkenlights.jid3.test.AllTests
1831# ejunit4 org.blinkenlights.jid3.test.FirstTest \
1832# org.blinkenlights.jid3.test.SecondTest
1833#
1834# @param $1 - -cp or -classpath
1835# @param $2 - classpath; junit and recorded dependencies get appended
1836# @param $@ - the rest of the parameters are passed to java
1837# ------------------------------------------------------------------------------
1838ejunit4() {
1839 debug-print-function ${FUNCNAME} $*
1840
1841 ejunit_ "junit-4" "${@}"
1842}
1843
1185# ------------------------------------------------------------------------------ 1844# ------------------------------------------------------------------------------
1186# @section-end helper 1845# @section-end helper
1187# ------------------------------------------------------------------------------ 1846# ------------------------------------------------------------------------------
1847
1848# ------------------------------------------------------------------------------
1849# @eclass-src_prepare
1850#
1851# src_prepare Searches for bundled jars
1852# Don't call directly, but via java-pkg-2_src_prepare!
1853# ------------------------------------------------------------------------------
1854
1855java-utils-2_src_prepare() {
1856 [[ ${EBUILD_PHASE} == prepare ]] &&
1857 java-pkg_func-exists java_prepare && java_prepare
1858
1859 # Remember that eant will call this unless called via Portage
1860 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1861 echo "Searching for bundled jars:"
1862 java-pkg_find-normal-jars || echo "None found."
1863 echo "Searching for bundled classes (no output if none found):"
1864 find "${WORKDIR}" -name "*.class"
1865 echo "Search done."
1866 fi
1867 touch "${T}/java-utils-2_src_prepare-run"
1868}
1869
1870# ------------------------------------------------------------------------------
1871# @eclass-pkg_preinst
1872#
1873# pkg_preinst Searches for missing and unneeded dependencies
1874# Don't call directly, but via java-pkg-2_pkg_preinst!
1875# ------------------------------------------------------------------------------
1876
1877java-utils-2_pkg_preinst() {
1878 if is-java-strict; then
1879 if has_version dev-java/java-dep-check; then
1880 [[ -e "${JAVA_PKG_ENV}" ]] || return
1881 local output=$(GENTOO_VM= java-dep-check --image "${D}" "${JAVA_PKG_ENV}")
1882 if [[ ${output} && has_version <=dev-java/java-dep-check-0.2 ]]; then
1883 ewarn "Possibly unneeded dependencies found in package.env:"
1884 for dep in ${output}; do
1885 ewarn "\t${dep}"
1886 done
1887 fi
1888 if [[ ${output} && has_version >dev-java/java-dep-check-0.2 ]]; then
1889 ewarn "${output}"
1890 fi
1891 else
1892 eerror "Install dev-java/java-dep-check for dependency checking"
1893 fi
1894 fi
1895}
1188 1896
1189# ------------------------------------------------------------------------------ 1897# ------------------------------------------------------------------------------
1190# @section-begin build 1898# @section-begin build
1191# @section-summary Build functions 1899# @section-summary Build functions
1192# 1900#
1196 1904
1197# ------------------------------------------------------------------------------ 1905# ------------------------------------------------------------------------------
1198# @ebuild-function eant 1906# @ebuild-function eant
1199# 1907#
1200# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1908# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1201# compiler. 1909# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1202# 1910# variables:
1911# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1912# gentoo.classpath property. Be sure to call
1913# java-ant_rewrite-classpath in src_unpack.
1914# EANT_NEEDS_TOOLS - add tools.jar to the gentoo.classpath. Should only be used
1915# for build-time purposes, the dependency is not recorded to
1916# package.env!
1917# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1203# ------------------------------------------------------------------------------ 1918# ------------------------------------------------------------------------------
1204eant() { 1919eant() {
1205 debug-print-function ${FUNCNAME} $* 1920 debug-print-function ${FUNCNAME} $*
1206 1921
1207 local antflags 1922 if [[ ${EBUILD_PHASE} = compile ]]; then
1923 java-ant-2_src_configure
1924 java-utils-2_src_prepare
1925 fi
1926
1927 if ! has java-ant-2 ${INHERITED}; then
1928 local msg="You should inherit java-ant-2 when using eant"
1929 java-pkg_announce-qa-violation "${msg}"
1930 fi
1931
1932 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1933
1208 java-pkg_init-compiler_ 1934 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1935 local compiler="${GENTOO_COMPILER}"
1210 1936
1211 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1937 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1212
1213 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1938 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1214 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1939 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1215 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1940 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1216 fi 1941 fi
1217 1942
1218 if [[ ${compiler} != "javac" ]]; then 1943 if [[ ${compiler} != "javac" ]]; then
1219 antflags="-Dbuild.compiler=${build_compiler}" 1944 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1220 # Figure out any extra stuff to put on the classpath for compilers aside 1945 # Figure out any extra stuff to put on the classpath for compilers aside
1221 # from javac 1946 # from javac
1222 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1947 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1223 # java-config -p 1948 # java-config -p
1224 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1949 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1225 if [[ -n ${build_compiler_deps} ]]; then 1950 if [[ -n ${build_compiler_deps} ]]; then
1226 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1951 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1227 fi 1952 fi
1228 fi 1953 fi
1229 1954
1955 for arg in "${@}"; do
1956 if [[ ${arg} = -lib ]]; then
1230 if is-java-strict; then 1957 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1958 eerror "You should not use the -lib argument to eant because it will fail"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1959 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1960 eerror "or ant properties to make dependencies available."
1961 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1962 eerror "split ant (>=dev-java/ant-core-1.7)."
1963 die "eant -lib is deprecated/forbidden"
1964 else
1965 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1966 echo "more info."
1967 fi
1233 fi 1968 fi
1234 1969 done
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1970
1236 antflags="${antflags} -debug" 1971 # parse WANT_ANT_TASKS for atoms
1972 local want_ant_tasks
1973 for i in ${WANT_ANT_TASKS}; do
1974 if [[ ${i} = */*:* ]]; then
1975 i=${i#*/}
1976 i=${i%:0}
1977 want_ant_tasks+="${i/:/-} "
1978 else
1979 want_ant_tasks+="${i} "
1237 fi 1980 fi
1238 1981 done
1982 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1983 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1984
1985 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1986 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1987
1988 # if ant-tasks is not set by ebuild or forced, use none
1989 ANT_TASKS="${ANT_TASKS:-none}"
1990
1991 # at this point, ANT_TASKS should be "all", "none" or explicit list
1992 if [[ "${ANT_TASKS}" == "all" ]]; then
1993 einfo "Using all available ANT_TASKS"
1994 elif [[ "${ANT_TASKS}" == "none" ]]; then
1995 einfo "Disabling all optional ANT_TASKS"
1996 else
1997 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1998 fi
1999
2000 export ANT_TASKS
2001
2002 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
2003 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
2004
2005 local gcp="${EANT_GENTOO_CLASSPATH}"
2006 local getjarsarg=""
2007
2008 if [[ ${EBUILD_PHASE} = "test" ]]; then
2009 antflags="${antflags} -DJunit.present=true"
2010 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
2011 getjarsarg="--with-dependencies"
2012 else
2013 antflags="${antflags} -Dmaven.test.skip=true"
2014 fi
2015
2016 local cp
2017
2018 for atom in ${gcp}; do
2019 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
2020 done
2021
2022 [[ -n "${EANT_NEEDS_TOOLS}" ]] && cp="${cp}:$(java-config --tools)"
2023
2024 if [[ ${cp} ]]; then
2025 # It seems ant does not like single quotes around ${cp}
2026 cp=${cp#:}
2027 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
2028 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
2029 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
2030 fi
2031
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 2032 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
2033 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 2034 ant ${antflags} "${@}" || die "eant failed"
1241
1242} 2035}
1243 2036
1244# ------------------------------------------------------------------------------ 2037# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 2038# @ebuild-function ejavac
1246# 2039#
1247# Javac wrapper function. Will use the appropriate compiler, based on 2040# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 2041# /etc/java-config/compilers.conf
1249# 2042#
1250# @param $@ - Arguments to be passed to the compiler 2043# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 2044# ------------------------------------------------------------------------------
1252ejavac() { 2045ejavac() {
1253 debug-print-function ${FUNCNAME} $* 2046 debug-print-function ${FUNCNAME} $*
1254 2047
1255 # FIXME using get-javac ends up printing stuff with einfo 2048 java-pkg_init-compiler_
2049
2050 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 2051 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 2052 if [[ ${?} != 0 ]]; then
2053 eerror "There was a problem determining compiler: ${compiler_executable}"
2054 die "get-javac failed"
2055 fi
1258 2056
2057 local javac_args
2058 javac_args="$(java-pkg_javac-args)"
2059 if [[ ${?} != 0 ]]; then
2060 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
2061 die "java-pkg_javac-args failed"
2062 fi
2063
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 2064 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 2065 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 2066}
1262 2067
1263# ------------------------------------------------------------------------------ 2068# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 2069# @ebuild-function java-pkg_filter-compiler
1265# 2070#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 2071# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 2072# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 2073#
1269# @param $@ - compilers to filter 2074# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 2075# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 2093# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 2094# @ebuild-function use_doc
1290# 2095#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 2096# Helper function for getting ant to build javadocs. If the user has USE=doc,
1292# then 'javadoc' or the argument are returned. Otherwise, there is no return. 2097# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 2098#
1294# The output of this should be passed to ant. 2099# The output of this should be passed to ant.
1295# 2100#
1296# Example: build javadocs by calling 'javadoc' target 2101# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 2102# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 2103# Example: build javadocs by calling 'apidoc' target
1303# ------------------------------------------------------------------------------ 2108# ------------------------------------------------------------------------------
1304use_doc() { 2109use_doc() {
1305 use doc && echo ${@:-javadoc} 2110 use doc && echo ${@:-javadoc}
1306} 2111}
1307 2112
2113
1308# ------------------------------------------------------------------------------ 2114# ------------------------------------------------------------------------------
1309# @section-end build 2115# @section-end build
1310# ------------------------------------------------------------------------------ 2116# ------------------------------------------------------------------------------
1311 2117
1312# ------------------------------------------------------------------------------ 2118# ------------------------------------------------------------------------------
1313# @section-begin internal 2119# @section-begin internal
1314# @section-summary Internal functions 2120# @section-summary Internal functions
1315# 2121#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 2122# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 2123# within the java eclasses.
1318# ------------------------------------------------------------------------------ 2124# ------------------------------------------------------------------------------
1319 2125
1320# ----------------------------------------------------------------------------- 2126# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 2127# @function-internal java-pkg_init
1322# 2128#
1323# The purpose of this function, as the name might imply, is to initialize the 2129# The purpose of this function, as the name might imply, is to initialize the
1324# Java environment. It ensures that that there aren't any environment variables 2130# Java environment. It ensures that that there aren't any environment variables
1325# that'll muss things up. It initializes some variables, which are used 2131# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 2132# internally. And most importantly, it'll switch the VM if necessary.
1327# 2133#
1328# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2134# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1329# call it during each of the phases of the merge process. 2135# call it during each of the phases of the merge process.
1330# 2136#
1331# ----------------------------------------------------------------------------- 2137# -----------------------------------------------------------------------------
1332java-pkg_init() { 2138java-pkg_init() {
2139 debug-print-function ${FUNCNAME} $*
1333 unset JAVAC 2140 unset JAVAC
1334 unset JAVA_HOME 2141 unset JAVA_HOME
2142
2143 java-config --help >/dev/null || {
2144 eerror ""
2145 eerror "Can't run java-config --help"
2146 eerror "Have you upgraded python recently but haven't"
2147 eerror "run python-updater yet?"
2148 die "Can't run java-config --help"
2149 }
2150
2151 # People do all kinds of weird things.
2152 # http://forums.gentoo.org/viewtopic-p-3943166.html
2153 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2154 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2155 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2156 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2157 ewarn "sun-jdk vms and and as such break configure scripts that"
2158 ewarn "use it (for example app-office/openoffice) so we filter it out."
2159 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2160 ewarn "make.conf for example) to silence this warning or"
2161 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2162 fi
2163
2164 if [[ -z ${accept} ]]; then
2165 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2166 # -version output
2167 unset _JAVA_OPTIONS
2168 # phase hooks make this run many times without this
2169 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2170 fi
2171
2172 if java-pkg_func-exists ant_src_unpack; then
2173 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2174 fi
2175
1335 java-pkg_init_paths_ 2176 java-pkg_init_paths_
1336 java-pkg_switch-vm 2177 java-pkg_switch-vm
1337 PATH=${JAVA_HOME}/bin:${PATH} 2178 PATH=${JAVA_HOME}/bin:${PATH}
1338 2179
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 2180 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 2181
1341 # Do some QA checks 2182 # Do some QA checks
1342 java-pkg_check-jikes 2183 java-pkg_check-jikes
1343 2184
2185 # Can't use unset here because Portage does not save the unset
2186 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
2187
1344 # When users have crazy classpaths some packages can fail to compile. 2188 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 2189 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 2190 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 2191 # from the CLASSPATH.
1348 unset CLASSPATH 2192 export CLASSPATH=
2193
2194 # Unset external ANT_ stuff
2195 export ANT_TASKS=
2196 export ANT_OPTS=
2197 export ANT_RESPECT_JAVA_HOME=
1349} 2198}
1350 2199
1351# ------------------------------------------------------------------------------ 2200# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 2201# @function-internal java-pkg-init-compiler_
1353# 2202#
1354# This function attempts to figure out what compiler should be used. It does 2203# This function attempts to figure out what compiler should be used. It does
1355# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 2204# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 2205# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 2206# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 2207#
1359# It will go through the list of compilers, and verify that it supports the 2208# It will go through the list of compilers, and verify that it supports the
1360# target and source that are needed. If it is not suitable, then the next 2209# target and source that are needed. If it is not suitable, then the next
1361# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 2210# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 2211# isn't done.
1363# 2212#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2234 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 2235 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 2236 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 2237 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 2238 fi
1390 2239
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 2240 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 2241
1393 # Figure out if we should announce what compiler we're using 2242 # Figure out if we should announce what compiler we're using
1394 local compiler 2243 local compiler
1395 for compiler in ${compilers}; do 2244 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 2247 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 2248 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 2249 export GENTOO_COMPILER="javac"
1401 break 2250 break
1402 fi 2251 fi
1403 2252
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 2253 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 2254 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 2255 einfo "Filtering ${compiler}"
1407 continue 2256 continue
1408 fi 2257 fi
1409 fi 2258 fi
1410 2259
1411 # for non-javac, we need to make sure it supports the right target and 2260 # for non-javac, we need to make sure it supports the right target and
1412 # source 2261 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 2262 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 2263 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 2264 local desired_target="$(java-pkg_get-target)"
1444 done 2293 done
1445 2294
1446 # If it hasn't been defined already, default to javac 2295 # If it hasn't been defined already, default to javac
1447 if [[ -z ${GENTOO_COMPILER} ]]; then 2296 if [[ -z ${GENTOO_COMPILER} ]]; then
1448 if [[ -n ${compilers} ]]; then 2297 if [[ -n ${compilers} ]]; then
1449 einfo "No suitable compiler found: defaulting javac for compilation" 2298 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1450 else 2299 else
1451 # probably don't need to notify users about the default. 2300 # probably don't need to notify users about the default.
1452 :;#einfo "Defaulting to javac for compilation" 2301 :;#einfo "Defaulting to javac for compilation"
1453 fi 2302 fi
2303 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2304 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2305 else
1454 export GENTOO_COMPILER=javac 2306 export GENTOO_COMPILER=javac
2307 fi
1455 else 2308 else
1456 einfo "Using ${GENTOO_COMPILER} for compilation" 2309 einfo "Using ${GENTOO_COMPILER} for compilation"
1457 fi 2310 fi
1458 2311
1459} 2312}
1475 fi 2328 fi
1476 2329
1477 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2330 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1478 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2331 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1479 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2332 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2333 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2334 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1480 2335
1481 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2336 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1482 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2337 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1483 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2338 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1484 2339
1497# Writes the package.env out to disk. 2352# Writes the package.env out to disk.
1498# 2353#
1499# ------------------------------------------------------------------------------ 2354# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 2355# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 2356java-pkg_do_write_() {
2357 debug-print-function ${FUNCNAME} $*
2358 java-pkg_init_paths_
1502 # Create directory for package.env 2359 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 2360 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2361 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2362 "${JAVA_PKG_DEPEND_FILE}" || -f \
2363 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1505 # Create package.env 2364 # Create package.env
1506 ( 2365 (
1507 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2366 echo "DESCRIPTION=\"${DESCRIPTION}\""
1508 echo "GENERATION=\"2\"" 2367 echo "GENERATION=\"2\""
2368 echo "SLOT=\"${SLOT}\""
2369 echo "CATEGORY=\"${CATEGORY}\""
2370 echo "PVR=\"${PVR}\""
1509 2371
1510 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2372 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2373 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2374 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2375 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2376 && echo "DEPEND=\"$(sort -u "${JAVA_PKG_DEPEND_FILE}" | tr '\n' ':')\""
2377 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2378 && echo "OPTIONAL_DEPEND=\"$(sort -u "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2379 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
2380 [[ -f "${JAVA_PKG_BUILD_DEPEND_FILE}" ]] \
2381 && echo "BUILD_DEPEND=\"$(sort -u "${JAVA_PKG_BUILD_DEPEND_FILE}" | tr '\n' ':')\""
1515 ) > "${JAVA_PKG_ENV}" 2382 ) > "${JAVA_PKG_ENV}"
1516 2383
1517 # register target/source 2384 # register target/source
1518 local target="$(java-pkg_get-target)" 2385 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 2386 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 2387 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 2388 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1529 2396
1530 2397
1531 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2398 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1532 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2399 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1533 2400
2401 # extra env variables
2402 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2403 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2404 # nested echo to remove leading/trailing spaces
2405 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2406 >> "${JAVA_PKG_ENV}" || die
2407 fi
2408
1534 # Strip unnecessary leading and trailing colons 2409 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 2410 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2411 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2412 else
2413 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2414 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2415 debug-print "write package.env."
1537 fi 2416 fi
1538} 2417}
1539
1540 2418
1541# ------------------------------------------------------------------------------ 2419# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 2420# @internal-function java-pkg_record-jar_
1543# 2421#
1544# Record a dependency to the package.env 2422# Record an (optional) dependency to the package.env
1545# 2423# @param --optional - record dependency as optional
2424# @param --build - record dependency as build_only
2425# @param $1 - package to record
2426# @param $2 - (optional) jar of package to record
1546# ------------------------------------------------------------------------------ 2427# ------------------------------------------------------------------------------
1547JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2428JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2429JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
2430JAVA_PKG_BUILD_DEPEND_FILE="${T}/java-pkg-build-depend"
1548 2431
1549java-pkg_record-jar_() { 2432java-pkg_record-jar_() {
1550 debug-print-function ${FUNCNAME} $* 2433 debug-print-function ${FUNCNAME} $*
2434
2435 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2436 case "${1}" in
2437 "--optional") depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"; shift;;
2438 "--build-only") depend_file="${JAVA_PKG_BUILD_DEPEND_FILE}"; shift;;
2439 esac
1551 2440
1552 local pkg=${1} jar=${2} append 2441 local pkg=${1} jar=${2} append
1553 if [[ -z "${jar}" ]]; then 2442 if [[ -z "${jar}" ]]; then
1554 append="${pkg}" 2443 append="${pkg}"
1555 else 2444 else
1556 append="$(basename ${jar})@${pkg}" 2445 append="$(basename ${jar})@${pkg}"
1557 fi 2446 fi
1558 2447
1559 echo ${append} >> ${JAVA_PKG_DEPEND} 2448 echo "${append}" >> "${depend_file}"
1560} 2449}
1561 2450
1562# ------------------------------------------------------------------------------ 2451# ------------------------------------------------------------------------------
1563# @internal-function java-pkg_append_ 2452# @internal-function java-pkg_append_
1564# 2453#
1588 fi 2477 fi
1589} 2478}
1590 2479
1591# ------------------------------------------------------------------------------ 2480# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 2481# @internal-function java-pkg_expand_dir_
1593# 2482#
1594# Gets the full path of the file/directory's parent. 2483# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 2484# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 2485# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 2486# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 2487java-pkg_expand_dir_() {
1608# 2497#
1609# @return 0 - function is declared 2498# @return 0 - function is declared
1610# @return 1 - function is undeclared 2499# @return 1 - function is undeclared
1611# ------------------------------------------------------------------------------ 2500# ------------------------------------------------------------------------------
1612java-pkg_func-exists() { 2501java-pkg_func-exists() {
1613 if [[ -n "$(declare -f ${1})" ]]; then 2502 declare -F ${1} > /dev/null
1614 return 0
1615 else
1616 return 1
1617 fi
1618} 2503}
1619 2504
1620# ------------------------------------------------------------------------------ 2505# ------------------------------------------------------------------------------
1621# @internal-function java-pkg_setup-vm 2506# @internal-function java-pkg_setup-vm
1622# 2507#
1625# ------------------------------------------------------------------------------ 2510# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 2511java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 2512 debug-print-function ${FUNCNAME} $*
1628 2513
1629 local vendor="$(java-pkg_get-vm-vendor)" 2514 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 2515 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 2516 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 2517 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 2518 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 2519 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C" 2520 addpredict "/proc/self/coredump_filter"
2521 elif [[ "${vendor}" == "oracle" ]]; then
2522 addpredict "/dev/random"
2523 addpredict "/proc/self/coredump_filter"
2524 elif [[ "${vendor}" == icedtea* ]] && java-pkg_is-vm-version-ge "1.7" ; then
2525 addpredict "/dev/random"
2526 addpredict "/proc/self/coredump_filter"
1636 elif [[ "${vendor}" == "jrockit" ]]; then 2527 elif [[ "${vendor}" == "jrockit" ]]; then
1637 addpredict "/proc/cpuinfo" 2528 addpredict "/proc/cpuinfo"
1638 fi 2529 fi
1639} 2530}
1640 2531
1647# @return 1 - Package does not depend on virtual/jdk 2538# @return 1 - Package does not depend on virtual/jdk
1648# ------------------------------------------------------------------------------ 2539# ------------------------------------------------------------------------------
1649java-pkg_needs-vm() { 2540java-pkg_needs-vm() {
1650 debug-print-function ${FUNCNAME} $* 2541 debug-print-function ${FUNCNAME} $*
1651 2542
1652 if [[ -n "$(echo ${DEPEND} | sed -e '\:virtual/jdk:!d')" ]]; then 2543 if [[ -n "$(echo ${JAVA_PKG_NV_DEPEND:-${DEPEND}} | sed -e '\:virtual/jdk:!d')" ]]; then
1653 return 0 2544 return 0
1654 fi 2545 fi
1655 2546
1656 return 1 2547 return 1
1657} 2548}
1684# @return - The version of the current VM 2575# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 2576# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 2577java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 2578 debug-print-function ${FUNCNAME} $*
1688 2579
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 2580 java-config -g PROVIDES_VERSION
1690} 2581}
1691 2582
1692# ------------------------------------------------------------------------------ 2583# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 2584# @internal-function java-pkg_switch-vm
1694# 2585#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2586# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 2587# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 2588# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 2589# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 2590java-pkg_switch-vm() {
2591 debug-print-function ${FUNCNAME} $*
2592
1700 if java-pkg_needs-vm; then 2593 if java-pkg_needs-vm; then
1701 # Use the VM specified by JAVA_PKG_FORCE_VM 2594 # Use the VM specified by JAVA_PKG_FORCE_VM
1702 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2595 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1703 # If you're forcing the VM, I hope you know what your doing... 2596 # If you're forcing the VM, I hope you know what your doing...
2597 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2598 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 2599 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2600 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1707 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2601 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1709 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2602 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
2603 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
2604 eerror "Unable to determine VM for building from dependencies:"
2605 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
2606 die "Failed to determine VM for building."
1710 else 2607 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2608 export GENTOO_VM
1712 fi 2609 fi
1713 # otherwise just make sure the current VM is sufficient 2610 # otherwise just make sure the current VM is sufficient
1714 else 2611 else
1715 java-pkg_ensure-vm-version-sufficient 2612 java-pkg_ensure-vm-version-sufficient
1716 fi 2613 fi
1717 debug-print "Using: $(java-config -f)" 2614 debug-print "Using: $(java-config -f)"
1718 2615
1719 java-pkg_setup-vm 2616 java-pkg_setup-vm
1720 2617
1721 export JAVA=$(java-config --java) 2618 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 2619 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 2620 JAVACFLAGS="$(java-pkg_javac-args)"
2621 if [[ ${?} != 0 ]]; then
2622 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
2623 die "java-pkg_javac-args failed"
2624 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 2625 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
2626 export JAVACFLAGS
1725 2627
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 2628 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 2629 export JDK_HOME=${JAVA_HOME}
1728 2630
1729 #TODO If you know a better solution let us know. 2631 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2632 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 2633
1732 local tann="${T}/announced-vm" 2634 local tann="${T}/announced-vm"
2635 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2636 # if people have for example modified eclasses some where
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2637 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1737 then
1738 einfo "Using: $(java-config -f)" 2638 einfo "Using: $(java-config -f)"
1739 [[ ! -f "${tann}" ]] && touch "${tann}" 2639 [[ ! -f "${tann}" ]] && touch "${tann}"
1740 fi
1741 fi 2640 fi
1742 2641
1743 else 2642 else
1744 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2643 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1745 fi 2644 fi
1750# 2649#
1751# Enhanced die for Java packages, which displays some information that may be 2650# Enhanced die for Java packages, which displays some information that may be
1752# useful for debugging bugs on bugzilla. 2651# useful for debugging bugs on bugzilla.
1753# ------------------------------------------------------------------------------ 2652# ------------------------------------------------------------------------------
1754#register_die_hook java-pkg_die 2653#register_die_hook java-pkg_die
1755if ! hasq java-pkg_die ${EBUILD_DEATH_HOOKS}; then 2654if ! has java-pkg_die ${EBUILD_DEATH_HOOKS}; then
1756 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die" 2655 EBUILD_DEATH_HOOKS="${EBUILD_DEATH_HOOKS} java-pkg_die"
1757fi 2656fi
1758 2657
1759java-pkg_die() { 2658java-pkg_die() {
1760 echo "!!! When you file a bug report, please include the following information:" >&2 2659 echo "!!! When you file a bug report, please include the following information:" >&2
1775 einfo "Classes" 2674 einfo "Classes"
1776 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2675 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1777 fi 2676 fi
1778} 2677}
1779 2678
1780# TODO document 2679# ------------------------------------------------------------------------------
2680# @internal-function java-pkg_verify-classes
2681#
1781# Verify that the classes were compiled for the right source / target 2682# Verify that the classes were compiled for the right source / target. Dies if
2683# not.
2684# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2685# ------------------------------------------------------------------------------
1782java-pkg_verify-classes() { 2686java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2687 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2688
2689 local version_verify="/usr/bin/class-version-verify.py"
2690
2691 if [[ ! -x "${version_verify}" ]]; then
2692 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2693 fi
2694
2695 if [[ ! -x "${version_verify}" ]]; then
2696 ewarn "Unable to perform class version checks as"
2697 ewarn "class-version-verify.py is unavailable"
2698 ewarn "Please install dev-java/javatoolkit."
2699 return
2700 fi
2701
2702 local target=$(java-pkg_get-target)
2703 local result
2704 local log="${T}/class-version-verify.log"
2705 if [[ -n "${1}" ]]; then
2706 ${version_verify} -v -t ${target} "${1}" > "${log}"
1786 result=$? 2707 result=$?
1787 eend ${result}
1788 if [[ ${result} == 0 ]]; then
1789 einfo "All good"
1790 else 2708 else
1791 ewarn "Possible problem" 2709 ebegin "Verifying java class versions (target: ${target})"
1792 die "Bad class files found" 2710 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2711 result=$?
2712 eend ${result}
2713 fi
2714 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2715 if [[ ${result} != 0 ]]; then
2716 eerror "Incorrect bytecode version found"
2717 [[ -n "${1}" ]] && eerror "in file: ${1}"
2718 eerror "See ${log} for more details."
2719 die "Incorrect bytecode found"
2720 fi
2721}
2722
2723# ----------------------------------------------------------------------------
2724# @internal-function java-pkg_ensure-dep
2725# Check that a package being used in jarfrom, getjars and getjar is contained
2726# within DEPEND or RDEPEND.
2727# @param $1 - empty - check both vars; "runtime" or "build" - check only
2728# RDEPEND, resp. DEPEND
2729# @param $2 - Package name and slot.
2730
2731java-pkg_ensure-dep() {
2732 debug-print-function ${FUNCNAME} $*
2733
2734 local limit_to="${1}"
2735 local target_pkg="${2}"
2736 local dev_error=""
2737
2738 # remove the version specification, which may include globbing (* and [123])
2739 local stripped_pkg=$(echo "${target_pkg}" | sed \
2740 's/-\([0-9*]*\(\[[0-9]*\]\)*\)*\(\.\([0-9*]*\(\[[0-9]*\]\)*\)*\)*$//')
2741
2742 debug-print "Matching against: ${stripped_pkg}"
2743
2744 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2745 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2746 dev_error="${dev_error} declared in DEPEND."
2747 if is-java-strict; then
2748 eerror "${dev_error}"
2749 die "${dev_error}"
2750 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2751 eerror "${dev_error}"
2752 elog "Because you have this package installed the package will"
2753 elog "build without problems, but please report this to"
2754 elog "http://bugs.gentoo.org"
1793 fi 2755 fi
1794} 2756 fi
1795 2757
2758 if [[ ${limit_to} != build ]]; then
2759 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2760 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2761 dev_error="The ebuild is attempting to use ${target_pkg},"
2762 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2763 dev_error="${dev_error} or PDEPEND."
2764 if is-java-strict; then
2765 eerror "${dev_error}"
2766 die "${dev_error}"
2767 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2768 eerror "${dev_error}"
2769 elog "The package will build without problems, but may fail to run"
2770 elog "if you don't have ${target_pkg} installed, so please report"
2771 elog "this to http://bugs.gentoo.org"
2772 fi
2773 fi
2774 fi
2775 fi
2776}
1796 2777
1797# ------------------------------------------------------------------------------ 2778# ------------------------------------------------------------------------------
1798# @section-end internal 2779# @section-end internal
1799# ------------------------------------------------------------------------------ 2780# ------------------------------------------------------------------------------
1800 2781
1801java-pkg_check-phase() { 2782java-pkg_check-phase() {
1802 local phase=${1} 2783 local phase=${1}
1803 local funcname=${2} 2784 local funcname=${FUNCNAME[1]}
1804 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2785 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1805 java-pkg_announce-qa-violation \
1806 "${funcname} used outside of src_${phase}" 2786 local msg="${funcname} used outside of src_${phase}"
2787 java-pkg_announce-qa-violation "${msg}"
1807 fi 2788 fi
1808} 2789}
1809 2790
1810java-pkg_check-versioned-jar() { 2791java-pkg_check-versioned-jar() {
1811 local jar=${1} 2792 local jar=${1}
1814 java-pkg_announce-qa-violation "installing versioned jar '${jar}'" 2795 java-pkg_announce-qa-violation "installing versioned jar '${jar}'"
1815 fi 2796 fi
1816} 2797}
1817 2798
1818java-pkg_check-jikes() { 2799java-pkg_check-jikes() {
1819 if hasq jikes ${IUSE}; then 2800 if has jikes ${IUSE}; then
1820 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2801 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1821 fi 2802 fi
1822} 2803}
1823 2804
1824java-pkg_announce-qa-violation() { 2805java-pkg_announce-qa-violation() {
1825 if is-java-strict; then 2806 local nodie
2807 if [[ ${1} == "--nodie" ]]; then
2808 nodie="true"
2809 shift
2810 fi
1826 echo "Java QA Notice: $@" >&2 2811 echo "Java QA Notice: $@" >&2
1827 increment-qa-violations 2812 increment-qa-violations
1828 fi 2813 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1829} 2814}
1830 2815
1831increment-qa-violations() { 2816increment-qa-violations() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 2817 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 2818 export JAVA_PKG_QA_VIOLATIONS
1834} 2819}
1835 2820
1836is-java-strict() { 2821is-java-strict() {
1837 hasq java-strict ${FEATURES}; 2822 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 2823 return $?
1839} 2824}
1840 2825
2826
1841# ------------------------------------------------------------------------------ 2827# ------------------------------------------------------------------------------
1842# @eclass-end 2828# @eclass-end
1843# ------------------------------------------------------------------------------ 2829# ------------------------------------------------------------------------------

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.147

  ViewVC Help
Powered by ViewVC 1.1.20