/[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.31
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# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.31 2006/12/03 18:41:25 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 15# @eclass-maintainer java@gentoo.org
15# 16#
16# This eclass provides functionality which is used by 17# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 18# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 19#
19# @warning 20# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 21# 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 22# 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. 23# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 24#
24# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
25 26
26inherit eutils versionator multilib 27inherit eutils versionator multilib
40 41
41# ----------------------------------------------------------------------------- 42# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 43# @variable-internal JAVA_PKG_E_DEPEND
43# 44#
44# This is a convience variable to be used from the other java eclasses. This is 45# 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 46# the version of java-config we want to use. We also need a recent version
46# portage, that includes phase hooks. 47# portage, that includes phase hooks.
47# ----------------------------------------------------------------------------- 48# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 49JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
49 50
50# ----------------------------------------------------------------------------- 51# -----------------------------------------------------------------------------
100# ----------------------------------------------------------------------------- 101# -----------------------------------------------------------------------------
101 102
102# ----------------------------------------------------------------------------- 103# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 104# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 105# @default /usr/share/java-config-2/compiler
105# 106#
106# Directory where compiler settings are saved, without trailing slash. 107# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 108# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 109# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 110JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 111
120 121
121# ----------------------------------------------------------------------------- 122# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 123# @variable-external JAVA_PKG_FORCE_COMPILER
123# 124#
124# Explicitly set a list of compilers to use. This is normally read from 125# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 126# JAVA_PKG_COMPILERS_CONF.
126# 127#
127# @note This should only be used internally or for testing. 128# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 129# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 130# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 131# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 151# @ebuild-function java-pkg_dojar
151# 152#
152# Installs any number of jars. 153# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 154# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 155# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 156# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 157# Instead, use java-pkg_newjar defined below.
157# 158#
158# @example 159# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 160# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 161#
222# will not work, because: 223# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 224# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 225# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 226# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 227# doesn't exist
227# 228#
228# you have to use it as: 229# you have to use it as:
229# 230#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 231# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 232#
232# @param $@ - jars to record 233# @param $@ - jars to record
287 cp "${original_jar}" "${new_jar_dest}" \ 288 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 289 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 290 java-pkg_dojar "${new_jar_dest}"
290} 291}
291 292
292
293# ------------------------------------------------------------------------------ 293# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 294# @ebuild-function java-pkg_addcp
295# 295#
296# Add something to the package's classpath. For jars, you should use dojar, 296# 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. 297# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 302java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 304 java-pkg_do_write_
305} 305}
306 306
307
308# ------------------------------------------------------------------------------ 307# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 308# @ebuild-function java-pkg_doso
310# 309#
311# Installs any number of JNI libraries 310# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 311# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 312# can be used change this path
314# 313#
315# Example: 314# Example:
370 java-pkg_check-phase install 369 java-pkg_check-phase install
371 370
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 371 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 372
374 java-pkg_init_paths_ 373 java-pkg_init_paths_
375 374
376 local lib target_dir 375 local lib target_dir
377 for lib in "$@" ; do 376 for lib in "$@" ; do
378 # Check the absolute path of the lib 377 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 378 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 379 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 427# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 428java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 429 debug-print-function ${FUNCNAME} $*
431 430
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 431 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 432
433 # from /usr/lib/portage/bin/dohtml -h
434 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 435 dohtml -f package-list "$@"
436
435 # this probably shouldn't be here but it provides 437 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 438 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 439 # old ebuilds.
438 java-pkg_recordjavadoc 440 java-pkg_recordjavadoc
439} 441}
440 442
441# TODO document 443# ------------------------------------------------------------------------------
444# @ebuild-function java-pkg_dojavadoc
445#
446# Installs javadoc documentation. This should be controlled by the doc use flag.
447#
448# @param $1: - The javadoc root directory.
449#
450# @example:
451# java-pkg_dojavadoc docs/api
452#
453# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 454java-pkg_dojavadoc() {
443 local dir="$1" 455 local dir="$1"
444 456
445 java-pkg_check-phase install 457 java-pkg_check-phase install
446 458
458} 470}
459 471
460# ------------------------------------------------------------------------------ 472# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 473# @ebuild-function java-pkg_dosrc
462# 474#
463# Installs a zip containing the source for a package, so it can used in 475# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 476# from IDEs like eclipse and netbeans.
465# 477#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 478# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 479#
468# It also should be controlled by USE=source. 480# It also should be controlled by USE=source.
469# 481#
470# @example: 482# @example:
471# java-pkg_dosrc src/* 483# java-pkg_dosrc src/*
472# 484#
473# ------------------------------------------------------------------------------ 485# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 486# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 487# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 488# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 489# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 490# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 491java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 492 debug-print-function ${FUNCNAME} $*
481 493
482 [ ${#} -lt 1 ] && die "At least one argument needed" 494 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 495 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 496 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 497 fi
486 498
487 java-pkg_check-phase install 499 java-pkg_check-phase install
488 500
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 501 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 502
491 java-pkg_init_paths_ 503 java-pkg_init_paths_
492 504
493 local zip_name="${PN}-src.zip" 505 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 506 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 530# @ebuild-function java-pkg_dolauncher
519# 531#
520# Make a wrapper script to lauch/start this package 532# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 533# If necessary, the wrapper will switch to the appropriate VM.
522# 534#
535# Can be called without parameters if the package installs only one jar
536# that has the Main-class attribute set. The wrapper will be named ${PN}.
537#
523# @param $1 - filename of launcher to create 538# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 539# @param $2 - options, as follows:
525# --main the.main.class.too.start 540# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 541# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 542# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 543# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 544# --pwd
530# -into 545# -into
531# -pre 546# -pre
532# ------------------------------------------------------------------------------ 547# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 548java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 549 debug-print-function ${FUNCNAME} $*
535 550
536 java-pkg_check-phase install 551 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 552 java-pkg_init_paths_
541 553
554 if [[ ${#} = 0 ]]; then
555 local name="${PN}"
556 else
542 local name="${1}" 557 local name="${1}"
558 shift
559 fi
560
543 # TODO rename to launcher 561 # TODO rename to launcher
544 local target="${T}/${name}" 562 local target="${T}/${name}"
563 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 564 local target_dir pre
546 shift
547 565
548 echo "#!/bin/bash" > "${target}" 566 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 567 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 568 local var=${1} value=${2}
551 if [[ "${var:0:2}" == "--" ]]; then 569 if [[ "${var:0:2}" == "--" ]]; then
570 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 571 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
572 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 573 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 574 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 575 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 576 pre="${value}"
557 fi 577 fi
558 shift 2 578 shift 2
559 done 579 done
580
581 # Test if no --jar and --main arguments were given and
582 # in that case check if the package only installs one jar
583 # and use that jar.
584 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
585 local cp="${JAVA_PKG_CLASSPATH}"
586 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
587 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
588 else
589 local msg="Not enough information to create a launcher given."
590 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
591 die "${msg}"
592 fi
593 fi
594
595 # Write the actual script
596 echo "#!/bin/bash" > "${target}"
597 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 598 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 599 cat "${var_tmp}" >> "${target}"
600 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 601 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 602
564 if [[ -n "${into}" ]]; then 603 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 604 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 605 local ret=$?
567 return ${ret} 606 return ${ret}
568 else 607 else
569 dobin "${target}" 608 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 636 echo "dowar: warning, skipping directory ${war}"
598 continue 637 continue
599 else 638 else
600 warpath="${war}" 639 warpath="${war}"
601 fi 640 fi
602 641
603 # Install those files like you mean it 642 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 643 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 644 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 645 doins ${warpath}
607 done 646 done
642# @ebuild-function java-pkg_jar-from 681# @ebuild-function java-pkg_jar-from
643# 682#
644# Makes a symlink to a jar from a certain package 683# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 684# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 685# You can use this function to replace these bundled dependencies.
686# The dependency is recorded into package.env DEPEND line, unless "--build-only"
687# is passed as the very first argument, for jars that have to be present only
688# at build time and are not needed on runtime (junit testing etc).
647# 689#
648# Example: get all jars from xerces slot 2 690# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 691# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 692# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 693# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 694# 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 695# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
696# Example: get junit.jar which is needed only for building
697# java-pkg_jar-from --build-only junit junit.jar
654# 698#
699# @param $1 - (optional) "--build-only" makes the jar(s) not added into
700# package.env DEPEND line.
655# @param $1 - Package to get jars from. 701# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 702# @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 703# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 704# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 705# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 706# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 707java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 708 debug-print-function ${FUNCNAME} $*
663 709
710 local build_only=""
711
712 if [[ "${1}" = "--build-only" ]]; then
713 build_only="true"
714 shift
715 fi
716
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 717 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 718
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 719 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 720
668 # default destjar to the target jar 721 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 722 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 723
724 local error_msg="There was a problem getting the classpath for ${target_pkg}."
725 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 726 classpath="$(java-config --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 727 [[ $? != 0 ]] && die ${error_msg}
673 728
674 local jar 729 local jar
675 for jar in ${classpath//:/ }; do 730 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 731 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 732 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 736 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 737 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 738 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 739 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 740 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 741 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 742 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 743 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 744 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 745 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 746 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 747 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 748 return 0
694 fi 749 fi
695 done 750 done
696 # if no target was specified, we're ok 751 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 752 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 769# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 770# @ebuild-function java-pkg_getjars
716# 771#
717# Get the classpath provided by any number of packages 772# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 773# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
774# The providing packages are recorded as dependencies into package.env DEPEND
775# line, unless "--build-only" is passed as the very first argument, for jars
776# that have to be present only at build time and are not needed on runtime
777# (junit testing etc).
719# 778#
720# Example: Get the classpath for xerces-2, 779# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 780# java-pkg_getjars xerces-2,xalan
722# Example Return: 781# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 782# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 783#
784# @param $1 - (optional) "--build-only" makes the jar(s) not added into
785# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 786# @param $2 - list of packages to get jars from
787# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 788# ------------------------------------------------------------------------------
727java-pkg_getjars() { 789java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 790 debug-print-function ${FUNCNAME} $*
729 791
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 792 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments"
731 793
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 794 if [[ "${1}" = "--build-only" ]]; then
795 local build_only="true"
796 shift
797 fi
798
733 local classpath pkg 799 local classpath pkgs="${1}"
734 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 800 jars="$(java-config --classpath=${pkgs})"
801 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
737 debug-print "${pkg}:${jars}" 802 debug-print "${pkgs}:${jars}"
738 # TODO should we ensure jars exist? 803
739 if [[ -z "${classpath}" ]]; then 804 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 805 classpath="${jars}"
741 else 806 else
742 classpath="${classpath}:${jars}" 807 classpath="${classpath}:${jars}"
743 fi 808 fi
809
810 # Only record jars that aren't build-only
811 if [[ -z "${build_only}" ]]; then
812 oldifs="${IFS}"
813 IFS=","
814 for pkg in ${pkgs}; do
744 java-pkg_record-jar_ "${pkg}" 815 java-pkg_record-jar_ "${pkg}"
745 done 816 done
817 IFS="${oldifs}"
818 fi
819
746 echo "${classpath}" 820 echo "${classpath}"
747} 821}
748 822
749# ------------------------------------------------------------------------------ 823# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 824# @ebuild-function java-pkg_getjar
751# 825#
752# Get the filename of a single jar from a package 826# Get the filename of a single jar from a package
827# The providing package is recorded as runtime dependency into package.env
828# DEPEND line, unless "--build-only" is passed as the very first argument, for
829# jars that have to be present only at build time and are not needed on runtime
830# (junit testing etc).
753# 831#
754# @example 832# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 833# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 834# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 835# /usr/share/xerces-2/lib/xml-apis.jar
758# 836#
837# @param $1 - (optional) "--build-only" makes the jar not added into
838# package.env DEPEND line.
759# @param $1 - package to use 839# @param $1 - package to use
760# @param $2 - jar to get 840# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 841# ------------------------------------------------------------------------------
762java-pkg_getjar() { 842java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 843 debug-print-function ${FUNCNAME} $*
844
845 local build_only=""
846
847 if [[ "${1}" = "--build-only" ]]; then
848 build_only="true"
849 shift
850 fi
764 851
765 local pkg="${1}" target_jar="${2}" jar 852 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 853 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 854 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 855
769 # TODO check that package is actually installed 856 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
857 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 858 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 859 [[ $? != 0 ]] && die ${error_msg}
860
772 for jar in ${classpath//:/ }; do 861 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 862 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 863 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 864 fi
776 865
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 866 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 867 # Only record jars that aren't build-only
868 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 869 echo "${jar}"
780 return 0 870 return 0
781 fi 871 fi
782 done 872 done
783 873
784 die "Could not find ${target_jar} in ${pkg}" 874 die "Could not find ${target_jar} in ${pkg}"
785 return 1 875 return 1
786} 876}
787 877
788# This function reads stdin, and based on that input, figures out how to 878# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 892# line="${line// /}"
803# 893#
804# # format: path=jarinfo 894# # format: path=jarinfo
805# local path=${line%%=*} 895# local path=${line%%=*}
806# local jarinfo=${line##*=} 896# local jarinfo=${line##*=}
807# 897#
808# # format: jar@package 898# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 899# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 900# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 901# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 902# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 915# @section-end query
826# ------------------------------------------------------------------------------ 916# ------------------------------------------------------------------------------
827 917
828# ------------------------------------------------------------------------------ 918# ------------------------------------------------------------------------------
829# @section-begin helper 919# @section-begin helper
830# @section-summary Helper functions 920# @section-summary Helper functions
831# 921#
832# Various other functions to use from an ebuild 922# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 923# ------------------------------------------------------------------------------
834 924
835# ------------------------------------------------------------------------------ 925# ------------------------------------------------------------------------------
841# jdbc-stdext 931# jdbc-stdext
842# jaf 932# jaf
843# jdbc-rowset 933# jdbc-rowset
844# jms 934# jms
845# 935#
846# @param $1 - Optionally indicate that the dependencies are controlled by 936# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 937# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 938# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 939# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 940# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 941# TODO rewrite to parse a line based declaration file instead -- karltk
945 fi 1035 fi
946} 1036}
947 1037
948# ------------------------------------------------------------------------------ 1038# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1039# @internal-function java-pkg_is-vm-version-sufficient
950# 1040#
951# @return zero - VM is sufficient 1041# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1042# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1043# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1044java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1045 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1065 die "Active Java VM too old"
976 fi 1066 fi
977} 1067}
978 1068
979# ------------------------------------------------------------------------------ 1069# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1070# @internal-function java-pkg_is-vm-version-eq
981# 1071#
982# @param $@ - VM version to compare current VM to 1072# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1073# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1074# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1075# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1076java-pkg_is-vm-version-eq() {
1016# 1106#
1017# @param $@ - VM version to compare current to 1107# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1108# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1109java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1110 debug-print-function ${FUNCNAME} $*
1021 1111
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1112 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1113 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1114 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1115 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1116 die "Active Java VM too old"
1027 fi 1117 fi
1028} 1118}
1029 1119
1030# ------------------------------------------------------------------------------ 1120# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1121# @internal-function java-pkg_is-vm-version-ge
1032# 1122#
1033# @param $@ - VM version to compare current VM to 1123# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1124# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1125# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1126# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1127java-pkg_is-vm-version-ge() {
1051 return 1 1141 return 1
1052 fi 1142 fi
1053 fi 1143 fi
1054} 1144}
1055 1145
1146java-pkg_set-current-vm() {
1147 export GENTOO_VM=${1}
1148}
1149
1150java-pkg_get-current-vm() {
1151 echo ${GENTOO_VM}
1152}
1153
1154java-pkg_current-vm-matches() {
1155 hasq $(java-pkg_get-current-vm) ${@}
1156 return $?
1157}
1158
1056# ------------------------------------------------------------------------------ 1159# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1160# @ebuild-function java-pkg_get-source
1058# 1161#
1059# Determines what source version should be used, for passing to -source. 1162# 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 1163# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1164#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1165# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1166# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1171# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1172# @ebuild-function java-pkg_get-target
1070# 1173#
1071# Determines what target version should be used, for passing to -target. 1174# 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 1175# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1176# version of your JDK.
1074# Remember doing this will mostly like cause things to break. 1177# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend. 1178# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm. 1179# Doesn't allow it to be higher then the active vm.
1077# 1180#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1181# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1182# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1183java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1184 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1185 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1186 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 1187 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} 1188 echo ${JAVA_PKG_WANT_TARGET}
1086 else 1189 else
1094} 1197}
1095 1198
1096java-pkg_get-javac() { 1199java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1200 debug-print-function ${FUNCNAME} $*
1098 1201
1099 java-pkg_init-compiler_ 1202
1100 local compiler="${GENTOO_COMPILER}" 1203 local compiler="${GENTOO_COMPILER}"
1101 1204
1102 local compiler_executable 1205 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1206 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1207 # nothing fancy needs to be done for javac
1112 unset JAVAC 1215 unset JAVAC
1113 # try to get value of JAVAC 1216 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1217 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1218 export JAVAC=${old_javac}
1116 1219
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1220 if [[ -z ${compiler_executable} ]]; then
1118 1221 echo "JAVAC is empty or undefined in ${compiler_env}"
1222 return 1
1223 fi
1224
1119 # check that it's executable 1225 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1226 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1227 echo "${compiler_executable} doesn't exist, or isn't executable"
1228 return 1
1123 fi 1229 fi
1124 else 1230 else
1125 eerror "Could not find environment file for ${compiler}" 1231 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1232 return 1
1127 fi 1233 fi
1128 fi 1234 fi
1129 echo ${compiler_executable} 1235 echo ${compiler_executable}
1130} 1236}
1131 1237
1132# ------------------------------------------------------------------------------ 1238# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1239# @ebuild-function java-pkg_javac-args
1134# 1240#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1241# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1242# to know what -source/-target to use.
1137# 1243#
1138# @return string - arguments to pass to javac, complete with -target and -source 1244# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1247 debug-print-function ${FUNCNAME} $*
1142 1248
1143 local want_source="$(java-pkg_get-source)" 1249 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1250 local want_target="$(java-pkg_get-target)"
1145 1251
1146 local source_str="-source ${want_source}" 1252 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1253 local target_str="-target ${want_target}"
1148 1254
1149 debug-print "want source: ${want_source}" 1255 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1256 debug-print "want target: ${want_target}"
1151 1257
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1258 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1259 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1260 echo "Could not find valid -source/-target values for javac"
1261 return 1
1155 else 1262 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1263 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1264 echo "${source_str} ${target_str}"
1158 else 1265 else
1159 echo "${target_str}" 1266 echo "${target_str}"
1180 ebeep 5 1287 ebeep 5
1181 die "No GCJ support found!" 1288 die "No GCJ support found!"
1182 fi 1289 fi
1183} 1290}
1184 1291
1292java-pkg_ensure-test() {
1293 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1294 eerror "You specified FEATURES=test, but USE=test is needed"
1295 eerror "to pull in the additional dependencies for testing"
1296 die "Need USE=test enabled"
1297 fi
1298}
1299
1185# ------------------------------------------------------------------------------ 1300# ------------------------------------------------------------------------------
1186# @section-end helper 1301# @section-end helper
1187# ------------------------------------------------------------------------------ 1302# ------------------------------------------------------------------------------
1188 1303
1189# ------------------------------------------------------------------------------ 1304# ------------------------------------------------------------------------------
1201# compiler. 1316# compiler.
1202# 1317#
1203# ------------------------------------------------------------------------------ 1318# ------------------------------------------------------------------------------
1204eant() { 1319eant() {
1205 debug-print-function ${FUNCNAME} $* 1320 debug-print-function ${FUNCNAME} $*
1321
1322 # FIXME get this working
1323# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1324# java-pkg_announce-qa-violation \
1325# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1326# fi
1206 1327
1207 local antflags 1328 local antflags
1208 java-pkg_init-compiler_ 1329 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1330 local compiler="${GENTOO_COMPILER}"
1210 1331
1229 1350
1230 if is-java-strict; then 1351 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1352 einfo "Disabling system classpath for ant"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1353 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1233 fi 1354 fi
1234 1355
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1356 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1236 antflags="${antflags} -debug" 1357 antflags="${antflags} -debug"
1237 fi 1358 fi
1238 1359
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1360 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 1361 ant ${antflags} "${@}" || die "eant failed"
1241 1362
1242} 1363}
1243 1364
1244# ------------------------------------------------------------------------------ 1365# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 1366# @ebuild-function ejavac
1246# 1367#
1247# Javac wrapper function. Will use the appropriate compiler, based on 1368# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 1369# /etc/java-config/compilers.conf
1249# 1370#
1250# @param $@ - Arguments to be passed to the compiler 1371# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 1372# ------------------------------------------------------------------------------
1252ejavac() { 1373ejavac() {
1253 debug-print-function ${FUNCNAME} $* 1374 debug-print-function ${FUNCNAME} $*
1254 1375
1255 # FIXME using get-javac ends up printing stuff with einfo 1376 java-pkg_init-compiler_
1377
1378 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 1379 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 1380 if [[ ${?} != 0 ]]; then
1381 eerror "There was a problem determining compiler: ${compiler_executable}"
1382 die "get-javac failed"
1383 fi
1258 1384
1385 local javac_args
1386 javac_args="$(java-pkg_javac-args)"
1387 if [[ ${?} != 0 ]]; then
1388 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1389 die "java-pkg_javac-args failed"
1390 fi
1391
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1392 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1393 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 1394}
1262 1395
1263# ------------------------------------------------------------------------------ 1396# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 1397# @ebuild-function java-pkg_filter-compiler
1265# 1398#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 1399# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1400# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 1401#
1269# @param $@ - compilers to filter 1402# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 1403# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 1421# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 1422# @ebuild-function use_doc
1290# 1423#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 1424# 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. 1425# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 1426#
1294# The output of this should be passed to ant. 1427# The output of this should be passed to ant.
1295# 1428#
1296# Example: build javadocs by calling 'javadoc' target 1429# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 1430# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 1431# Example: build javadocs by calling 'apidoc' target
1306} 1439}
1307 1440
1308# ------------------------------------------------------------------------------ 1441# ------------------------------------------------------------------------------
1309# @section-end build 1442# @section-end build
1310# ------------------------------------------------------------------------------ 1443# ------------------------------------------------------------------------------
1311 1444
1312# ------------------------------------------------------------------------------ 1445# ------------------------------------------------------------------------------
1313# @section-begin internal 1446# @section-begin internal
1314# @section-summary Internal functions 1447# @section-summary Internal functions
1315# 1448#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 1449# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 1450# within the java eclasses.
1318# ------------------------------------------------------------------------------ 1451# ------------------------------------------------------------------------------
1319 1452
1320# ----------------------------------------------------------------------------- 1453# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 1454# @function-internal java-pkg_init
1322# 1455#
1323# The purpose of this function, as the name might imply, is to initialize the 1456# 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 1457# 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 1458# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 1459# internally. And most importantly, it'll switch the VM if necessary.
1327# 1460#
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 1472 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 1473
1341 # Do some QA checks 1474 # Do some QA checks
1342 java-pkg_check-jikes 1475 java-pkg_check-jikes
1343 1476
1344 # When users have crazy classpaths some packages can fail to compile. 1477 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 1478 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 1479 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 1480 # from the CLASSPATH.
1348 unset CLASSPATH 1481 unset CLASSPATH
1349} 1482}
1350 1483
1351# ------------------------------------------------------------------------------ 1484# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 1485# @function-internal java-pkg-init-compiler_
1353# 1486#
1354# This function attempts to figure out what compiler should be used. It does 1487# 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 1488# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 1489# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1490# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 1491#
1359# It will go through the list of compilers, and verify that it supports the 1492# 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 1493# 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 1494# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 1495# isn't done.
1363# 1496#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1518 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1519 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 1520 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 1521 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 1522 fi
1390 1523
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1524 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 1525
1393 # Figure out if we should announce what compiler we're using 1526 # Figure out if we should announce what compiler we're using
1394 local compiler 1527 local compiler
1395 for compiler in ${compilers}; do 1528 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 1531 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 1532 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 1533 export GENTOO_COMPILER="javac"
1401 break 1534 break
1402 fi 1535 fi
1403 1536
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1537 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1538 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 1539 einfo "Filtering ${compiler}"
1407 continue 1540 continue
1408 fi 1541 fi
1409 fi 1542 fi
1410 1543
1411 # for non-javac, we need to make sure it supports the right target and 1544 # for non-javac, we need to make sure it supports the right target and
1412 # source 1545 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1546 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 1547 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 1548 local desired_target="$(java-pkg_get-target)"
1497# Writes the package.env out to disk. 1630# Writes the package.env out to disk.
1498# 1631#
1499# ------------------------------------------------------------------------------ 1632# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 1633# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 1634java-pkg_do_write_() {
1635 java-pkg_init_paths_
1502 # Create directory for package.env 1636 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 1637 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1638 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1505 # Create package.env 1639 # Create package.env
1506 ( 1640 (
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1645 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1646 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1647 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1648 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1515 ) > "${JAVA_PKG_ENV}" 1649 ) > "${JAVA_PKG_ENV}"
1516 1650
1517 # register target/source 1651 # register target/source
1518 local target="$(java-pkg_get-target)" 1652 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 1653 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1654 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1655 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1534 # Strip unnecessary leading and trailing colons 1668 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 1669 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1670 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1537 fi 1671 fi
1538} 1672}
1539
1540 1673
1541# ------------------------------------------------------------------------------ 1674# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 1675# @internal-function java-pkg_record-jar_
1543# 1676#
1544# Record a dependency to the package.env 1677# Record a dependency to the package.env
1588 fi 1721 fi
1589} 1722}
1590 1723
1591# ------------------------------------------------------------------------------ 1724# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 1725# @internal-function java-pkg_expand_dir_
1593# 1726#
1594# Gets the full path of the file/directory's parent. 1727# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 1728# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 1729# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 1730# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 1731java-pkg_expand_dir_() {
1625# ------------------------------------------------------------------------------ 1758# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 1759java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 1760 debug-print-function ${FUNCNAME} $*
1628 1761
1629 local vendor="$(java-pkg_get-vm-vendor)" 1762 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1763 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 1764 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 1765 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 1766 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 1767 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C" 1768 export LANG="C" LC_ALL="C"
1684# @return - The version of the current VM 1817# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 1818# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 1819java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 1820 debug-print-function ${FUNCNAME} $*
1688 1821
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1822 java-config -g PROVIDES_VERSION
1690} 1823}
1691 1824
1692# ------------------------------------------------------------------------------ 1825# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 1826# @internal-function java-pkg_switch-vm
1694# 1827#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1828# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 1829# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 1830# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 1831# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 1832java-pkg_switch-vm() {
1700 if java-pkg_needs-vm; then 1833 if java-pkg_needs-vm; then
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1837 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 1838 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1839 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}" 1840 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1841 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}}")" 1842 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1710 else 1843 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1844 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1845 fi
1846 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1847 eerror "Unable to determine VM for building from dependencies."
1848 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1849 echo "VNEED: ${JAVA_PKG_VNEED}"
1850 else
1851 export GENTOO_VM
1712 fi 1852 fi
1713 # otherwise just make sure the current VM is sufficient 1853 # otherwise just make sure the current VM is sufficient
1714 else 1854 else
1715 java-pkg_ensure-vm-version-sufficient 1855 java-pkg_ensure-vm-version-sufficient
1716 fi 1856 fi
1717 debug-print "Using: $(java-config -f)" 1857 debug-print "Using: $(java-config -f)"
1718 1858
1719 java-pkg_setup-vm 1859 java-pkg_setup-vm
1720 1860
1721 export JAVA=$(java-config --java) 1861 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 1862 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 1863 JAVACFLAGS="$(java-pkg_javac-args)"
1864 if [[ ${?} != 0 ]]; then
1865 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1866 die "java-pkg_javac-args failed"
1867 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1868 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1869 export JAVACFLAGS
1725 1870
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1871 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 1872 export JDK_HOME=${JAVA_HOME}
1728 1873
1729 #TODO If you know a better solution let us know. 1874 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1875 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 1876
1732 local tann="${T}/announced-vm" 1877 local tann="${T}/announced-vm"
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1878 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs 1879 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg 1880 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1881 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1780# TODO document 1925# TODO document
1781# Verify that the classes were compiled for the right source / target 1926# Verify that the classes were compiled for the right source / target
1782java-pkg_verify-classes() { 1927java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions" 1928 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1929 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1930 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1786 result=$? 1931 result=$?
1787 eend ${result} 1932 eend ${result}
1788 if [[ ${result} == 0 ]]; then 1933 if [[ ${result} == 0 ]]; then
1789 einfo "All good" 1934 einfo "All good"
1790 else 1935 else
1791 ewarn "Possible problem" 1936 ewarn "Possible problem"
1792 die "Bad class files found" 1937 die "Bad class files found"
1793 fi 1938 fi
1794} 1939}
1795 1940
1796
1797# ------------------------------------------------------------------------------ 1941# ------------------------------------------------------------------------------
1798# @section-end internal 1942# @section-end internal
1799# ------------------------------------------------------------------------------ 1943# ------------------------------------------------------------------------------
1800 1944
1801java-pkg_check-phase() { 1945java-pkg_check-phase() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 1976 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 1977 export JAVA_PKG_QA_VIOLATIONS
1834} 1978}
1835 1979
1836is-java-strict() { 1980is-java-strict() {
1837 hasq java-strict ${FEATURES}; 1981 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 1982 return $?
1839} 1983}
1840 1984
1841# ------------------------------------------------------------------------------ 1985# ------------------------------------------------------------------------------
1842# @eclass-end 1986# @eclass-end

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

  ViewVC Help
Powered by ViewVC 1.1.20