/[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.3 Revision 1.22
11# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
12# @eclass-begin 12# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
15# 15#
16# This eclass provides functionality which is used by 16# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 18#
19# @warning 19# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 20# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 21# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 22# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 23#
24# ----------------------------------------------------------------------------- 24# -----------------------------------------------------------------------------
25 25
26inherit eutils versionator multilib 26inherit eutils versionator multilib
33# ----------------------------------------------------------------------------- 33# -----------------------------------------------------------------------------
34 34
35# Make sure we use java-config-2 35# Make sure we use java-config-2
36export WANT_JAVA_CONFIG="2" 36export WANT_JAVA_CONFIG="2"
37 37
38# TODO document
39JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
40
38# ----------------------------------------------------------------------------- 41# -----------------------------------------------------------------------------
39# @variable-internal JAVA_PKG_E_DEPEND 42# @variable-internal JAVA_PKG_E_DEPEND
40# 43#
41# This is a convience variable to be used from the other java eclasses. This is 44# This is a convience variable to be used from the other java eclasses. This is
42# the version of java-config we want to use. We also need a recent version 45# the version of java-config we want to use. We also need a recent version
43# portage, that includes phase hooks. 46# portage, that includes phase hooks.
44# ----------------------------------------------------------------------------- 47# -----------------------------------------------------------------------------
45JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 >=sys-apps/portage-2.1_pre1" 48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
46 49
47# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
48# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 51# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
49# @variable-default yes 52# @variable-default yes
50# 53#
97# ----------------------------------------------------------------------------- 100# -----------------------------------------------------------------------------
98 101
99# ----------------------------------------------------------------------------- 102# -----------------------------------------------------------------------------
100# @variable-internal JAVA_PKG_COMPILER_DIR 103# @variable-internal JAVA_PKG_COMPILER_DIR
101# @default /usr/share/java-config-2/compiler 104# @default /usr/share/java-config-2/compiler
102# 105#
103# Directory where compiler settings are saved, without trailing slash. 106# Directory where compiler settings are saved, without trailing slash.
104# Probably shouldn't touch this variable. 107# Probably shouldn't touch this variable.
105# ----------------------------------------------------------------------------- 108# -----------------------------------------------------------------------------
106JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
107 110
117 120
118# ----------------------------------------------------------------------------- 121# -----------------------------------------------------------------------------
119# @variable-external JAVA_PKG_FORCE_COMPILER 122# @variable-external JAVA_PKG_FORCE_COMPILER
120# 123#
121# Explicitly set a list of compilers to use. This is normally read from 124# Explicitly set a list of compilers to use. This is normally read from
122# JAVA_PKG_COMPILERS_CONF. 125# JAVA_PKG_COMPILERS_CONF.
123# 126#
124# @note This should only be used internally or for testing. 127# @note This should only be used internally or for testing.
125# @example Use jikes and javac, in that order 128# @example Use jikes and javac, in that order
126# JAVA_PKG_FORCE_COMPILER="jikes javac" 129# JAVA_PKG_FORCE_COMPILER="jikes javac"
127# ----------------------------------------------------------------------------- 130# -----------------------------------------------------------------------------
147# @ebuild-function java-pkg_dojar 150# @ebuild-function java-pkg_dojar
148# 151#
149# Installs any number of jars. 152# Installs any number of jars.
150# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
151# You can use java-pkg_jarinto to change this path. 154# You can use java-pkg_jarinto to change this path.
152# You should never install a jar with a package version in the filename. 155# You should never install a jar with a package version in the filename.
153# Instead, use java-pkg_newjar defined below. 156# Instead, use java-pkg_newjar defined below.
154# 157#
155# @example 158# @example
156# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
157# 160#
206# Records an already installed jar in the package.env 209# Records an already installed jar in the package.env
207# This would mostly be used if the package has make or a custom script to 210# This would mostly be used if the package has make or a custom script to
208# install things. 211# install things.
209# 212#
210# Example: 213# Example:
211# java-pkg-regjar ${D}/opt/foo/lib/foo.jar 214# java-pkg_regjar ${D}/opt/foo/lib/foo.jar
215#
216# WARNING:
217# if you want to use shell expansion, you have to use ${D}/... as the for in
218# this function will not be able to expand the path, here's an example:
219#
220# java-pkg_regjar /opt/my-java/lib/*.jar
221#
222# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist
227#
228# you have to use it as:
229#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
212# 231#
213# @param $@ - jars to record 232# @param $@ - jars to record
214# ------------------------------------------------------------------------------ 233# ------------------------------------------------------------------------------
215# TODO fix me! 234# TODO should we be making sure the jar is present on ${D} or wherever?
216java-pkg_regjar() { 235java-pkg_regjar() {
217 debug-print-function ${FUNCNAME} $* 236 debug-print-function ${FUNCNAME} $*
218 237
219 java-pkg_check-phase install 238 java-pkg_check-phase install
220 239
224 243
225 local jar jar_dir jar_file 244 local jar jar_dir jar_file
226 for jar in "$@"; do 245 for jar in "$@"; do
227 # TODO use java-pkg_check-versioned-jar 246 # TODO use java-pkg_check-versioned-jar
228 if [[ -e "${jar}" ]]; then 247 if [[ -e "${jar}" ]]; then
248 # nelchael: we should strip ${D} in this case too, here's why:
249 # imagine such call:
250 # java-pkg_regjar ${D}/opt/java/*.jar
251 # such call will fall into this case (-e ${jar}) and will
252 # record paths with ${D} in package.env
229 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar}" 253 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
230 elif [[ -e "${D}${jar}" ]]; then 254 elif [[ -e "${D}${jar}" ]]; then
231 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 255 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
232 else 256 else
233 die "${jar} does not exist" 257 die "${jar} does not exist"
234 fi 258 fi
255 local original_jar="${1}" 279 local original_jar="${1}"
256 local new_jar="${2:-${PN}.jar}" 280 local new_jar="${2:-${PN}.jar}"
257 local new_jar_dest="${T}/${new_jar}" 281 local new_jar_dest="${T}/${new_jar}"
258 282
259 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 283 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
260 [[ ! -f ${original_jar} ]] && die "${new_jar} does not exist!" 284 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!"
261 285
262 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 286 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
263 cp "${original_jar}" "${new_jar_dest}" \ 287 cp "${original_jar}" "${new_jar_dest}" \
264 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 288 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
265 java-pkg_dojar "${new_jar_dest}" 289 java-pkg_dojar "${new_jar_dest}"
281} 305}
282 306
283 307
284# ------------------------------------------------------------------------------ 308# ------------------------------------------------------------------------------
285# @ebuild-function java-pkg_doso 309# @ebuild-function java-pkg_doso
286# 310#
287# Installs any number of JNI libraries 311# Installs any number of JNI libraries
288# 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
289# can be used change this path 313# can be used change this path
290# 314#
291# Example: 315# Example:
346 java-pkg_check-phase install 370 java-pkg_check-phase install
347 371
348 [[ ${#} -lt 1 ]] && "at least one argument needed" 372 [[ ${#} -lt 1 ]] && "at least one argument needed"
349 373
350 java-pkg_init_paths_ 374 java-pkg_init_paths_
351 375
352 local lib target_dir 376 local lib target_dir
353 for lib in "$@" ; do 377 for lib in "$@" ; do
354 # Check the absolute path of the lib 378 # Check the absolute path of the lib
355 if [[ -e "${lib}" ]] ; then 379 if [[ -e "${lib}" ]] ; then
356 target_dir="$(java-pkg_expand_dir_ ${lib})" 380 target_dir="$(java-pkg_expand_dir_ ${lib})"
434} 458}
435 459
436# ------------------------------------------------------------------------------ 460# ------------------------------------------------------------------------------
437# @ebuild-function java-pkg_dosrc 461# @ebuild-function java-pkg_dosrc
438# 462#
439# Installs a zip containing the source for a package, so it can used in 463# Installs a zip containing the source for a package, so it can used in
440# from IDEs like eclipse and netbeans. 464# from IDEs like eclipse and netbeans.
441# 465#
442# Ebuild needs to DEPEND on app-arch/zip to use this. 466# Ebuild needs to DEPEND on app-arch/zip to use this.
443# 467#
444# It also should be controlled by USE=source. 468# It also should be controlled by USE=source.
445# 469#
446# @example: 470# @example:
447# java-pkg_dosrc src/* 471# java-pkg_dosrc src/*
448# 472#
449# ------------------------------------------------------------------------------ 473# ------------------------------------------------------------------------------
450# TODO change so it the arguments it takes are the base directories containing 474# TODO change so it the arguments it takes are the base directories containing
451# source -nichoj 475# source -nichoj
452# TODO should we be able to handle multiple calls to dosrc? -nichoj 476# TODO should we be able to handle multiple calls to dosrc? -nichoj
453# TODO maybe we can take an existing zip/jar? -nichoj 477# TODO maybe we can take an existing zip/jar? -nichoj
454# FIXME apparently this fails if you give it an empty directories 478# FIXME apparently this fails if you give it an empty directories
455java-pkg_dosrc() { 479java-pkg_dosrc() {
456 debug-print-function ${FUNCNAME} $* 480 debug-print-function ${FUNCNAME} $*
457 481
458 [ ${#} -lt 1 ] && die "At least one argument needed" 482 [ ${#} -lt 1 ] && die "At least one argument needed"
459 if ! hasq source ${IUSE}; then 483 if ! hasq source ${IUSE}; then
460 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
461 fi 485 fi
462 486
463 java-pkg_check-phase install 487 java-pkg_check-phase install
464 488
465 [[ ${#} -lt 1 ]] && die "At least one argument needed" 489 [[ ${#} -lt 1 ]] && die "At least one argument needed"
466 490
467 java-pkg_init_paths_ 491 java-pkg_init_paths_
468 492
469 local zip_name="${PN}-src.zip" 493 local zip_name="${PN}-src.zip"
470 local zip_path="${T}/${zip_name}" 494 local zip_path="${T}/${zip_name}"
498# 522#
499# @param $1 - filename of launcher to create 523# @param $1 - filename of launcher to create
500# @param $2 - options, as follows: 524# @param $2 - options, as follows:
501# --main the.main.class.too.start 525# --main the.main.class.too.start
502# --jar /the/jar/too/launch.jar 526# --jar /the/jar/too/launch.jar
503# --java_args 'Extra arguments to pass too jave' 527# --java_args 'Extra arguments to pass to java'
504# --pkg_args 'extra arguments too pass too the package' 528# --pkg_args 'Extra arguments too pass to the package'
505# --pwd 529# --pwd
506# -into 530# -into
507# -pre 531# -pre
508# ------------------------------------------------------------------------------ 532# ------------------------------------------------------------------------------
509java-pkg_dolauncher() { 533java-pkg_dolauncher() {
516 java-pkg_init_paths_ 540 java-pkg_init_paths_
517 541
518 local name="${1}" 542 local name="${1}"
519 # TODO rename to launcher 543 # TODO rename to launcher
520 local target="${T}/${name}" 544 local target="${T}/${name}"
545 local var_tmp="${T}/launcher_variables_tmp"
521 local target_dir pre 546 local target_dir pre
522 shift 547 shift
523 548
524 echo "#!/bin/bash" > "${target}" 549 # Process the other the rest of the arguments
525 while [[ -n "${1}" && -n "${2}" ]]; do 550 while [[ -n "${1}" && -n "${2}" ]]; do
526 local var=${1} value=${2} 551 local var=${1} value=${2}
527 if [[ "${var:0:2}" == "--" ]]; then 552 if [[ "${var:0:2}" == "--" ]]; then
528 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 553 echo "gjl_${var:2}=\"${value}\"" >> "${var_tmp}"
529 elif [[ "${var}" == "-into" ]]; then 554 elif [[ "${var}" == "-into" ]]; then
530 target_dir="${value}" 555 target_dir="${value}"
531 elif [[ "${var}" == "-pre" ]]; then 556 elif [[ "${var}" == "-pre" ]]; then
532 pre="${value}" 557 pre="${value}"
533 fi 558 fi
534 shift 2 559 shift 2
535 done 560 done
561
562 # Write the actual script
563 echo "#!/bin/bash" > "${target}"
564 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
536 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 565 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
537 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 566 cat "${var_tmp}" >> "${target}"
567 rm -f "${var_tmp}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 568 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 569
540 if [[ -n "${into}" ]]; then 570 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 571 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 572 local ret=$?
543 return ${ret} 573 return ${ret}
544 else 574 else
545 dobin "${target}" 575 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 603 echo "dowar: warning, skipping directory ${war}"
574 continue 604 continue
575 else 605 else
576 warpath="${war}" 606 warpath="${war}"
577 fi 607 fi
578 608
579 # Install those files like you mean it 609 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 610 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 611 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 612 doins ${warpath}
583 done 613 done
618# @ebuild-function java-pkg_jar-from 648# @ebuild-function java-pkg_jar-from
619# 649#
620# Makes a symlink to a jar from a certain package 650# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 651# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 652# You can use this function to replace these bundled dependencies.
653# The dependency is recorded into package.env DEPEND line, unless "--build-only"
654# is passed as the very first argument, for jars that have to be present only
655# at build time and are not needed on runtime (junit testing etc).
623# 656#
624# Example: get all jars from xerces slot 2 657# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 658# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 659# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 660# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 661# Example: get a specific jar from xerces slot 2, and name it diffrently
629# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 662# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
663# Example: get junit.jar which is needed only for building
664# java-pkg_jar-from --build-only junit junit.jar
630# 665#
666# @param $1 - (optional) "--build-only" makes the jar(s) not added into
667# package.env DEPEND line.
631# @param $1 - Package to get jars from. 668# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 669# @param $2 - jar from package. If not specified, all jars will be used.
633# @param $3 - When a single jar is specified, destination filename of the 670# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 671# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 672# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 673# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 674java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 675 debug-print-function ${FUNCNAME} $*
639 676
677 local build_only=""
678
679 if [[ "${1}" = "--build-only" ]]; then
680 build_only="true"
681 shift
682 fi
683
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 684 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 685
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 686 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 687
644 # default destjar to the target jar 688 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 689 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 690
691 local error_msg="There was a problem getting the classpath for ${target_pkg}."
692 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 693 classpath="$(java-config --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 694 [[ $? != 0 ]] && die ${error_msg}
649 695
650 local jar 696 local jar
651 for jar in ${classpath//:/ }; do 697 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 698 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 699 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 703 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 704 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 705 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 706 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 707 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 708 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 709 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 710 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 711 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 712 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 713 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 714 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 715 return 0
670 fi 716 fi
671 done 717 done
672 # if no target was specified, we're ok 718 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 719 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 736# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 737# @ebuild-function java-pkg_getjars
692# 738#
693# Get the classpath provided by any number of packages 739# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 740# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
741# The providing packages are recorded as dependencies into package.env DEPEND
742# line, unless "--build-only" is passed as the very first argument, for jars
743# that have to be present only at build time and are not needed on runtime
744# (junit testing etc).
695# 745#
696# Example: Get the classpath for xerces-2, 746# Example: Get the classpath for xerces-2,
697# java-pkg_getjars xerces-2 xalan 747# java-pkg_getjars xerces-2 xalan
698# Example Return: 748# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 749# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 750#
751# @param $1 - (optional) "--build-only" makes the jar(s) not added into
752# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 753# @param $@ - list of packages to get jars from
702# ------------------------------------------------------------------------------ 754# ------------------------------------------------------------------------------
703java-pkg_getjars() { 755java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 756 debug-print-function ${FUNCNAME} $*
757
758 local build_only=""
759
760 if [[ "${1}" = "--build-only" ]]; then
761 build_only="true"
762 shift
763 fi
705 764
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 765 [[ ${#} -lt 1 ]] && die "At least one argument needed"
707 766
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 767 # NOTE could probably just pass $@ to java-config --classpath. and return it
709 local classpath pkg 768 local classpath pkg
710 for pkg in ${@//,/ }; do 769 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 770 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 771 jars="$(java-config --classpath=${pkg})"
772 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
713 debug-print "${pkg}:${jars}" 773 debug-print "${pkg}:${jars}"
714 # TODO should we ensure jars exist? 774
715 if [[ -z "${classpath}" ]]; then 775 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 776 classpath="${jars}"
717 else 777 else
718 classpath="${classpath}:${jars}" 778 classpath="${classpath}:${jars}"
719 fi 779 fi
720 java-pkg_record-jar_ "${pkg}" 780 # Only record jars that aren't build-only
781 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
721 done 782 done
722 echo "${classpath}" 783 echo "${classpath}"
723} 784}
724 785
725# ------------------------------------------------------------------------------ 786# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 787# @ebuild-function java-pkg_getjar
727# 788#
728# Get the filename of a single jar from a package 789# Get the filename of a single jar from a package
790# The providing package is recorded as runtime dependency into package.env
791# DEPEND line, unless "--build-only" is passed as the very first argument, for
792# jars that have to be present only at build time and are not needed on runtime
793# (junit testing etc).
729# 794#
730# @example 795# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 796# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 797# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 798# /usr/share/xerces-2/lib/xml-apis.jar
734# 799#
800# @param $1 - (optional) "--build-only" makes the jar not added into
801# package.env DEPEND line.
735# @param $1 - package to use 802# @param $1 - package to use
736# @param $2 - jar to get 803# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 804# ------------------------------------------------------------------------------
738java-pkg_getjar() { 805java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 806 debug-print-function ${FUNCNAME} $*
807
808 local build_only=""
809
810 if [[ "${1}" = "--build-only" ]]; then
811 build_only="true"
812 shift
813 fi
740 814
741 local pkg="${1}" target_jar="${2}" jar 815 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 816 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 817 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 818
745 # TODO check that package is actually installed 819 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
820 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 821 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 822 [[ $? != 0 ]] && die ${error_msg}
823
748 for jar in ${classpath//:/ }; do 824 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 825 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 826 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 827 fi
752 828
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 829 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 830 # Only record jars that aren't build-only
831 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 832 echo "${jar}"
756 return 0 833 return 0
757 fi 834 fi
758 done 835 done
759 836
760 die "Could not find ${target_jar} in ${pkg}" 837 die "Could not find ${target_jar} in ${pkg}"
761 return 1 838 return 1
762} 839}
763 840
764# This function reads stdin, and based on that input, figures out how to 841# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 855# line="${line// /}"
779# 856#
780# # format: path=jarinfo 857# # format: path=jarinfo
781# local path=${line%%=*} 858# local path=${line%%=*}
782# local jarinfo=${line##*=} 859# local jarinfo=${line##*=}
783# 860#
784# # format: jar@package 861# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 862# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 863# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 864# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 865# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 878# @section-end query
802# ------------------------------------------------------------------------------ 879# ------------------------------------------------------------------------------
803 880
804# ------------------------------------------------------------------------------ 881# ------------------------------------------------------------------------------
805# @section-begin helper 882# @section-begin helper
806# @section-summary Helper functions 883# @section-summary Helper functions
807# 884#
808# Various other functions to use from an ebuild 885# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 886# ------------------------------------------------------------------------------
810 887
811# ------------------------------------------------------------------------------ 888# ------------------------------------------------------------------------------
817# jdbc-stdext 894# jdbc-stdext
818# jaf 895# jaf
819# jdbc-rowset 896# jdbc-rowset
820# jms 897# jms
821# 898#
822# @param $1 - Optionally indicate that the dependencies are controlled by 899# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 900# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 901# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 902# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 903# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 904# TODO rewrite to parse a line based declaration file instead -- karltk
921 fi 998 fi
922} 999}
923 1000
924# ------------------------------------------------------------------------------ 1001# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1002# @internal-function java-pkg_is-vm-version-sufficient
926# 1003#
927# @return zero - VM is sufficient 1004# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1005# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1006# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1007java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1008 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1028 die "Active Java VM too old"
952 fi 1029 fi
953} 1030}
954 1031
955# ------------------------------------------------------------------------------ 1032# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1033# @internal-function java-pkg_is-vm-version-eq
957# 1034#
958# @param $@ - VM version to compare current VM to 1035# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1036# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1037# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1038# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1039java-pkg_is-vm-version-eq() {
992# 1069#
993# @param $@ - VM version to compare current to 1070# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1071# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1072java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1073 debug-print-function ${FUNCNAME} $*
997 1074
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1075 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1076 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1077 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1078 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1079 die "Active Java VM too old"
1003 fi 1080 fi
1004} 1081}
1005 1082
1006# ------------------------------------------------------------------------------ 1083# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1084# @internal-function java-pkg_is-vm-version-ge
1008# 1085#
1009# @param $@ - VM version to compare current VM to 1086# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1087# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1088# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1089# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1090java-pkg_is-vm-version-ge() {
1027 return 1 1104 return 1
1028 fi 1105 fi
1029 fi 1106 fi
1030} 1107}
1031 1108
1109java-pkg_set-current-vm() {
1110 export GENTOO_VM=${1}
1111}
1112
1113java-pkg_get-current-vm() {
1114 echo ${GENTOO_VM}
1115}
1116
1117java-pkg_current-vm-matches() {
1118 hasq $(java-pkg_get-current-vm) ${@}
1119 return $?
1120}
1121
1032# ------------------------------------------------------------------------------ 1122# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1123# @ebuild-function java-pkg_get-source
1034# 1124#
1035# Determines what source version should be used, for passing to -source. 1125# Determines what source version should be used, for passing to -source.
1036# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1126# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1127#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1128# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1129# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1134# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1135# @ebuild-function java-pkg_get-target
1046# 1136#
1047# Determines what target version should be used, for passing to -target. 1137# Determines what target version should be used, for passing to -target.
1048# If you don't care about lower versions, you can set _WANT_TARGET to the 1138# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1139# version of your JDK.
1050# Remember doing this will mostly like cause things to break. 1140# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend. 1141# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm. 1142# Doesn't allow it to be higher then the active vm.
1053# 1143#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1144# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1145# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1146java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1147 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1148 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1149 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1060 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then 1150 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1061 echo ${JAVA_PKG_WANT_TARGET} 1151 echo ${JAVA_PKG_WANT_TARGET}
1062 else 1152 else
1089 # try to get value of JAVAC 1179 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1180 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1181 export JAVAC=${old_javac}
1092 1182
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1183 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}"
1094 1184
1095 # check that it's executable 1185 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1186 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!" 1187 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1188 die "${compiler_executable} doesn't exist, or isn't executable"
1099 fi 1189 fi
1104 fi 1194 fi
1105 echo ${compiler_executable} 1195 echo ${compiler_executable}
1106} 1196}
1107 1197
1108# ------------------------------------------------------------------------------ 1198# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1199# @ebuild-function java-pkg_javac-args
1110# 1200#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1201# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1202# to know what -source/-target to use.
1113# 1203#
1114# @return string - arguments to pass to javac, complete with -target and -source 1204# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1207 debug-print-function ${FUNCNAME} $*
1118 1208
1119 local want_source="$(java-pkg_get-source)" 1209 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1210 local want_target="$(java-pkg_get-target)"
1121 1211
1122 local source_str="-source ${want_source}" 1212 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1213 local target_str="-target ${want_target}"
1124 1214
1125 debug-print "want source: ${want_source}" 1215 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1216 debug-print "want target: ${want_target}"
1127 1217
1139 1229
1140# TODO document 1230# TODO document
1141java-pkg_get-jni-cflags() { 1231java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1232 local flags="-I${JAVA_HOME}/include"
1143 1233
1234 # TODO do a check that the directories are valid
1144 # TODO figure out how to cope with other things than linux... 1235 # TODO figure out how to cope with other things than linux...
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1236 flags="${flags} -I${JAVA_HOME}/include/linux"
1146 1237
1147 echo ${flags} 1238 echo ${flags}
1148} 1239}
1149 1240
1241java-pkg_ensure-gcj() {
1242 if ! built_with_use sys-devel/gcc gcj ; then
1243 ewarn
1244 ewarn "You must build gcc with the gcj support to build with gcj"
1245 ewarn
1246 ebeep 5
1247 die "No GCJ support found!"
1248 fi
1249}
1250
1251java-pkg_ensure-test() {
1252 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1253 eerror "You specified FEATURES=test, but USE=test is needed"
1254 eerror "to pull in the additional dependencies for testing"
1255 die "Need USE=test enabled"
1256 fi
1257}
1258
1150# ------------------------------------------------------------------------------ 1259# ------------------------------------------------------------------------------
1151# @section-end helper 1260# @section-end helper
1152# ------------------------------------------------------------------------------ 1261# ------------------------------------------------------------------------------
1153 1262
1154# ------------------------------------------------------------------------------ 1263# ------------------------------------------------------------------------------
1166# compiler. 1275# compiler.
1167# 1276#
1168# ------------------------------------------------------------------------------ 1277# ------------------------------------------------------------------------------
1169eant() { 1278eant() {
1170 debug-print-function ${FUNCNAME} $* 1279 debug-print-function ${FUNCNAME} $*
1280
1281 # FIXME get this working
1282# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1283# java-pkg_announce-qa-violation \
1284# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1285# fi
1171 1286
1172 local antflags 1287 local antflags
1173 java-pkg_init-compiler_ 1288 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1289 local compiler="${GENTOO_COMPILER}"
1175 1290
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1304 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1190 if [[ -n ${build_compiler_deps} ]]; then 1305 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1306 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1307 fi
1193 fi 1308 fi
1194 1309
1310 if is-java-strict; then
1311 einfo "Disabling system classpath for ant"
1312 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1313 fi
1314
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1315 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1316 antflags="${antflags} -debug"
1197 fi 1317 fi
1198 1318
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1319 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1320 ant ${antflags} "${@}" || die "eant failed"
1201 1321
1202} 1322}
1203 1323
1204# ------------------------------------------------------------------------------ 1324# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1325# @ebuild-function ejavac
1206# 1326#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1327# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1328# /etc/java-config/compilers.conf
1209# 1329#
1210# @param $@ - Arguments to be passed to the compiler 1330# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1331# ------------------------------------------------------------------------------
1212ejavac() { 1332ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1333 debug-print-function ${FUNCNAME} $*
1214 1334
1335 # FIXME using get-javac ends up printing stuff with einfo
1215 local compiler_executable=$(java-pkg_get-javac) 1336# local compiler_executable=$(java-pkg_get-javac)
1337 local compiler_executable="javac"
1216 1338
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1339 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1340 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed"
1219} 1341}
1220 1342
1221# ------------------------------------------------------------------------------ 1343# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1344# @ebuild-function java-pkg_filter-compiler
1223# 1345#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1346# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1347# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1348#
1227# @param $@ - compilers to filter 1349# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1350# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1351java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1352 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1353}
1232 1354
1233# ------------------------------------------------------------------------------ 1355# ------------------------------------------------------------------------------
1356# @ebuild-function java-pkg_force-compiler
1357#
1358# Used to force the use of particular compilers. Should be used in src_compile.
1359# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1360# OutOfMemoryErrors that may come up.
1361#
1362# @param $@ - compilers to force
1363# ------------------------------------------------------------------------------
1364java-pkg_force-compiler() {
1365 JAVA_PKG_FORCE_COMPILER="$@"
1366}
1367
1368# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1369# @ebuild-function use_doc
1235# 1370#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1371# Helper function for getting ant to build javadocs. If the user has USE=doc,
1237# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1372# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1373#
1239# The output of this should be passed to ant. 1374# The output of this should be passed to ant.
1240# 1375#
1241# Example: build javadocs by calling 'javadoc' target 1376# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1377# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1378# Example: build javadocs by calling 'apidoc' target
1251} 1386}
1252 1387
1253# ------------------------------------------------------------------------------ 1388# ------------------------------------------------------------------------------
1254# @section-end build 1389# @section-end build
1255# ------------------------------------------------------------------------------ 1390# ------------------------------------------------------------------------------
1256 1391
1257# ------------------------------------------------------------------------------ 1392# ------------------------------------------------------------------------------
1258# @section-begin internal 1393# @section-begin internal
1259# @section-summary Internal functions 1394# @section-summary Internal functions
1260# 1395#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1396# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1397# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1398# ------------------------------------------------------------------------------
1264 1399
1265# ----------------------------------------------------------------------------- 1400# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1401# @function-internal java-pkg_init
1267# 1402#
1268# The purpose of this function, as the name might imply, is to initialize the 1403# The purpose of this function, as the name might imply, is to initialize the
1269# Java environment. It ensures that that there aren't any environment variables 1404# Java environment. It ensures that that there aren't any environment variables
1270# that'll muss things up. It initializes some variables, which are used 1405# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1406# internally. And most importantly, it'll switch the VM if necessary.
1272# 1407#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1419 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1420
1286 # Do some QA checks 1421 # Do some QA checks
1287 java-pkg_check-jikes 1422 java-pkg_check-jikes
1288 1423
1289 # When users have crazy classpaths some packages can fail to compile. 1424 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1425 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1426 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1427 # from the CLASSPATH.
1293 unset CLASSPATH 1428 unset CLASSPATH
1294} 1429}
1295 1430
1296# ------------------------------------------------------------------------------ 1431# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1432# @function-internal java-pkg-init-compiler_
1298# 1433#
1299# This function attempts to figure out what compiler should be used. It does 1434# This function attempts to figure out what compiler should be used. It does
1300# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1435# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1436# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1437# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1438#
1304# It will go through the list of compilers, and verify that it supports the 1439# It will go through the list of compilers, and verify that it supports the
1305# target and source that are needed. If it is not suitable, then the next 1440# target and source that are needed. If it is not suitable, then the next
1306# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1441# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1442# isn't done.
1308# 1443#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1465 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1466 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1467 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1468 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1469 fi
1335 1470
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1471 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1472
1338 # Figure out if we should announce what compiler we're using 1473 # Figure out if we should announce what compiler we're using
1339 local compiler 1474 local compiler
1340 for compiler in ${compilers}; do 1475 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1478 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1479 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1480 export GENTOO_COMPILER="javac"
1346 break 1481 break
1347 fi 1482 fi
1348 1483
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1484 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1485 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1486 einfo "Filtering ${compiler}"
1352 continue 1487 continue
1353 fi 1488 fi
1354 fi 1489 fi
1355 1490
1356 # for non-javac, we need to make sure it supports the right target and 1491 # for non-javac, we need to make sure it supports the right target and
1357 # source 1492 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1493 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1494 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1495 local desired_target="$(java-pkg_get-target)"
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1591 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1592 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1593 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1459 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1594 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 1595 ) > "${JAVA_PKG_ENV}"
1461 1596
1462 # register target/source 1597 # register target/source
1463 local target="$(java-pkg_get-target)" 1598 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 1599 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1600 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1601 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1533 fi 1668 fi
1534} 1669}
1535 1670
1536# ------------------------------------------------------------------------------ 1671# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 1672# @internal-function java-pkg_expand_dir_
1538# 1673#
1539# Gets the full path of the file/directory's parent. 1674# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 1675# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 1676# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 1677# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 1678java-pkg_expand_dir_() {
1629# @return - The version of the current VM 1764# @return - The version of the current VM
1630# ------------------------------------------------------------------------------ 1765# ------------------------------------------------------------------------------
1631java-pkg_get-vm-version() { 1766java-pkg_get-vm-version() {
1632 debug-print-function ${FUNCNAME} $* 1767 debug-print-function ${FUNCNAME} $*
1633 1768
1634 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1769 java-config -g PROVIDES_VERSION
1635} 1770}
1636 1771
1637# ------------------------------------------------------------------------------ 1772# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 1773# @internal-function java-pkg_switch-vm
1639# 1774#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1775# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 1776# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 1777# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 1778# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 1779java-pkg_switch-vm() {
1645 if java-pkg_needs-vm; then 1780 if java-pkg_needs-vm; then
1658 # otherwise just make sure the current VM is sufficient 1793 # otherwise just make sure the current VM is sufficient
1659 else 1794 else
1660 java-pkg_ensure-vm-version-sufficient 1795 java-pkg_ensure-vm-version-sufficient
1661 fi 1796 fi
1662 debug-print "Using: $(java-config -f)" 1797 debug-print "Using: $(java-config -f)"
1663 1798
1664 java-pkg_setup-vm 1799 java-pkg_setup-vm
1665 1800
1666 export JAVA=$(java-config -java) 1801 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 1802 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 1803 export JAVACFLAGS="$(java-pkg_javac-args)"
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1804 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1670 1805
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1806 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 1807 export JDK_HOME=${JAVA_HOME}
1673 1808
1674 #TODO If you know a better solution let us know. 1809 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1810 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 1811
1677 local tann="${T}/announced-vm" 1812 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1813 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 1814 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 1815 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1816 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1841 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1842 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 1843 echo "and of course, the output of emerge --info" >&2
1709} 1844}
1710 1845
1846
1847# TODO document
1848# List jars in the source directory, ${S}
1849java-pkg_jar-list() {
1850 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1851 einfo "Linked Jars"
1852 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1853 einfo "Jars"
1854 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1855 einfo "Classes"
1856 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1857 fi
1858}
1859
1860# TODO document
1861# Verify that the classes were compiled for the right source / target
1862java-pkg_verify-classes() {
1863 ebegin "Verifying java class versions"
1864 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1865 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1866 result=$?
1867 eend ${result}
1868 if [[ ${result} == 0 ]]; then
1869 einfo "All good"
1870 else
1871 ewarn "Possible problem"
1872 die "Bad class files found"
1873 fi
1874}
1875
1876
1711# ------------------------------------------------------------------------------ 1877# ------------------------------------------------------------------------------
1712# @section-end internal 1878# @section-end internal
1713# ------------------------------------------------------------------------------ 1879# ------------------------------------------------------------------------------
1714 1880
1715java-pkg_check-phase() { 1881java-pkg_check-phase() {
1716 local phase=${1} 1882 local phase=${1}
1717 local funcname=${2} 1883 local funcname=${2}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 1884 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \ 1885 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 1886 "${funcname} used outside of src_${phase}"
1722 fi 1887 fi
1723} 1888}
1724 1889
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 1900 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 1901 fi
1737} 1902}
1738 1903
1739java-pkg_announce-qa-violation() { 1904java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 1905 if is-java-strict; then
1741 echo "Java QA Notice: $@" >&2 1906 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 1907 increment-qa-violations
1743 fi 1908 fi
1744} 1909}
1745 1910
1746increment-qa-violations() { 1911increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 1912 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 1913 export JAVA_PKG_QA_VIOLATIONS
1749} 1914}
1750 1915
1916is-java-strict() {
1917 [[ -n ${JAVA_PKG_STRICT} ]]
1918 return $?
1919}
1920
1751# ------------------------------------------------------------------------------ 1921# ------------------------------------------------------------------------------
1752# @eclass-end 1922# @eclass-end
1753# ------------------------------------------------------------------------------ 1923# ------------------------------------------------------------------------------

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.22

  ViewVC Help
Powered by ViewVC 1.1.20