/[gentoo-x86]/eclass/java-utils-2.eclass
Gentoo

Diff of /eclass/java-utils-2.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.10 Revision 1.29
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.29 2006/12/03 13:05:06 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
305} 306}
306 307
307 308
308# ------------------------------------------------------------------------------ 309# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 310# @ebuild-function java-pkg_doso
310# 311#
311# Installs any number of JNI libraries 312# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 313# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 314# can be used change this path
314# 315#
315# Example: 316# Example:
370 java-pkg_check-phase install 371 java-pkg_check-phase install
371 372
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 373 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 374
374 java-pkg_init_paths_ 375 java-pkg_init_paths_
375 376
376 local lib target_dir 377 local lib target_dir
377 for lib in "$@" ; do 378 for lib in "$@" ; do
378 # Check the absolute path of the lib 379 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 380 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 381 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 429# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 430java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 431 debug-print-function ${FUNCNAME} $*
431 432
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 433 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
434
433 # TODO-nichoj find out what exactly -f package-list does 435 # TODO-nichoj find out what exactly -f package-list does
434 dohtml -f package-list "$@" 436 dohtml -f package-list "$@"
435 # this probably shouldn't be here but it provides 437 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 438 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 439 # old ebuilds.
458} 460}
459 461
460# ------------------------------------------------------------------------------ 462# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 463# @ebuild-function java-pkg_dosrc
462# 464#
463# Installs a zip containing the source for a package, so it can used in 465# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 466# from IDEs like eclipse and netbeans.
465# 467#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 468# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 469#
468# It also should be controlled by USE=source. 470# It also should be controlled by USE=source.
469# 471#
470# @example: 472# @example:
471# java-pkg_dosrc src/* 473# java-pkg_dosrc src/*
472# 474#
473# ------------------------------------------------------------------------------ 475# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 476# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 477# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 478# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 479# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 480# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 481java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 482 debug-print-function ${FUNCNAME} $*
481 483
482 [ ${#} -lt 1 ] && die "At least one argument needed" 484 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 485 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 486 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 487 fi
486 488
487 java-pkg_check-phase install 489 java-pkg_check-phase install
488 490
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 491 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 492
491 java-pkg_init_paths_ 493 java-pkg_init_paths_
492 494
493 local zip_name="${PN}-src.zip" 495 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 496 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 520# @ebuild-function java-pkg_dolauncher
519# 521#
520# Make a wrapper script to lauch/start this package 522# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 523# If necessary, the wrapper will switch to the appropriate VM.
522# 524#
525# Can be called without parameters if the package installs only one jar
526# that has the Main-class attribute set. The wrapper will be named ${PN}.
527#
523# @param $1 - filename of launcher to create 528# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 529# @param $2 - options, as follows:
525# --main the.main.class.too.start 530# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 531# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 532# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 533# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 534# --pwd
530# -into 535# -into
531# -pre 536# -pre
532# ------------------------------------------------------------------------------ 537# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 538java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 539 debug-print-function ${FUNCNAME} $*
535 540
536 java-pkg_check-phase install 541 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 542 java-pkg_init_paths_
541 543
544 if [[ ${#} = 0 ]]; then
545 local name="${PN}"
546 else
542 local name="${1}" 547 local name="${1}"
548 shift
549 fi
550
543 # TODO rename to launcher 551 # TODO rename to launcher
544 local target="${T}/${name}" 552 local target="${T}/${name}"
553 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 554 local target_dir pre
546 shift
547 555
548 echo "#!/bin/bash" > "${target}" 556 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 557 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 558 local var=${1} value=${2}
551 if [[ "${var:0:2}" == "--" ]]; then 559 if [[ "${var:0:2}" == "--" ]]; then
560 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 561 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
562 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 563 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 564 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 565 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 566 pre="${value}"
557 fi 567 fi
558 shift 2 568 shift 2
559 done 569 done
570
571 # Test if no --jar and --main arguments were given and
572 # in that case check if the package only installs one jar
573 # and use that jar.
574 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
575 local cp="${JAVA_PKG_CLASSPATH}"
576 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
577 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
578 else
579 local msg="Not enough information to create a launcher given."
580 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
581 die "${msg}"
582 fi
583 fi
584
585 # Write the actual script
586 echo "#!/bin/bash" > "${target}"
587 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 588 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 589 cat "${var_tmp}" >> "${target}"
590 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 591 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 592
564 if [[ -n "${into}" ]]; then 593 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 594 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 595 local ret=$?
567 return ${ret} 596 return ${ret}
568 else 597 else
569 dobin "${target}" 598 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 626 echo "dowar: warning, skipping directory ${war}"
598 continue 627 continue
599 else 628 else
600 warpath="${war}" 629 warpath="${war}"
601 fi 630 fi
602 631
603 # Install those files like you mean it 632 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 633 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 634 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 635 doins ${warpath}
607 done 636 done
642# @ebuild-function java-pkg_jar-from 671# @ebuild-function java-pkg_jar-from
643# 672#
644# Makes a symlink to a jar from a certain package 673# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 674# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 675# You can use this function to replace these bundled dependencies.
676# The dependency is recorded into package.env DEPEND line, unless "--build-only"
677# is passed as the very first argument, for jars that have to be present only
678# at build time and are not needed on runtime (junit testing etc).
647# 679#
648# Example: get all jars from xerces slot 2 680# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 681# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 682# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 683# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 684# 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 685# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
686# Example: get junit.jar which is needed only for building
687# java-pkg_jar-from --build-only junit junit.jar
654# 688#
689# @param $1 - (optional) "--build-only" makes the jar(s) not added into
690# package.env DEPEND line.
655# @param $1 - Package to get jars from. 691# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 692# @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 693# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 694# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 695# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 696# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 697java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 698 debug-print-function ${FUNCNAME} $*
663 699
700 local build_only=""
701
702 if [[ "${1}" = "--build-only" ]]; then
703 build_only="true"
704 shift
705 fi
706
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 707 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 708
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 709 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 710
668 # default destjar to the target jar 711 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 712 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 713
714 local error_msg="There was a problem getting the classpath for ${target_pkg}."
715 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 716 classpath="$(java-config --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 717 [[ $? != 0 ]] && die ${error_msg}
673 718
674 local jar 719 local jar
675 for jar in ${classpath//:/ }; do 720 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 721 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 722 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 726 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 727 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 728 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 729 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 730 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 731 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 732 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 733 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 734 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 735 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 736 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 737 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 738 return 0
694 fi 739 fi
695 done 740 done
696 # if no target was specified, we're ok 741 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 742 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 759# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 760# @ebuild-function java-pkg_getjars
716# 761#
717# Get the classpath provided by any number of packages 762# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 763# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
764# The providing packages are recorded as dependencies into package.env DEPEND
765# line, unless "--build-only" is passed as the very first argument, for jars
766# that have to be present only at build time and are not needed on runtime
767# (junit testing etc).
719# 768#
720# Example: Get the classpath for xerces-2, 769# Example: Get the classpath for xerces-2,
721# java-pkg_getjars xerces-2 xalan 770# java-pkg_getjars xerces-2 xalan
722# Example Return: 771# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 772# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 773#
774# @param $1 - (optional) "--build-only" makes the jar(s) not added into
775# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 776# @param $@ - list of packages to get jars from
726# ------------------------------------------------------------------------------ 777# ------------------------------------------------------------------------------
727java-pkg_getjars() { 778java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 779 debug-print-function ${FUNCNAME} $*
780
781 local build_only=""
782
783 if [[ "${1}" = "--build-only" ]]; then
784 build_only="true"
785 shift
786 fi
729 787
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 788 [[ ${#} -lt 1 ]] && die "At least one argument needed"
731 789
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 790 # NOTE could probably just pass $@ to java-config --classpath. and return it
733 local classpath pkg 791 local classpath pkg
734 for pkg in ${@//,/ }; do 792 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do 793 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 794 jars="$(java-config --classpath=${pkg})"
795 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
737 debug-print "${pkg}:${jars}" 796 debug-print "${pkg}:${jars}"
738 # TODO should we ensure jars exist? 797
739 if [[ -z "${classpath}" ]]; then 798 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 799 classpath="${jars}"
741 else 800 else
742 classpath="${classpath}:${jars}" 801 classpath="${classpath}:${jars}"
743 fi 802 fi
744 java-pkg_record-jar_ "${pkg}" 803 # Only record jars that aren't build-only
804 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
745 done 805 done
746 echo "${classpath}" 806 echo "${classpath}"
747} 807}
748 808
749# ------------------------------------------------------------------------------ 809# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 810# @ebuild-function java-pkg_getjar
751# 811#
752# Get the filename of a single jar from a package 812# Get the filename of a single jar from a package
813# The providing package is recorded as runtime dependency into package.env
814# DEPEND line, unless "--build-only" is passed as the very first argument, for
815# jars that have to be present only at build time and are not needed on runtime
816# (junit testing etc).
753# 817#
754# @example 818# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 819# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 820# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 821# /usr/share/xerces-2/lib/xml-apis.jar
758# 822#
823# @param $1 - (optional) "--build-only" makes the jar not added into
824# package.env DEPEND line.
759# @param $1 - package to use 825# @param $1 - package to use
760# @param $2 - jar to get 826# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 827# ------------------------------------------------------------------------------
762java-pkg_getjar() { 828java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 829 debug-print-function ${FUNCNAME} $*
830
831 local build_only=""
832
833 if [[ "${1}" = "--build-only" ]]; then
834 build_only="true"
835 shift
836 fi
764 837
765 local pkg="${1}" target_jar="${2}" jar 838 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 839 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 840 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 841
769 # TODO check that package is actually installed 842 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
843 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 844 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 845 [[ $? != 0 ]] && die ${error_msg}
846
772 for jar in ${classpath//:/ }; do 847 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 848 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 849 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 850 fi
776 851
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 852 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 853 # Only record jars that aren't build-only
854 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 855 echo "${jar}"
780 return 0 856 return 0
781 fi 857 fi
782 done 858 done
783 859
784 die "Could not find ${target_jar} in ${pkg}" 860 die "Could not find ${target_jar} in ${pkg}"
785 return 1 861 return 1
786} 862}
787 863
788# This function reads stdin, and based on that input, figures out how to 864# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 878# line="${line// /}"
803# 879#
804# # format: path=jarinfo 880# # format: path=jarinfo
805# local path=${line%%=*} 881# local path=${line%%=*}
806# local jarinfo=${line##*=} 882# local jarinfo=${line##*=}
807# 883#
808# # format: jar@package 884# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 885# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 886# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 887# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 888# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 901# @section-end query
826# ------------------------------------------------------------------------------ 902# ------------------------------------------------------------------------------
827 903
828# ------------------------------------------------------------------------------ 904# ------------------------------------------------------------------------------
829# @section-begin helper 905# @section-begin helper
830# @section-summary Helper functions 906# @section-summary Helper functions
831# 907#
832# Various other functions to use from an ebuild 908# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 909# ------------------------------------------------------------------------------
834 910
835# ------------------------------------------------------------------------------ 911# ------------------------------------------------------------------------------
841# jdbc-stdext 917# jdbc-stdext
842# jaf 918# jaf
843# jdbc-rowset 919# jdbc-rowset
844# jms 920# jms
845# 921#
846# @param $1 - Optionally indicate that the dependencies are controlled by 922# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 923# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 924# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 925# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 926# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 927# TODO rewrite to parse a line based declaration file instead -- karltk
945 fi 1021 fi
946} 1022}
947 1023
948# ------------------------------------------------------------------------------ 1024# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1025# @internal-function java-pkg_is-vm-version-sufficient
950# 1026#
951# @return zero - VM is sufficient 1027# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1028# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1029# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1030java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1031 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1051 die "Active Java VM too old"
976 fi 1052 fi
977} 1053}
978 1054
979# ------------------------------------------------------------------------------ 1055# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1056# @internal-function java-pkg_is-vm-version-eq
981# 1057#
982# @param $@ - VM version to compare current VM to 1058# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1059# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1060# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1061# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1062java-pkg_is-vm-version-eq() {
1016# 1092#
1017# @param $@ - VM version to compare current to 1093# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1094# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1095java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1096 debug-print-function ${FUNCNAME} $*
1021 1097
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1098 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1099 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1100 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1101 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1102 die "Active Java VM too old"
1027 fi 1103 fi
1028} 1104}
1029 1105
1030# ------------------------------------------------------------------------------ 1106# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1107# @internal-function java-pkg_is-vm-version-ge
1032# 1108#
1033# @param $@ - VM version to compare current VM to 1109# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1110# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1111# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1112# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1113java-pkg_is-vm-version-ge() {
1051 return 1 1127 return 1
1052 fi 1128 fi
1053 fi 1129 fi
1054} 1130}
1055 1131
1132java-pkg_set-current-vm() {
1133 export GENTOO_VM=${1}
1134}
1135
1136java-pkg_get-current-vm() {
1137 echo ${GENTOO_VM}
1138}
1139
1140java-pkg_current-vm-matches() {
1141 hasq $(java-pkg_get-current-vm) ${@}
1142 return $?
1143}
1144
1056# ------------------------------------------------------------------------------ 1145# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1146# @ebuild-function java-pkg_get-source
1058# 1147#
1059# Determines what source version should be used, for passing to -source. 1148# Determines what source version should be used, for passing to -source.
1060# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1149# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1150#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1151# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1152# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1157# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1158# @ebuild-function java-pkg_get-target
1070# 1159#
1071# Determines what target version should be used, for passing to -target. 1160# Determines what target version should be used, for passing to -target.
1072# If you don't care about lower versions, you can set _WANT_TARGET to the 1161# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1162# version of your JDK.
1074# Remember doing this will mostly like cause things to break. 1163# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend. 1164# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm. 1165# Doesn't allow it to be higher then the active vm.
1077# 1166#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1167# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1168# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1169java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1170 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1171 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1172 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1084 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then 1173 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1085 echo ${JAVA_PKG_WANT_TARGET} 1174 echo ${JAVA_PKG_WANT_TARGET}
1086 else 1175 else
1094} 1183}
1095 1184
1096java-pkg_get-javac() { 1185java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1186 debug-print-function ${FUNCNAME} $*
1098 1187
1099 java-pkg_init-compiler_ 1188
1100 local compiler="${GENTOO_COMPILER}" 1189 local compiler="${GENTOO_COMPILER}"
1101 1190
1102 local compiler_executable 1191 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1192 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1193 # nothing fancy needs to be done for javac
1112 unset JAVAC 1201 unset JAVAC
1113 # try to get value of JAVAC 1202 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1203 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1204 export JAVAC=${old_javac}
1116 1205
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1206 if [[ -z ${compiler_executable} ]]; then
1118 1207 echo "JAVAC is empty or undefined in ${compiler_env}"
1208 return 1
1209 fi
1210
1119 # check that it's executable 1211 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1212 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1213 echo "${compiler_executable} doesn't exist, or isn't executable"
1214 return 1
1123 fi 1215 fi
1124 else 1216 else
1125 eerror "Could not find environment file for ${compiler}" 1217 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1218 return 1
1127 fi 1219 fi
1128 fi 1220 fi
1129 echo ${compiler_executable} 1221 echo ${compiler_executable}
1130} 1222}
1131 1223
1132# ------------------------------------------------------------------------------ 1224# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1225# @ebuild-function java-pkg_javac-args
1134# 1226#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1227# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1228# to know what -source/-target to use.
1137# 1229#
1138# @return string - arguments to pass to javac, complete with -target and -source 1230# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1233 debug-print-function ${FUNCNAME} $*
1142 1234
1143 local want_source="$(java-pkg_get-source)" 1235 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1236 local want_target="$(java-pkg_get-target)"
1145 1237
1146 local source_str="-source ${want_source}" 1238 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1239 local target_str="-target ${want_target}"
1148 1240
1149 debug-print "want source: ${want_source}" 1241 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1242 debug-print "want target: ${want_target}"
1151 1243
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1244 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1245 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1246 echo "Could not find valid -source/-target values for javac"
1247 return 1
1155 else 1248 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1249 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1250 echo "${source_str} ${target_str}"
1158 else 1251 else
1159 echo "${target_str}" 1252 echo "${target_str}"
1180 ebeep 5 1273 ebeep 5
1181 die "No GCJ support found!" 1274 die "No GCJ support found!"
1182 fi 1275 fi
1183} 1276}
1184 1277
1278java-pkg_ensure-test() {
1279 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1280 eerror "You specified FEATURES=test, but USE=test is needed"
1281 eerror "to pull in the additional dependencies for testing"
1282 die "Need USE=test enabled"
1283 fi
1284}
1285
1185# ------------------------------------------------------------------------------ 1286# ------------------------------------------------------------------------------
1186# @section-end helper 1287# @section-end helper
1187# ------------------------------------------------------------------------------ 1288# ------------------------------------------------------------------------------
1188 1289
1189# ------------------------------------------------------------------------------ 1290# ------------------------------------------------------------------------------
1201# compiler. 1302# compiler.
1202# 1303#
1203# ------------------------------------------------------------------------------ 1304# ------------------------------------------------------------------------------
1204eant() { 1305eant() {
1205 debug-print-function ${FUNCNAME} $* 1306 debug-print-function ${FUNCNAME} $*
1307
1308 # FIXME get this working
1309# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1310# java-pkg_announce-qa-violation \
1311# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1312# fi
1206 1313
1207 local antflags 1314 local antflags
1208 java-pkg_init-compiler_ 1315 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1316 local compiler="${GENTOO_COMPILER}"
1210 1317
1229 1336
1230 if is-java-strict; then 1337 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1338 einfo "Disabling system classpath for ant"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1339 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1233 fi 1340 fi
1234 1341
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1342 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1236 antflags="${antflags} -debug" 1343 antflags="${antflags} -debug"
1237 fi 1344 fi
1238 1345
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1346 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 1347 ant ${antflags} "${@}" || die "eant failed"
1241 1348
1242} 1349}
1243 1350
1244# ------------------------------------------------------------------------------ 1351# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 1352# @ebuild-function ejavac
1246# 1353#
1247# Javac wrapper function. Will use the appropriate compiler, based on 1354# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 1355# /etc/java-config/compilers.conf
1249# 1356#
1250# @param $@ - Arguments to be passed to the compiler 1357# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 1358# ------------------------------------------------------------------------------
1252ejavac() { 1359ejavac() {
1253 debug-print-function ${FUNCNAME} $* 1360 debug-print-function ${FUNCNAME} $*
1254 1361
1255 # FIXME using get-javac ends up printing stuff with einfo 1362 java-pkg_init-compiler_
1363
1364 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 1365 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 1366 if [[ ${?} != 0 ]]; then
1367 eerror "There was a problem determining compiler: ${compiler_executable}"
1368 die "get-javac failed"
1369 fi
1258 1370
1371 local javac_args
1372 javac_args="$(java-pkg_javac-args)"
1373 if [[ ${?} != 0 ]]; then
1374 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1375 die "java-pkg_javac-args failed"
1376 fi
1377
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1378 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1379 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 1380}
1262 1381
1263# ------------------------------------------------------------------------------ 1382# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 1383# @ebuild-function java-pkg_filter-compiler
1265# 1384#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 1385# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1386# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 1387#
1269# @param $@ - compilers to filter 1388# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 1389# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 1407# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 1408# @ebuild-function use_doc
1290# 1409#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 1410# Helper function for getting ant to build javadocs. If the user has USE=doc,
1292# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1411# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 1412#
1294# The output of this should be passed to ant. 1413# The output of this should be passed to ant.
1295# 1414#
1296# Example: build javadocs by calling 'javadoc' target 1415# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 1416# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 1417# Example: build javadocs by calling 'apidoc' target
1306} 1425}
1307 1426
1308# ------------------------------------------------------------------------------ 1427# ------------------------------------------------------------------------------
1309# @section-end build 1428# @section-end build
1310# ------------------------------------------------------------------------------ 1429# ------------------------------------------------------------------------------
1311 1430
1312# ------------------------------------------------------------------------------ 1431# ------------------------------------------------------------------------------
1313# @section-begin internal 1432# @section-begin internal
1314# @section-summary Internal functions 1433# @section-summary Internal functions
1315# 1434#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 1435# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 1436# within the java eclasses.
1318# ------------------------------------------------------------------------------ 1437# ------------------------------------------------------------------------------
1319 1438
1320# ----------------------------------------------------------------------------- 1439# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 1440# @function-internal java-pkg_init
1322# 1441#
1323# The purpose of this function, as the name might imply, is to initialize the 1442# The purpose of this function, as the name might imply, is to initialize the
1324# Java environment. It ensures that that there aren't any environment variables 1443# Java environment. It ensures that that there aren't any environment variables
1325# that'll muss things up. It initializes some variables, which are used 1444# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 1445# internally. And most importantly, it'll switch the VM if necessary.
1327# 1446#
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 1458 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 1459
1341 # Do some QA checks 1460 # Do some QA checks
1342 java-pkg_check-jikes 1461 java-pkg_check-jikes
1343 1462
1344 # When users have crazy classpaths some packages can fail to compile. 1463 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 1464 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 1465 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 1466 # from the CLASSPATH.
1348 unset CLASSPATH 1467 unset CLASSPATH
1349} 1468}
1350 1469
1351# ------------------------------------------------------------------------------ 1470# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 1471# @function-internal java-pkg-init-compiler_
1353# 1472#
1354# This function attempts to figure out what compiler should be used. It does 1473# This function attempts to figure out what compiler should be used. It does
1355# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1474# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 1475# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1476# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 1477#
1359# It will go through the list of compilers, and verify that it supports the 1478# It will go through the list of compilers, and verify that it supports the
1360# target and source that are needed. If it is not suitable, then the next 1479# target and source that are needed. If it is not suitable, then the next
1361# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1480# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 1481# isn't done.
1363# 1482#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1504 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1505 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 1506 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 1507 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 1508 fi
1390 1509
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1510 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 1511
1393 # Figure out if we should announce what compiler we're using 1512 # Figure out if we should announce what compiler we're using
1394 local compiler 1513 local compiler
1395 for compiler in ${compilers}; do 1514 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 1517 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 1518 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 1519 export GENTOO_COMPILER="javac"
1401 break 1520 break
1402 fi 1521 fi
1403 1522
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1523 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1524 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 1525 einfo "Filtering ${compiler}"
1407 continue 1526 continue
1408 fi 1527 fi
1409 fi 1528 fi
1410 1529
1411 # for non-javac, we need to make sure it supports the right target and 1530 # for non-javac, we need to make sure it supports the right target and
1412 # source 1531 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1532 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 1533 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 1534 local desired_target="$(java-pkg_get-target)"
1497# Writes the package.env out to disk. 1616# Writes the package.env out to disk.
1498# 1617#
1499# ------------------------------------------------------------------------------ 1618# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 1619# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 1620java-pkg_do_write_() {
1621 java-pkg_init_paths_
1502 # Create directory for package.env 1622 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 1623 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1624 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1505 # Create package.env 1625 # Create package.env
1506 ( 1626 (
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1631 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1632 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1633 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1634 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1515 ) > "${JAVA_PKG_ENV}" 1635 ) > "${JAVA_PKG_ENV}"
1516 1636
1517 # register target/source 1637 # register target/source
1518 local target="$(java-pkg_get-target)" 1638 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 1639 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1640 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1641 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1534 # Strip unnecessary leading and trailing colons 1654 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 1655 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1656 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1537 fi 1657 fi
1538} 1658}
1539
1540 1659
1541# ------------------------------------------------------------------------------ 1660# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 1661# @internal-function java-pkg_record-jar_
1543# 1662#
1544# Record a dependency to the package.env 1663# Record a dependency to the package.env
1588 fi 1707 fi
1589} 1708}
1590 1709
1591# ------------------------------------------------------------------------------ 1710# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 1711# @internal-function java-pkg_expand_dir_
1593# 1712#
1594# Gets the full path of the file/directory's parent. 1713# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 1714# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 1715# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 1716# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 1717java-pkg_expand_dir_() {
1625# ------------------------------------------------------------------------------ 1744# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 1745java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 1746 debug-print-function ${FUNCNAME} $*
1628 1747
1629 local vendor="$(java-pkg_get-vm-vendor)" 1748 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1749 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 1750 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 1751 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 1752 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 1753 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C" 1754 export LANG="C" LC_ALL="C"
1684# @return - The version of the current VM 1803# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 1804# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 1805java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 1806 debug-print-function ${FUNCNAME} $*
1688 1807
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1808 java-config -g PROVIDES_VERSION
1690} 1809}
1691 1810
1692# ------------------------------------------------------------------------------ 1811# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 1812# @internal-function java-pkg_switch-vm
1694# 1813#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1814# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 1815# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 1816# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 1817# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 1818java-pkg_switch-vm() {
1700 if java-pkg_needs-vm; then 1819 if java-pkg_needs-vm; then
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1823 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 1824 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1825 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1707 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1826 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1827 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1709 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1828 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1710 else 1829 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1830 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1831 fi
1832 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1833 eerror "Unable to determine VM for building from dependencies."
1834 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1835 echo "VNEED: ${JAVA_PKG_VNEED}"
1836 else
1837 export GENTOO_VM
1712 fi 1838 fi
1713 # otherwise just make sure the current VM is sufficient 1839 # otherwise just make sure the current VM is sufficient
1714 else 1840 else
1715 java-pkg_ensure-vm-version-sufficient 1841 java-pkg_ensure-vm-version-sufficient
1716 fi 1842 fi
1717 debug-print "Using: $(java-config -f)" 1843 debug-print "Using: $(java-config -f)"
1718 1844
1719 java-pkg_setup-vm 1845 java-pkg_setup-vm
1720 1846
1721 export JAVA=$(java-config --java) 1847 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 1848 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 1849 JAVACFLAGS="$(java-pkg_javac-args)"
1850 if [[ ${?} != 0 ]]; then
1851 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1852 die "java-pkg_javac-args failed"
1853 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1854 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1855 export JAVACFLAGS
1725 1856
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1857 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 1858 export JDK_HOME=${JAVA_HOME}
1728 1859
1729 #TODO If you know a better solution let us know. 1860 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1861 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 1862
1732 local tann="${T}/announced-vm" 1863 local tann="${T}/announced-vm"
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1864 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs 1865 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg 1866 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1867 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1780# TODO document 1911# TODO document
1781# Verify that the classes were compiled for the right source / target 1912# Verify that the classes were compiled for the right source / target
1782java-pkg_verify-classes() { 1913java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions" 1914 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1915 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1916 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1786 result=$? 1917 result=$?
1787 eend ${result} 1918 eend ${result}
1788 if [[ ${result} == 0 ]]; then 1919 if [[ ${result} == 0 ]]; then
1789 einfo "All good" 1920 einfo "All good"
1790 else 1921 else
1791 ewarn "Possible problem" 1922 ewarn "Possible problem"
1792 die "Bad class files found" 1923 die "Bad class files found"
1793 fi 1924 fi
1794} 1925}
1795 1926
1796
1797# ------------------------------------------------------------------------------ 1927# ------------------------------------------------------------------------------
1798# @section-end internal 1928# @section-end internal
1799# ------------------------------------------------------------------------------ 1929# ------------------------------------------------------------------------------
1800 1930
1801java-pkg_check-phase() { 1931java-pkg_check-phase() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 1962 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 1963 export JAVA_PKG_QA_VIOLATIONS
1834} 1964}
1835 1965
1836is-java-strict() { 1966is-java-strict() {
1837 hasq java-strict ${FEATURES}; 1967 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 1968 return $?
1839} 1969}
1840 1970
1841# ------------------------------------------------------------------------------ 1971# ------------------------------------------------------------------------------
1842# @eclass-end 1972# @eclass-end

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

  ViewVC Help
Powered by ViewVC 1.1.20