/[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.20
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}"
538 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 567 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
539 568
540 if [[ -n "${into}" ]]; then 569 if [[ -n "${target_dir}" ]]; then
541 DESTTREE="${target_dir}" dobin "${target}" 570 DESTTREE="${target_dir}" dobin "${target}"
542 local ret=$? 571 local ret=$?
543 return ${ret} 572 return ${ret}
544 else 573 else
545 dobin "${target}" 574 dobin "${target}"
573 echo "dowar: warning, skipping directory ${war}" 602 echo "dowar: warning, skipping directory ${war}"
574 continue 603 continue
575 else 604 else
576 warpath="${war}" 605 warpath="${war}"
577 fi 606 fi
578 607
579 # Install those files like you mean it 608 # Install those files like you mean it
580 INSOPTIONS="-m 0644" \ 609 INSOPTIONS="-m 0644" \
581 INSDESTTREE=${JAVA_PKG_WARDEST} \ 610 INSDESTTREE=${JAVA_PKG_WARDEST} \
582 doins ${warpath} 611 doins ${warpath}
583 done 612 done
618# @ebuild-function java-pkg_jar-from 647# @ebuild-function java-pkg_jar-from
619# 648#
620# Makes a symlink to a jar from a certain package 649# Makes a symlink to a jar from a certain package
621# A lot of java packages include dependencies in a lib/ directory 650# A lot of java packages include dependencies in a lib/ directory
622# You can use this function to replace these bundled dependencies. 651# You can use this function to replace these bundled dependencies.
652# The dependency is recorded into package.env DEPEND line, unless "--build-only"
653# is passed as the very first argument, for jars that have to be present only
654# at build time and are not needed on runtime (junit testing etc).
623# 655#
624# Example: get all jars from xerces slot 2 656# Example: get all jars from xerces slot 2
625# java-pkg_jar-from xerces-2 657# java-pkg_jar-from xerces-2
626# Example: get a specific jar from xerces slot 2 658# Example: get a specific jar from xerces slot 2
627# java-pkg_jar-from xerces-2 xml-apis.jar 659# java-pkg_jar-from xerces-2 xml-apis.jar
628# Example get a specific jar from xerces slot 2, and name it diffrently 660# 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 661# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
662# Example: get junit.jar which is needed only for building
663# java-pkg_jar-from --build-only junit junit.jar
630# 664#
665# @param $1 - (optional) "--build-only" makes the jar(s) not added into
666# package.env DEPEND line.
631# @param $1 - Package to get jars from. 667# @param $1 - Package to get jars from.
632# @param $2 - jar from package. If not specified, all jars will be used. 668# @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 669# @param $3 - When a single jar is specified, destination filename of the
634# symlink. Defaults to the name of the jar. 670# symlink. Defaults to the name of the jar.
635# ------------------------------------------------------------------------------ 671# ------------------------------------------------------------------------------
636# TODO could probably be cleaned up a little 672# TODO could probably be cleaned up a little
637java-pkg_jar-from() { 673java-pkg_jar-from() {
638 debug-print-function ${FUNCNAME} $* 674 debug-print-function ${FUNCNAME} $*
639 675
676 local build_only=""
677
678 if [[ "${1}" = "--build-only" ]]; then
679 build_only="true"
680 shift
681 fi
682
640 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 683 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
641 684
642 [[ -z ${target_pkg} ]] && die "Must specify a package" 685 [[ -z ${target_pkg} ]] && die "Must specify a package"
643 686
644 # default destjar to the target jar 687 # default destjar to the target jar
645 [[ -z "${destjar}" ]] && destjar="${target_jar}" 688 [[ -z "${destjar}" ]] && destjar="${target_jar}"
646 689
690 local error_msg="There was a problem getting the classpath for ${target_pkg}."
691 local classpath
647 local classpath="$(java-config --classpath=${target_pkg})" 692 classpath="$(java-config --classpath=${target_pkg})"
648 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 693 [[ $? != 0 ]] && die ${error_msg}
649 694
650 local jar 695 local jar
651 for jar in ${classpath//:/ }; do 696 for jar in ${classpath//:/ }; do
652 local jar_name=$(basename "${jar}") 697 local jar_name=$(basename "${jar}")
653 if [[ ! -f "${jar}" ]] ; then 698 if [[ ! -f "${jar}" ]] ; then
657 # If no specific target jar was indicated, link it 702 # If no specific target jar was indicated, link it
658 if [[ -z "${target_jar}" ]] ; then 703 if [[ -z "${target_jar}" ]] ; then
659 [[ -f "${target_jar}" ]] && rm "${target_jar}" 704 [[ -f "${target_jar}" ]] && rm "${target_jar}"
660 ln -snf "${jar}" \ 705 ln -snf "${jar}" \
661 || die "Failed to make symlink from ${jar} to ${jar_name}" 706 || die "Failed to make symlink from ${jar} to ${jar_name}"
662 java-pkg_record-jar_ "${target_pkg}" "${jar}" 707 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
663 # otherwise, if the current jar is the target jar, link it 708 # otherwise, if the current jar is the target jar, link it
664 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 709 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
665 [[ -f "${destjar}" ]] && rm "${destjar}" 710 [[ -f "${destjar}" ]] && rm "${destjar}"
666 ln -snf "${jar}" "${destjar}" \ 711 ln -snf "${jar}" "${destjar}" \
667 || die "Failed to make symlink from ${jar} to ${destjar}" 712 || die "Failed to make symlink from ${jar} to ${destjar}"
668 java-pkg_record-jar_ "${target_pkg}" "${jar}" 713 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
669 return 0 714 return 0
670 fi 715 fi
671 done 716 done
672 # if no target was specified, we're ok 717 # if no target was specified, we're ok
673 if [[ -z "${target_jar}" ]] ; then 718 if [[ -z "${target_jar}" ]] ; then
690# ------------------------------------------------------------------------------ 735# ------------------------------------------------------------------------------
691# @ebuild-function java-pkg_getjars 736# @ebuild-function java-pkg_getjars
692# 737#
693# Get the classpath provided by any number of packages 738# Get the classpath provided by any number of packages
694# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 739# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
740# The providing packages are recorded as dependencies into package.env DEPEND
741# line, unless "--build-only" is passed as the very first argument, for jars
742# that have to be present only at build time and are not needed on runtime
743# (junit testing etc).
695# 744#
696# Example: Get the classpath for xerces-2, 745# Example: Get the classpath for xerces-2,
697# java-pkg_getjars xerces-2 xalan 746# java-pkg_getjars xerces-2 xalan
698# Example Return: 747# Example Return:
699# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 748# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
700# 749#
750# @param $1 - (optional) "--build-only" makes the jar(s) not added into
751# package.env DEPEND line.
701# @param $@ - list of packages to get jars from 752# @param $@ - list of packages to get jars from
702# ------------------------------------------------------------------------------ 753# ------------------------------------------------------------------------------
703java-pkg_getjars() { 754java-pkg_getjars() {
704 debug-print-function ${FUNCNAME} $* 755 debug-print-function ${FUNCNAME} $*
756
757 local build_only=""
758
759 if [[ "${1}" = "--build-only" ]]; then
760 build_only="true"
761 shift
762 fi
705 763
706 [[ ${#} -lt 1 ]] && die "At least one argument needed" 764 [[ ${#} -lt 1 ]] && die "At least one argument needed"
707 765
708 # NOTE could probably just pass $@ to java-config --classpath. and return it 766 # NOTE could probably just pass $@ to java-config --classpath. and return it
709 local classpath pkg 767 local classpath pkg
710 for pkg in ${@//,/ }; do 768 for pkg in ${@//,/ }; do
711 #for pkg in $(echo "$@" | tr ',' ' '); do 769 #for pkg in $(echo "$@" | tr ',' ' '); do
712 jars="$(java-config --classpath=${pkg})" 770 jars="$(java-config --classpath=${pkg})"
771 [[ -z "${jars}" ]] && die "java-config --classpath=${pkg} failed"
713 debug-print "${pkg}:${jars}" 772 debug-print "${pkg}:${jars}"
714 # TODO should we ensure jars exist? 773
715 if [[ -z "${classpath}" ]]; then 774 if [[ -z "${classpath}" ]]; then
716 classpath="${jars}" 775 classpath="${jars}"
717 else 776 else
718 classpath="${classpath}:${jars}" 777 classpath="${classpath}:${jars}"
719 fi 778 fi
720 java-pkg_record-jar_ "${pkg}" 779 # Only record jars that aren't build-only
780 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
721 done 781 done
722 echo "${classpath}" 782 echo "${classpath}"
723} 783}
724 784
725# ------------------------------------------------------------------------------ 785# ------------------------------------------------------------------------------
726# @ebuild-function java-pkg_getjar 786# @ebuild-function java-pkg_getjar
727# 787#
728# Get the filename of a single jar from a package 788# Get the filename of a single jar from a package
789# The providing package is recorded as runtime dependency into package.env
790# DEPEND line, unless "--build-only" is passed as the very first argument, for
791# jars that have to be present only at build time and are not needed on runtime
792# (junit testing etc).
729# 793#
730# @example 794# @example
731# java-pkg_getjar xerces-2 xml-apis.jar 795# java-pkg_getjar xerces-2 xml-apis.jar
732# @example-return 796# @example-return
733# /usr/share/xerces-2/lib/xml-apis.jar 797# /usr/share/xerces-2/lib/xml-apis.jar
734# 798#
799# @param $1 - (optional) "--build-only" makes the jar not added into
800# package.env DEPEND line.
735# @param $1 - package to use 801# @param $1 - package to use
736# @param $2 - jar to get 802# @param $2 - jar to get
737# ------------------------------------------------------------------------------ 803# ------------------------------------------------------------------------------
738java-pkg_getjar() { 804java-pkg_getjar() {
739 debug-print-function ${FUNCNAME} $* 805 debug-print-function ${FUNCNAME} $*
806
807 local build_only=""
808
809 if [[ "${1}" = "--build-only" ]]; then
810 build_only="true"
811 shift
812 fi
740 813
741 local pkg="${1}" target_jar="${2}" jar 814 local pkg="${1}" target_jar="${2}" jar
742 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 815 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
743 [[ -z ${target_jar} ]] && die "Must specify jar to get" 816 [[ -z ${target_jar} ]] && die "Must specify jar to get"
744 817
745 # TODO check that package is actually installed 818 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
819 local classpath
746 local classpath=$(java-config --classpath=${pkg}) 820 classpath=$(java-config --classpath=${pkg})
747 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 821 [[ $? != 0 ]] && die ${error_msg}
822
748 for jar in ${classpath//:/ }; do 823 for jar in ${classpath//:/ }; do
749 if [[ ! -f "${jar}" ]] ; then 824 if [[ ! -f "${jar}" ]] ; then
750 die "Installation problems with jars in ${pkg} - is it installed?" 825 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
751 fi 826 fi
752 827
753 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 828 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
754 java-pkg_record-jar_ "${pkg}" "${jar}" 829 # Only record jars that aren't build-only
830 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
755 echo "${jar}" 831 echo "${jar}"
756 return 0 832 return 0
757 fi 833 fi
758 done 834 done
759 835
760 die "Could not find ${target_jar} in ${pkg}" 836 die "Could not find ${target_jar} in ${pkg}"
761 return 1 837 return 1
762} 838}
763 839
764# This function reads stdin, and based on that input, figures out how to 840# This function reads stdin, and based on that input, figures out how to
778# line="${line// /}" 854# line="${line// /}"
779# 855#
780# # format: path=jarinfo 856# # format: path=jarinfo
781# local path=${line%%=*} 857# local path=${line%%=*}
782# local jarinfo=${line##*=} 858# local jarinfo=${line##*=}
783# 859#
784# # format: jar@package 860# # format: jar@package
785# local jar=${jarinfo%%@*}.jar 861# local jar=${jarinfo%%@*}.jar
786# local package=${jarinfo##*@} 862# local package=${jarinfo##*@}
787# if [[ -n ${replace_only} ]]; then 863# if [[ -n ${replace_only} ]]; then
788# [[ ! -f $path ]] && die "No jar exists at ${path}" 864# [[ ! -f $path ]] && die "No jar exists at ${path}"
801# @section-end query 877# @section-end query
802# ------------------------------------------------------------------------------ 878# ------------------------------------------------------------------------------
803 879
804# ------------------------------------------------------------------------------ 880# ------------------------------------------------------------------------------
805# @section-begin helper 881# @section-begin helper
806# @section-summary Helper functions 882# @section-summary Helper functions
807# 883#
808# Various other functions to use from an ebuild 884# Various other functions to use from an ebuild
809# ------------------------------------------------------------------------------ 885# ------------------------------------------------------------------------------
810 886
811# ------------------------------------------------------------------------------ 887# ------------------------------------------------------------------------------
817# jdbc-stdext 893# jdbc-stdext
818# jaf 894# jaf
819# jdbc-rowset 895# jdbc-rowset
820# jms 896# jms
821# 897#
822# @param $1 - Optionally indicate that the dependencies are controlled by 898# @param $1 - Optionally indicate that the dependencies are controlled by
823# a use flag by specifying '--use' Requires $2. 899# a use flag by specifying '--use' Requires $2.
824# @param $2 - USE flag which will enable the dependencies. 900# @param $2 - USE flag which will enable the dependencies.
825# @param $@ - virtual packages to add depenedencies for 901# @param $@ - virtual packages to add depenedencies for
826# ------------------------------------------------------------------------------ 902# ------------------------------------------------------------------------------
827# TODO rewrite to parse a line based declaration file instead -- karltk 903# TODO rewrite to parse a line based declaration file instead -- karltk
921 fi 997 fi
922} 998}
923 999
924# ------------------------------------------------------------------------------ 1000# ------------------------------------------------------------------------------
925# @internal-function java-pkg_is-vm-version-sufficient 1001# @internal-function java-pkg_is-vm-version-sufficient
926# 1002#
927# @return zero - VM is sufficient 1003# @return zero - VM is sufficient
928# @return non-zero - VM is not sufficient 1004# @return non-zero - VM is not sufficient
929# ------------------------------------------------------------------------------ 1005# ------------------------------------------------------------------------------
930java-pkg_is-vm-version-sufficient() { 1006java-pkg_is-vm-version-sufficient() {
931 debug-print-function ${FUNCNAME} $* 1007 debug-print-function ${FUNCNAME} $*
951 die "Active Java VM too old" 1027 die "Active Java VM too old"
952 fi 1028 fi
953} 1029}
954 1030
955# ------------------------------------------------------------------------------ 1031# ------------------------------------------------------------------------------
956# @internal-function java-pkg_is-vm-version-eq 1032# @internal-function java-pkg_is-vm-version-eq
957# 1033#
958# @param $@ - VM version to compare current VM to 1034# @param $@ - VM version to compare current VM to
959# @return zero - VM versions are equal 1035# @return zero - VM versions are equal
960# @return non-zero - VM version are not equal 1036# @return non-zero - VM version are not equal
961# ------------------------------------------------------------------------------ 1037# ------------------------------------------------------------------------------
962java-pkg_is-vm-version-eq() { 1038java-pkg_is-vm-version-eq() {
992# 1068#
993# @param $@ - VM version to compare current to 1069# @param $@ - VM version to compare current to
994# ------------------------------------------------------------------------------ 1070# ------------------------------------------------------------------------------
995java-pkg_ensure-vm-version-ge() { 1071java-pkg_ensure-vm-version-ge() {
996 debug-print-function ${FUNCNAME} $* 1072 debug-print-function ${FUNCNAME} $*
997 1073
998 if ! java-pkg_is-vm-version-ge "$@" ; then 1074 if ! java-pkg_is-vm-version-ge "$@" ; then
999 debug-print "vm is not suffient" 1075 debug-print "vm is not suffient"
1000 eerror "This package requires a Java VM version >= $@" 1076 eerror "This package requires a Java VM version >= $@"
1001 einfo "Please use java-config -S to set the correct one" 1077 einfo "Please use java-config -S to set the correct one"
1002 die "Active Java VM too old" 1078 die "Active Java VM too old"
1003 fi 1079 fi
1004} 1080}
1005 1081
1006# ------------------------------------------------------------------------------ 1082# ------------------------------------------------------------------------------
1007# @internal-function java-pkg_is-vm-version-ge 1083# @internal-function java-pkg_is-vm-version-ge
1008# 1084#
1009# @param $@ - VM version to compare current VM to 1085# @param $@ - VM version to compare current VM to
1010# @return zero - current VM version is greater than checked version 1086# @return zero - current VM version is greater than checked version
1011# @return non-zero - current VM version is not greater than checked version 1087# @return non-zero - current VM version is not greater than checked version
1012# ------------------------------------------------------------------------------ 1088# ------------------------------------------------------------------------------
1013java-pkg_is-vm-version-ge() { 1089java-pkg_is-vm-version-ge() {
1027 return 1 1103 return 1
1028 fi 1104 fi
1029 fi 1105 fi
1030} 1106}
1031 1107
1108java-pkg_set-current-vm() {
1109 export GENTOO_VM=${1}
1110}
1111
1112java-pkg_get-current-vm() {
1113 echo ${GENTOO_VM}
1114}
1115
1116java-pkg_current-vm-matches() {
1117 hasq $(java-pkg_get-current-vm) ${@}
1118 return $?
1119}
1120
1032# ------------------------------------------------------------------------------ 1121# ------------------------------------------------------------------------------
1033# @ebuild-function java-pkg_get-source 1122# @ebuild-function java-pkg_get-source
1034# 1123#
1035# Determines what source version should be used, for passing to -source. 1124# 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 1125# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1037# 1126#
1038# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1127# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1039# ------------------------------------------------------------------------------ 1128# ------------------------------------------------------------------------------
1044# ------------------------------------------------------------------------------ 1133# ------------------------------------------------------------------------------
1045# @ebuild-function java-pkg_get-target 1134# @ebuild-function java-pkg_get-target
1046# 1135#
1047# Determines what target version should be used, for passing to -target. 1136# 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 1137# If you don't care about lower versions, you can set _WANT_TARGET to the
1049# version of your JDK. 1138# version of your JDK.
1050# Remember doing this will mostly like cause things to break. 1139# Remember doing this will mostly like cause things to break.
1051# Doesn't allow it to be lower then the one in depend. 1140# Doesn't allow it to be lower then the one in depend.
1052# Doesn't allow it to be higher then the active vm. 1141# Doesn't allow it to be higher then the active vm.
1053# 1142#
1054# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1143# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1055# ------------------------------------------------------------------------------ 1144# ------------------------------------------------------------------------------
1056java-pkg_get-target() { 1145java-pkg_get-target() {
1057 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1146 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1058 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1147 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1059 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1148 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 1149 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} 1150 echo ${JAVA_PKG_WANT_TARGET}
1062 else 1151 else
1089 # try to get value of JAVAC 1178 # try to get value of JAVAC
1090 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1179 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1091 export JAVAC=${old_javac} 1180 export JAVAC=${old_javac}
1092 1181
1093 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1182 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}"
1094 1183
1095 # check that it's executable 1184 # check that it's executable
1096 if [[ ! -x ${compiler_executable} ]]; then 1185 if [[ ! -x ${compiler_executable} ]]; then
1097 eerror "Could not find ${compiler_executable}!" 1186 eerror "Could not find ${compiler_executable}!"
1098 die "${compiler_executable} doesn't exist, or isn't executable" 1187 die "${compiler_executable} doesn't exist, or isn't executable"
1099 fi 1188 fi
1104 fi 1193 fi
1105 echo ${compiler_executable} 1194 echo ${compiler_executable}
1106} 1195}
1107 1196
1108# ------------------------------------------------------------------------------ 1197# ------------------------------------------------------------------------------
1109# @ebuild-function java-pkg_javac-args 1198# @ebuild-function java-pkg_javac-args
1110# 1199#
1111# If an ebuild uses javac directly, instead of using ejavac, it should call this 1200# If an ebuild uses javac directly, instead of using ejavac, it should call this
1112# to know what -source/-target to use. 1201# to know what -source/-target to use.
1113# 1202#
1114# @return string - arguments to pass to javac, complete with -target and -source 1203# @return string - arguments to pass to javac, complete with -target and -source
1117 debug-print-function ${FUNCNAME} $* 1206 debug-print-function ${FUNCNAME} $*
1118 1207
1119 local want_source="$(java-pkg_get-source)" 1208 local want_source="$(java-pkg_get-source)"
1120 local want_target="$(java-pkg_get-target)" 1209 local want_target="$(java-pkg_get-target)"
1121 1210
1122 local source_str="-source ${want_source}" 1211 local source_str="-source ${want_source}"
1123 local target_str="-target ${want_target}" 1212 local target_str="-target ${want_target}"
1124 1213
1125 debug-print "want source: ${want_source}" 1214 debug-print "want source: ${want_source}"
1126 debug-print "want target: ${want_target}" 1215 debug-print "want target: ${want_target}"
1127 1216
1139 1228
1140# TODO document 1229# TODO document
1141java-pkg_get-jni-cflags() { 1230java-pkg_get-jni-cflags() {
1142 local flags="-I${JAVA_HOME}/include" 1231 local flags="-I${JAVA_HOME}/include"
1143 1232
1233 # TODO do a check that the directories are valid
1144 # TODO figure out how to cope with other things than linux... 1234 # TODO figure out how to cope with other things than linux...
1145 flags="${flags} -I${JAVA_HOME}/include/linux" 1235 flags="${flags} -I${JAVA_HOME}/include/linux"
1146 1236
1147 echo ${flags} 1237 echo ${flags}
1148} 1238}
1149 1239
1240java-pkg_ensure-gcj() {
1241 if ! built_with_use sys-devel/gcc gcj ; then
1242 ewarn
1243 ewarn "You must build gcc with the gcj support to build with gcj"
1244 ewarn
1245 ebeep 5
1246 die "No GCJ support found!"
1247 fi
1248}
1249
1250java-pkg_ensure-test() {
1251 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then
1252 eerror "You specified FEATURES=test, but USE=test is needed"
1253 eerror "to pull in the additional dependencies for testing"
1254 die "Need USE=test enabled"
1255 fi
1256}
1257
1150# ------------------------------------------------------------------------------ 1258# ------------------------------------------------------------------------------
1151# @section-end helper 1259# @section-end helper
1152# ------------------------------------------------------------------------------ 1260# ------------------------------------------------------------------------------
1153 1261
1154# ------------------------------------------------------------------------------ 1262# ------------------------------------------------------------------------------
1166# compiler. 1274# compiler.
1167# 1275#
1168# ------------------------------------------------------------------------------ 1276# ------------------------------------------------------------------------------
1169eant() { 1277eant() {
1170 debug-print-function ${FUNCNAME} $* 1278 debug-print-function ${FUNCNAME} $*
1279
1280 # FIXME get this working
1281# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1282# java-pkg_announce-qa-violation \
1283# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1284# fi
1171 1285
1172 local antflags 1286 local antflags
1173 java-pkg_init-compiler_ 1287 java-pkg_init-compiler_
1174 local compiler="${GENTOO_COMPILER}" 1288 local compiler="${GENTOO_COMPILER}"
1175 1289
1189 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1303 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 1304 if [[ -n ${build_compiler_deps} ]]; then
1191 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1305 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1192 fi 1306 fi
1193 fi 1307 fi
1194 1308
1309 if is-java-strict; then
1310 einfo "Disabling system classpath for ant"
1311 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1312 fi
1313
1195 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1314 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1196 antflags="${antflags} -debug" 1315 antflags="${antflags} -debug"
1197 fi 1316 fi
1198 1317
1199 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1318 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1200 ant ${antflags} "${@}" || die "eant failed" 1319 ant ${antflags} "${@}" || die "eant failed"
1201 1320
1202} 1321}
1203 1322
1204# ------------------------------------------------------------------------------ 1323# ------------------------------------------------------------------------------
1205# @ebuild-function ejavac 1324# @ebuild-function ejavac
1206# 1325#
1207# Javac wrapper function. Will use the appropriate compiler, based on 1326# Javac wrapper function. Will use the appropriate compiler, based on
1208# /etc/java-config/compilers.conf 1327# /etc/java-config/compilers.conf
1209# 1328#
1210# @param $@ - Arguments to be passed to the compiler 1329# @param $@ - Arguments to be passed to the compiler
1211# ------------------------------------------------------------------------------ 1330# ------------------------------------------------------------------------------
1212ejavac() { 1331ejavac() {
1213 debug-print-function ${FUNCNAME} $* 1332 debug-print-function ${FUNCNAME} $*
1214 1333
1334 # FIXME using get-javac ends up printing stuff with einfo
1215 local compiler_executable=$(java-pkg_get-javac) 1335# local compiler_executable=$(java-pkg_get-javac)
1336 local compiler_executable="javac"
1216 1337
1217 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1338 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}"
1218 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1339 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed"
1219} 1340}
1220 1341
1221# ------------------------------------------------------------------------------ 1342# ------------------------------------------------------------------------------
1222# @ebuild-function java-pkg_filter-compiler 1343# @ebuild-function java-pkg_filter-compiler
1223# 1344#
1224# Used to prevent the use of some compilers. Should be used in src_compile. 1345# Used to prevent the use of some compilers. Should be used in src_compile.
1225# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1346# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1226# 1347#
1227# @param $@ - compilers to filter 1348# @param $@ - compilers to filter
1228# ------------------------------------------------------------------------------ 1349# ------------------------------------------------------------------------------
1229java-pkg_filter-compiler() { 1350java-pkg_filter-compiler() {
1230 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@" 1351 JAVA_PKG_FILTER_COMPILER="${JAVA_PKG_FILTER_COMPILER} $@"
1231} 1352}
1232 1353
1233# ------------------------------------------------------------------------------ 1354# ------------------------------------------------------------------------------
1355# @ebuild-function java-pkg_force-compiler
1356#
1357# Used to force the use of particular compilers. Should be used in src_compile.
1358# A common use of this would be to force ecj-3.1 to be used on amd64, to avoid
1359# OutOfMemoryErrors that may come up.
1360#
1361# @param $@ - compilers to force
1362# ------------------------------------------------------------------------------
1363java-pkg_force-compiler() {
1364 JAVA_PKG_FORCE_COMPILER="$@"
1365}
1366
1367# ------------------------------------------------------------------------------
1234# @ebuild-function use_doc 1368# @ebuild-function use_doc
1235# 1369#
1236# Helper function for getting ant to build javadocs. If the user has USE=doc, 1370# 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. 1371# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1238# 1372#
1239# The output of this should be passed to ant. 1373# The output of this should be passed to ant.
1240# 1374#
1241# Example: build javadocs by calling 'javadoc' target 1375# Example: build javadocs by calling 'javadoc' target
1242# eant $(use_doc) 1376# eant $(use_doc)
1243# Example: build javadocs by calling 'apidoc' target 1377# Example: build javadocs by calling 'apidoc' target
1251} 1385}
1252 1386
1253# ------------------------------------------------------------------------------ 1387# ------------------------------------------------------------------------------
1254# @section-end build 1388# @section-end build
1255# ------------------------------------------------------------------------------ 1389# ------------------------------------------------------------------------------
1256 1390
1257# ------------------------------------------------------------------------------ 1391# ------------------------------------------------------------------------------
1258# @section-begin internal 1392# @section-begin internal
1259# @section-summary Internal functions 1393# @section-summary Internal functions
1260# 1394#
1261# Do __NOT__ use any of these from an ebuild! These are only to be used from 1395# Do __NOT__ use any of these from an ebuild! These are only to be used from
1262# within the java eclasses. 1396# within the java eclasses.
1263# ------------------------------------------------------------------------------ 1397# ------------------------------------------------------------------------------
1264 1398
1265# ----------------------------------------------------------------------------- 1399# -----------------------------------------------------------------------------
1266# @function-internal java-pkg_init 1400# @function-internal java-pkg_init
1267# 1401#
1268# The purpose of this function, as the name might imply, is to initialize the 1402# 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 1403# 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 1404# that'll muss things up. It initializes some variables, which are used
1271# internally. And most importantly, it'll switch the VM if necessary. 1405# internally. And most importantly, it'll switch the VM if necessary.
1272# 1406#
1284 # TODO we will probably want to set JAVAC and JAVACFLAGS 1418 # TODO we will probably want to set JAVAC and JAVACFLAGS
1285 1419
1286 # Do some QA checks 1420 # Do some QA checks
1287 java-pkg_check-jikes 1421 java-pkg_check-jikes
1288 1422
1289 # When users have crazy classpaths some packages can fail to compile. 1423 # When users have crazy classpaths some packages can fail to compile.
1290 # and everything should work with empty CLASSPATH. 1424 # and everything should work with empty CLASSPATH.
1291 # This also helps prevent unexpected dependencies on random things 1425 # This also helps prevent unexpected dependencies on random things
1292 # from the CLASSPATH. 1426 # from the CLASSPATH.
1293 unset CLASSPATH 1427 unset CLASSPATH
1294} 1428}
1295 1429
1296# ------------------------------------------------------------------------------ 1430# ------------------------------------------------------------------------------
1297# @function-internal java-pkg-init-compiler_ 1431# @function-internal java-pkg-init-compiler_
1298# 1432#
1299# This function attempts to figure out what compiler should be used. It does 1433# 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 1434# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1301# COMPILERS variable defined there. 1435# COMPILERS variable defined there.
1302# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1436# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1303# 1437#
1304# It will go through the list of compilers, and verify that it supports the 1438# 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 1439# 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 1440# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1307# isn't done. 1441# isn't done.
1308# 1442#
1330 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1464 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1331 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1465 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1332 else 1466 else
1333 compilers=${JAVA_PKG_FORCE_COMPILER} 1467 compilers=${JAVA_PKG_FORCE_COMPILER}
1334 fi 1468 fi
1335 1469
1336 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1470 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1337 1471
1338 # Figure out if we should announce what compiler we're using 1472 # Figure out if we should announce what compiler we're using
1339 local compiler 1473 local compiler
1340 for compiler in ${compilers}; do 1474 for compiler in ${compilers}; do
1343 if [[ ${compiler} = "javac" ]]; then 1477 if [[ ${compiler} = "javac" ]]; then
1344 debug-print "Found javac... breaking" 1478 debug-print "Found javac... breaking"
1345 export GENTOO_COMPILER="javac" 1479 export GENTOO_COMPILER="javac"
1346 break 1480 break
1347 fi 1481 fi
1348 1482
1349 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1483 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1350 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1484 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1351 einfo "Filtering ${compiler}" 1485 einfo "Filtering ${compiler}"
1352 continue 1486 continue
1353 fi 1487 fi
1354 fi 1488 fi
1355 1489
1356 # for non-javac, we need to make sure it supports the right target and 1490 # for non-javac, we need to make sure it supports the right target and
1357 # source 1491 # source
1358 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1492 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1359 if [[ -f ${compiler_env} ]]; then 1493 if [[ -f ${compiler_env} ]]; then
1360 local desired_target="$(java-pkg_get-target)" 1494 local desired_target="$(java-pkg_get-target)"
1456 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1590 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1457 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1591 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1458 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1592 [[ -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 ! 1593 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1460 ) > "${JAVA_PKG_ENV}" 1594 ) > "${JAVA_PKG_ENV}"
1461 1595
1462 # register target/source 1596 # register target/source
1463 local target="$(java-pkg_get-target)" 1597 local target="$(java-pkg_get-target)"
1464 local source="$(java-pkg_get-source)" 1598 local source="$(java-pkg_get-source)"
1465 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1599 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1466 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1600 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1533 fi 1667 fi
1534} 1668}
1535 1669
1536# ------------------------------------------------------------------------------ 1670# ------------------------------------------------------------------------------
1537# @internal-function java-pkg_expand_dir_ 1671# @internal-function java-pkg_expand_dir_
1538# 1672#
1539# Gets the full path of the file/directory's parent. 1673# Gets the full path of the file/directory's parent.
1540# @param $1 - file/directory to find parent directory for 1674# @param $1 - file/directory to find parent directory for
1541# @return - path to $1's parent directory 1675# @return - path to $1's parent directory
1542# ------------------------------------------------------------------------------ 1676# ------------------------------------------------------------------------------
1543java-pkg_expand_dir_() { 1677java-pkg_expand_dir_() {
1635} 1769}
1636 1770
1637# ------------------------------------------------------------------------------ 1771# ------------------------------------------------------------------------------
1638# @internal-function java-pkg_switch-vm 1772# @internal-function java-pkg_switch-vm
1639# 1773#
1640# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1774# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1641# verify that the current VM is sufficient. 1775# verify that the current VM is sufficient.
1642# Setup the environment for the VM being used. 1776# Setup the environment for the VM being used.
1643# ------------------------------------------------------------------------------ 1777# ------------------------------------------------------------------------------
1644java-pkg_switch-vm() { 1778java-pkg_switch-vm() {
1645 if java-pkg_needs-vm; then 1779 if java-pkg_needs-vm; then
1658 # otherwise just make sure the current VM is sufficient 1792 # otherwise just make sure the current VM is sufficient
1659 else 1793 else
1660 java-pkg_ensure-vm-version-sufficient 1794 java-pkg_ensure-vm-version-sufficient
1661 fi 1795 fi
1662 debug-print "Using: $(java-config -f)" 1796 debug-print "Using: $(java-config -f)"
1663 1797
1664 java-pkg_setup-vm 1798 java-pkg_setup-vm
1665 1799
1666 export JAVA=$(java-config -java) 1800 export JAVA=$(java-config --java)
1667 export JAVAC=$(java-config -javac) 1801 export JAVAC=$(java-config --javac)
1668 export JAVACFLAGS="$(java-pkg_javac-args)" 1802 export JAVACFLAGS="$(java-pkg_javac-args)"
1669 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1803 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1670 1804
1671 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1805 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1672 export JDK_HOME=${JAVA_HOME} 1806 export JDK_HOME=${JAVA_HOME}
1673 1807
1674 #TODO If you know a better solution let us know. 1808 #TODO If you know a better solution let us know.
1675 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1809 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1676 1810
1677 local tann="${T}/announced-vm" 1811 local tann="${T}/announced-vm"
1678 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1812 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1679 # Add a check for setup/preinst phase... to avoid duplicate outputs 1813 # Add a check for setup/preinst phase... to avoid duplicate outputs
1680 # for when FEATURES=buildpkg 1814 # for when FEATURES=buildpkg
1681 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1815 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1706 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2 1840 echo "GENTOO_VM=${GENTOO_VM} CLASSPATH=\"${CLASSPATH}\" JAVA_HOME=\"${JAVA_HOME}\"" >&2
1707 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2 1841 echo "JAVACFLAGS=\"${JAVACFLAGS}\" COMPILER=\"${GENTOO_COMPILER}\"" >&2
1708 echo "and of course, the output of emerge --info" >&2 1842 echo "and of course, the output of emerge --info" >&2
1709} 1843}
1710 1844
1845
1846# TODO document
1847# List jars in the source directory, ${S}
1848java-pkg_jar-list() {
1849 if [[ -n "${JAVA_PKG_DEBUG}" ]]; then
1850 einfo "Linked Jars"
1851 find "${S}" -type l -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1852 einfo "Jars"
1853 find "${S}" -type f -name '*.jar' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1854 einfo "Classes"
1855 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1856 fi
1857}
1858
1859# TODO document
1860# Verify that the classes were compiled for the right source / target
1861java-pkg_verify-classes() {
1862 ebegin "Verifying java class versions"
1863 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1864 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1865 result=$?
1866 eend ${result}
1867 if [[ ${result} == 0 ]]; then
1868 einfo "All good"
1869 else
1870 ewarn "Possible problem"
1871 die "Bad class files found"
1872 fi
1873}
1874
1875
1711# ------------------------------------------------------------------------------ 1876# ------------------------------------------------------------------------------
1712# @section-end internal 1877# @section-end internal
1713# ------------------------------------------------------------------------------ 1878# ------------------------------------------------------------------------------
1714 1879
1715java-pkg_check-phase() { 1880java-pkg_check-phase() {
1716 local phase=${1} 1881 local phase=${1}
1717 local funcname=${2} 1882 local funcname=${2}
1718 # TODO add check for java-stricter
1719 if [[ ${EBUILD_PHASE} != ${phase} ]]; then 1883 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then
1720 java-pkg_announce-qa-violation \ 1884 java-pkg_announce-qa-violation \
1721 "${funcname} used outside of src_${phase}" 1885 "${funcname} used outside of src_${phase}"
1722 fi 1886 fi
1723} 1887}
1724 1888
1735 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 1899 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1736 fi 1900 fi
1737} 1901}
1738 1902
1739java-pkg_announce-qa-violation() { 1903java-pkg_announce-qa-violation() {
1740 if hasq java-strict ${FEATURES}; then 1904 if is-java-strict; then
1741 echo "Java QA Notice: $@" >&2 1905 echo "Java QA Notice: $@" >&2
1742 increment-qa-violations 1906 increment-qa-violations
1743 fi 1907 fi
1744} 1908}
1745 1909
1746increment-qa-violations() { 1910increment-qa-violations() {
1747 let "JAVA_PKG_QA_VIOLATIONS+=1" 1911 let "JAVA_PKG_QA_VIOLATIONS+=1"
1748 export JAVA_PKG_QA_VIOLATIONS 1912 export JAVA_PKG_QA_VIOLATIONS
1749} 1913}
1750 1914
1915is-java-strict() {
1916 [[ -n ${JAVA_PKG_STRICT} ]]
1917 return $?
1918}
1919
1751# ------------------------------------------------------------------------------ 1920# ------------------------------------------------------------------------------
1752# @eclass-end 1921# @eclass-end
1753# ------------------------------------------------------------------------------ 1922# ------------------------------------------------------------------------------

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

  ViewVC Help
Powered by ViewVC 1.1.20