/[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.28 Revision 1.107
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.107 2008/05/03 21:28:45 betelgeuse 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
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
27 27
28IUSE="elibc_FreeBSD"
29
28# ----------------------------------------------------------------------------- 30# -----------------------------------------------------------------------------
29# @section-begin variables 31# @section-begin variables
30# @section-title Variables 32# @section-title Variables
31# 33#
32# Summary of variables which control the behavior of building Java packges. 34# Summary of variables which control the behavior of building Java packges.
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.
65# -----------------------------------------------------------------------------
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_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.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
49 77
50# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
52# @variable-default yes 80# @variable-default yes
53# 81#
127# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
131 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
132# TODO document me 174# TODO document me
133JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
134 176
135# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
136# @section-end variables 178# @section-end variables
143# 185#
144# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
145# libraries, etc. 187# libraries, etc.
146# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
147 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
148 230
149# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
151# 233#
152# Installs any number of jars. 234# Installs any number of jars.
171 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
172 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
173 255
174 local jar 256 local jar
175 # for each jar 257 # for each jar
176 for jar in "$@"; do 258 for jar in "${@}"; do
177 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
178 260
179 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
180 262
181 # check if it exists 263 # check if it exists
182 if [[ -e "${jar}" ]] ; then 264 if [[ -e "${jar}" ]] ; then
265 # Don't overwrite if jar has already been installed with the same
266 # name
267 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
268 if [[ -e "${dest}" ]]; then
269 ewarn "Overwriting ${dest}"
270 fi
271
183 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
184 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
185 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
186 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
187 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
188 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
189 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
199 done 291 done
200 292
201 java-pkg_do_write_ 293 java-pkg_do_write_
202} 294}
203 295
296# ------------------------------------------------------------------------------
297# @internal-function depend-java-query
298#
299# Wrapper for the depend-java-query binary to enable passing USE in env.
300# Using env variables keeps this eclass working with java-config versions that
301# do not handle use flags.
302# ------------------------------------------------------------------------------
204 303
304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
307 USE="${USE}" /usr/bin/depend-java-query "${@}"
308}
205 309
206# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
207# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
208# 312#
209# Records an already installed jar in the package.env 313# Records an already installed jar in the package.env
240 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
241 345
242 java-pkg_init_paths_ 346 java-pkg_init_paths_
243 347
244 local jar jar_dir jar_file 348 local jar jar_dir jar_file
245 for jar in "$@"; do 349 for jar in "${@}"; do
246 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
247 if [[ -e "${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
248 # nelchael: we should strip ${D} in this case too, here's why: 358 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call: 359 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 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 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
257 die "${jar} does not exist" 370 die "${jar} does not exist"
258 fi 371 fi
259 done 372 done
260 373
261 java-pkg_do_write_ 374 java-pkg_do_write_
262} 375}
263
264 376
265# ------------------------------------------------------------------------------ 377# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 378# @ebuild-function java-pkg_newjar
267# 379#
268# Installs a jar with a new name 380# Installs a jar with a new name
279 local original_jar="${1}" 391 local original_jar="${1}"
280 local new_jar="${2:-${PN}.jar}" 392 local new_jar="${2:-${PN}.jar}"
281 local new_jar_dest="${T}/${new_jar}" 393 local new_jar_dest="${T}/${new_jar}"
282 394
283 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 395 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 396 [[ ! -f ${original_jar} ]] \
397 && die "${original_jar} does not exist or is not a file!"
285 398
286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 399 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
287 cp "${original_jar}" "${new_jar_dest}" \ 400 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 401 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 402 java-pkg_dojar "${new_jar_dest}"
290} 403}
291 404
292
293# ------------------------------------------------------------------------------ 405# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 406# @ebuild-function java-pkg_addcp
295# 407#
296# Add something to the package's classpath. For jars, you should use dojar, 408# 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. 409# newjar, or regjar. This is typically used to add directories to the classpath.
301# ------------------------------------------------------------------------------ 413# ------------------------------------------------------------------------------
302java-pkg_addcp() { 414java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 415 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 416 java-pkg_do_write_
305} 417}
306
307 418
308# ------------------------------------------------------------------------------ 419# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 420# @ebuild-function java-pkg_doso
310# 421#
311# Installs any number of JNI libraries 422# Installs any number of JNI libraries
340 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
341 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
342 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
343 else 454 else
344 # TODO use dosym 455 # TODO use dosym
456 ln -s "$(readlink "${lib}")" \
345 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 457 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
346 debug-print "${lib} is a symlink, linking accordanly" 458 debug-print "${lib} is a symlink, linking accordanly"
347 fi 459 fi
348 # otherwise die 460 # otherwise die
349 else 461 else
350 die "${lib} does not exist" 462 die "${lib} does not exist"
429java-pkg_dohtml() { 541java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 542 debug-print-function ${FUNCNAME} $*
431 543
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 544 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 545
434 # TODO-nichoj find out what exactly -f package-list does 546 # from /usr/lib/portage/bin/dohtml -h
547 # -f Set list of allowed extensionless file names.
435 dohtml -f package-list "$@" 548 dohtml -f package-list "$@"
549
436 # this probably shouldn't be here but it provides 550 # this probably shouldn't be here but it provides
437 # a reasonable way to catch # docs for all of the 551 # a reasonable way to catch # docs for all of the
438 # old ebuilds. 552 # old ebuilds.
439 java-pkg_recordjavadoc 553 java-pkg_recordjavadoc
440} 554}
441 555
442# TODO document 556# ------------------------------------------------------------------------------
557# @ebuild-function java-pkg_dojavadoc
558#
559# Installs javadoc documentation. This should be controlled by the doc use flag.
560#
561# @param $1: optional --symlink creates to symlink like this for html
562# documentation bundles.
563# @param $2: - The javadoc root directory.
564#
565# @example:
566# java-pkg_dojavadoc docs/api
567# java-pkg_dojavadoc --symlink apidocs docs/api
568#
569# ------------------------------------------------------------------------------
443java-pkg_dojavadoc() { 570java-pkg_dojavadoc() {
571 debug-print-function ${FUNCNAME} $*
572
573 # For html documentation bundles that link to Javadoc
574 local symlink
575 if [[ ${1} = --symlink ]]; then
576 symlink=${2}
577 shift 2
578 fi
579
444 local dir="$1" 580 local dir="$1"
581 local dest=/usr/share/doc/${PF}/html
582
583 # QA checks
445 584
446 java-pkg_check-phase install 585 java-pkg_check-phase install
447 586
448 [[ -z "${dir}" ]] && die "Must specify a directory!" 587 [[ -z "${dir}" ]] && die "Must specify a directory!"
449 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 588 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
589 if [[ ! -e "${dir}/index.html" ]]; then
590 local msg="No index.html in javadoc directory"
591 ewarn "${msg}"
592 is-java-strict && die "${msg}"
593 fi
594
595 if [[ -e ${D}/${dest}/api ]]; then
596 eerror "${dest} already exists. Will not overwrite."
597 die "${dest}"
598 fi
599
600 # Renaming to match our directory layout
450 601
451 local dir_to_install="${dir}" 602 local dir_to_install="${dir}"
452 if [[ "$(basename "${dir}")" != "api" ]]; then 603 if [[ "$(basename "${dir}")" != "api" ]]; then
453 dir_to_install="${T}/api" 604 dir_to_install="${T}/api"
454 # TODO use doins 605 # TODO use doins
455 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 606 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
456 fi 607 fi
457 608
609 # Actual installation
610
458 java-pkg_dohtml -r ${dir_to_install} 611 java-pkg_dohtml -r "${dir_to_install}"
612
613 # Let's make a symlink to the directory we have everything else under
614 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
615
616 if [[ ${symlink} ]]; then
617 debug-print "symlinking ${dest}/{api,${symlink}}"
618 dosym ${dest}/{api,${symlink}} || die
619 fi
459} 620}
460 621
461# ------------------------------------------------------------------------------ 622# ------------------------------------------------------------------------------
462# @ebuild-function java-pkg_dosrc 623# @ebuild-function java-pkg_dosrc
463# 624#
479# FIXME apparently this fails if you give it an empty directories 640# FIXME apparently this fails if you give it an empty directories
480java-pkg_dosrc() { 641java-pkg_dosrc() {
481 debug-print-function ${FUNCNAME} $* 642 debug-print-function ${FUNCNAME} $*
482 643
483 [ ${#} -lt 1 ] && die "At least one argument needed" 644 [ ${#} -lt 1 ] && die "At least one argument needed"
484 if ! hasq source ${IUSE}; then
485 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
486 fi
487 645
488 java-pkg_check-phase install 646 java-pkg_check-phase install
489 647
490 [[ ${#} -lt 1 ]] && die "At least one argument needed" 648 [[ ${#} -lt 1 ]] && die "At least one argument needed"
649
650 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
651 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
652 java-pkg_announce-qa-violation ${msg}
653 fi
491 654
492 java-pkg_init_paths_ 655 java-pkg_init_paths_
493 656
494 local zip_name="${PN}-src.zip" 657 local zip_name="${PN}-src.zip"
495 local zip_path="${T}/${zip_name}" 658 local zip_path="${T}/${zip_name}"
496 local dir 659 local dir
497 for dir in ${@}; do 660 for dir in "${@}"; do
498 local dir_parent=$(dirname "${dir}") 661 local dir_parent=$(dirname "${dir}")
499 local dir_name=$(basename "${dir}") 662 local dir_name=$(basename "${dir}")
500 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 663 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
501 zip -q -r ${zip_path} ${dir_name} -i '*.java' 664 zip -q -r ${zip_path} ${dir_name} -i '*.java'
502 local result=$? 665 local result=$?
527# @param $1 - filename of launcher to create 690# @param $1 - filename of launcher to create
528# @param $2 - options, as follows: 691# @param $2 - options, as follows:
529# --main the.main.class.too.start 692# --main the.main.class.too.start
530# --jar /the/jar/too/launch.jar or just <name>.jar 693# --jar /the/jar/too/launch.jar or just <name>.jar
531# --java_args 'Extra arguments to pass to java' 694# --java_args 'Extra arguments to pass to java'
532# --pkg_args 'Extra arguments too pass to the package' 695# --pkg_args 'Extra arguments to pass to the package'
533# --pwd 696# --pwd Directory the launcher changes to before executing java
534# -into 697# -into Directory to install the launcher to, instead of /usr/bin
535# -pre 698# -pre Prepend contents of this file to the launcher
536# ------------------------------------------------------------------------------ 699# ------------------------------------------------------------------------------
537java-pkg_dolauncher() { 700java-pkg_dolauncher() {
538 debug-print-function ${FUNCNAME} $* 701 debug-print-function ${FUNCNAME} $*
539 702
540 java-pkg_check-phase install 703 java-pkg_check-phase install
552 local var_tmp="${T}/launcher_variables_tmp" 715 local var_tmp="${T}/launcher_variables_tmp"
553 local target_dir pre 716 local target_dir pre
554 717
555 # Process the other the rest of the arguments 718 # Process the other the rest of the arguments
556 while [[ -n "${1}" && -n "${2}" ]]; do 719 while [[ -n "${1}" && -n "${2}" ]]; do
557 local var=${1} value=${2} 720 local var="${1}" value="${2}"
558 if [[ "${var:0:2}" == "--" ]]; then 721 if [[ "${var:0:2}" == "--" ]]; then
559 local var=${var:2} 722 local var=${var:2}
560 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 723 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
561 local gjl_${var}="${value}" 724 local gjl_${var}="${value}"
562 elif [[ "${var}" == "-into" ]]; then 725 elif [[ "${var}" == "-into" ]]; then
581 fi 744 fi
582 fi 745 fi
583 746
584 # Write the actual script 747 # Write the actual script
585 echo "#!/bin/bash" > "${target}" 748 echo "#!/bin/bash" > "${target}"
586 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 749 if [[ -n "${pre}" ]]; then
750 if [[ -f "${pre}" ]]; then
751 cat "${pre}" >> "${target}"
752 else
753 die "-pre specified file '${pre}' does not exist"
754 fi
755 fi
587 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 756 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
588 cat "${var_tmp}" >> "${target}" 757 cat "${var_tmp}" >> "${target}"
589 rm -f "${var_tmp}" 758 rm -f "${var_tmp}"
590 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 759 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
591 760
683# Example: get a specific jar from xerces slot 2, and name it diffrently 852# Example: get a specific jar from xerces slot 2, and name it diffrently
684# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 853# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
685# Example: get junit.jar which is needed only for building 854# Example: get junit.jar which is needed only for building
686# java-pkg_jar-from --build-only junit junit.jar 855# java-pkg_jar-from --build-only junit junit.jar
687# 856#
688# @param $1 - (optional) "--build-only" makes the jar(s) not added into 857# @param $opt
689# package.env DEPEND line. 858# --build-only - makes the jar(s) not added into package.env DEPEND line.
690# @param $1 - Package to get jars from. 859# (assumed automatically when called inside src_test)
860# --with-dependencies - get jars also from requested package's dependencies
861# transitively.
862# --virtual - Packages passed to this function are to be handled as virtuals
863# and will not have individual jar dependencies recorded.
864# --into $dir - symlink jar(s) into $dir (must exist) instead of .
865# @param $1 - Package to get jars from, or comma-separated list of packages in
866# case other parameters are not used.
691# @param $2 - jar from package. If not specified, all jars will be used. 867# @param $2 - jar from package. If not specified, all jars will be used.
692# @param $3 - When a single jar is specified, destination filename of the 868# @param $3 - When a single jar is specified, destination filename of the
693# symlink. Defaults to the name of the jar. 869# symlink. Defaults to the name of the jar.
694# ------------------------------------------------------------------------------ 870# ------------------------------------------------------------------------------
695# TODO could probably be cleaned up a little 871# TODO could probably be cleaned up a little
696java-pkg_jar-from() { 872java-pkg_jar-from() {
697 debug-print-function ${FUNCNAME} $* 873 debug-print-function ${FUNCNAME} $*
698 874
699 local build_only="" 875 local build_only=""
876 local destdir="."
877 local deep=""
878 local virtual=""
700 879
880 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
881
882 while [[ "${1}" == --* ]]; do
701 if [[ "${1}" = "--build-only" ]]; then 883 if [[ "${1}" = "--build-only" ]]; then
702 build_only="true" 884 build_only="build"
885 elif [[ "${1}" = "--with-dependencies" ]]; then
886 deep="--with-dependencies"
887 elif [[ "${1}" = "--virtual" ]]; then
888 virtual="true"
889 elif [[ "${1}" = "--into" ]]; then
890 destdir="${2}"
891 shift
892 else
893 die "java-pkg_jar-from called with unknown parameter: ${1}"
894 fi
703 shift 895 shift
704 fi 896 done
705 897
706 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 898 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
707 899
708 [[ -z ${target_pkg} ]] && die "Must specify a package" 900 [[ -z ${target_pkg} ]] && die "Must specify a package"
901
902 if [[ "${EAPI}" == "1" ]]; then
903 target_pkg="${target_pkg//:/-}"
904 fi
709 905
710 # default destjar to the target jar 906 # default destjar to the target jar
711 [[ -z "${destjar}" ]] && destjar="${target_jar}" 907 [[ -z "${destjar}" ]] && destjar="${target_jar}"
712 908
713 local error_msg="There was a problem getting the classpath for ${target_pkg}." 909 local error_msg="There was a problem getting the classpath for ${target_pkg}."
714 local classpath 910 local classpath
715 classpath="$(java-config --classpath=${target_pkg})" 911 classpath="$(java-config ${deep} --classpath=${target_pkg})"
716 [[ $? != 0 ]] && die ${error_msg} 912 [[ $? != 0 ]] && die ${error_msg}
913
914 # When we have commas this functions is called to bring jars from multiple
915 # packages. This affects recording of dependencencies performed later
916 # which expects one package only, so we do it here.
917 if [[ ${target_pkg} = *,* ]]; then
918 for pkg in ${target_pkg//,/ }; do
919 java-pkg_ensure-dep "${build_only}" "${pkg}"
920 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
921 done
922 # setting this disables further record-jar_ calls later
923 build_only="build"
924 else
925 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
926 fi
927
928 # Record the entire virtual as a dependency so that
929 # no jars are missed.
930 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
931 java-pkg_record-jar_ "${target_pkg}"
932 # setting this disables further record-jars_ calls later
933 build_only="build"
934 fi
935
936 pushd ${destdir} > /dev/null \
937 || die "failed to change directory to ${destdir}"
717 938
718 local jar 939 local jar
719 for jar in ${classpath//:/ }; do 940 for jar in ${classpath//:/ }; do
720 local jar_name=$(basename "${jar}") 941 local jar_name=$(basename "${jar}")
721 if [[ ! -f "${jar}" ]] ; then 942 if [[ ! -f "${jar}" ]] ; then
732 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 953 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
733 [[ -f "${destjar}" ]] && rm "${destjar}" 954 [[ -f "${destjar}" ]] && rm "${destjar}"
734 ln -snf "${jar}" "${destjar}" \ 955 ln -snf "${jar}" "${destjar}" \
735 || die "Failed to make symlink from ${jar} to ${destjar}" 956 || die "Failed to make symlink from ${jar} to ${destjar}"
736 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 957 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
958 popd > /dev/null
737 return 0 959 return 0
738 fi 960 fi
739 done 961 done
962 popd > /dev/null
740 # if no target was specified, we're ok 963 # if no target was specified, we're ok
741 if [[ -z "${target_jar}" ]] ; then 964 if [[ -z "${target_jar}" ]] ; then
742 return 0 965 return 0
743 # otherwise, die bitterly 966 # otherwise, die bitterly
744 else 967 else
763# The providing packages are recorded as dependencies into package.env DEPEND 986# The providing packages are recorded as dependencies into package.env DEPEND
764# line, unless "--build-only" is passed as the very first argument, for jars 987# line, unless "--build-only" is passed as the very first argument, for jars
765# that have to be present only at build time and are not needed on runtime 988# that have to be present only at build time and are not needed on runtime
766# (junit testing etc). 989# (junit testing etc).
767# 990#
768# Example: Get the classpath for xerces-2, 991# Example: Get the classpath for xerces-2 and xalan,
769# java-pkg_getjars xerces-2 xalan 992# java-pkg_getjars xerces-2,xalan
770# Example Return: 993# Example Return:
771# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 994# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
772# 995#
773# @param $1 - (optional) "--build-only" makes the jar(s) not added into 996# @param $opt
774# package.env DEPEND line. 997# --build-only - makes the jar(s) not added into package.env DEPEND line.
998# (assumed automatically when called inside src_test)
999# --with-dependencies - get jars also from requested package's dependencies
1000# transitively.
775# @param $@ - list of packages to get jars from 1001# @param $1 - list of packages to get jars from
1002# (passed to java-config --classpath)
776# ------------------------------------------------------------------------------ 1003# ------------------------------------------------------------------------------
777java-pkg_getjars() { 1004java-pkg_getjars() {
778 debug-print-function ${FUNCNAME} $* 1005 debug-print-function ${FUNCNAME} $*
779 1006
780 local build_only="" 1007 local build_only=""
1008 local deep=""
781 1009
1010 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1011
1012 while [[ "${1}" == --* ]]; do
782 if [[ "${1}" = "--build-only" ]]; then 1013 if [[ "${1}" = "--build-only" ]]; then
783 build_only="true" 1014 build_only="build"
1015 elif [[ "${1}" = "--with-dependencies" ]]; then
1016 deep="--with-dependencies"
1017 else
1018 die "java-pkg_jar-from called with unknown parameter: ${1}"
1019 fi
784 shift 1020 shift
785 fi
786
787 [[ ${#} -lt 1 ]] && die "At least one argument needed"
788
789 # NOTE could probably just pass $@ to java-config --classpath. and return it
790 local classpath pkg
791 for pkg in ${@//,/ }; do
792 #for pkg in $(echo "$@" | tr ',' ' '); do
793 jars="$(java-config --classpath=${pkg})"
794 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
795 debug-print "${pkg}:${jars}"
796
797 if [[ -z "${classpath}" ]]; then
798 classpath="${jars}"
799 else
800 classpath="${classpath}:${jars}"
801 fi
802 # Only record jars that aren't build-only
803 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
804 done 1021 done
805 echo "${classpath}" 1022
1023 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1024
1025
1026 local pkgs="${1}"
1027
1028 if [[ "${EAPI}" == "1" ]]; then
1029 pkgs="${pkgs//:/-}"
1030 fi
1031
1032 jars="$(java-config ${deep} --classpath=${pkgs})"
1033 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
1034 debug-print "${pkgs}:${jars}"
1035
1036 for pkg in ${pkgs//,/ }; do
1037 java-pkg_ensure-dep "${build_only}" "${pkg}"
1038 done
1039
1040 # Only record jars that aren't build-only
1041 if [[ -z "${build_only}" ]]; then
1042 for pkg in ${pkgs//,/ }; do
1043 java-pkg_record-jar_ "${pkg}"
1044 done
1045 fi
1046
1047 echo "${jars}"
806} 1048}
807 1049
808# ------------------------------------------------------------------------------ 1050# ------------------------------------------------------------------------------
809# @ebuild-function java-pkg_getjar 1051# @ebuild-function java-pkg_getjar
810# 1052#
817# @example 1059# @example
818# java-pkg_getjar xerces-2 xml-apis.jar 1060# java-pkg_getjar xerces-2 xml-apis.jar
819# @example-return 1061# @example-return
820# /usr/share/xerces-2/lib/xml-apis.jar 1062# /usr/share/xerces-2/lib/xml-apis.jar
821# 1063#
822# @param $1 - (optional) "--build-only" makes the jar not added into 1064# @param $opt
823# package.env DEPEND line. 1065# --build-only - makes the jar not added into package.env DEPEND line.
1066# --virtual - Packages passed to this function are to be handled as virtuals
1067# and will not have individual jar dependencies recorded.
824# @param $1 - package to use 1068# @param $1 - package to use
825# @param $2 - jar to get 1069# @param $2 - jar to get
826# ------------------------------------------------------------------------------ 1070# ------------------------------------------------------------------------------
827java-pkg_getjar() { 1071java-pkg_getjar() {
828 debug-print-function ${FUNCNAME} $* 1072 debug-print-function ${FUNCNAME} $*
829 1073
830 local build_only="" 1074 local build_only=""
1075 local virtual=""
831 1076
1077 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1078
1079 while [[ "${1}" == --* ]]; do
832 if [[ "${1}" = "--build-only" ]]; then 1080 if [[ "${1}" = "--build-only" ]]; then
833 build_only="true" 1081 build_only="build"
1082 elif [[ "${1}" == "--virtual" ]]; then
1083 virtual="true"
1084 else
1085 die "java-pkg_getjar called with unknown parameter: ${1}"
1086 fi
834 shift 1087 shift
835 fi 1088 done
1089
1090 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
836 1091
837 local pkg="${1}" target_jar="${2}" jar 1092 local pkg="${1}" target_jar="${2}" jar
1093
1094 if [[ "${EAPI}" == "1" ]]; then
1095 pkg="${pkg//:/-}"
1096 fi
1097
838 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1098 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
839 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1099 [[ -z ${target_jar} ]] && die "Must specify jar to get"
840 1100
841 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1101 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
842 local classpath 1102 local classpath
843 classpath=$(java-config --classpath=${pkg}) 1103 classpath=$(java-config --classpath=${pkg})
844 [[ $? != 0 ]] && die ${error_msg} 1104 [[ $? != 0 ]] && die ${error_msg}
1105
1106 java-pkg_ensure-dep "${build_only}" "${pkg}"
1107
1108 # Record the package(Virtual) as a dependency and then set build_only
1109 # So that individual jars are not recorded.
1110 if [[ -n "${virtual}" ]]; then
1111 java-pkg_record-jar_ "${pkg}"
1112 build_only="true"
1113 fi
845 1114
846 for jar in ${classpath//:/ }; do 1115 for jar in ${classpath//:/ }; do
847 if [[ ! -f "${jar}" ]] ; then 1116 if [[ ! -f "${jar}" ]] ; then
848 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1117 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
849 fi 1118 fi
856 fi 1125 fi
857 done 1126 done
858 1127
859 die "Could not find ${target_jar} in ${pkg}" 1128 die "Could not find ${target_jar} in ${pkg}"
860 return 1 1129 return 1
1130}
1131
1132# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_register-dependency
1134#
1135# Registers runtime dependency on a package, list of packages, or a single jar
1136# from a package, into package.env DEPEND line. Can only be called in
1137# src_install phase.
1138# Intended for binary packages where you don't need to symlink the jars or get
1139# their classpath during build. As such, the dependencies only need to be
1140# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1141#
1142# @param $1 - comma-separated list of packages, or a single package
1143# @param $2 - if param $1 is a single package, optionally specify the jar
1144# to depend on
1145#
1146# Example: Record the dependency on whole xerces-2 and xalan,
1147# java-pkg_register-dependency xerces-2,xalan
1148# Example: Record the dependency on ant.jar from ant-core
1149# java-pkg_register-dependency ant-core ant.jar
1150#
1151# Note: Passing both list of packages as the first parameter AND specifying the
1152# jar as the second is not allowed and will cause the function to die. We assume
1153# that there's more chance one passes such combination as a mistake, than that
1154# there are more packages providing identically named jar without class
1155# collisions.
1156# ------------------------------------------------------------------------------
1157java-pkg_register-dependency() {
1158 debug-print-function ${FUNCNAME} $*
1159
1160 java-pkg_check-phase install
1161
1162 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1163
1164 local pkgs="${1}"
1165 local jar="${2}"
1166
1167 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1168
1169 if [[ "${EAPI}" == "1" ]]; then
1170 pkgs="${pkgs//:/-}"
1171 fi
1172
1173 if [[ -z "${jar}" ]]; then
1174 for pkg in ${pkgs//,/ }; do
1175 java-pkg_ensure-dep runtime "${pkg}"
1176 java-pkg_record-jar_ "${pkg}"
1177 done
1178 else
1179 [[ ${pkgs} == *,* ]] && \
1180 die "${FUNCNAME} called with both package list and jar name"
1181 java-pkg_ensure-dep runtime "${pkgs}"
1182 java-pkg_record-jar_ "${pkgs}" "${jar}"
1183 fi
1184
1185 java-pkg_do_write_
1186}
1187
1188# ------------------------------------------------------------------------------
1189# @ebuild-function java-pkg_register-optional-dependency
1190#
1191# Registers optional runtime dependency on a package, list of packages, or a
1192# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1193# called in src_install phase.
1194# Intended for packages that can use other packages when those are in classpath.
1195# Will be put on classpath by launcher if they are installed. Typical case is
1196# JDBC implementations for various databases. It's better than having USE flag
1197# for each implementation triggering hard dependency.
1198#
1199# @param $1 - comma-separated list of packages, or a single package
1200# @param $2 - if param $1 is a single package, optionally specify the jar
1201# to depend on
1202#
1203# Example: Record the optional dependency on some jdbc providers
1204# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1205#
1206# Note: Passing both list of packages as the first parameter AND specifying the
1207# jar as the second is not allowed and will cause the function to die. We assume
1208# that there's more chance one passes such combination as a mistake, than that
1209# there are more packages providing identically named jar without class
1210# collisions.
1211# ------------------------------------------------------------------------------
1212java-pkg_register-optional-dependency() {
1213 debug-print-function ${FUNCNAME} $*
1214
1215 java-pkg_check-phase install
1216
1217 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1218
1219 local pkgs="${1}"
1220 local jar="${2}"
1221
1222 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1223
1224 if [[ "${EAPI}" == "1" ]]; then
1225 pkgs="${pkgs//:/-}"
1226 fi
1227
1228 if [[ -z "${jar}" ]]; then
1229 for pkg in ${pkgs//,/ }; do
1230 java-pkg_record-jar_ --optional "${pkg}"
1231 done
1232 else
1233 [[ ${pkgs} == *,* ]] && \
1234 die "${FUNCNAME} called with both package list and jar name"
1235 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1236 fi
1237
1238 java-pkg_do_write_
1239}
1240
1241# ------------------------------------------------------------------------------
1242# @ebuild-function java-pkg_register-environment-variable
1243#
1244# Register an arbitrary environment variable into package.env. The gjl launcher
1245# for this package or any package depending on this will export it into
1246# environement before executing java command.
1247# Must only be called in src_install phase.
1248#
1249# @param $1 - variable name
1250# @param $2 - variable value
1251# ------------------------------------------------------------------------------
1252JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1253JAVA_PKG_EXTRA_ENV_VARS=""
1254java-pkg_register-environment-variable() {
1255 debug-print-function ${FUNCNAME} $*
1256
1257 java-pkg_check-phase install
1258
1259 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1260
1261 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1262 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1263
1264 java-pkg_do_write_
861} 1265}
862 1266
863# This function reads stdin, and based on that input, figures out how to 1267# This function reads stdin, and based on that input, figures out how to
864# populate jars from the filesystem. 1268# populate jars from the filesystem.
865# Need to figure out a good way of making use of this, ie be able to use a 1269# Need to figure out a good way of making use of this, ie be able to use a
982# 1386#
983# export DEPEND="${DEPEND} ${depstr}" 1387# export DEPEND="${DEPEND} ${depstr}"
984# export RDEPEND="${RDEPEND} ${depstr}" 1388# export RDEPEND="${RDEPEND} ${depstr}"
985#} 1389#}
986 1390
1391# ------------------------------------------------------------------------------
1392# @ebuild-function java-pkg_find-normal-jars
1393#
1394# Find the files with suffix .jar file in the given directory or $WORKDIR
1395#
1396# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1397# ------------------------------------------------------------------------------
1398java-pkg_find-normal-jars() {
1399 local dir=$1
1400 [[ "${dir}" ]] || dir="${WORKDIR}"
1401 local found
1402 for jar in $(find "${dir}" -name "*.jar" -type f); do
1403 echo "${jar}"
1404 found="true"
1405 done
1406 [[ "${found}" ]]
1407 return $?
1408}
1409
1410# ------------------------------------------------------------------------------
1411# @ebuild-function java-pkg_ensure-no-bundled-jars
1412#
1413# Try to locate bundled jar files in ${WORKDIR} and die if found.
987# This should be used after S has been populated with symlinks to jars 1414# This function should be called after WORKDIR has been populated with symlink
988# TODO document 1415# to system jar files or bundled jars removed.
1416# ------------------------------------------------------------------------------
989java-pkg_ensure-no-bundled-jars() { 1417java-pkg_ensure-no-bundled-jars() {
990 debug-print-function ${FUNCNAME} $* 1418 debug-print-function ${FUNCNAME} $*
991 pushd ${WORKDIR} >/dev/null 2>/dev/null
992 1419
993 local bundled_jars=$(find . -name "*.jar" -type f) 1420 local bundled_jars=$(java-pkg_find-normal-jars)
994 if [[ -n ${bundled_jars} ]]; then 1421 if [[ -n ${bundled_jars} ]]; then
995 echo "Bundled jars found:" 1422 echo "Bundled jars found:"
996 local jar 1423 local jar
997 for jar in ${bundled_jars}; do 1424 for jar in ${bundled_jars}; do
998 echo $(pwd)${jar/./} 1425 echo $(pwd)${jar/./}
999 done 1426 done
1000 die "Bundled jars found!" 1427 die "Bundled jars found!"
1001
1002 fi 1428 fi
1003 popd >/dev/null 2>/dev/null
1004} 1429}
1005 1430
1006# ------------------------------------------------------------------------------ 1431# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_ensure-vm-version-sufficient 1432# @internal-function java-pkg_ensure-vm-version-sufficient
1008# 1433#
1157# @ebuild-function java-pkg_get-target 1582# @ebuild-function java-pkg_get-target
1158# 1583#
1159# Determines what target version should be used, for passing to -target. 1584# Determines what target version should be used, for passing to -target.
1160# If you don't care about lower versions, you can set _WANT_TARGET to the 1585# If you don't care about lower versions, you can set _WANT_TARGET to the
1161# version of your JDK. 1586# version of your JDK.
1162# Remember doing this will mostly like cause things to break.
1163# Doesn't allow it to be lower then the one in depend.
1164# Doesn't allow it to be higher then the active vm.
1165# 1587#
1166# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1588# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1167# ------------------------------------------------------------------------------ 1589# ------------------------------------------------------------------------------
1168java-pkg_get-target() { 1590java-pkg_get-target() {
1169 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1170 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1171 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1172 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1173 echo ${JAVA_PKG_WANT_TARGET}
1174 else
1175 echo ${min}
1176 fi
1177 else
1178 echo ${min}
1179 fi
1180
1181 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1591 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1182} 1592}
1183 1593
1184java-pkg_get-javac() { 1594java-pkg_get-javac() {
1185 debug-print-function ${FUNCNAME} $* 1595 debug-print-function ${FUNCNAME} $*
1186 1596
1255 1665
1256# TODO document 1666# TODO document
1257java-pkg_get-jni-cflags() { 1667java-pkg_get-jni-cflags() {
1258 local flags="-I${JAVA_HOME}/include" 1668 local flags="-I${JAVA_HOME}/include"
1259 1669
1670 local platform="linux"
1671 use elibc_FreeBSD && platform="freebsd"
1672
1260 # TODO do a check that the directories are valid 1673 # TODO do a check that the directories are valid
1261 # TODO figure out how to cope with other things than linux...
1262 flags="${flags} -I${JAVA_HOME}/include/linux" 1674 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1263 1675
1264 echo ${flags} 1676 echo ${flags}
1265} 1677}
1266 1678
1267java-pkg_ensure-gcj() { 1679java-pkg_ensure-gcj() {
1273 die "No GCJ support found!" 1685 die "No GCJ support found!"
1274 fi 1686 fi
1275} 1687}
1276 1688
1277java-pkg_ensure-test() { 1689java-pkg_ensure-test() {
1278 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1690 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1691 && hasq test ${IUSE} && ! use test;
1692 then
1279 eerror "You specified FEATURES=test, but USE=test is needed" 1693 eerror "You specified FEATURES=test, but USE=test is needed"
1280 eerror "to pull in the additional dependencies for testing" 1694 eerror "to pull in the additional dependencies for testing"
1281 die "Need USE=test enabled" 1695 die "Need USE=test enabled"
1282 fi 1696 fi
1283} 1697}
1284 1698
1285# ------------------------------------------------------------------------------ 1699# ------------------------------------------------------------------------------
1700# @ebuild-function java-pkg_register-ant-task
1701#
1702# Register this package as ant task, so that ant will load it when no specific
1703# ANT_TASKS are specified. Note that even without this registering, all packages
1704# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1705# packages, but can be also used by other ebuilds that used to symlink their
1706# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1707# compatibility.
1708#
1709# @param --version x.y Register only for ant version x.y (otherwise for any ant
1710# version). Used by the ant-* packages to prevent loading of mismatched
1711# ant-core ant tasks after core was updated, before the tasks are updated,
1712# without a need for blockers.
1713# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1714# ------------------------------------------------------------------------------
1715java-pkg_register-ant-task() {
1716 local TASKS_DIR="tasks"
1717
1718 # check for --version x.y parameters
1719 while [[ -n "${1}" && -n "${2}" ]]; do
1720 local var="${1#--}"
1721 local val="${2}"
1722 if [[ "${var}" == "version" ]]; then
1723 TASKS_DIR="tasks-${val}"
1724 else
1725 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1726 fi
1727 shift 2
1728 done
1729
1730 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1731
1732 dodir /usr/share/ant/${TASKS_DIR}
1733 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1734}
1735
1736# ------------------------------------------------------------------------------
1737# @internal-function java-pkg_ant-tasks-depend
1738#
1739# Translates the WANT_ANT_TASKS variable into valid dependencies.
1740# ------------------------------------------------------------------------------
1741java-pkg_ant-tasks-depend() {
1742 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1743
1744 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1745 local DEP=""
1746 for i in ${WANT_ANT_TASKS}
1747 do
1748 if [[ ${i} != ant-* ]]; then
1749 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1750 return 1
1751 fi
1752 DEP="${DEP}dev-java/${i} "
1753 done
1754 echo ${DEP}
1755 return 0
1756 else
1757 return 0
1758 fi
1759}
1760
1761# ------------------------------------------------------------------------------
1762# @ebuild-function ejunit
1763#
1764# 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# Examples:
1768# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1769# ejunit org.blinkenlights.jid3.test.AllTests
1770#
1771# @param $1 - -cp or -classpath
1772# @param $2 - classpath; junit and recorded dependencies get appended
1773# @param $@ - the rest of the parameters are passed to java
1774# ------------------------------------------------------------------------------
1775ejunit() {
1776 debug-print-function ${FUNCNAME} $*
1777
1778 local pkgs
1779 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1780 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1781 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1782 done
1783 fi
1784
1785 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1786 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1787 cp="${2}:${cp}"
1788 shift 2
1789 else
1790 cp=".:${cp}"
1791 fi
1792
1793 local runner=junit.textui.TestRunner
1794 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1795 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1796}
1797
1798# ------------------------------------------------------------------------------
1286# @section-end helper 1799# @section-end helper
1287# ------------------------------------------------------------------------------ 1800# ------------------------------------------------------------------------------
1288 1801
1289# ------------------------------------------------------------------------------ 1802# ------------------------------------------------------------------------------
1290# @section-begin build 1803# @section-begin build
1296 1809
1297# ------------------------------------------------------------------------------ 1810# ------------------------------------------------------------------------------
1298# @ebuild-function eant 1811# @ebuild-function eant
1299# 1812#
1300# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1813# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1301# compiler. 1814# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1302# 1815# variables:
1816# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1817# gentoo.classpath property. Be sure to call
1818# java-ant_rewrite-classpath in src_unpack.
1819# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1820# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1303# ------------------------------------------------------------------------------ 1821# ------------------------------------------------------------------------------
1304eant() { 1822eant() {
1305 debug-print-function ${FUNCNAME} $* 1823 debug-print-function ${FUNCNAME} $*
1306 1824
1307 # FIXME get this working 1825 if [[ ${EBUILD_PHASE} = compile ]]; then
1308# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1826 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1827 # finally get rid of the hooks without breaking stuff
1828
1829 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1830 && java-ant_ignore-system-classes "${S}/build.xml"
1831
1832 if hasq java-ant-2 ${INHERITED}; then
1833 java-ant_bsfix
1834 fi
1835
1836 # eant can be called multiple times
1837 JAVA_PKG_BSFIX="off"
1838
1839 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1840 echo "Searching for bundled jars:"
1841 java-pkg_find-normal-jars || echo "None found."
1842 echo "Searching for bundled classes (no output if none found):"
1843 find "${WORKDIR}" -name "*.class"
1844 echo "Search done."
1845 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1846 fi
1847 fi
1848
1849 if ! hasq java-ant-2 ${INHERITED}; then
1850 local msg="You should inherit java-ant-2 when using eant"
1309# java-pkg_announce-qa-violation \ 1851 java-pkg_announce-qa-violation "${msg}"
1310# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1311# fi 1852 fi
1312 1853
1313 local antflags 1854 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1855
1314 java-pkg_init-compiler_ 1856 java-pkg_init-compiler_
1315 local compiler="${GENTOO_COMPILER}" 1857 local compiler="${GENTOO_COMPILER}"
1316 1858
1317 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1859 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1318
1319 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1860 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1320 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1861 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1321 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1862 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1322 fi 1863 fi
1323 1864
1324 if [[ ${compiler} != "javac" ]]; then 1865 if [[ ${compiler} != "javac" ]]; then
1325 antflags="-Dbuild.compiler=${build_compiler}" 1866 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1326 # Figure out any extra stuff to put on the classpath for compilers aside 1867 # Figure out any extra stuff to put on the classpath for compilers aside
1327 # from javac 1868 # from javac
1328 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1869 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1329 # java-config -p 1870 # java-config -p
1330 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1871 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1331 if [[ -n ${build_compiler_deps} ]]; then 1872 if [[ -n ${build_compiler_deps} ]]; then
1332 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1873 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1333 fi 1874 fi
1334 fi 1875 fi
1335 1876
1877 for arg in "${@}"; do
1878 if [[ ${arg} = -lib ]]; then
1336 if is-java-strict; then 1879 if is-java-strict; then
1337 einfo "Disabling system classpath for ant" 1880 eerror "You should not use the -lib argument to eant because it will fail"
1338 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1881 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1882 eerror "or ant properties to make dependencies available."
1883 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1884 eerror "split ant (>=dev-java/ant-core-1.7)."
1885 die "eant -lib is deprecated/forbidden"
1886 else
1887 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1888 echo "more info."
1889 fi
1339 fi 1890 fi
1891 done
1340 1892
1341 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1893 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1342 antflags="${antflags} -debug" 1894 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1895
1896 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1897 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1898
1899 # if ant-tasks is not set by ebuild or forced, use none
1900 ANT_TASKS="${ANT_TASKS:-none}"
1901
1902 # at this point, ANT_TASKS should be "all", "none" or explicit list
1903 if [[ "${ANT_TASKS}" == "all" ]]; then
1904 einfo "Using all available ANT_TASKS"
1905 elif [[ "${ANT_TASKS}" == "none" ]]; then
1906 einfo "Disabling all optional ANT_TASKS"
1907 else
1908 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1909 fi
1910
1911 export ANT_TASKS
1912
1913 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1914 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1915
1916 local gcp="${EANT_GENTOO_CLASSPATH}"
1917 local getjarsarg=""
1918
1919 if [[ ${EBUILD_PHASE} = "test" ]]; then
1920 antflags="${antflags} -DJunit.present=true"
1921 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1922 getjarsarg="--with-dependencies"
1923 fi
1924
1925 local cp
1926
1927 for atom in ${gcp}; do
1928 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1929 done
1930
1931 if [[ ${cp} ]]; then
1932 # It seems ant does not like single quotes around ${cp}
1933 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1343 fi 1934 fi
1344 1935
1345 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1936 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1937 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1346 ant ${antflags} "${@}" || die "eant failed" 1938 ant ${antflags} "${@}" || die "eant failed"
1347
1348} 1939}
1349 1940
1350# ------------------------------------------------------------------------------ 1941# ------------------------------------------------------------------------------
1351# @ebuild-function ejavac 1942# @ebuild-function ejavac
1352# 1943#
1421# ------------------------------------------------------------------------------ 2012# ------------------------------------------------------------------------------
1422use_doc() { 2013use_doc() {
1423 use doc && echo ${@:-javadoc} 2014 use doc && echo ${@:-javadoc}
1424} 2015}
1425 2016
2017
1426# ------------------------------------------------------------------------------ 2018# ------------------------------------------------------------------------------
1427# @section-end build 2019# @section-end build
1428# ------------------------------------------------------------------------------ 2020# ------------------------------------------------------------------------------
1429 2021
1430# ------------------------------------------------------------------------------ 2022# ------------------------------------------------------------------------------
1446# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2038# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1447# call it during each of the phases of the merge process. 2039# call it during each of the phases of the merge process.
1448# 2040#
1449# ----------------------------------------------------------------------------- 2041# -----------------------------------------------------------------------------
1450java-pkg_init() { 2042java-pkg_init() {
2043 debug-print-function ${FUNCNAME} $*
1451 unset JAVAC 2044 unset JAVAC
1452 unset JAVA_HOME 2045 unset JAVA_HOME
2046
2047 # People do all kinds of weird things.
2048 # http://forums.gentoo.org/viewtopic-p-3943166.html
2049 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2050 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2051 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2052 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2053 ewarn "sun-jdk vms and and as such break configure scripts that"
2054 ewarn "use it (for example app-office/openoffice) so we filter it out."
2055 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2056 ewarn "make.conf for example) to silence this warning or"
2057 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2058 fi
2059
2060 if [[ -z ${accept} ]]; then
2061 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2062 # -version output
2063 unset _JAVA_OPTIONS
2064 # phase hooks make this run many times without this
2065 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2066 fi
2067
2068 if java-pkg_func-exists ant_src_unpack; then
2069 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2070 fi
2071
1453 java-pkg_init_paths_ 2072 java-pkg_init_paths_
1454 java-pkg_switch-vm 2073 java-pkg_switch-vm
1455 PATH=${JAVA_HOME}/bin:${PATH} 2074 PATH=${JAVA_HOME}/bin:${PATH}
1456 2075
1457 # TODO we will probably want to set JAVAC and JAVACFLAGS 2076 # TODO we will probably want to set JAVAC and JAVACFLAGS
1458 2077
1459 # Do some QA checks 2078 # Do some QA checks
1460 java-pkg_check-jikes 2079 java-pkg_check-jikes
2080
2081 # Can't use unset here because Portage does not save the unset
2082 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1461 2083
1462 # When users have crazy classpaths some packages can fail to compile. 2084 # When users have crazy classpaths some packages can fail to compile.
1463 # and everything should work with empty CLASSPATH. 2085 # and everything should work with empty CLASSPATH.
1464 # This also helps prevent unexpected dependencies on random things 2086 # This also helps prevent unexpected dependencies on random things
1465 # from the CLASSPATH. 2087 # from the CLASSPATH.
1466 unset CLASSPATH 2088 export CLASSPATH=
2089
2090 # Unset external ANT_ stuff
2091 export ANT_TASKS=
2092 export ANT_OPTS=
1467} 2093}
1468 2094
1469# ------------------------------------------------------------------------------ 2095# ------------------------------------------------------------------------------
1470# @function-internal java-pkg-init-compiler_ 2096# @function-internal java-pkg-init-compiler_
1471# 2097#
1562 done 2188 done
1563 2189
1564 # If it hasn't been defined already, default to javac 2190 # If it hasn't been defined already, default to javac
1565 if [[ -z ${GENTOO_COMPILER} ]]; then 2191 if [[ -z ${GENTOO_COMPILER} ]]; then
1566 if [[ -n ${compilers} ]]; then 2192 if [[ -n ${compilers} ]]; then
1567 einfo "No suitable compiler found: defaulting javac for compilation" 2193 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1568 else 2194 else
1569 # probably don't need to notify users about the default. 2195 # probably don't need to notify users about the default.
1570 :;#einfo "Defaulting to javac for compilation" 2196 :;#einfo "Defaulting to javac for compilation"
1571 fi 2197 fi
2198 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2199 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2200 else
1572 export GENTOO_COMPILER=javac 2201 export GENTOO_COMPILER=javac
2202 fi
1573 else 2203 else
1574 einfo "Using ${GENTOO_COMPILER} for compilation" 2204 einfo "Using ${GENTOO_COMPILER} for compilation"
1575 fi 2205 fi
1576 2206
1577} 2207}
1593 fi 2223 fi
1594 2224
1595 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2225 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1596 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2226 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1597 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2227 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2228 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2229 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1598 2230
1599 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2231 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1600 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2232 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1601 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2233 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1602 2234
1615# Writes the package.env out to disk. 2247# Writes the package.env out to disk.
1616# 2248#
1617# ------------------------------------------------------------------------------ 2249# ------------------------------------------------------------------------------
1618# TODO change to do-write, to match everything else 2250# TODO change to do-write, to match everything else
1619java-pkg_do_write_() { 2251java-pkg_do_write_() {
2252 debug-print-function ${FUNCNAME} $*
1620 java-pkg_init_paths_ 2253 java-pkg_init_paths_
1621 # Create directory for package.env 2254 # Create directory for package.env
1622 dodir "${JAVA_PKG_SHAREPATH}" 2255 dodir "${JAVA_PKG_SHAREPATH}"
1623 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2256 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2257 "${JAVA_PKG_DEPEND_FILE}" || -f \
2258 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1624 # Create package.env 2259 # Create package.env
1625 ( 2260 (
1626 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2261 echo "DESCRIPTION=\"${DESCRIPTION}\""
1627 echo "GENERATION=\"2\"" 2262 echo "GENERATION=\"2\""
2263 echo "SLOT=\"${SLOT}\""
1628 2264
1629 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2265 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1630 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2266 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1631 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2267 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1632 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2268 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2269 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2270 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2271 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1633 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2272 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1634 ) > "${JAVA_PKG_ENV}" 2273 ) > "${JAVA_PKG_ENV}"
1635 2274
1636 # register target/source 2275 # register target/source
1637 local target="$(java-pkg_get-target)" 2276 local target="$(java-pkg_get-target)"
1648 2287
1649 2288
1650 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2289 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1651 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2290 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1652 2291
2292 # extra env variables
2293 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2294 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2295 # nested echo to remove leading/trailing spaces
2296 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2297 >> "${JAVA_PKG_ENV}" || die
2298 fi
2299
1653 # Strip unnecessary leading and trailing colons 2300 # Strip unnecessary leading and trailing colons
1654 # TODO try to cleanup if possible 2301 # TODO try to cleanup if possible
1655 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2302 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2303 else
2304 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2305 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2306 debug-print "write package.env."
1656 fi 2307 fi
1657} 2308}
1658 2309
1659# ------------------------------------------------------------------------------ 2310# ------------------------------------------------------------------------------
1660# @internal-function java-pkg_record-jar_ 2311# @internal-function java-pkg_record-jar_
1661# 2312#
1662# Record a dependency to the package.env 2313# Record an (optional) dependency to the package.env
1663# 2314# @param --optional - record dependency as optional
2315# @param $1 - package to record
2316# @param $2 - (optional) jar of package to record
1664# ------------------------------------------------------------------------------ 2317# ------------------------------------------------------------------------------
1665JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2318JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2319JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1666 2320
1667java-pkg_record-jar_() { 2321java-pkg_record-jar_() {
1668 debug-print-function ${FUNCNAME} $* 2322 debug-print-function ${FUNCNAME} $*
2323
2324 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2325 if [[ "${1}" == "--optional" ]]; then
2326 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2327 shift
2328 fi
1669 2329
1670 local pkg=${1} jar=${2} append 2330 local pkg=${1} jar=${2} append
1671 if [[ -z "${jar}" ]]; then 2331 if [[ -z "${jar}" ]]; then
1672 append="${pkg}" 2332 append="${pkg}"
1673 else 2333 else
1674 append="$(basename ${jar})@${pkg}" 2334 append="$(basename ${jar})@${pkg}"
1675 fi 2335 fi
1676 2336
1677 echo ${append} >> ${JAVA_PKG_DEPEND} 2337 echo "${append}" >> "${depend_file}"
1678} 2338}
1679 2339
1680# ------------------------------------------------------------------------------ 2340# ------------------------------------------------------------------------------
1681# @internal-function java-pkg_append_ 2341# @internal-function java-pkg_append_
1682# 2342#
1742# 2402#
1743# ------------------------------------------------------------------------------ 2403# ------------------------------------------------------------------------------
1744java-pkg_setup-vm() { 2404java-pkg_setup-vm() {
1745 debug-print-function ${FUNCNAME} $* 2405 debug-print-function ${FUNCNAME} $*
1746 2406
2407 export LANG="C" LC_ALL="C"
2408
1747 local vendor="$(java-pkg_get-vm-vendor)" 2409 local vendor="$(java-pkg_get-vm-vendor)"
1748 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2410 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1749 addpredict "/dev/random" 2411 addpredict "/dev/random"
1750 elif [[ "${vendor}" == "ibm" ]]; then 2412 elif [[ "${vendor}" == "ibm" ]]; then
1751 addpredict "/proc/self/maps" 2413 addpredict "/proc/self/maps"
1752 addpredict "/proc/cpuinfo" 2414 addpredict "/proc/cpuinfo"
1753 export LANG="C" LC_ALL="C"
1754 elif [[ "${vendor}" == "jrockit" ]]; then 2415 elif [[ "${vendor}" == "jrockit" ]]; then
1755 addpredict "/proc/cpuinfo" 2416 addpredict "/proc/cpuinfo"
1756 fi 2417 fi
1757} 2418}
1758 2419
1813# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2474# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1814# verify that the current VM is sufficient. 2475# verify that the current VM is sufficient.
1815# Setup the environment for the VM being used. 2476# Setup the environment for the VM being used.
1816# ------------------------------------------------------------------------------ 2477# ------------------------------------------------------------------------------
1817java-pkg_switch-vm() { 2478java-pkg_switch-vm() {
2479 debug-print-function ${FUNCNAME} $*
2480
1818 if java-pkg_needs-vm; then 2481 if java-pkg_needs-vm; then
1819 # Use the VM specified by JAVA_PKG_FORCE_VM 2482 # Use the VM specified by JAVA_PKG_FORCE_VM
1820 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2483 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1821 # If you're forcing the VM, I hope you know what your doing... 2484 # If you're forcing the VM, I hope you know what your doing...
2485 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1822 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2486 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1823 # if we're allowed to switch the vm... 2487 # if we're allowed to switch the vm...
1824 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2488 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1825 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2489 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1826 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2490 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1827 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2491 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1828 else 2492 else
1829 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 2493 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1830 fi 2494 fi
1831 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then 2495 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1832 eerror "Unable to determine VM for building from dependencies." 2496 eerror "Unable to determine VM for building from dependencies:"
1833 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}" 2497 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1834 echo "VNEED: ${JAVA_PKG_VNEED}" 2498 echo "VNEED: ${JAVA_PKG_VNEED}"
2499 die "Failed to determine VM for building."
1835 else 2500 else
1836 export GENTOO_VM 2501 export GENTOO_VM
1837 fi 2502 fi
1838 # otherwise just make sure the current VM is sufficient 2503 # otherwise just make sure the current VM is sufficient
1839 else 2504 else
1858 2523
1859 #TODO If you know a better solution let us know. 2524 #TODO If you know a better solution let us know.
1860 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2525 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1861 2526
1862 local tann="${T}/announced-vm" 2527 local tann="${T}/announced-vm"
2528 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2529 # if people have for example modified eclasses some where
1863 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2530 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1864 # Add a check for setup/preinst phase... to avoid duplicate outputs
1865 # for when FEATURES=buildpkg
1866 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1867 then
1868 einfo "Using: $(java-config -f)" 2531 einfo "Using: $(java-config -f)"
1869 [[ ! -f "${tann}" ]] && touch "${tann}" 2532 [[ ! -f "${tann}" ]] && touch "${tann}"
1870 fi
1871 fi 2533 fi
1872 2534
1873 else 2535 else
1874 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2536 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1875 fi 2537 fi
1905 einfo "Classes" 2567 einfo "Classes"
1906 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2568 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1907 fi 2569 fi
1908} 2570}
1909 2571
1910# TODO document 2572# ------------------------------------------------------------------------------
2573# @internal-function java-pkg_verify-classes
2574#
1911# Verify that the classes were compiled for the right source / target 2575# Verify that the classes were compiled for the right source / target. Dies if
2576# not.
2577# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2578# ------------------------------------------------------------------------------
1912java-pkg_verify-classes() { 2579java-pkg_verify-classes() {
1913 ebegin "Verifying java class versions"
1914 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2580 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1915 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2581 local target=$(java-pkg_get-target)
2582 local result
2583 local log="${T}/class-version-verify.log"
2584 if [[ -n "${1}" ]]; then
2585 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1916 result=$? 2586 result=$?
1917 eend ${result}
1918 if [[ ${result} == 0 ]]; then
1919 einfo "All good"
1920 else 2587 else
1921 ewarn "Possible problem" 2588 ebegin "Verifying java class versions (target: ${target})"
1922 die "Bad class files found" 2589 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2590 result=$?
2591 eend ${result}
2592 fi
2593 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2594 if [[ ${result} != 0 ]]; then
2595 eerror "Incorrect bytecode version found"
2596 [[ -n "${1}" ]] && eerror "in file: ${1}"
2597 eerror "See ${log} for more details."
2598 die "Incorrect bytecode found"
2599 fi
2600}
2601
2602# ----------------------------------------------------------------------------
2603# @internal-function java-pkg_ensure-dep
2604# Check that a package being used in jarfrom, getjars and getjar is contained
2605# within DEPEND or RDEPEND.
2606# @param $1 - empty - check both vars; "runtime" or "build" - check only
2607# RDEPEND, resp. DEPEND
2608# @param $2 - Package name and slot.
2609
2610java-pkg_ensure-dep() {
2611 debug-print-function ${FUNCNAME} $*
2612
2613 local limit_to="${1}"
2614 local target_pkg="${2}"
2615 local dev_error=""
2616
2617 local stripped_pkg=$(echo "${target_pkg}" | sed \
2618 's/-[0-9]*\(\.[0-9]\)*$//')
2619
2620 debug-print "Matching against: ${stripped_pkg}"
2621
2622 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2623 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2624 dev_error="${dev_error} declared in DEPEND."
2625 if is-java-strict; then
2626 eerror "${dev_error}"
2627 die "${dev_error}"
2628 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2629 eerror "${dev_error}"
2630 elog "Because you have this package installed the package will"
2631 elog "build without problems, but please report this to"
2632 elog "http://bugs.gentoo.org"
2633 fi
2634 fi
2635
2636 if [[ ${limit_to} != build ]]; then
2637 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2638 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2639 dev_error="The ebuild is attempting to use ${target_pkg},"
2640 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2641 dev_error="${dev_error} or PDEPEND."
2642 if is-java-strict; then
2643 eerror "${dev_error}"
2644 die "${dev_error}"
2645 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2646 eerror "${dev_error}"
2647 elog "The package will build without problems, but may fail to run"
2648 elog "if you don't have ${target_pkg} installed, so please report"
2649 elog "this to http://bugs.gentoo.org"
2650 fi
2651 fi
2652 fi
1923 fi 2653 fi
1924} 2654}
1925 2655
1926# ------------------------------------------------------------------------------ 2656# ------------------------------------------------------------------------------
1927# @section-end internal 2657# @section-end internal
1928# ------------------------------------------------------------------------------ 2658# ------------------------------------------------------------------------------
1929 2659
1930java-pkg_check-phase() { 2660java-pkg_check-phase() {
1931 local phase=${1} 2661 local phase=${1}
1932 local funcname=${2} 2662 local funcname=${FUNCNAME[1]}
1933 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2663 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1934 java-pkg_announce-qa-violation \
1935 "${funcname} used outside of src_${phase}" 2664 local msg="${funcname} used outside of src_${phase}"
2665 java-pkg_announce-qa-violation "${msg}"
1936 fi 2666 fi
1937} 2667}
1938 2668
1939java-pkg_check-versioned-jar() { 2669java-pkg_check-versioned-jar() {
1940 local jar=${1} 2670 local jar=${1}
1949 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2679 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1950 fi 2680 fi
1951} 2681}
1952 2682
1953java-pkg_announce-qa-violation() { 2683java-pkg_announce-qa-violation() {
1954 if is-java-strict; then 2684 local nodie
2685 if [[ ${1} == "--nodie" ]]; then
2686 nodie="true"
2687 shift
2688 fi
1955 echo "Java QA Notice: $@" >&2 2689 echo "Java QA Notice: $@" >&2
1956 increment-qa-violations 2690 increment-qa-violations
1957 fi 2691 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1958} 2692}
1959 2693
1960increment-qa-violations() { 2694increment-qa-violations() {
1961 let "JAVA_PKG_QA_VIOLATIONS+=1" 2695 let "JAVA_PKG_QA_VIOLATIONS+=1"
1962 export JAVA_PKG_QA_VIOLATIONS 2696 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.107

  ViewVC Help
Powered by ViewVC 1.1.20