/[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.12 Revision 1.25
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
40 40
41# ----------------------------------------------------------------------------- 41# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 42# @variable-internal JAVA_PKG_E_DEPEND
43# 43#
44# This is a convience variable to be used from the other java eclasses. This is 44# 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 45# the version of java-config we want to use. We also need a recent version
46# portage, that includes phase hooks. 46# portage, that includes phase hooks.
47# ----------------------------------------------------------------------------- 47# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
49 49
50# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
100# ----------------------------------------------------------------------------- 100# -----------------------------------------------------------------------------
101 101
102# ----------------------------------------------------------------------------- 102# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 103# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 104# @default /usr/share/java-config-2/compiler
105# 105#
106# Directory where compiler settings are saved, without trailing slash. 106# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 107# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 108# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 110
120 120
121# ----------------------------------------------------------------------------- 121# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 122# @variable-external JAVA_PKG_FORCE_COMPILER
123# 123#
124# Explicitly set a list of compilers to use. This is normally read from 124# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 125# JAVA_PKG_COMPILERS_CONF.
126# 126#
127# @note This should only be used internally or for testing. 127# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 128# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 129# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 130# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 150# @ebuild-function java-pkg_dojar
151# 151#
152# Installs any number of jars. 152# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 154# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 155# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 156# Instead, use java-pkg_newjar defined below.
157# 157#
158# @example 158# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 160#
222# will not work, because: 222# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 223# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 224# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 226# doesn't exist
227# 227#
228# you have to use it as: 228# you have to use it as:
229# 229#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 231#
232# @param $@ - jars to record 232# @param $@ - jars to record
305} 305}
306 306
307 307
308# ------------------------------------------------------------------------------ 308# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 309# @ebuild-function java-pkg_doso
310# 310#
311# Installs any number of JNI libraries 311# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 312# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 313# can be used change this path
314# 314#
315# Example: 315# Example:
370 java-pkg_check-phase install 370 java-pkg_check-phase install
371 371
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 372 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 373
374 java-pkg_init_paths_ 374 java-pkg_init_paths_
375 375
376 local lib target_dir 376 local lib target_dir
377 for lib in "$@" ; do 377 for lib in "$@" ; do
378 # Check the absolute path of the lib 378 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 379 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 380 target_dir="$(java-pkg_expand_dir_ ${lib})"
458} 458}
459 459
460# ------------------------------------------------------------------------------ 460# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 461# @ebuild-function java-pkg_dosrc
462# 462#
463# Installs a zip containing the source for a package, so it can used in 463# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 464# from IDEs like eclipse and netbeans.
465# 465#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 466# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 467#
468# It also should be controlled by USE=source. 468# It also should be controlled by USE=source.
469# 469#
470# @example: 470# @example:
471# java-pkg_dosrc src/* 471# java-pkg_dosrc src/*
472# 472#
473# ------------------------------------------------------------------------------ 473# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 474# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 475# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 476# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 477# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 478# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 479java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 480 debug-print-function ${FUNCNAME} $*
481 481
482 [ ${#} -lt 1 ] && die "At least one argument needed" 482 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 483 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 485 fi
486 486
487 java-pkg_check-phase install 487 java-pkg_check-phase install
488 488
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 489 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 490
491 java-pkg_init_paths_ 491 java-pkg_init_paths_
492 492
493 local zip_name="${PN}-src.zip" 493 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 494 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 518# @ebuild-function java-pkg_dolauncher
519# 519#
520# Make a wrapper script to lauch/start this package 520# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 521# If necessary, the wrapper will switch to the appropriate VM.
522# 522#
523# Can be called without parameters if the package installs only one jar
524# that has the Main-class attribute set. The wrapper will be named ${PN}.
525#
523# @param $1 - filename of launcher to create 526# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 527# @param $2 - options, as follows:
525# --main the.main.class.too.start 528# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 529# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 530# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 531# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 532# --pwd
530# -into 533# -into
531# -pre 534# -pre
532# ------------------------------------------------------------------------------ 535# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 536java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 537 debug-print-function ${FUNCNAME} $*
535 538
536 java-pkg_check-phase install 539 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 540 java-pkg_init_paths_
541 541
542 if [[ ${#} = 0 ]]; then
543 local name="${PN}"
544 else
542 local name="${1}" 545 local name="${1}"
546 shift
547 fi
548
543 # TODO rename to launcher 549 # TODO rename to launcher
544 local target="${T}/${name}" 550 local target="${T}/${name}"
551 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 552 local target_dir pre
546 shift
547 553
548 echo "#!/bin/bash" > "${target}" 554 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 555 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 556 local var=${1} value=${2}
551 if [[ "${var:0:2}" == "--" ]]; then 557 if [[ "${var:0:2}" == "--" ]]; then
558 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 559 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
560 local gjl_${var}=${value}
553 elif [[ "${var}" == "-into" ]]; then 561 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 562 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 563 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 564 pre="${value}"
557 fi 565 fi
558 shift 2 566 shift 2
559 done 567 done
568
569 # Test if no --jar and --main arguments were given and
570 # in that case check if the package only installs one jar
571 # and use that jar.
572 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
573 local cp="${JAVA_PKG_CLASSPATH}"
574 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
575 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
576 else
577 local msg="Not enough information to create a launcher given."
578 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
579 die "${msg}"
580 fi
581 fi
582
583 # Write the actual script
584 echo "#!/bin/bash" > "${target}"
585 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 586 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 587 cat "${var_tmp}" >> "${target}"
588 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 589 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 590
564 if [[ -n "${into}" ]]; then 591 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 592 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 593 local ret=$?
567 return ${ret} 594 return ${ret}
568 else 595 else
569 dobin "${target}" 596 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 624 echo "dowar: warning, skipping directory ${war}"
598 continue 625 continue
599 else 626 else
600 warpath="${war}" 627 warpath="${war}"
601 fi 628 fi
602 629
603 # Install those files like you mean it 630 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 631 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 632 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 633 doins ${warpath}
607 done 634 done
642# @ebuild-function java-pkg_jar-from 669# @ebuild-function java-pkg_jar-from
643# 670#
644# Makes a symlink to a jar from a certain package 671# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 672# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 673# You can use this function to replace these bundled dependencies.
674# The dependency is recorded into package.env DEPEND line, unless "--build-only"
675# is passed as the very first argument, for jars that have to be present only
676# at build time and are not needed on runtime (junit testing etc).
647# 677#
648# Example: get all jars from xerces slot 2 678# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 679# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 680# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 681# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 682# 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 683# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
684# Example: get junit.jar which is needed only for building
685# java-pkg_jar-from --build-only junit junit.jar
654# 686#
687# @param $1 - (optional) "--build-only" makes the jar(s) not added into
688# package.env DEPEND line.
655# @param $1 - Package to get jars from. 689# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 690# @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 691# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 692# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 693# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 694# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 695java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 696 debug-print-function ${FUNCNAME} $*
663 697
698 local build_only=""
699
700 if [[ "${1}" = "--build-only" ]]; then
701 build_only="true"
702 shift
703 fi
704
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 705 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 706
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 707 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 708
668 # default destjar to the target jar 709 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 710 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 711
712 local error_msg="There was a problem getting the classpath for ${target_pkg}."
713 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 714 classpath="$(java-config --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 715 [[ $? != 0 ]] && die ${error_msg}
673 716
674 local jar 717 local jar
675 for jar in ${classpath//:/ }; do 718 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 719 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 720 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 724 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 725 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 726 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 727 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 728 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 729 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 730 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 731 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 732 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 733 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 734 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 735 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 736 return 0
694 fi 737 fi
695 done 738 done
696 # if no target was specified, we're ok 739 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 740 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 757# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 758# @ebuild-function java-pkg_getjars
716# 759#
717# Get the classpath provided by any number of packages 760# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 761# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
762# The providing packages are recorded as dependencies into package.env DEPEND
763# line, unless "--build-only" is passed as the very first argument, for jars
764# that have to be present only at build time and are not needed on runtime
765# (junit testing etc).
719# 766#
720# Example: Get the classpath for xerces-2, 767# Example: Get the classpath for xerces-2,
721# java-pkg_getjars xerces-2 xalan 768# java-pkg_getjars xerces-2 xalan
722# Example Return: 769# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 770# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 771#
772# @param $1 - (optional) "--build-only" makes the jar(s) not added into
773# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 774# @param $@ - list of packages to get jars from
726# ------------------------------------------------------------------------------ 775# ------------------------------------------------------------------------------
727java-pkg_getjars() { 776java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 777 debug-print-function ${FUNCNAME} $*
778
779 local build_only=""
780
781 if [[ "${1}" = "--build-only" ]]; then
782 build_only="true"
783 shift
784 fi
729 785
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 786 [[ ${#} -lt 1 ]] && die "At least one argument needed"
731 787
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 788 # NOTE could probably just pass $@ to java-config --classpath. and return it
733 local classpath pkg 789 local classpath pkg
734 for pkg in ${@//,/ }; do 790 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 791 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 792 jars="$(java-config --classpath=${pkg})"
793 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
737 debug-print "${pkg}:${jars}" 794 debug-print "${pkg}:${jars}"
738 # TODO should we ensure jars exist? 795
739 if [[ -z "${classpath}" ]]; then 796 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 797 classpath="${jars}"
741 else 798 else
742 classpath="${classpath}:${jars}" 799 classpath="${classpath}:${jars}"
743 fi 800 fi
744 java-pkg_record-jar_ "${pkg}" 801 # Only record jars that aren't build-only
802 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
745 done 803 done
746 echo "${classpath}" 804 echo "${classpath}"
747} 805}
748 806
749# ------------------------------------------------------------------------------ 807# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 808# @ebuild-function java-pkg_getjar
751# 809#
752# Get the filename of a single jar from a package 810# Get the filename of a single jar from a package
811# The providing package is recorded as runtime dependency into package.env
812# DEPEND line, unless "--build-only" is passed as the very first argument, for
813# jars that have to be present only at build time and are not needed on runtime
814# (junit testing etc).
753# 815#
754# @example 816# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 817# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 818# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 819# /usr/share/xerces-2/lib/xml-apis.jar
758# 820#
821# @param $1 - (optional) "--build-only" makes the jar not added into
822# package.env DEPEND line.
759# @param $1 - package to use 823# @param $1 - package to use
760# @param $2 - jar to get 824# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 825# ------------------------------------------------------------------------------
762java-pkg_getjar() { 826java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 827 debug-print-function ${FUNCNAME} $*
828
829 local build_only=""
830
831 if [[ "${1}" = "--build-only" ]]; then
832 build_only="true"
833 shift
834 fi
764 835
765 local pkg="${1}" target_jar="${2}" jar 836 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 837 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 838 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 839
769 # TODO check that package is actually installed 840 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
841 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 842 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 843 [[ $? != 0 ]] && die ${error_msg}
844
772 for jar in ${classpath//:/ }; do 845 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 846 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 847 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 848 fi
776 849
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 850 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 851 # Only record jars that aren't build-only
852 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 853 echo "${jar}"
780 return 0 854 return 0
781 fi 855 fi
782 done 856 done
783 857
784 die "Could not find ${target_jar} in ${pkg}" 858 die "Could not find ${target_jar} in ${pkg}"
785 return 1 859 return 1
786} 860}
787 861
788# This function reads stdin, and based on that input, figures out how to 862# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 876# line="${line// /}"
803# 877#
804# # format: path=jarinfo 878# # format: path=jarinfo
805# local path=${line%%=*} 879# local path=${line%%=*}
806# local jarinfo=${line##*=} 880# local jarinfo=${line##*=}
807# 881#
808# # format: jar@package 882# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 883# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 884# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 885# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 886# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 899# @section-end query
826# ------------------------------------------------------------------------------ 900# ------------------------------------------------------------------------------
827 901
828# ------------------------------------------------------------------------------ 902# ------------------------------------------------------------------------------
829# @section-begin helper 903# @section-begin helper
830# @section-summary Helper functions 904# @section-summary Helper functions
831# 905#
832# Various other functions to use from an ebuild 906# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 907# ------------------------------------------------------------------------------
834 908
835# ------------------------------------------------------------------------------ 909# ------------------------------------------------------------------------------
841# jdbc-stdext 915# jdbc-stdext
842# jaf 916# jaf
843# jdbc-rowset 917# jdbc-rowset
844# jms 918# jms
845# 919#
846# @param $1 - Optionally indicate that the dependencies are controlled by 920# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 921# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 922# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 923# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 924# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 925# TODO rewrite to parse a line based declaration file instead -- karltk
945 fi 1019 fi
946} 1020}
947 1021
948# ------------------------------------------------------------------------------ 1022# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1023# @internal-function java-pkg_is-vm-version-sufficient
950# 1024#
951# @return zero - VM is sufficient 1025# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1026# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1027# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1028java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1029 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1049 die "Active Java VM too old"
976 fi 1050 fi
977} 1051}
978 1052
979# ------------------------------------------------------------------------------ 1053# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1054# @internal-function java-pkg_is-vm-version-eq
981# 1055#
982# @param $@ - VM version to compare current VM to 1056# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1057# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1058# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1059# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1060java-pkg_is-vm-version-eq() {
1016# 1090#
1017# @param $@ - VM version to compare current to 1091# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1092# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1093java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1094 debug-print-function ${FUNCNAME} $*
1021 1095
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1096 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1097 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1098 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1099 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1100 die "Active Java VM too old"
1027 fi 1101 fi
1028} 1102}
1029 1103
1030# ------------------------------------------------------------------------------ 1104# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1105# @internal-function java-pkg_is-vm-version-ge
1032# 1106#
1033# @param $@ - VM version to compare current VM to 1107# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1108# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1109# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1110# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1111java-pkg_is-vm-version-ge() {
1060java-pkg_get-current-vm() { 1134java-pkg_get-current-vm() {
1061 echo ${GENTOO_VM} 1135 echo ${GENTOO_VM}
1062} 1136}
1063 1137
1064java-pkg_current-vm-matches() { 1138java-pkg_current-vm-matches() {
1065 hasq java-pkg_get-currenv-vm ${@} 1139 hasq $(java-pkg_get-current-vm) ${@}
1066 return $? 1140 return $?
1067} 1141}
1068 1142
1069# ------------------------------------------------------------------------------ 1143# ------------------------------------------------------------------------------
1070# @ebuild-function java-pkg_get-source 1144# @ebuild-function java-pkg_get-source
1071# 1145#
1072# Determines what source version should be used, for passing to -source. 1146# Determines what source version should be used, for passing to -source.
1073# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1147# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1074# 1148#
1075# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1149# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1076# ------------------------------------------------------------------------------ 1150# ------------------------------------------------------------------------------
1081# ------------------------------------------------------------------------------ 1155# ------------------------------------------------------------------------------
1082# @ebuild-function java-pkg_get-target 1156# @ebuild-function java-pkg_get-target
1083# 1157#
1084# Determines what target version should be used, for passing to -target. 1158# Determines what target version should be used, for passing to -target.
1085# If you don't care about lower versions, you can set _WANT_TARGET to the 1159# If you don't care about lower versions, you can set _WANT_TARGET to the
1086# version of your JDK. 1160# version of your JDK.
1087# Remember doing this will mostly like cause things to break. 1161# Remember doing this will mostly like cause things to break.
1088# Doesn't allow it to be lower then the one in depend. 1162# Doesn't allow it to be lower then the one in depend.
1089# Doesn't allow it to be higher then the active vm. 1163# Doesn't allow it to be higher then the active vm.
1090# 1164#
1091# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1165# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1092# ------------------------------------------------------------------------------ 1166# ------------------------------------------------------------------------------
1093java-pkg_get-target() { 1167java-pkg_get-target() {
1094 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1168 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1095 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1169 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1096 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1170 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1097 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then 1171 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1098 echo ${JAVA_PKG_WANT_TARGET} 1172 echo ${JAVA_PKG_WANT_TARGET}
1099 else 1173 else
1107} 1181}
1108 1182
1109java-pkg_get-javac() { 1183java-pkg_get-javac() {
1110 debug-print-function ${FUNCNAME} $* 1184 debug-print-function ${FUNCNAME} $*
1111 1185
1112 java-pkg_init-compiler_ 1186
1113 local compiler="${GENTOO_COMPILER}" 1187 local compiler="${GENTOO_COMPILER}"
1114 1188
1115 local compiler_executable 1189 local compiler_executable
1116 if [[ "${compiler}" = "javac" ]]; then 1190 if [[ "${compiler}" = "javac" ]]; then
1117 # nothing fancy needs to be done for javac 1191 # nothing fancy needs to be done for javac
1125 unset JAVAC 1199 unset JAVAC
1126 # try to get value of JAVAC 1200 # try to get value of JAVAC
1127 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1201 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1128 export JAVAC=${old_javac} 1202 export JAVAC=${old_javac}
1129 1203
1130 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1204 if [[ -z ${compiler_executable} ]]; then
1131 1205 echo "JAVAC is empty or undefined in ${compiler_env}"
1206 return 1
1207 fi
1208
1132 # check that it's executable 1209 # check that it's executable
1133 if [[ ! -x ${compiler_executable} ]]; then 1210 if [[ ! -x ${compiler_executable} ]]; then
1134 eerror "Could not find ${compiler_executable}!"
1135 die "${compiler_executable} doesn't exist, or isn't executable" 1211 echo "${compiler_executable} doesn't exist, or isn't executable"
1212 return 1
1136 fi 1213 fi
1137 else 1214 else
1138 eerror "Could not find environment file for ${compiler}" 1215 echo "Could not find environment file for ${compiler}"
1139 die "Could not find ${compiler_env}" 1216 return 1
1140 fi 1217 fi
1141 fi 1218 fi
1142 echo ${compiler_executable} 1219 echo ${compiler_executable}
1143} 1220}
1144 1221
1145# ------------------------------------------------------------------------------ 1222# ------------------------------------------------------------------------------
1146# @ebuild-function java-pkg_javac-args 1223# @ebuild-function java-pkg_javac-args
1147# 1224#
1148# If an ebuild uses javac directly, instead of using ejavac, it should call this 1225# If an ebuild uses javac directly, instead of using ejavac, it should call this
1149# to know what -source/-target to use. 1226# to know what -source/-target to use.
1150# 1227#
1151# @return string - arguments to pass to javac, complete with -target and -source 1228# @return string - arguments to pass to javac, complete with -target and -source
1154 debug-print-function ${FUNCNAME} $* 1231 debug-print-function ${FUNCNAME} $*
1155 1232
1156 local want_source="$(java-pkg_get-source)" 1233 local want_source="$(java-pkg_get-source)"
1157 local want_target="$(java-pkg_get-target)" 1234 local want_target="$(java-pkg_get-target)"
1158 1235
1159 local source_str="-source ${want_source}" 1236 local source_str="-source ${want_source}"
1160 local target_str="-target ${want_target}" 1237 local target_str="-target ${want_target}"
1161 1238
1162 debug-print "want source: ${want_source}" 1239 debug-print "want source: ${want_source}"
1163 debug-print "want target: ${want_target}" 1240 debug-print "want target: ${want_target}"
1164 1241
1165 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1242 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1166 debug-print "could not find valid -source/-target values" 1243 debug-print "could not find valid -source/-target values for javac"
1167 die "Could not find valid -source/-target values" 1244 echo "Could not find valid -source/-target values for javac"
1245 return 1
1168 else 1246 else
1169 if java-pkg_is-vm-version-ge "1.4"; then 1247 if java-pkg_is-vm-version-ge "1.4"; then
1170 echo "${source_str} ${target_str}" 1248 echo "${source_str} ${target_str}"
1171 else 1249 else
1172 echo "${target_str}" 1250 echo "${target_str}"
1190 ewarn 1268 ewarn
1191 ewarn "You must build gcc with the gcj support to build with gcj" 1269 ewarn "You must build gcc with the gcj support to build with gcj"
1192 ewarn 1270 ewarn
1193 ebeep 5 1271 ebeep 5
1194 die "No GCJ support found!" 1272 die "No GCJ support found!"
1273 fi
1274}
1275
1276java-pkg_ensure-test() {
1277 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1278 eerror "You specified FEATURES=test, but USE=test is needed"
1279 eerror "to pull in the additional dependencies for testing"
1280 die "Need USE=test enabled"
1195 fi 1281 fi
1196} 1282}
1197 1283
1198# ------------------------------------------------------------------------------ 1284# ------------------------------------------------------------------------------
1199# @section-end helper 1285# @section-end helper
1248 1334
1249 if is-java-strict; then 1335 if is-java-strict; then
1250 einfo "Disabling system classpath for ant" 1336 einfo "Disabling system classpath for ant"
1251 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1337 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1252 fi 1338 fi
1253 1339
1254 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1340 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1255 antflags="${antflags} -debug" 1341 antflags="${antflags} -debug"
1256 fi 1342 fi
1257 1343
1258 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1344 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1259 ant ${antflags} "${@}" || die "eant failed" 1345 ant ${antflags} "${@}" || die "eant failed"
1260 1346
1261} 1347}
1262 1348
1263# ------------------------------------------------------------------------------ 1349# ------------------------------------------------------------------------------
1264# @ebuild-function ejavac 1350# @ebuild-function ejavac
1265# 1351#
1266# Javac wrapper function. Will use the appropriate compiler, based on 1352# Javac wrapper function. Will use the appropriate compiler, based on
1267# /etc/java-config/compilers.conf 1353# /etc/java-config/compilers.conf
1268# 1354#
1269# @param $@ - Arguments to be passed to the compiler 1355# @param $@ - Arguments to be passed to the compiler
1270# ------------------------------------------------------------------------------ 1356# ------------------------------------------------------------------------------
1271ejavac() { 1357ejavac() {
1272 debug-print-function ${FUNCNAME} $* 1358 debug-print-function ${FUNCNAME} $*
1273 1359
1274 # FIXME using get-javac ends up printing stuff with einfo 1360 java-pkg_init-compiler_
1361
1362 local compiler_executable
1275# local compiler_executable=$(java-pkg_get-javac) 1363 compiler_executable=$(java-pkg_get-javac)
1276 local compiler_executable="javac" 1364 if [[ ${?} != 0 ]]; then
1365 eerror "There was a problem determining compiler: ${compiler_executable}"
1366 die "get-javac failed"
1367 fi
1277 1368
1369 local javac_args
1370 javac_args="$(java-pkg_javac-args)"
1371 if [[ ${?} != 0 ]]; then
1372 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1373 die "java-pkg_javac-args failed"
1374 fi
1375
1278 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1376 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1279 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1377 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1280} 1378}
1281 1379
1282# ------------------------------------------------------------------------------ 1380# ------------------------------------------------------------------------------
1283# @ebuild-function java-pkg_filter-compiler 1381# @ebuild-function java-pkg_filter-compiler
1284# 1382#
1285# Used to prevent the use of some compilers. Should be used in src_compile. 1383# Used to prevent the use of some compilers. Should be used in src_compile.
1286# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1384# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1287# 1385#
1288# @param $@ - compilers to filter 1386# @param $@ - compilers to filter
1289# ------------------------------------------------------------------------------ 1387# ------------------------------------------------------------------------------
1307# ------------------------------------------------------------------------------ 1405# ------------------------------------------------------------------------------
1308# @ebuild-function use_doc 1406# @ebuild-function use_doc
1309# 1407#
1310# Helper function for getting ant to build javadocs. If the user has USE=doc, 1408# Helper function for getting ant to build javadocs. If the user has USE=doc,
1311# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1409# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1312# 1410#
1313# The output of this should be passed to ant. 1411# The output of this should be passed to ant.
1314# 1412#
1315# Example: build javadocs by calling 'javadoc' target 1413# Example: build javadocs by calling 'javadoc' target
1316# eant $(use_doc) 1414# eant $(use_doc)
1317# Example: build javadocs by calling 'apidoc' target 1415# Example: build javadocs by calling 'apidoc' target
1325} 1423}
1326 1424
1327# ------------------------------------------------------------------------------ 1425# ------------------------------------------------------------------------------
1328# @section-end build 1426# @section-end build
1329# ------------------------------------------------------------------------------ 1427# ------------------------------------------------------------------------------
1330 1428
1331# ------------------------------------------------------------------------------ 1429# ------------------------------------------------------------------------------
1332# @section-begin internal 1430# @section-begin internal
1333# @section-summary Internal functions 1431# @section-summary Internal functions
1334# 1432#
1335# Do __NOT__ use any of these from an ebuild! These are only to be used from 1433# Do __NOT__ use any of these from an ebuild! These are only to be used from
1336# within the java eclasses. 1434# within the java eclasses.
1337# ------------------------------------------------------------------------------ 1435# ------------------------------------------------------------------------------
1338 1436
1339# ----------------------------------------------------------------------------- 1437# -----------------------------------------------------------------------------
1340# @function-internal java-pkg_init 1438# @function-internal java-pkg_init
1341# 1439#
1342# The purpose of this function, as the name might imply, is to initialize the 1440# The purpose of this function, as the name might imply, is to initialize the
1343# Java environment. It ensures that that there aren't any environment variables 1441# Java environment. It ensures that that there aren't any environment variables
1344# that'll muss things up. It initializes some variables, which are used 1442# that'll muss things up. It initializes some variables, which are used
1345# internally. And most importantly, it'll switch the VM if necessary. 1443# internally. And most importantly, it'll switch the VM if necessary.
1346# 1444#
1358 # TODO we will probably want to set JAVAC and JAVACFLAGS 1456 # TODO we will probably want to set JAVAC and JAVACFLAGS
1359 1457
1360 # Do some QA checks 1458 # Do some QA checks
1361 java-pkg_check-jikes 1459 java-pkg_check-jikes
1362 1460
1363 # When users have crazy classpaths some packages can fail to compile. 1461 # When users have crazy classpaths some packages can fail to compile.
1364 # and everything should work with empty CLASSPATH. 1462 # and everything should work with empty CLASSPATH.
1365 # This also helps prevent unexpected dependencies on random things 1463 # This also helps prevent unexpected dependencies on random things
1366 # from the CLASSPATH. 1464 # from the CLASSPATH.
1367 unset CLASSPATH 1465 unset CLASSPATH
1368} 1466}
1369 1467
1370# ------------------------------------------------------------------------------ 1468# ------------------------------------------------------------------------------
1371# @function-internal java-pkg-init-compiler_ 1469# @function-internal java-pkg-init-compiler_
1372# 1470#
1373# This function attempts to figure out what compiler should be used. It does 1471# This function attempts to figure out what compiler should be used. It does
1374# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1472# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1375# COMPILERS variable defined there. 1473# COMPILERS variable defined there.
1376# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1474# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1377# 1475#
1378# It will go through the list of compilers, and verify that it supports the 1476# It will go through the list of compilers, and verify that it supports the
1379# target and source that are needed. If it is not suitable, then the next 1477# target and source that are needed. If it is not suitable, then the next
1380# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1478# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1381# isn't done. 1479# isn't done.
1382# 1480#
1404 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1502 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1405 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1503 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1406 else 1504 else
1407 compilers=${JAVA_PKG_FORCE_COMPILER} 1505 compilers=${JAVA_PKG_FORCE_COMPILER}
1408 fi 1506 fi
1409 1507
1410 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1508 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1411 1509
1412 # Figure out if we should announce what compiler we're using 1510 # Figure out if we should announce what compiler we're using
1413 local compiler 1511 local compiler
1414 for compiler in ${compilers}; do 1512 for compiler in ${compilers}; do
1417 if [[ ${compiler} = "javac" ]]; then 1515 if [[ ${compiler} = "javac" ]]; then
1418 debug-print "Found javac... breaking" 1516 debug-print "Found javac... breaking"
1419 export GENTOO_COMPILER="javac" 1517 export GENTOO_COMPILER="javac"
1420 break 1518 break
1421 fi 1519 fi
1422 1520
1423 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1521 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1424 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1522 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1425 einfo "Filtering ${compiler}" 1523 einfo "Filtering ${compiler}"
1426 continue 1524 continue
1427 fi 1525 fi
1428 fi 1526 fi
1429 1527
1430 # for non-javac, we need to make sure it supports the right target and 1528 # for non-javac, we need to make sure it supports the right target and
1431 # source 1529 # source
1432 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1530 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1433 if [[ -f ${compiler_env} ]]; then 1531 if [[ -f ${compiler_env} ]]; then
1434 local desired_target="$(java-pkg_get-target)" 1532 local desired_target="$(java-pkg_get-target)"
1530 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1628 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1531 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1629 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1532 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1630 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1533 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1631 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1534 ) > "${JAVA_PKG_ENV}" 1632 ) > "${JAVA_PKG_ENV}"
1535 1633
1536 # register target/source 1634 # register target/source
1537 local target="$(java-pkg_get-target)" 1635 local target="$(java-pkg_get-target)"
1538 local source="$(java-pkg_get-source)" 1636 local source="$(java-pkg_get-source)"
1539 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1637 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1540 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1638 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1607 fi 1705 fi
1608} 1706}
1609 1707
1610# ------------------------------------------------------------------------------ 1708# ------------------------------------------------------------------------------
1611# @internal-function java-pkg_expand_dir_ 1709# @internal-function java-pkg_expand_dir_
1612# 1710#
1613# Gets the full path of the file/directory's parent. 1711# Gets the full path of the file/directory's parent.
1614# @param $1 - file/directory to find parent directory for 1712# @param $1 - file/directory to find parent directory for
1615# @return - path to $1's parent directory 1713# @return - path to $1's parent directory
1616# ------------------------------------------------------------------------------ 1714# ------------------------------------------------------------------------------
1617java-pkg_expand_dir_() { 1715java-pkg_expand_dir_() {
1644# ------------------------------------------------------------------------------ 1742# ------------------------------------------------------------------------------
1645java-pkg_setup-vm() { 1743java-pkg_setup-vm() {
1646 debug-print-function ${FUNCNAME} $* 1744 debug-print-function ${FUNCNAME} $*
1647 1745
1648 local vendor="$(java-pkg_get-vm-vendor)" 1746 local vendor="$(java-pkg_get-vm-vendor)"
1649 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1747 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1650 addpredict "/dev/random" 1748 addpredict "/dev/random"
1651 elif [[ "${vendor}" == "ibm" ]]; then 1749 elif [[ "${vendor}" == "ibm" ]]; then
1652 addpredict "/proc/self/maps" 1750 addpredict "/proc/self/maps"
1653 addpredict "/proc/cpuinfo" 1751 addpredict "/proc/cpuinfo"
1654 export LANG="C" LC_ALL="C" 1752 export LANG="C" LC_ALL="C"
1703# @return - The version of the current VM 1801# @return - The version of the current VM
1704# ------------------------------------------------------------------------------ 1802# ------------------------------------------------------------------------------
1705java-pkg_get-vm-version() { 1803java-pkg_get-vm-version() {
1706 debug-print-function ${FUNCNAME} $* 1804 debug-print-function ${FUNCNAME} $*
1707 1805
1708 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1806 java-config -g PROVIDES_VERSION
1709} 1807}
1710 1808
1711# ------------------------------------------------------------------------------ 1809# ------------------------------------------------------------------------------
1712# @internal-function java-pkg_switch-vm 1810# @internal-function java-pkg_switch-vm
1713# 1811#
1714# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1812# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1715# verify that the current VM is sufficient. 1813# verify that the current VM is sufficient.
1716# Setup the environment for the VM being used. 1814# Setup the environment for the VM being used.
1717# ------------------------------------------------------------------------------ 1815# ------------------------------------------------------------------------------
1718java-pkg_switch-vm() { 1816java-pkg_switch-vm() {
1719 if java-pkg_needs-vm; then 1817 if java-pkg_needs-vm; then
1723 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1821 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1724 # if we're allowed to switch the vm... 1822 # if we're allowed to switch the vm...
1725 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1823 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1726 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1824 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1727 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1825 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1728 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1826 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1729 else 1827 else
1730 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1828 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1829 fi
1830 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1831 eerror "Unable to determine VM for building from dependencies."
1832 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1833 echo "VNEED: ${JAVA_PKG_VNEED}"
1834 else
1835 export GENTOO_VM
1731 fi 1836 fi
1732 # otherwise just make sure the current VM is sufficient 1837 # otherwise just make sure the current VM is sufficient
1733 else 1838 else
1734 java-pkg_ensure-vm-version-sufficient 1839 java-pkg_ensure-vm-version-sufficient
1735 fi 1840 fi
1736 debug-print "Using: $(java-config -f)" 1841 debug-print "Using: $(java-config -f)"
1737 1842
1738 java-pkg_setup-vm 1843 java-pkg_setup-vm
1739 1844
1740 export JAVA=$(java-config --java) 1845 export JAVA=$(java-config --java)
1741 export JAVAC=$(java-config --javac) 1846 export JAVAC=$(java-config --javac)
1742 export JAVACFLAGS="$(java-pkg_javac-args)" 1847 JAVACFLAGS="$(java-pkg_javac-args)"
1848 if [[ ${?} != 0 ]]; then
1849 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1850 die "java-pkg_javac-args failed"
1851 fi
1743 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1852 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1853 export JAVACFLAGS
1744 1854
1745 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1855 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1746 export JDK_HOME=${JAVA_HOME} 1856 export JDK_HOME=${JAVA_HOME}
1747 1857
1748 #TODO If you know a better solution let us know. 1858 #TODO If you know a better solution let us know.
1749 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1859 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1750 1860
1751 local tann="${T}/announced-vm" 1861 local tann="${T}/announced-vm"
1752 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1862 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1753 # Add a check for setup/preinst phase... to avoid duplicate outputs 1863 # Add a check for setup/preinst phase... to avoid duplicate outputs
1754 # for when FEATURES=buildpkg 1864 # for when FEATURES=buildpkg
1755 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1865 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1799# TODO document 1909# TODO document
1800# Verify that the classes were compiled for the right source / target 1910# Verify that the classes were compiled for the right source / target
1801java-pkg_verify-classes() { 1911java-pkg_verify-classes() {
1802 ebegin "Verifying java class versions" 1912 ebegin "Verifying java class versions"
1803 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1913 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1804 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1914 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1805 result=$? 1915 result=$?
1806 eend ${result} 1916 eend ${result}
1807 if [[ ${result} == 0 ]]; then 1917 if [[ ${result} == 0 ]]; then
1808 einfo "All good" 1918 einfo "All good"
1809 else 1919 else
1851 let "JAVA_PKG_QA_VIOLATIONS+=1" 1961 let "JAVA_PKG_QA_VIOLATIONS+=1"
1852 export JAVA_PKG_QA_VIOLATIONS 1962 export JAVA_PKG_QA_VIOLATIONS
1853} 1963}
1854 1964
1855is-java-strict() { 1965is-java-strict() {
1856 hasq java-strict ${FEATURES} && ! hasq -java-strict ${FEATURES} 1966 [[ -n ${JAVA_PKG_STRICT} ]]
1857 return $? 1967 return $?
1858} 1968}
1859 1969
1860# ------------------------------------------------------------------------------ 1970# ------------------------------------------------------------------------------
1861# @eclass-end 1971# @eclass-end

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20