/[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.30
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.30 2006/12/03 17:42:53 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
302java-pkg_addcp() { 303java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 304 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 305 java-pkg_do_write_
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})"
428# ------------------------------------------------------------------------------ 428# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 429java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 430 debug-print-function ${FUNCNAME} $*
431 431
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433
433 # TODO-nichoj find out what exactly -f package-list does 434 # TODO-nichoj find out what exactly -f package-list does
434 dohtml -f package-list "$@" 435 dohtml -f package-list "$@"
435 # this probably shouldn't be here but it provides 436 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 437 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 438 # old ebuilds.
438 java-pkg_recordjavadoc 439 java-pkg_recordjavadoc
439} 440}
440 441
441# TODO document 442# ------------------------------------------------------------------------------
443# @ebuild-function java-pkg_dojavadoc
444#
445# Installs javadoc documentation. This should be controlled by the doc use flag.
446#
447# @param $1: - The javadoc root directory.
448#
449# @example:
450# java-pkg_dojavadoc docs/api
451#
452# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 453java-pkg_dojavadoc() {
443 local dir="$1" 454 local dir="$1"
444 455
445 java-pkg_check-phase install 456 java-pkg_check-phase install
446 457
458} 469}
459 470
460# ------------------------------------------------------------------------------ 471# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 472# @ebuild-function java-pkg_dosrc
462# 473#
463# Installs a zip containing the source for a package, so it can used in 474# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 475# from IDEs like eclipse and netbeans.
465# 476#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 477# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 478#
468# It also should be controlled by USE=source. 479# It also should be controlled by USE=source.
469# 480#
470# @example: 481# @example:
471# java-pkg_dosrc src/* 482# java-pkg_dosrc src/*
472# 483#
473# ------------------------------------------------------------------------------ 484# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 485# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 486# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 487# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 488# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 489# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 490java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 491 debug-print-function ${FUNCNAME} $*
481 492
482 [ ${#} -lt 1 ] && die "At least one argument needed" 493 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 494 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 495 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 496 fi
486 497
487 java-pkg_check-phase install 498 java-pkg_check-phase install
488 499
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 500 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 501
491 java-pkg_init_paths_ 502 java-pkg_init_paths_
492 503
493 local zip_name="${PN}-src.zip" 504 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 505 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 529# @ebuild-function java-pkg_dolauncher
519# 530#
520# Make a wrapper script to lauch/start this package 531# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 532# If necessary, the wrapper will switch to the appropriate VM.
522# 533#
534# Can be called without parameters if the package installs only one jar
535# that has the Main-class attribute set. The wrapper will be named ${PN}.
536#
523# @param $1 - filename of launcher to create 537# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 538# @param $2 - options, as follows:
525# --main the.main.class.too.start 539# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 540# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 541# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 542# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 543# --pwd
530# -into 544# -into
531# -pre 545# -pre
532# ------------------------------------------------------------------------------ 546# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 547java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 548 debug-print-function ${FUNCNAME} $*
535 549
536 java-pkg_check-phase install 550 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 551 java-pkg_init_paths_
541 552
553 if [[ ${#} = 0 ]]; then
554 local name="${PN}"
555 else
542 local name="${1}" 556 local name="${1}"
557 shift
558 fi
559
543 # TODO rename to launcher 560 # TODO rename to launcher
544 local target="${T}/${name}" 561 local target="${T}/${name}"
562 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 563 local target_dir pre
546 shift
547 564
548 echo "#!/bin/bash" > "${target}" 565 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 566 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 567 local var=${1} value=${2}
551 if [[ "${var:0:2}" == "--" ]]; then 568 if [[ "${var:0:2}" == "--" ]]; then
569 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 570 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
571 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 572 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 573 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 574 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 575 pre="${value}"
557 fi 576 fi
558 shift 2 577 shift 2
559 done 578 done
579
580 # Test if no --jar and --main arguments were given and
581 # in that case check if the package only installs one jar
582 # and use that jar.
583 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
584 local cp="${JAVA_PKG_CLASSPATH}"
585 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
586 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
587 else
588 local msg="Not enough information to create a launcher given."
589 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
590 die "${msg}"
591 fi
592 fi
593
594 # Write the actual script
595 echo "#!/bin/bash" > "${target}"
596 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 597 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 598 cat "${var_tmp}" >> "${target}"
599 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 600 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 601
564 if [[ -n "${into}" ]]; then 602 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 603 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 604 local ret=$?
567 return ${ret} 605 return ${ret}
568 else 606 else
569 dobin "${target}" 607 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 635 echo "dowar: warning, skipping directory ${war}"
598 continue 636 continue
599 else 637 else
600 warpath="${war}" 638 warpath="${war}"
601 fi 639 fi
602 640
603 # Install those files like you mean it 641 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 642 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 643 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 644 doins ${warpath}
607 done 645 done
642# @ebuild-function java-pkg_jar-from 680# @ebuild-function java-pkg_jar-from
643# 681#
644# Makes a symlink to a jar from a certain package 682# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 683# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 684# You can use this function to replace these bundled dependencies.
685# The dependency is recorded into package.env DEPEND line, unless "--build-only"
686# is passed as the very first argument, for jars that have to be present only
687# at build time and are not needed on runtime (junit testing etc).
647# 688#
648# Example: get all jars from xerces slot 2 689# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 690# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 691# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 692# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 693# 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 694# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
695# Example: get junit.jar which is needed only for building
696# java-pkg_jar-from --build-only junit junit.jar
654# 697#
698# @param $1 - (optional) "--build-only" makes the jar(s) not added into
699# package.env DEPEND line.
655# @param $1 - Package to get jars from. 700# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 701# @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 702# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 703# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 704# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 705# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 706java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 707 debug-print-function ${FUNCNAME} $*
663 708
709 local build_only=""
710
711 if [[ "${1}" = "--build-only" ]]; then
712 build_only="true"
713 shift
714 fi
715
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 716 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 717
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 718 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 719
668 # default destjar to the target jar 720 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 721 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 722
723 local error_msg="There was a problem getting the classpath for ${target_pkg}."
724 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 725 classpath="$(java-config --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 726 [[ $? != 0 ]] && die ${error_msg}
673 727
674 local jar 728 local jar
675 for jar in ${classpath//:/ }; do 729 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 730 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 731 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 735 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 736 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 737 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 738 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 739 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 740 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 741 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 742 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 743 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 744 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 745 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 746 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 747 return 0
694 fi 748 fi
695 done 749 done
696 # if no target was specified, we're ok 750 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 751 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 768# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 769# @ebuild-function java-pkg_getjars
716# 770#
717# Get the classpath provided by any number of packages 771# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 772# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
773# The providing packages are recorded as dependencies into package.env DEPEND
774# line, unless "--build-only" is passed as the very first argument, for jars
775# that have to be present only at build time and are not needed on runtime
776# (junit testing etc).
719# 777#
720# Example: Get the classpath for xerces-2, 778# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 779# java-pkg_getjars xerces-2,xalan
722# Example Return: 780# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 781# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 782#
783# @param $1 - (optional) "--build-only" makes the jar(s) not added into
784# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 785# @param $2 - list of packages to get jars from
786# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 787# ------------------------------------------------------------------------------
727java-pkg_getjars() { 788java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 789 debug-print-function ${FUNCNAME} $*
729 790
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 791 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments"
731 792
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 793 if [[ "${1}" = "--build-only" ]]; then
794 local build_only="true"
795 shift
796 fi
797
733 local classpath pkg 798 local classpath pkgs="${1}"
734 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 799 jars="$(java-config --classpath=${pkgs})"
800 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
737 debug-print "${pkg}:${jars}" 801 debug-print "${pkgs}:${jars}"
738 # TODO should we ensure jars exist? 802
739 if [[ -z "${classpath}" ]]; then 803 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 804 classpath="${jars}"
741 else 805 else
742 classpath="${classpath}:${jars}" 806 classpath="${classpath}:${jars}"
743 fi 807 fi
808
809 # Only record jars that aren't build-only
810 if [[ -z "${build_only}" ]]; then
811 oldifs="${IFS}"
812 IFS=":"
813 for pkg in ${pkgs}; do
744 java-pkg_record-jar_ "${pkg}" 814 java-pkg_record-jar_ "${pkg}"
745 done 815 done
816 IFS="${oldifs}"
817 fi
818
746 echo "${classpath}" 819 echo "${classpath}"
747} 820}
748 821
749# ------------------------------------------------------------------------------ 822# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 823# @ebuild-function java-pkg_getjar
751# 824#
752# Get the filename of a single jar from a package 825# Get the filename of a single jar from a package
826# The providing package is recorded as runtime dependency into package.env
827# DEPEND line, unless "--build-only" is passed as the very first argument, for
828# jars that have to be present only at build time and are not needed on runtime
829# (junit testing etc).
753# 830#
754# @example 831# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 832# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 833# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 834# /usr/share/xerces-2/lib/xml-apis.jar
758# 835#
836# @param $1 - (optional) "--build-only" makes the jar not added into
837# package.env DEPEND line.
759# @param $1 - package to use 838# @param $1 - package to use
760# @param $2 - jar to get 839# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 840# ------------------------------------------------------------------------------
762java-pkg_getjar() { 841java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 842 debug-print-function ${FUNCNAME} $*
843
844 local build_only=""
845
846 if [[ "${1}" = "--build-only" ]]; then
847 build_only="true"
848 shift
849 fi
764 850
765 local pkg="${1}" target_jar="${2}" jar 851 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 852 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 853 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 854
769 # TODO check that package is actually installed 855 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
856 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 857 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 858 [[ $? != 0 ]] && die ${error_msg}
859
772 for jar in ${classpath//:/ }; do 860 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 861 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 862 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 863 fi
776 864
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 865 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 866 # Only record jars that aren't build-only
867 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 868 echo "${jar}"
780 return 0 869 return 0
781 fi 870 fi
782 done 871 done
783 872
784 die "Could not find ${target_jar} in ${pkg}" 873 die "Could not find ${target_jar} in ${pkg}"
785 return 1 874 return 1
786} 875}
787 876
788# This function reads stdin, and based on that input, figures out how to 877# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 891# line="${line// /}"
803# 892#
804# # format: path=jarinfo 893# # format: path=jarinfo
805# local path=${line%%=*} 894# local path=${line%%=*}
806# local jarinfo=${line##*=} 895# local jarinfo=${line##*=}
807# 896#
808# # format: jar@package 897# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 898# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 899# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 900# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 901# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 914# @section-end query
826# ------------------------------------------------------------------------------ 915# ------------------------------------------------------------------------------
827 916
828# ------------------------------------------------------------------------------ 917# ------------------------------------------------------------------------------
829# @section-begin helper 918# @section-begin helper
830# @section-summary Helper functions 919# @section-summary Helper functions
831# 920#
832# Various other functions to use from an ebuild 921# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 922# ------------------------------------------------------------------------------
834 923
835# ------------------------------------------------------------------------------ 924# ------------------------------------------------------------------------------
841# jdbc-stdext 930# jdbc-stdext
842# jaf 931# jaf
843# jdbc-rowset 932# jdbc-rowset
844# jms 933# jms
845# 934#
846# @param $1 - Optionally indicate that the dependencies are controlled by 935# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 936# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 937# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 938# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 939# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 940# TODO rewrite to parse a line based declaration file instead -- karltk
945 fi 1034 fi
946} 1035}
947 1036
948# ------------------------------------------------------------------------------ 1037# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1038# @internal-function java-pkg_is-vm-version-sufficient
950# 1039#
951# @return zero - VM is sufficient 1040# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1041# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1042# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1043java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1044 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1064 die "Active Java VM too old"
976 fi 1065 fi
977} 1066}
978 1067
979# ------------------------------------------------------------------------------ 1068# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1069# @internal-function java-pkg_is-vm-version-eq
981# 1070#
982# @param $@ - VM version to compare current VM to 1071# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1072# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1073# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1074# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1075java-pkg_is-vm-version-eq() {
1016# 1105#
1017# @param $@ - VM version to compare current to 1106# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1107# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1108java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1109 debug-print-function ${FUNCNAME} $*
1021 1110
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1111 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1112 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1113 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1114 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1115 die "Active Java VM too old"
1027 fi 1116 fi
1028} 1117}
1029 1118
1030# ------------------------------------------------------------------------------ 1119# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1120# @internal-function java-pkg_is-vm-version-ge
1032# 1121#
1033# @param $@ - VM version to compare current VM to 1122# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1123# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1124# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1125# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1126java-pkg_is-vm-version-ge() {
1060java-pkg_get-current-vm() { 1149java-pkg_get-current-vm() {
1061 echo ${GENTOO_VM} 1150 echo ${GENTOO_VM}
1062} 1151}
1063 1152
1064java-pkg_current-vm-matches() { 1153java-pkg_current-vm-matches() {
1065 hasq java-pkg_get-currenv-vm ${@} 1154 hasq $(java-pkg_get-current-vm) ${@}
1066 return $? 1155 return $?
1067} 1156}
1068 1157
1069# ------------------------------------------------------------------------------ 1158# ------------------------------------------------------------------------------
1070# @ebuild-function java-pkg_get-source 1159# @ebuild-function java-pkg_get-source
1071# 1160#
1072# Determines what source version should be used, for passing to -source. 1161# 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 1162# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1074# 1163#
1075# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1164# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1076# ------------------------------------------------------------------------------ 1165# ------------------------------------------------------------------------------
1081# ------------------------------------------------------------------------------ 1170# ------------------------------------------------------------------------------
1082# @ebuild-function java-pkg_get-target 1171# @ebuild-function java-pkg_get-target
1083# 1172#
1084# Determines what target version should be used, for passing to -target. 1173# 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 1174# If you don't care about lower versions, you can set _WANT_TARGET to the
1086# version of your JDK. 1175# version of your JDK.
1087# Remember doing this will mostly like cause things to break. 1176# Remember doing this will mostly like cause things to break.
1088# Doesn't allow it to be lower then the one in depend. 1177# Doesn't allow it to be lower then the one in depend.
1089# Doesn't allow it to be higher then the active vm. 1178# Doesn't allow it to be higher then the active vm.
1090# 1179#
1091# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1180# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1092# ------------------------------------------------------------------------------ 1181# ------------------------------------------------------------------------------
1093java-pkg_get-target() { 1182java-pkg_get-target() {
1094 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1183 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1095 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1184 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1096 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1185 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 1186 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} 1187 echo ${JAVA_PKG_WANT_TARGET}
1099 else 1188 else
1107} 1196}
1108 1197
1109java-pkg_get-javac() { 1198java-pkg_get-javac() {
1110 debug-print-function ${FUNCNAME} $* 1199 debug-print-function ${FUNCNAME} $*
1111 1200
1112 java-pkg_init-compiler_ 1201
1113 local compiler="${GENTOO_COMPILER}" 1202 local compiler="${GENTOO_COMPILER}"
1114 1203
1115 local compiler_executable 1204 local compiler_executable
1116 if [[ "${compiler}" = "javac" ]]; then 1205 if [[ "${compiler}" = "javac" ]]; then
1117 # nothing fancy needs to be done for javac 1206 # nothing fancy needs to be done for javac
1125 unset JAVAC 1214 unset JAVAC
1126 # try to get value of JAVAC 1215 # try to get value of JAVAC
1127 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1216 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1128 export JAVAC=${old_javac} 1217 export JAVAC=${old_javac}
1129 1218
1130 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1219 if [[ -z ${compiler_executable} ]]; then
1131 1220 echo "JAVAC is empty or undefined in ${compiler_env}"
1221 return 1
1222 fi
1223
1132 # check that it's executable 1224 # check that it's executable
1133 if [[ ! -x ${compiler_executable} ]]; then 1225 if [[ ! -x ${compiler_executable} ]]; then
1134 eerror "Could not find ${compiler_executable}!"
1135 die "${compiler_executable} doesn't exist, or isn't executable" 1226 echo "${compiler_executable} doesn't exist, or isn't executable"
1227 return 1
1136 fi 1228 fi
1137 else 1229 else
1138 eerror "Could not find environment file for ${compiler}" 1230 echo "Could not find environment file for ${compiler}"
1139 die "Could not find ${compiler_env}" 1231 return 1
1140 fi 1232 fi
1141 fi 1233 fi
1142 echo ${compiler_executable} 1234 echo ${compiler_executable}
1143} 1235}
1144 1236
1145# ------------------------------------------------------------------------------ 1237# ------------------------------------------------------------------------------
1146# @ebuild-function java-pkg_javac-args 1238# @ebuild-function java-pkg_javac-args
1147# 1239#
1148# If an ebuild uses javac directly, instead of using ejavac, it should call this 1240# If an ebuild uses javac directly, instead of using ejavac, it should call this
1149# to know what -source/-target to use. 1241# to know what -source/-target to use.
1150# 1242#
1151# @return string - arguments to pass to javac, complete with -target and -source 1243# @return string - arguments to pass to javac, complete with -target and -source
1154 debug-print-function ${FUNCNAME} $* 1246 debug-print-function ${FUNCNAME} $*
1155 1247
1156 local want_source="$(java-pkg_get-source)" 1248 local want_source="$(java-pkg_get-source)"
1157 local want_target="$(java-pkg_get-target)" 1249 local want_target="$(java-pkg_get-target)"
1158 1250
1159 local source_str="-source ${want_source}" 1251 local source_str="-source ${want_source}"
1160 local target_str="-target ${want_target}" 1252 local target_str="-target ${want_target}"
1161 1253
1162 debug-print "want source: ${want_source}" 1254 debug-print "want source: ${want_source}"
1163 debug-print "want target: ${want_target}" 1255 debug-print "want target: ${want_target}"
1164 1256
1165 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1257 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1166 debug-print "could not find valid -source/-target values" 1258 debug-print "could not find valid -source/-target values for javac"
1167 die "Could not find valid -source/-target values" 1259 echo "Could not find valid -source/-target values for javac"
1260 return 1
1168 else 1261 else
1169 if java-pkg_is-vm-version-ge "1.4"; then 1262 if java-pkg_is-vm-version-ge "1.4"; then
1170 echo "${source_str} ${target_str}" 1263 echo "${source_str} ${target_str}"
1171 else 1264 else
1172 echo "${target_str}" 1265 echo "${target_str}"
1190 ewarn 1283 ewarn
1191 ewarn "You must build gcc with the gcj support to build with gcj" 1284 ewarn "You must build gcc with the gcj support to build with gcj"
1192 ewarn 1285 ewarn
1193 ebeep 5 1286 ebeep 5
1194 die "No GCJ support found!" 1287 die "No GCJ support found!"
1288 fi
1289}
1290
1291java-pkg_ensure-test() {
1292 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1293 eerror "You specified FEATURES=test, but USE=test is needed"
1294 eerror "to pull in the additional dependencies for testing"
1295 die "Need USE=test enabled"
1195 fi 1296 fi
1196} 1297}
1197 1298
1198# ------------------------------------------------------------------------------ 1299# ------------------------------------------------------------------------------
1199# @section-end helper 1300# @section-end helper
1248 1349
1249 if is-java-strict; then 1350 if is-java-strict; then
1250 einfo "Disabling system classpath for ant" 1351 einfo "Disabling system classpath for ant"
1251 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1352 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1252 fi 1353 fi
1253 1354
1254 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1355 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1255 antflags="${antflags} -debug" 1356 antflags="${antflags} -debug"
1256 fi 1357 fi
1257 1358
1258 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1359 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1259 ant ${antflags} "${@}" || die "eant failed" 1360 ant ${antflags} "${@}" || die "eant failed"
1260 1361
1261} 1362}
1262 1363
1263# ------------------------------------------------------------------------------ 1364# ------------------------------------------------------------------------------
1264# @ebuild-function ejavac 1365# @ebuild-function ejavac
1265# 1366#
1266# Javac wrapper function. Will use the appropriate compiler, based on 1367# Javac wrapper function. Will use the appropriate compiler, based on
1267# /etc/java-config/compilers.conf 1368# /etc/java-config/compilers.conf
1268# 1369#
1269# @param $@ - Arguments to be passed to the compiler 1370# @param $@ - Arguments to be passed to the compiler
1270# ------------------------------------------------------------------------------ 1371# ------------------------------------------------------------------------------
1271ejavac() { 1372ejavac() {
1272 debug-print-function ${FUNCNAME} $* 1373 debug-print-function ${FUNCNAME} $*
1273 1374
1274 # FIXME using get-javac ends up printing stuff with einfo 1375 java-pkg_init-compiler_
1376
1377 local compiler_executable
1275# local compiler_executable=$(java-pkg_get-javac) 1378 compiler_executable=$(java-pkg_get-javac)
1276 local compiler_executable="javac" 1379 if [[ ${?} != 0 ]]; then
1380 eerror "There was a problem determining compiler: ${compiler_executable}"
1381 die "get-javac failed"
1382 fi
1277 1383
1384 local javac_args
1385 javac_args="$(java-pkg_javac-args)"
1386 if [[ ${?} != 0 ]]; then
1387 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1388 die "java-pkg_javac-args failed"
1389 fi
1390
1278 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1391 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1279 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1392 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1280} 1393}
1281 1394
1282# ------------------------------------------------------------------------------ 1395# ------------------------------------------------------------------------------
1283# @ebuild-function java-pkg_filter-compiler 1396# @ebuild-function java-pkg_filter-compiler
1284# 1397#
1285# Used to prevent the use of some compilers. Should be used in src_compile. 1398# Used to prevent the use of some compilers. Should be used in src_compile.
1286# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1399# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1287# 1400#
1288# @param $@ - compilers to filter 1401# @param $@ - compilers to filter
1289# ------------------------------------------------------------------------------ 1402# ------------------------------------------------------------------------------
1307# ------------------------------------------------------------------------------ 1420# ------------------------------------------------------------------------------
1308# @ebuild-function use_doc 1421# @ebuild-function use_doc
1309# 1422#
1310# Helper function for getting ant to build javadocs. If the user has USE=doc, 1423# 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. 1424# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1312# 1425#
1313# The output of this should be passed to ant. 1426# The output of this should be passed to ant.
1314# 1427#
1315# Example: build javadocs by calling 'javadoc' target 1428# Example: build javadocs by calling 'javadoc' target
1316# eant $(use_doc) 1429# eant $(use_doc)
1317# Example: build javadocs by calling 'apidoc' target 1430# Example: build javadocs by calling 'apidoc' target
1325} 1438}
1326 1439
1327# ------------------------------------------------------------------------------ 1440# ------------------------------------------------------------------------------
1328# @section-end build 1441# @section-end build
1329# ------------------------------------------------------------------------------ 1442# ------------------------------------------------------------------------------
1330 1443
1331# ------------------------------------------------------------------------------ 1444# ------------------------------------------------------------------------------
1332# @section-begin internal 1445# @section-begin internal
1333# @section-summary Internal functions 1446# @section-summary Internal functions
1334# 1447#
1335# Do __NOT__ use any of these from an ebuild! These are only to be used from 1448# Do __NOT__ use any of these from an ebuild! These are only to be used from
1336# within the java eclasses. 1449# within the java eclasses.
1337# ------------------------------------------------------------------------------ 1450# ------------------------------------------------------------------------------
1338 1451
1339# ----------------------------------------------------------------------------- 1452# -----------------------------------------------------------------------------
1340# @function-internal java-pkg_init 1453# @function-internal java-pkg_init
1341# 1454#
1342# The purpose of this function, as the name might imply, is to initialize the 1455# 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 1456# 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 1457# that'll muss things up. It initializes some variables, which are used
1345# internally. And most importantly, it'll switch the VM if necessary. 1458# internally. And most importantly, it'll switch the VM if necessary.
1346# 1459#
1358 # TODO we will probably want to set JAVAC and JAVACFLAGS 1471 # TODO we will probably want to set JAVAC and JAVACFLAGS
1359 1472
1360 # Do some QA checks 1473 # Do some QA checks
1361 java-pkg_check-jikes 1474 java-pkg_check-jikes
1362 1475
1363 # When users have crazy classpaths some packages can fail to compile. 1476 # When users have crazy classpaths some packages can fail to compile.
1364 # and everything should work with empty CLASSPATH. 1477 # and everything should work with empty CLASSPATH.
1365 # This also helps prevent unexpected dependencies on random things 1478 # This also helps prevent unexpected dependencies on random things
1366 # from the CLASSPATH. 1479 # from the CLASSPATH.
1367 unset CLASSPATH 1480 unset CLASSPATH
1368} 1481}
1369 1482
1370# ------------------------------------------------------------------------------ 1483# ------------------------------------------------------------------------------
1371# @function-internal java-pkg-init-compiler_ 1484# @function-internal java-pkg-init-compiler_
1372# 1485#
1373# This function attempts to figure out what compiler should be used. It does 1486# 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 1487# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1375# COMPILERS variable defined there. 1488# COMPILERS variable defined there.
1376# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1489# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1377# 1490#
1378# It will go through the list of compilers, and verify that it supports the 1491# 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 1492# 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 1493# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1381# isn't done. 1494# isn't done.
1382# 1495#
1404 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1517 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1405 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1518 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1406 else 1519 else
1407 compilers=${JAVA_PKG_FORCE_COMPILER} 1520 compilers=${JAVA_PKG_FORCE_COMPILER}
1408 fi 1521 fi
1409 1522
1410 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1523 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1411 1524
1412 # Figure out if we should announce what compiler we're using 1525 # Figure out if we should announce what compiler we're using
1413 local compiler 1526 local compiler
1414 for compiler in ${compilers}; do 1527 for compiler in ${compilers}; do
1417 if [[ ${compiler} = "javac" ]]; then 1530 if [[ ${compiler} = "javac" ]]; then
1418 debug-print "Found javac... breaking" 1531 debug-print "Found javac... breaking"
1419 export GENTOO_COMPILER="javac" 1532 export GENTOO_COMPILER="javac"
1420 break 1533 break
1421 fi 1534 fi
1422 1535
1423 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1536 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1424 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1537 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1425 einfo "Filtering ${compiler}" 1538 einfo "Filtering ${compiler}"
1426 continue 1539 continue
1427 fi 1540 fi
1428 fi 1541 fi
1429 1542
1430 # for non-javac, we need to make sure it supports the right target and 1543 # for non-javac, we need to make sure it supports the right target and
1431 # source 1544 # source
1432 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1545 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1433 if [[ -f ${compiler_env} ]]; then 1546 if [[ -f ${compiler_env} ]]; then
1434 local desired_target="$(java-pkg_get-target)" 1547 local desired_target="$(java-pkg_get-target)"
1516# Writes the package.env out to disk. 1629# Writes the package.env out to disk.
1517# 1630#
1518# ------------------------------------------------------------------------------ 1631# ------------------------------------------------------------------------------
1519# TODO change to do-write, to match everything else 1632# TODO change to do-write, to match everything else
1520java-pkg_do_write_() { 1633java-pkg_do_write_() {
1634 java-pkg_init_paths_
1521 # Create directory for package.env 1635 # Create directory for package.env
1522 dodir "${JAVA_PKG_SHAREPATH}" 1636 dodir "${JAVA_PKG_SHAREPATH}"
1523 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1637 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1524 # Create package.env 1638 # Create package.env
1525 ( 1639 (
1530 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1644 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1531 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1645 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1532 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1646 [[ -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 ! 1647 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1534 ) > "${JAVA_PKG_ENV}" 1648 ) > "${JAVA_PKG_ENV}"
1535 1649
1536 # register target/source 1650 # register target/source
1537 local target="$(java-pkg_get-target)" 1651 local target="$(java-pkg_get-target)"
1538 local source="$(java-pkg_get-source)" 1652 local source="$(java-pkg_get-source)"
1539 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1653 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1540 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1654 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1553 # Strip unnecessary leading and trailing colons 1667 # Strip unnecessary leading and trailing colons
1554 # TODO try to cleanup if possible 1668 # TODO try to cleanup if possible
1555 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1669 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1556 fi 1670 fi
1557} 1671}
1558
1559 1672
1560# ------------------------------------------------------------------------------ 1673# ------------------------------------------------------------------------------
1561# @internal-function java-pkg_record-jar_ 1674# @internal-function java-pkg_record-jar_
1562# 1675#
1563# Record a dependency to the package.env 1676# Record a dependency to the package.env
1607 fi 1720 fi
1608} 1721}
1609 1722
1610# ------------------------------------------------------------------------------ 1723# ------------------------------------------------------------------------------
1611# @internal-function java-pkg_expand_dir_ 1724# @internal-function java-pkg_expand_dir_
1612# 1725#
1613# Gets the full path of the file/directory's parent. 1726# Gets the full path of the file/directory's parent.
1614# @param $1 - file/directory to find parent directory for 1727# @param $1 - file/directory to find parent directory for
1615# @return - path to $1's parent directory 1728# @return - path to $1's parent directory
1616# ------------------------------------------------------------------------------ 1729# ------------------------------------------------------------------------------
1617java-pkg_expand_dir_() { 1730java-pkg_expand_dir_() {
1644# ------------------------------------------------------------------------------ 1757# ------------------------------------------------------------------------------
1645java-pkg_setup-vm() { 1758java-pkg_setup-vm() {
1646 debug-print-function ${FUNCNAME} $* 1759 debug-print-function ${FUNCNAME} $*
1647 1760
1648 local vendor="$(java-pkg_get-vm-vendor)" 1761 local vendor="$(java-pkg_get-vm-vendor)"
1649 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1762 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1650 addpredict "/dev/random" 1763 addpredict "/dev/random"
1651 elif [[ "${vendor}" == "ibm" ]]; then 1764 elif [[ "${vendor}" == "ibm" ]]; then
1652 addpredict "/proc/self/maps" 1765 addpredict "/proc/self/maps"
1653 addpredict "/proc/cpuinfo" 1766 addpredict "/proc/cpuinfo"
1654 export LANG="C" LC_ALL="C" 1767 export LANG="C" LC_ALL="C"
1703# @return - The version of the current VM 1816# @return - The version of the current VM
1704# ------------------------------------------------------------------------------ 1817# ------------------------------------------------------------------------------
1705java-pkg_get-vm-version() { 1818java-pkg_get-vm-version() {
1706 debug-print-function ${FUNCNAME} $* 1819 debug-print-function ${FUNCNAME} $*
1707 1820
1708 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1821 java-config -g PROVIDES_VERSION
1709} 1822}
1710 1823
1711# ------------------------------------------------------------------------------ 1824# ------------------------------------------------------------------------------
1712# @internal-function java-pkg_switch-vm 1825# @internal-function java-pkg_switch-vm
1713# 1826#
1714# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1827# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1715# verify that the current VM is sufficient. 1828# verify that the current VM is sufficient.
1716# Setup the environment for the VM being used. 1829# Setup the environment for the VM being used.
1717# ------------------------------------------------------------------------------ 1830# ------------------------------------------------------------------------------
1718java-pkg_switch-vm() { 1831java-pkg_switch-vm() {
1719 if java-pkg_needs-vm; then 1832 if java-pkg_needs-vm; then
1723 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1836 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1724 # if we're allowed to switch the vm... 1837 # if we're allowed to switch the vm...
1725 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1838 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}" 1839 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1727 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1840 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}}")" 1841 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1729 else 1842 else
1730 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1843 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1844 fi
1845 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1846 eerror "Unable to determine VM for building from dependencies."
1847 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1848 echo "VNEED: ${JAVA_PKG_VNEED}"
1849 else
1850 export GENTOO_VM
1731 fi 1851 fi
1732 # otherwise just make sure the current VM is sufficient 1852 # otherwise just make sure the current VM is sufficient
1733 else 1853 else
1734 java-pkg_ensure-vm-version-sufficient 1854 java-pkg_ensure-vm-version-sufficient
1735 fi 1855 fi
1736 debug-print "Using: $(java-config -f)" 1856 debug-print "Using: $(java-config -f)"
1737 1857
1738 java-pkg_setup-vm 1858 java-pkg_setup-vm
1739 1859
1740 export JAVA=$(java-config --java) 1860 export JAVA=$(java-config --java)
1741 export JAVAC=$(java-config --javac) 1861 export JAVAC=$(java-config --javac)
1742 export JAVACFLAGS="$(java-pkg_javac-args)" 1862 JAVACFLAGS="$(java-pkg_javac-args)"
1863 if [[ ${?} != 0 ]]; then
1864 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1865 die "java-pkg_javac-args failed"
1866 fi
1743 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1867 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1868 export JAVACFLAGS
1744 1869
1745 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1870 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1746 export JDK_HOME=${JAVA_HOME} 1871 export JDK_HOME=${JAVA_HOME}
1747 1872
1748 #TODO If you know a better solution let us know. 1873 #TODO If you know a better solution let us know.
1749 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1874 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1750 1875
1751 local tann="${T}/announced-vm" 1876 local tann="${T}/announced-vm"
1752 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1877 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1753 # Add a check for setup/preinst phase... to avoid duplicate outputs 1878 # Add a check for setup/preinst phase... to avoid duplicate outputs
1754 # for when FEATURES=buildpkg 1879 # for when FEATURES=buildpkg
1755 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1880 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1799# TODO document 1924# TODO document
1800# Verify that the classes were compiled for the right source / target 1925# Verify that the classes were compiled for the right source / target
1801java-pkg_verify-classes() { 1926java-pkg_verify-classes() {
1802 ebegin "Verifying java class versions" 1927 ebegin "Verifying java class versions"
1803 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1928 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1804 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1929 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1805 result=$? 1930 result=$?
1806 eend ${result} 1931 eend ${result}
1807 if [[ ${result} == 0 ]]; then 1932 if [[ ${result} == 0 ]]; then
1808 einfo "All good" 1933 einfo "All good"
1809 else 1934 else
1810 ewarn "Possible problem" 1935 ewarn "Possible problem"
1811 die "Bad class files found" 1936 die "Bad class files found"
1812 fi 1937 fi
1813} 1938}
1814 1939
1815
1816# ------------------------------------------------------------------------------ 1940# ------------------------------------------------------------------------------
1817# @section-end internal 1941# @section-end internal
1818# ------------------------------------------------------------------------------ 1942# ------------------------------------------------------------------------------
1819 1943
1820java-pkg_check-phase() { 1944java-pkg_check-phase() {
1851 let "JAVA_PKG_QA_VIOLATIONS+=1" 1975 let "JAVA_PKG_QA_VIOLATIONS+=1"
1852 export JAVA_PKG_QA_VIOLATIONS 1976 export JAVA_PKG_QA_VIOLATIONS
1853} 1977}
1854 1978
1855is-java-strict() { 1979is-java-strict() {
1856 hasq java-strict ${FEATURES} && ! hasq -java-strict ${FEATURES} 1980 [[ -n ${JAVA_PKG_STRICT} ]]
1857 return $? 1981 return $?
1858} 1982}
1859 1983
1860# ------------------------------------------------------------------------------ 1984# ------------------------------------------------------------------------------
1861# @eclass-end 1985# @eclass-end

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

  ViewVC Help
Powered by ViewVC 1.1.20