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

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

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

Revision 1.10 Revision 1.34
4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org> 4# Copyright (c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
5# Copyright (c) 2004-2005, Gentoo Foundation 5# Copyright (c) 2004-2005, Gentoo Foundation
6# 6#
7# Licensed under the GNU General Public License, v2 7# Licensed under the GNU General Public License, v2
8# 8#
9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.34 2006/12/08 12:12:04 betelgeuse Exp $
9 10
10 11
11# ----------------------------------------------------------------------------- 12# -----------------------------------------------------------------------------
12# @eclass-begin 13# @eclass-begin
13# @eclass-shortdesc Java Utility eclass 14# @eclass-shortdesc Java Utility eclass
14# @eclass-maintainer java@gentoo.org 15# @eclass-maintainer java@gentoo.org
15# 16#
16# This eclass provides functionality which is used by 17# This eclass provides functionality which is used by
17# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds. 18# java-pkg.eclass and java-pkg-opt.eclass as well as from ebuilds.
18# 19#
19# @warning 20# @warning
20# You probably don't want to inherit this directly from an ebuild. Instead, 21# You probably don't want to inherit this directly from an ebuild. Instead,
21# you should inherit java-ant for Ant-based Java packages, java-pkg for other 22# you should inherit java-ant for Ant-based Java packages, java-pkg for other
22# Java packages, or java-pkg-opt for packages that have optional Java support. 23# Java packages, or java-pkg-opt for packages that have optional Java support.
23# 24#
24# ----------------------------------------------------------------------------- 25# -----------------------------------------------------------------------------
25 26
26inherit eutils versionator multilib 27inherit eutils versionator multilib
28
29IUSE="elibc_FreeBSD"
27 30
28# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
29# @section-begin variables 32# @section-begin variables
30# @section-title Variables 33# @section-title Variables
31# 34#
40 43
41# ----------------------------------------------------------------------------- 44# -----------------------------------------------------------------------------
42# @variable-internal JAVA_PKG_E_DEPEND 45# @variable-internal JAVA_PKG_E_DEPEND
43# 46#
44# This is a convience variable to be used from the other java eclasses. This is 47# This is a convience variable to be used from the other java eclasses. This is
45# the version of java-config we want to use. We also need a recent version 48# the version of java-config we want to use. We also need a recent version
46# portage, that includes phase hooks. 49# portage, that includes phase hooks.
47# ----------------------------------------------------------------------------- 50# -----------------------------------------------------------------------------
48JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}"
49 52
50# ----------------------------------------------------------------------------- 53# -----------------------------------------------------------------------------
100# ----------------------------------------------------------------------------- 103# -----------------------------------------------------------------------------
101 104
102# ----------------------------------------------------------------------------- 105# -----------------------------------------------------------------------------
103# @variable-internal JAVA_PKG_COMPILER_DIR 106# @variable-internal JAVA_PKG_COMPILER_DIR
104# @default /usr/share/java-config-2/compiler 107# @default /usr/share/java-config-2/compiler
105# 108#
106# Directory where compiler settings are saved, without trailing slash. 109# Directory where compiler settings are saved, without trailing slash.
107# Probably shouldn't touch this variable. 110# Probably shouldn't touch this variable.
108# ----------------------------------------------------------------------------- 111# -----------------------------------------------------------------------------
109JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"} 112JAVA_PKG_COMPILER_DIR=${JAVA_PKG_COMPILER_DIR:="/usr/share/java-config-2/compiler"}
110 113
120 123
121# ----------------------------------------------------------------------------- 124# -----------------------------------------------------------------------------
122# @variable-external JAVA_PKG_FORCE_COMPILER 125# @variable-external JAVA_PKG_FORCE_COMPILER
123# 126#
124# Explicitly set a list of compilers to use. This is normally read from 127# Explicitly set a list of compilers to use. This is normally read from
125# JAVA_PKG_COMPILERS_CONF. 128# JAVA_PKG_COMPILERS_CONF.
126# 129#
127# @note This should only be used internally or for testing. 130# @note This should only be used internally or for testing.
128# @example Use jikes and javac, in that order 131# @example Use jikes and javac, in that order
129# JAVA_PKG_FORCE_COMPILER="jikes javac" 132# JAVA_PKG_FORCE_COMPILER="jikes javac"
130# ----------------------------------------------------------------------------- 133# -----------------------------------------------------------------------------
150# @ebuild-function java-pkg_dojar 153# @ebuild-function java-pkg_dojar
151# 154#
152# Installs any number of jars. 155# Installs any number of jars.
153# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default. 156# Jar's will be installed into /usr/share/${PN}(-${SLOT})/lib/ by default.
154# You can use java-pkg_jarinto to change this path. 157# You can use java-pkg_jarinto to change this path.
155# You should never install a jar with a package version in the filename. 158# You should never install a jar with a package version in the filename.
156# Instead, use java-pkg_newjar defined below. 159# Instead, use java-pkg_newjar defined below.
157# 160#
158# @example 161# @example
159# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar 162# java-pkg_dojar dist/${PN}.jar dist/${PN}-core.jar
160# 163#
222# will not work, because: 225# will not work, because:
223# * the `for jar in "$@"` can't expand the path to jar file names, as they 226# * the `for jar in "$@"` can't expand the path to jar file names, as they
224# don't exist yet 227# don't exist yet
225# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar' 228# * all `if ...` inside for will fail - the file '/opt/my-java/lib/*.jar'
226# doesn't exist 229# doesn't exist
227# 230#
228# you have to use it as: 231# you have to use it as:
229# 232#
230# java-pkg_regjar ${D}/opt/my-java/lib/*.jar 233# java-pkg_regjar ${D}/opt/my-java/lib/*.jar
231# 234#
232# @param $@ - jars to record 235# @param $@ - jars to record
259 done 262 done
260 263
261 java-pkg_do_write_ 264 java-pkg_do_write_
262} 265}
263 266
264
265# ------------------------------------------------------------------------------ 267# ------------------------------------------------------------------------------
266# @ebuild-function java-pkg_newjar 268# @ebuild-function java-pkg_newjar
267# 269#
268# Installs a jar with a new name 270# Installs a jar with a new name
269# 271#
287 cp "${original_jar}" "${new_jar_dest}" \ 289 cp "${original_jar}" "${new_jar_dest}" \
288 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 290 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
289 java-pkg_dojar "${new_jar_dest}" 291 java-pkg_dojar "${new_jar_dest}"
290} 292}
291 293
292
293# ------------------------------------------------------------------------------ 294# ------------------------------------------------------------------------------
294# @ebuild-function java-pkg_addcp 295# @ebuild-function java-pkg_addcp
295# 296#
296# Add something to the package's classpath. For jars, you should use dojar, 297# Add something to the package's classpath. For jars, you should use dojar,
297# newjar, or regjar. This is typically used to add directories to the classpath. 298# newjar, or regjar. This is typically used to add directories to the classpath.
302java-pkg_addcp() { 303java-pkg_addcp() {
303 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}" 304 java-pkg_append_ JAVA_PKG_CLASSPATH "${@}"
304 java-pkg_do_write_ 305 java-pkg_do_write_
305} 306}
306 307
307
308# ------------------------------------------------------------------------------ 308# ------------------------------------------------------------------------------
309# @ebuild-function java-pkg_doso 309# @ebuild-function java-pkg_doso
310# 310#
311# Installs any number of JNI libraries 311# Installs any number of JNI libraries
312# They will be installed into /usr/lib by default, but java-pkg_sointo 312# They will be installed into /usr/lib by default, but java-pkg_sointo
313# can be used change this path 313# can be used change this path
314# 314#
315# Example: 315# Example:
370 java-pkg_check-phase install 370 java-pkg_check-phase install
371 371
372 [[ ${#} -lt 1 ]] && "at least one argument needed" 372 [[ ${#} -lt 1 ]] && "at least one argument needed"
373 373
374 java-pkg_init_paths_ 374 java-pkg_init_paths_
375 375
376 local lib target_dir 376 local lib target_dir
377 for lib in "$@" ; do 377 for lib in "$@" ; do
378 # Check the absolute path of the lib 378 # Check the absolute path of the lib
379 if [[ -e "${lib}" ]] ; then 379 if [[ -e "${lib}" ]] ; then
380 target_dir="$(java-pkg_expand_dir_ ${lib})" 380 target_dir="$(java-pkg_expand_dir_ ${lib})"
428# ------------------------------------------------------------------------------ 428# ------------------------------------------------------------------------------
429java-pkg_dohtml() { 429java-pkg_dohtml() {
430 debug-print-function ${FUNCNAME} $* 430 debug-print-function ${FUNCNAME} $*
431 431
432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}" 432 [[ ${#} -lt 1 ]] && die "At least one argument required for ${FUNCNAME}"
433 # TODO-nichoj find out what exactly -f package-list does 433
434 # from /usr/lib/portage/bin/dohtml -h
435 # -f Set list of allowed extensionless file names.
434 dohtml -f package-list "$@" 436 dohtml -f package-list "$@"
437
435 # this probably shouldn't be here but it provides 438 # this probably shouldn't be here but it provides
436 # a reasonable way to catch # docs for all of the 439 # a reasonable way to catch # docs for all of the
437 # old ebuilds. 440 # old ebuilds.
438 java-pkg_recordjavadoc 441 java-pkg_recordjavadoc
439} 442}
440 443
441# TODO document 444# ------------------------------------------------------------------------------
445# @ebuild-function java-pkg_dojavadoc
446#
447# Installs javadoc documentation. This should be controlled by the doc use flag.
448#
449# @param $1: - The javadoc root directory.
450#
451# @example:
452# java-pkg_dojavadoc docs/api
453#
454# ------------------------------------------------------------------------------
442java-pkg_dojavadoc() { 455java-pkg_dojavadoc() {
443 local dir="$1" 456 local dir="$1"
444 457
445 java-pkg_check-phase install 458 java-pkg_check-phase install
446 459
458} 471}
459 472
460# ------------------------------------------------------------------------------ 473# ------------------------------------------------------------------------------
461# @ebuild-function java-pkg_dosrc 474# @ebuild-function java-pkg_dosrc
462# 475#
463# Installs a zip containing the source for a package, so it can used in 476# Installs a zip containing the source for a package, so it can used in
464# from IDEs like eclipse and netbeans. 477# from IDEs like eclipse and netbeans.
465# 478#
466# Ebuild needs to DEPEND on app-arch/zip to use this. 479# Ebuild needs to DEPEND on app-arch/zip to use this.
467# 480#
468# It also should be controlled by USE=source. 481# It also should be controlled by USE=source.
469# 482#
470# @example: 483# @example:
471# java-pkg_dosrc src/* 484# java-pkg_dosrc src/*
472# 485#
473# ------------------------------------------------------------------------------ 486# ------------------------------------------------------------------------------
474# TODO change so it the arguments it takes are the base directories containing 487# TODO change so it the arguments it takes are the base directories containing
475# source -nichoj 488# source -nichoj
476# TODO should we be able to handle multiple calls to dosrc? -nichoj 489# TODO should we be able to handle multiple calls to dosrc? -nichoj
477# TODO maybe we can take an existing zip/jar? -nichoj 490# TODO maybe we can take an existing zip/jar? -nichoj
478# FIXME apparently this fails if you give it an empty directories 491# FIXME apparently this fails if you give it an empty directories
479java-pkg_dosrc() { 492java-pkg_dosrc() {
480 debug-print-function ${FUNCNAME} $* 493 debug-print-function ${FUNCNAME} $*
481 494
482 [ ${#} -lt 1 ] && die "At least one argument needed" 495 [ ${#} -lt 1 ] && die "At least one argument needed"
483 if ! hasq source ${IUSE}; then 496 if ! hasq source ${IUSE}; then
484 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE" 497 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
485 fi 498 fi
486 499
487 java-pkg_check-phase install 500 java-pkg_check-phase install
488 501
489 [[ ${#} -lt 1 ]] && die "At least one argument needed" 502 [[ ${#} -lt 1 ]] && die "At least one argument needed"
490 503
491 java-pkg_init_paths_ 504 java-pkg_init_paths_
492 505
493 local zip_name="${PN}-src.zip" 506 local zip_name="${PN}-src.zip"
494 local zip_path="${T}/${zip_name}" 507 local zip_path="${T}/${zip_name}"
518# @ebuild-function java-pkg_dolauncher 531# @ebuild-function java-pkg_dolauncher
519# 532#
520# Make a wrapper script to lauch/start this package 533# Make a wrapper script to lauch/start this package
521# If necessary, the wrapper will switch to the appropriate VM. 534# If necessary, the wrapper will switch to the appropriate VM.
522# 535#
536# Can be called without parameters if the package installs only one jar
537# that has the Main-class attribute set. The wrapper will be named ${PN}.
538#
523# @param $1 - filename of launcher to create 539# @param $1 - filename of launcher to create
524# @param $2 - options, as follows: 540# @param $2 - options, as follows:
525# --main the.main.class.too.start 541# --main the.main.class.too.start
526# --jar /the/jar/too/launch.jar 542# --jar /the/jar/too/launch.jar or just <name>.jar
527# --java_args 'Extra arguments to pass too jave' 543# --java_args 'Extra arguments to pass to java'
528# --pkg_args 'extra arguments too pass too the package' 544# --pkg_args 'Extra arguments too pass to the package'
529# --pwd 545# --pwd
530# -into 546# -into
531# -pre 547# -pre
532# ------------------------------------------------------------------------------ 548# ------------------------------------------------------------------------------
533java-pkg_dolauncher() { 549java-pkg_dolauncher() {
534 debug-print-function ${FUNCNAME} $* 550 debug-print-function ${FUNCNAME} $*
535 551
536 java-pkg_check-phase install 552 java-pkg_check-phase install
537
538 [[ ${#} -lt 1 ]] && die "Need at least one argument"
539
540 java-pkg_init_paths_ 553 java-pkg_init_paths_
541 554
555 if [[ ${#} = 0 ]]; then
556 local name="${PN}"
557 else
542 local name="${1}" 558 local name="${1}"
559 shift
560 fi
561
543 # TODO rename to launcher 562 # TODO rename to launcher
544 local target="${T}/${name}" 563 local target="${T}/${name}"
564 local var_tmp="${T}/launcher_variables_tmp"
545 local target_dir pre 565 local target_dir pre
546 shift
547 566
548 echo "#!/bin/bash" > "${target}" 567 # Process the other the rest of the arguments
549 while [[ -n "${1}" && -n "${2}" ]]; do 568 while [[ -n "${1}" && -n "${2}" ]]; do
550 local var=${1} value=${2} 569 local var=${1} value=${2}
551 if [[ "${var:0:2}" == "--" ]]; then 570 if [[ "${var:0:2}" == "--" ]]; then
571 local var=${var:2}
552 echo "gjl_${var:2}=\"${value}\"" >> "${target}" 572 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
573 local gjl_${var}="${value}"
553 elif [[ "${var}" == "-into" ]]; then 574 elif [[ "${var}" == "-into" ]]; then
554 target_dir="${value}" 575 target_dir="${value}"
555 elif [[ "${var}" == "-pre" ]]; then 576 elif [[ "${var}" == "-pre" ]]; then
556 pre="${value}" 577 pre="${value}"
557 fi 578 fi
558 shift 2 579 shift 2
559 done 580 done
581
582 # Test if no --jar and --main arguments were given and
583 # in that case check if the package only installs one jar
584 # and use that jar.
585 if [[ -z "${gjl_jar}" && -z "${gjl_main}" ]]; then
586 local cp="${JAVA_PKG_CLASSPATH}"
587 if [[ "${cp/:}" = "${cp}" && "${cp%.jar}" != "${cp}" ]]; then
588 echo "gjl_jar=\"${JAVA_PKG_CLASSPATH}\"" >> "${var_tmp}"
589 else
590 local msg="Not enough information to create a launcher given."
591 msg="${msg} Please give --jar or --main argument to ${FUNCNAME}."
592 die "${msg}"
593 fi
594 fi
595
596 # Write the actual script
597 echo "#!/bin/bash" > "${target}"
598 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}"
560 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 599 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
561 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 600 cat "${var_tmp}" >> "${target}"
601 rm -f "${var_tmp}"
562 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 602 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
563 603
564 if [[ -n "${into}" ]]; then 604 if [[ -n "${target_dir}" ]]; then
565 DESTTREE="${target_dir}" dobin "${target}" 605 DESTTREE="${target_dir}" dobin "${target}"
566 local ret=$? 606 local ret=$?
567 return ${ret} 607 return ${ret}
568 else 608 else
569 dobin "${target}" 609 dobin "${target}"
597 echo "dowar: warning, skipping directory ${war}" 637 echo "dowar: warning, skipping directory ${war}"
598 continue 638 continue
599 else 639 else
600 warpath="${war}" 640 warpath="${war}"
601 fi 641 fi
602 642
603 # Install those files like you mean it 643 # Install those files like you mean it
604 INSOPTIONS="-m 0644" \ 644 INSOPTIONS="-m 0644" \
605 INSDESTTREE=${JAVA_PKG_WARDEST} \ 645 INSDESTTREE=${JAVA_PKG_WARDEST} \
606 doins ${warpath} 646 doins ${warpath}
607 done 647 done
642# @ebuild-function java-pkg_jar-from 682# @ebuild-function java-pkg_jar-from
643# 683#
644# Makes a symlink to a jar from a certain package 684# Makes a symlink to a jar from a certain package
645# A lot of java packages include dependencies in a lib/ directory 685# A lot of java packages include dependencies in a lib/ directory
646# You can use this function to replace these bundled dependencies. 686# You can use this function to replace these bundled dependencies.
687# The dependency is recorded into package.env DEPEND line, unless "--build-only"
688# is passed as the very first argument, for jars that have to be present only
689# at build time and are not needed on runtime (junit testing etc).
647# 690#
648# Example: get all jars from xerces slot 2 691# Example: get all jars from xerces slot 2
649# java-pkg_jar-from xerces-2 692# java-pkg_jar-from xerces-2
650# Example: get a specific jar from xerces slot 2 693# Example: get a specific jar from xerces slot 2
651# java-pkg_jar-from xerces-2 xml-apis.jar 694# java-pkg_jar-from xerces-2 xml-apis.jar
652# Example get a specific jar from xerces slot 2, and name it diffrently 695# Example: get a specific jar from xerces slot 2, and name it diffrently
653# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 696# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
697# Example: get junit.jar which is needed only for building
698# java-pkg_jar-from --build-only junit junit.jar
654# 699#
700# @param $1 - (optional) "--build-only" makes the jar(s) not added into
701# package.env DEPEND line.
655# @param $1 - Package to get jars from. 702# @param $1 - Package to get jars from.
656# @param $2 - jar from package. If not specified, all jars will be used. 703# @param $2 - jar from package. If not specified, all jars will be used.
657# @param $3 - When a single jar is specified, destination filename of the 704# @param $3 - When a single jar is specified, destination filename of the
658# symlink. Defaults to the name of the jar. 705# symlink. Defaults to the name of the jar.
659# ------------------------------------------------------------------------------ 706# ------------------------------------------------------------------------------
660# TODO could probably be cleaned up a little 707# TODO could probably be cleaned up a little
661java-pkg_jar-from() { 708java-pkg_jar-from() {
662 debug-print-function ${FUNCNAME} $* 709 debug-print-function ${FUNCNAME} $*
663 710
711 local build_only=""
712
713 if [[ "${1}" = "--build-only" ]]; then
714 build_only="true"
715 shift
716 fi
717
664 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 718 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
665 719
666 [[ -z ${target_pkg} ]] && die "Must specify a package" 720 [[ -z ${target_pkg} ]] && die "Must specify a package"
667 721
668 # default destjar to the target jar 722 # default destjar to the target jar
669 [[ -z "${destjar}" ]] && destjar="${target_jar}" 723 [[ -z "${destjar}" ]] && destjar="${target_jar}"
670 724
725 local error_msg="There was a problem getting the classpath for ${target_pkg}."
726 local classpath
671 local classpath="$(java-config --classpath=${target_pkg})" 727 classpath="$(java-config --classpath=${target_pkg})"
672 [[ $? != 0 ]] && die "There was a problem getting the classpath for ${target_pkg}" 728 [[ $? != 0 ]] && die ${error_msg}
673 729
674 local jar 730 local jar
675 for jar in ${classpath//:/ }; do 731 for jar in ${classpath//:/ }; do
676 local jar_name=$(basename "${jar}") 732 local jar_name=$(basename "${jar}")
677 if [[ ! -f "${jar}" ]] ; then 733 if [[ ! -f "${jar}" ]] ; then
681 # If no specific target jar was indicated, link it 737 # If no specific target jar was indicated, link it
682 if [[ -z "${target_jar}" ]] ; then 738 if [[ -z "${target_jar}" ]] ; then
683 [[ -f "${target_jar}" ]] && rm "${target_jar}" 739 [[ -f "${target_jar}" ]] && rm "${target_jar}"
684 ln -snf "${jar}" \ 740 ln -snf "${jar}" \
685 || die "Failed to make symlink from ${jar} to ${jar_name}" 741 || die "Failed to make symlink from ${jar} to ${jar_name}"
686 java-pkg_record-jar_ "${target_pkg}" "${jar}" 742 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
687 # otherwise, if the current jar is the target jar, link it 743 # otherwise, if the current jar is the target jar, link it
688 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 744 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
689 [[ -f "${destjar}" ]] && rm "${destjar}" 745 [[ -f "${destjar}" ]] && rm "${destjar}"
690 ln -snf "${jar}" "${destjar}" \ 746 ln -snf "${jar}" "${destjar}" \
691 || die "Failed to make symlink from ${jar} to ${destjar}" 747 || die "Failed to make symlink from ${jar} to ${destjar}"
692 java-pkg_record-jar_ "${target_pkg}" "${jar}" 748 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
693 return 0 749 return 0
694 fi 750 fi
695 done 751 done
696 # if no target was specified, we're ok 752 # if no target was specified, we're ok
697 if [[ -z "${target_jar}" ]] ; then 753 if [[ -z "${target_jar}" ]] ; then
714# ------------------------------------------------------------------------------ 770# ------------------------------------------------------------------------------
715# @ebuild-function java-pkg_getjars 771# @ebuild-function java-pkg_getjars
716# 772#
717# Get the classpath provided by any number of packages 773# Get the classpath provided by any number of packages
718# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'. 774# Among other things, this can be passed to 'javac -classpath' or 'ant -lib'.
775# The providing packages are recorded as dependencies into package.env DEPEND
776# line, unless "--build-only" is passed as the very first argument, for jars
777# that have to be present only at build time and are not needed on runtime
778# (junit testing etc).
719# 779#
720# Example: Get the classpath for xerces-2, 780# Example: Get the classpath for xerces-2 and xalan,
721# java-pkg_getjars xerces-2 xalan 781# java-pkg_getjars xerces-2,xalan
722# Example Return: 782# Example Return:
723# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 783# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
724# 784#
785# @param $1 - (optional) "--build-only" makes the jar(s) not added into
786# package.env DEPEND line.
725# @param $@ - list of packages to get jars from 787# @param $2 - list of packages to get jars from
788# (passed to java-config --classpath)
726# ------------------------------------------------------------------------------ 789# ------------------------------------------------------------------------------
727java-pkg_getjars() { 790java-pkg_getjars() {
728 debug-print-function ${FUNCNAME} $* 791 debug-print-function ${FUNCNAME} $*
729 792
730 [[ ${#} -lt 1 ]] && die "At least one argument needed" 793 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments"
731 794
732 # NOTE could probably just pass $@ to java-config --classpath. and return it 795 if [[ "${1}" = "--build-only" ]]; then
796 local build_only="true"
797 shift
798 fi
799
733 local classpath pkg 800 local classpath pkgs="${1}"
734 for pkg in ${@//,/ }; do
735 #for pkg in $(echo "$@" | tr ',' ' '); do
736 jars="$(java-config --classpath=${pkg})" 801 jars="$(java-config --classpath=${pkgs})"
802 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
737 debug-print "${pkg}:${jars}" 803 debug-print "${pkgs}:${jars}"
738 # TODO should we ensure jars exist? 804
739 if [[ -z "${classpath}" ]]; then 805 if [[ -z "${classpath}" ]]; then
740 classpath="${jars}" 806 classpath="${jars}"
741 else 807 else
742 classpath="${classpath}:${jars}" 808 classpath="${classpath}:${jars}"
743 fi 809 fi
810
811 # Only record jars that aren't build-only
812 if [[ -z "${build_only}" ]]; then
813 oldifs="${IFS}"
814 IFS=","
815 for pkg in ${pkgs}; do
744 java-pkg_record-jar_ "${pkg}" 816 java-pkg_record-jar_ "${pkg}"
745 done 817 done
818 IFS="${oldifs}"
819 fi
820
746 echo "${classpath}" 821 echo "${classpath}"
747} 822}
748 823
749# ------------------------------------------------------------------------------ 824# ------------------------------------------------------------------------------
750# @ebuild-function java-pkg_getjar 825# @ebuild-function java-pkg_getjar
751# 826#
752# Get the filename of a single jar from a package 827# Get the filename of a single jar from a package
828# The providing package is recorded as runtime dependency into package.env
829# DEPEND line, unless "--build-only" is passed as the very first argument, for
830# jars that have to be present only at build time and are not needed on runtime
831# (junit testing etc).
753# 832#
754# @example 833# @example
755# java-pkg_getjar xerces-2 xml-apis.jar 834# java-pkg_getjar xerces-2 xml-apis.jar
756# @example-return 835# @example-return
757# /usr/share/xerces-2/lib/xml-apis.jar 836# /usr/share/xerces-2/lib/xml-apis.jar
758# 837#
838# @param $1 - (optional) "--build-only" makes the jar not added into
839# package.env DEPEND line.
759# @param $1 - package to use 840# @param $1 - package to use
760# @param $2 - jar to get 841# @param $2 - jar to get
761# ------------------------------------------------------------------------------ 842# ------------------------------------------------------------------------------
762java-pkg_getjar() { 843java-pkg_getjar() {
763 debug-print-function ${FUNCNAME} $* 844 debug-print-function ${FUNCNAME} $*
845
846 local build_only=""
847
848 if [[ "${1}" = "--build-only" ]]; then
849 build_only="true"
850 shift
851 fi
764 852
765 local pkg="${1}" target_jar="${2}" jar 853 local pkg="${1}" target_jar="${2}" jar
766 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 854 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
767 [[ -z ${target_jar} ]] && die "Must specify jar to get" 855 [[ -z ${target_jar} ]] && die "Must specify jar to get"
768 856
769 # TODO check that package is actually installed 857 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
858 local classpath
770 local classpath=$(java-config --classpath=${pkg}) 859 classpath=$(java-config --classpath=${pkg})
771 [[ $? != 0 ]] && die "There could not find classpath for ${pkg}. Are you sure its installed?" 860 [[ $? != 0 ]] && die ${error_msg}
861
772 for jar in ${classpath//:/ }; do 862 for jar in ${classpath//:/ }; do
773 if [[ ! -f "${jar}" ]] ; then 863 if [[ ! -f "${jar}" ]] ; then
774 die "Installation problems with jars in ${pkg} - is it installed?" 864 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
775 fi 865 fi
776 866
777 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then 867 if [[ "$(basename ${jar})" == "${target_jar}" ]] ; then
778 java-pkg_record-jar_ "${pkg}" "${jar}" 868 # Only record jars that aren't build-only
869 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}" "${jar}"
779 echo "${jar}" 870 echo "${jar}"
780 return 0 871 return 0
781 fi 872 fi
782 done 873 done
783 874
784 die "Could not find ${target_jar} in ${pkg}" 875 die "Could not find ${target_jar} in ${pkg}"
785 return 1 876 return 1
786} 877}
787 878
788# This function reads stdin, and based on that input, figures out how to 879# This function reads stdin, and based on that input, figures out how to
802# line="${line// /}" 893# line="${line// /}"
803# 894#
804# # format: path=jarinfo 895# # format: path=jarinfo
805# local path=${line%%=*} 896# local path=${line%%=*}
806# local jarinfo=${line##*=} 897# local jarinfo=${line##*=}
807# 898#
808# # format: jar@package 899# # format: jar@package
809# local jar=${jarinfo%%@*}.jar 900# local jar=${jarinfo%%@*}.jar
810# local package=${jarinfo##*@} 901# local package=${jarinfo##*@}
811# if [[ -n ${replace_only} ]]; then 902# if [[ -n ${replace_only} ]]; then
812# [[ ! -f $path ]] && die "No jar exists at ${path}" 903# [[ ! -f $path ]] && die "No jar exists at ${path}"
825# @section-end query 916# @section-end query
826# ------------------------------------------------------------------------------ 917# ------------------------------------------------------------------------------
827 918
828# ------------------------------------------------------------------------------ 919# ------------------------------------------------------------------------------
829# @section-begin helper 920# @section-begin helper
830# @section-summary Helper functions 921# @section-summary Helper functions
831# 922#
832# Various other functions to use from an ebuild 923# Various other functions to use from an ebuild
833# ------------------------------------------------------------------------------ 924# ------------------------------------------------------------------------------
834 925
835# ------------------------------------------------------------------------------ 926# ------------------------------------------------------------------------------
841# jdbc-stdext 932# jdbc-stdext
842# jaf 933# jaf
843# jdbc-rowset 934# jdbc-rowset
844# jms 935# jms
845# 936#
846# @param $1 - Optionally indicate that the dependencies are controlled by 937# @param $1 - Optionally indicate that the dependencies are controlled by
847# a use flag by specifying '--use' Requires $2. 938# a use flag by specifying '--use' Requires $2.
848# @param $2 - USE flag which will enable the dependencies. 939# @param $2 - USE flag which will enable the dependencies.
849# @param $@ - virtual packages to add depenedencies for 940# @param $@ - virtual packages to add depenedencies for
850# ------------------------------------------------------------------------------ 941# ------------------------------------------------------------------------------
851# TODO rewrite to parse a line based declaration file instead -- karltk 942# TODO rewrite to parse a line based declaration file instead -- karltk
945 fi 1036 fi
946} 1037}
947 1038
948# ------------------------------------------------------------------------------ 1039# ------------------------------------------------------------------------------
949# @internal-function java-pkg_is-vm-version-sufficient 1040# @internal-function java-pkg_is-vm-version-sufficient
950# 1041#
951# @return zero - VM is sufficient 1042# @return zero - VM is sufficient
952# @return non-zero - VM is not sufficient 1043# @return non-zero - VM is not sufficient
953# ------------------------------------------------------------------------------ 1044# ------------------------------------------------------------------------------
954java-pkg_is-vm-version-sufficient() { 1045java-pkg_is-vm-version-sufficient() {
955 debug-print-function ${FUNCNAME} $* 1046 debug-print-function ${FUNCNAME} $*
975 die "Active Java VM too old" 1066 die "Active Java VM too old"
976 fi 1067 fi
977} 1068}
978 1069
979# ------------------------------------------------------------------------------ 1070# ------------------------------------------------------------------------------
980# @internal-function java-pkg_is-vm-version-eq 1071# @internal-function java-pkg_is-vm-version-eq
981# 1072#
982# @param $@ - VM version to compare current VM to 1073# @param $@ - VM version to compare current VM to
983# @return zero - VM versions are equal 1074# @return zero - VM versions are equal
984# @return non-zero - VM version are not equal 1075# @return non-zero - VM version are not equal
985# ------------------------------------------------------------------------------ 1076# ------------------------------------------------------------------------------
986java-pkg_is-vm-version-eq() { 1077java-pkg_is-vm-version-eq() {
1016# 1107#
1017# @param $@ - VM version to compare current to 1108# @param $@ - VM version to compare current to
1018# ------------------------------------------------------------------------------ 1109# ------------------------------------------------------------------------------
1019java-pkg_ensure-vm-version-ge() { 1110java-pkg_ensure-vm-version-ge() {
1020 debug-print-function ${FUNCNAME} $* 1111 debug-print-function ${FUNCNAME} $*
1021 1112
1022 if ! java-pkg_is-vm-version-ge "$@" ; then 1113 if ! java-pkg_is-vm-version-ge "$@" ; then
1023 debug-print "vm is not suffient" 1114 debug-print "vm is not suffient"
1024 eerror "This package requires a Java VM version >= $@" 1115 eerror "This package requires a Java VM version >= $@"
1025 einfo "Please use java-config -S to set the correct one" 1116 einfo "Please use java-config -S to set the correct one"
1026 die "Active Java VM too old" 1117 die "Active Java VM too old"
1027 fi 1118 fi
1028} 1119}
1029 1120
1030# ------------------------------------------------------------------------------ 1121# ------------------------------------------------------------------------------
1031# @internal-function java-pkg_is-vm-version-ge 1122# @internal-function java-pkg_is-vm-version-ge
1032# 1123#
1033# @param $@ - VM version to compare current VM to 1124# @param $@ - VM version to compare current VM to
1034# @return zero - current VM version is greater than checked version 1125# @return zero - current VM version is greater than checked version
1035# @return non-zero - current VM version is not greater than checked version 1126# @return non-zero - current VM version is not greater than checked version
1036# ------------------------------------------------------------------------------ 1127# ------------------------------------------------------------------------------
1037java-pkg_is-vm-version-ge() { 1128java-pkg_is-vm-version-ge() {
1051 return 1 1142 return 1
1052 fi 1143 fi
1053 fi 1144 fi
1054} 1145}
1055 1146
1147java-pkg_set-current-vm() {
1148 export GENTOO_VM=${1}
1149}
1150
1151java-pkg_get-current-vm() {
1152 echo ${GENTOO_VM}
1153}
1154
1155java-pkg_current-vm-matches() {
1156 hasq $(java-pkg_get-current-vm) ${@}
1157 return $?
1158}
1159
1056# ------------------------------------------------------------------------------ 1160# ------------------------------------------------------------------------------
1057# @ebuild-function java-pkg_get-source 1161# @ebuild-function java-pkg_get-source
1058# 1162#
1059# Determines what source version should be used, for passing to -source. 1163# Determines what source version should be used, for passing to -source.
1060# Unless you want to break things you probably shouldn't set _WANT_SOURCE 1164# Unless you want to break things you probably shouldn't set _WANT_SOURCE
1061# 1165#
1062# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE 1166# @return string - Either the lowest possible source, or JAVA_PKG_WANT_SOURCE
1063# ------------------------------------------------------------------------------ 1167# ------------------------------------------------------------------------------
1068# ------------------------------------------------------------------------------ 1172# ------------------------------------------------------------------------------
1069# @ebuild-function java-pkg_get-target 1173# @ebuild-function java-pkg_get-target
1070# 1174#
1071# Determines what target version should be used, for passing to -target. 1175# Determines what target version should be used, for passing to -target.
1072# If you don't care about lower versions, you can set _WANT_TARGET to the 1176# If you don't care about lower versions, you can set _WANT_TARGET to the
1073# version of your JDK. 1177# version of your JDK.
1074# Remember doing this will mostly like cause things to break. 1178# Remember doing this will mostly like cause things to break.
1075# Doesn't allow it to be lower then the one in depend. 1179# Doesn't allow it to be lower then the one in depend.
1076# Doesn't allow it to be higher then the active vm. 1180# Doesn't allow it to be higher then the active vm.
1077# 1181#
1078# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1182# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1079# ------------------------------------------------------------------------------ 1183# ------------------------------------------------------------------------------
1080java-pkg_get-target() { 1184java-pkg_get-target() {
1081 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}") 1185 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1082 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then 1186 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1083 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)" 1187 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1084 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then 1188 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1085 echo ${JAVA_PKG_WANT_TARGET} 1189 echo ${JAVA_PKG_WANT_TARGET}
1086 else 1190 else
1094} 1198}
1095 1199
1096java-pkg_get-javac() { 1200java-pkg_get-javac() {
1097 debug-print-function ${FUNCNAME} $* 1201 debug-print-function ${FUNCNAME} $*
1098 1202
1099 java-pkg_init-compiler_ 1203
1100 local compiler="${GENTOO_COMPILER}" 1204 local compiler="${GENTOO_COMPILER}"
1101 1205
1102 local compiler_executable 1206 local compiler_executable
1103 if [[ "${compiler}" = "javac" ]]; then 1207 if [[ "${compiler}" = "javac" ]]; then
1104 # nothing fancy needs to be done for javac 1208 # nothing fancy needs to be done for javac
1112 unset JAVAC 1216 unset JAVAC
1113 # try to get value of JAVAC 1217 # try to get value of JAVAC
1114 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})" 1218 compiler_executable="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${JAVAC})"
1115 export JAVAC=${old_javac} 1219 export JAVAC=${old_javac}
1116 1220
1117 [[ -z ${compiler_executable} ]] && die "JAVAC is empty or undefined in ${compiler_env}" 1221 if [[ -z ${compiler_executable} ]]; then
1118 1222 echo "JAVAC is empty or undefined in ${compiler_env}"
1223 return 1
1224 fi
1225
1119 # check that it's executable 1226 # check that it's executable
1120 if [[ ! -x ${compiler_executable} ]]; then 1227 if [[ ! -x ${compiler_executable} ]]; then
1121 eerror "Could not find ${compiler_executable}!"
1122 die "${compiler_executable} doesn't exist, or isn't executable" 1228 echo "${compiler_executable} doesn't exist, or isn't executable"
1229 return 1
1123 fi 1230 fi
1124 else 1231 else
1125 eerror "Could not find environment file for ${compiler}" 1232 echo "Could not find environment file for ${compiler}"
1126 die "Could not find ${compiler_env}" 1233 return 1
1127 fi 1234 fi
1128 fi 1235 fi
1129 echo ${compiler_executable} 1236 echo ${compiler_executable}
1130} 1237}
1131 1238
1132# ------------------------------------------------------------------------------ 1239# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_javac-args 1240# @ebuild-function java-pkg_javac-args
1134# 1241#
1135# If an ebuild uses javac directly, instead of using ejavac, it should call this 1242# If an ebuild uses javac directly, instead of using ejavac, it should call this
1136# to know what -source/-target to use. 1243# to know what -source/-target to use.
1137# 1244#
1138# @return string - arguments to pass to javac, complete with -target and -source 1245# @return string - arguments to pass to javac, complete with -target and -source
1141 debug-print-function ${FUNCNAME} $* 1248 debug-print-function ${FUNCNAME} $*
1142 1249
1143 local want_source="$(java-pkg_get-source)" 1250 local want_source="$(java-pkg_get-source)"
1144 local want_target="$(java-pkg_get-target)" 1251 local want_target="$(java-pkg_get-target)"
1145 1252
1146 local source_str="-source ${want_source}" 1253 local source_str="-source ${want_source}"
1147 local target_str="-target ${want_target}" 1254 local target_str="-target ${want_target}"
1148 1255
1149 debug-print "want source: ${want_source}" 1256 debug-print "want source: ${want_source}"
1150 debug-print "want target: ${want_target}" 1257 debug-print "want target: ${want_target}"
1151 1258
1152 if [[ -z "${want_source}" || -z "${want_target}" ]]; then 1259 if [[ -z "${want_source}" || -z "${want_target}" ]]; then
1153 debug-print "could not find valid -source/-target values" 1260 debug-print "could not find valid -source/-target values for javac"
1154 die "Could not find valid -source/-target values" 1261 echo "Could not find valid -source/-target values for javac"
1262 return 1
1155 else 1263 else
1156 if java-pkg_is-vm-version-ge "1.4"; then 1264 if java-pkg_is-vm-version-ge "1.4"; then
1157 echo "${source_str} ${target_str}" 1265 echo "${source_str} ${target_str}"
1158 else 1266 else
1159 echo "${target_str}" 1267 echo "${target_str}"
1163 1271
1164# TODO document 1272# TODO document
1165java-pkg_get-jni-cflags() { 1273java-pkg_get-jni-cflags() {
1166 local flags="-I${JAVA_HOME}/include" 1274 local flags="-I${JAVA_HOME}/include"
1167 1275
1276 local platform="linux"
1277 use elibc_FreeBSD && platform="freebsd"
1278
1168 # TODO do a check that the directories are valid 1279 # TODO do a check that the directories are valid
1169 # TODO figure out how to cope with other things than linux...
1170 flags="${flags} -I${JAVA_HOME}/include/linux" 1280 flags="${flags} -I${JAVA_HOME}/include/${platform}"
1171 1281
1172 echo ${flags} 1282 echo ${flags}
1173} 1283}
1174 1284
1175java-pkg_ensure-gcj() { 1285java-pkg_ensure-gcj() {
1180 ebeep 5 1290 ebeep 5
1181 die "No GCJ support found!" 1291 die "No GCJ support found!"
1182 fi 1292 fi
1183} 1293}
1184 1294
1295java-pkg_ensure-test() {
1296 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1297 && hasq test ${IUSE} && ! use test;
1298 then
1299 eerror "You specified FEATURES=test, but USE=test is needed"
1300 eerror "to pull in the additional dependencies for testing"
1301 die "Need USE=test enabled"
1302 fi
1303}
1304
1185# ------------------------------------------------------------------------------ 1305# ------------------------------------------------------------------------------
1186# @section-end helper 1306# @section-end helper
1187# ------------------------------------------------------------------------------ 1307# ------------------------------------------------------------------------------
1188 1308
1189# ------------------------------------------------------------------------------ 1309# ------------------------------------------------------------------------------
1201# compiler. 1321# compiler.
1202# 1322#
1203# ------------------------------------------------------------------------------ 1323# ------------------------------------------------------------------------------
1204eant() { 1324eant() {
1205 debug-print-function ${FUNCNAME} $* 1325 debug-print-function ${FUNCNAME} $*
1326
1327 # FIXME get this working
1328# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then
1329# java-pkg_announce-qa-violation \
1330# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1331# fi
1206 1332
1207 local antflags 1333 local antflags
1208 java-pkg_init-compiler_ 1334 java-pkg_init-compiler_
1209 local compiler="${GENTOO_COMPILER}" 1335 local compiler="${GENTOO_COMPILER}"
1210 1336
1229 1355
1230 if is-java-strict; then 1356 if is-java-strict; then
1231 einfo "Disabling system classpath for ant" 1357 einfo "Disabling system classpath for ant"
1232 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1358 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1233 fi 1359 fi
1234 1360
1235 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1361 if [[ -n ${JAVA_PKG_DEBUG} ]]; then
1236 antflags="${antflags} -debug" 1362 antflags="${antflags} -debug"
1237 fi 1363 fi
1238 1364
1239 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1365 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1240 ant ${antflags} "${@}" || die "eant failed" 1366 ant ${antflags} "${@}" || die "eant failed"
1241 1367
1242} 1368}
1243 1369
1244# ------------------------------------------------------------------------------ 1370# ------------------------------------------------------------------------------
1245# @ebuild-function ejavac 1371# @ebuild-function ejavac
1246# 1372#
1247# Javac wrapper function. Will use the appropriate compiler, based on 1373# Javac wrapper function. Will use the appropriate compiler, based on
1248# /etc/java-config/compilers.conf 1374# /etc/java-config/compilers.conf
1249# 1375#
1250# @param $@ - Arguments to be passed to the compiler 1376# @param $@ - Arguments to be passed to the compiler
1251# ------------------------------------------------------------------------------ 1377# ------------------------------------------------------------------------------
1252ejavac() { 1378ejavac() {
1253 debug-print-function ${FUNCNAME} $* 1379 debug-print-function ${FUNCNAME} $*
1254 1380
1255 # FIXME using get-javac ends up printing stuff with einfo 1381 java-pkg_init-compiler_
1382
1383 local compiler_executable
1256# local compiler_executable=$(java-pkg_get-javac) 1384 compiler_executable=$(java-pkg_get-javac)
1257 local compiler_executable="javac" 1385 if [[ ${?} != 0 ]]; then
1386 eerror "There was a problem determining compiler: ${compiler_executable}"
1387 die "get-javac failed"
1388 fi
1258 1389
1390 local javac_args
1391 javac_args="$(java-pkg_javac-args)"
1392 if [[ ${?} != 0 ]]; then
1393 eerror "There was a problem determining JAVACFLAGS: ${javac_args}"
1394 die "java-pkg_javac-args failed"
1395 fi
1396
1259 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} $(java-pkg_javac-args) "${@}" 1397 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ${compiler_executable} ${javac_args} "${@}"
1260 ${compiler_executable} $(java-pkg_javac-args) "${@}" || die "ejavac failed" 1398 ${compiler_executable} ${javac_args} "${@}" || die "ejavac failed"
1261} 1399}
1262 1400
1263# ------------------------------------------------------------------------------ 1401# ------------------------------------------------------------------------------
1264# @ebuild-function java-pkg_filter-compiler 1402# @ebuild-function java-pkg_filter-compiler
1265# 1403#
1266# Used to prevent the use of some compilers. Should be used in src_compile. 1404# Used to prevent the use of some compilers. Should be used in src_compile.
1267# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER 1405# Basically, it just appends onto JAVA_PKG_FILTER_COMPILER
1268# 1406#
1269# @param $@ - compilers to filter 1407# @param $@ - compilers to filter
1270# ------------------------------------------------------------------------------ 1408# ------------------------------------------------------------------------------
1288# ------------------------------------------------------------------------------ 1426# ------------------------------------------------------------------------------
1289# @ebuild-function use_doc 1427# @ebuild-function use_doc
1290# 1428#
1291# Helper function for getting ant to build javadocs. If the user has USE=doc, 1429# Helper function for getting ant to build javadocs. If the user has USE=doc,
1292# then 'javadoc' or the argument are returned. Otherwise, there is no return. 1430# then 'javadoc' or the argument are returned. Otherwise, there is no return.
1293# 1431#
1294# The output of this should be passed to ant. 1432# The output of this should be passed to ant.
1295# 1433#
1296# Example: build javadocs by calling 'javadoc' target 1434# Example: build javadocs by calling 'javadoc' target
1297# eant $(use_doc) 1435# eant $(use_doc)
1298# Example: build javadocs by calling 'apidoc' target 1436# Example: build javadocs by calling 'apidoc' target
1306} 1444}
1307 1445
1308# ------------------------------------------------------------------------------ 1446# ------------------------------------------------------------------------------
1309# @section-end build 1447# @section-end build
1310# ------------------------------------------------------------------------------ 1448# ------------------------------------------------------------------------------
1311 1449
1312# ------------------------------------------------------------------------------ 1450# ------------------------------------------------------------------------------
1313# @section-begin internal 1451# @section-begin internal
1314# @section-summary Internal functions 1452# @section-summary Internal functions
1315# 1453#
1316# Do __NOT__ use any of these from an ebuild! These are only to be used from 1454# Do __NOT__ use any of these from an ebuild! These are only to be used from
1317# within the java eclasses. 1455# within the java eclasses.
1318# ------------------------------------------------------------------------------ 1456# ------------------------------------------------------------------------------
1319 1457
1320# ----------------------------------------------------------------------------- 1458# -----------------------------------------------------------------------------
1321# @function-internal java-pkg_init 1459# @function-internal java-pkg_init
1322# 1460#
1323# The purpose of this function, as the name might imply, is to initialize the 1461# The purpose of this function, as the name might imply, is to initialize the
1324# Java environment. It ensures that that there aren't any environment variables 1462# Java environment. It ensures that that there aren't any environment variables
1325# that'll muss things up. It initializes some variables, which are used 1463# that'll muss things up. It initializes some variables, which are used
1326# internally. And most importantly, it'll switch the VM if necessary. 1464# internally. And most importantly, it'll switch the VM if necessary.
1327# 1465#
1339 # TODO we will probably want to set JAVAC and JAVACFLAGS 1477 # TODO we will probably want to set JAVAC and JAVACFLAGS
1340 1478
1341 # Do some QA checks 1479 # Do some QA checks
1342 java-pkg_check-jikes 1480 java-pkg_check-jikes
1343 1481
1344 # When users have crazy classpaths some packages can fail to compile. 1482 # When users have crazy classpaths some packages can fail to compile.
1345 # and everything should work with empty CLASSPATH. 1483 # and everything should work with empty CLASSPATH.
1346 # This also helps prevent unexpected dependencies on random things 1484 # This also helps prevent unexpected dependencies on random things
1347 # from the CLASSPATH. 1485 # from the CLASSPATH.
1348 unset CLASSPATH 1486 unset CLASSPATH
1349} 1487}
1350 1488
1351# ------------------------------------------------------------------------------ 1489# ------------------------------------------------------------------------------
1352# @function-internal java-pkg-init-compiler_ 1490# @function-internal java-pkg-init-compiler_
1353# 1491#
1354# This function attempts to figure out what compiler should be used. It does 1492# This function attempts to figure out what compiler should be used. It does
1355# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the 1493# this by reading the file at JAVA_PKG_COMPILERS_CONF, and checking the
1356# COMPILERS variable defined there. 1494# COMPILERS variable defined there.
1357# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER 1495# This can be overridden by a list in JAVA_PKG_FORCE_COMPILER
1358# 1496#
1359# It will go through the list of compilers, and verify that it supports the 1497# It will go through the list of compilers, and verify that it supports the
1360# target and source that are needed. If it is not suitable, then the next 1498# target and source that are needed. If it is not suitable, then the next
1361# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking 1499# compiler is checked. When JAVA_PKG_FORCE_COMPILER is defined, this checking
1362# isn't done. 1500# isn't done.
1363# 1501#
1385 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1523 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1386 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})" 1524 compilers="$(source ${JAVA_PKG_COMPILERS_CONF} 1>/dev/null 2>&1; echo ${COMPILERS})"
1387 else 1525 else
1388 compilers=${JAVA_PKG_FORCE_COMPILER} 1526 compilers=${JAVA_PKG_FORCE_COMPILER}
1389 fi 1527 fi
1390 1528
1391 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}" 1529 debug-print "Read \"${compilers}\" from ${JAVA_PKG_COMPILERS_CONF}"
1392 1530
1393 # Figure out if we should announce what compiler we're using 1531 # Figure out if we should announce what compiler we're using
1394 local compiler 1532 local compiler
1395 for compiler in ${compilers}; do 1533 for compiler in ${compilers}; do
1398 if [[ ${compiler} = "javac" ]]; then 1536 if [[ ${compiler} = "javac" ]]; then
1399 debug-print "Found javac... breaking" 1537 debug-print "Found javac... breaking"
1400 export GENTOO_COMPILER="javac" 1538 export GENTOO_COMPILER="javac"
1401 break 1539 break
1402 fi 1540 fi
1403 1541
1404 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then 1542 if has ${compiler} ${JAVA_PKG_FILTER_COMPILER}; then
1405 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then 1543 if [[ -z ${JAVA_PKG_FORCE_COMPILER} ]]; then
1406 einfo "Filtering ${compiler}" 1544 einfo "Filtering ${compiler}"
1407 continue 1545 continue
1408 fi 1546 fi
1409 fi 1547 fi
1410 1548
1411 # for non-javac, we need to make sure it supports the right target and 1549 # for non-javac, we need to make sure it supports the right target and
1412 # source 1550 # source
1413 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1551 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1414 if [[ -f ${compiler_env} ]]; then 1552 if [[ -f ${compiler_env} ]]; then
1415 local desired_target="$(java-pkg_get-target)" 1553 local desired_target="$(java-pkg_get-target)"
1497# Writes the package.env out to disk. 1635# Writes the package.env out to disk.
1498# 1636#
1499# ------------------------------------------------------------------------------ 1637# ------------------------------------------------------------------------------
1500# TODO change to do-write, to match everything else 1638# TODO change to do-write, to match everything else
1501java-pkg_do_write_() { 1639java-pkg_do_write_() {
1640 java-pkg_init_paths_
1502 # Create directory for package.env 1641 # Create directory for package.env
1503 dodir "${JAVA_PKG_SHAREPATH}" 1642 dodir "${JAVA_PKG_SHAREPATH}"
1504 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 1643 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then
1505 # Create package.env 1644 # Create package.env
1506 ( 1645 (
1511 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 1650 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1512 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 1651 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1513 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 1652 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\""
1514 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 1653 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1515 ) > "${JAVA_PKG_ENV}" 1654 ) > "${JAVA_PKG_ENV}"
1516 1655
1517 # register target/source 1656 # register target/source
1518 local target="$(java-pkg_get-target)" 1657 local target="$(java-pkg_get-target)"
1519 local source="$(java-pkg_get-source)" 1658 local source="$(java-pkg_get-source)"
1520 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}" 1659 [[ -n ${target} ]] && echo "TARGET=\"${target}\"" >> "${JAVA_PKG_ENV}"
1521 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}" 1660 [[ -n ${source} ]] && echo "SOURCE=\"${source}\"" >> "${JAVA_PKG_ENV}"
1534 # Strip unnecessary leading and trailing colons 1673 # Strip unnecessary leading and trailing colons
1535 # TODO try to cleanup if possible 1674 # TODO try to cleanup if possible
1536 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 1675 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
1537 fi 1676 fi
1538} 1677}
1539
1540 1678
1541# ------------------------------------------------------------------------------ 1679# ------------------------------------------------------------------------------
1542# @internal-function java-pkg_record-jar_ 1680# @internal-function java-pkg_record-jar_
1543# 1681#
1544# Record a dependency to the package.env 1682# Record a dependency to the package.env
1588 fi 1726 fi
1589} 1727}
1590 1728
1591# ------------------------------------------------------------------------------ 1729# ------------------------------------------------------------------------------
1592# @internal-function java-pkg_expand_dir_ 1730# @internal-function java-pkg_expand_dir_
1593# 1731#
1594# Gets the full path of the file/directory's parent. 1732# Gets the full path of the file/directory's parent.
1595# @param $1 - file/directory to find parent directory for 1733# @param $1 - file/directory to find parent directory for
1596# @return - path to $1's parent directory 1734# @return - path to $1's parent directory
1597# ------------------------------------------------------------------------------ 1735# ------------------------------------------------------------------------------
1598java-pkg_expand_dir_() { 1736java-pkg_expand_dir_() {
1625# ------------------------------------------------------------------------------ 1763# ------------------------------------------------------------------------------
1626java-pkg_setup-vm() { 1764java-pkg_setup-vm() {
1627 debug-print-function ${FUNCNAME} $* 1765 debug-print-function ${FUNCNAME} $*
1628 1766
1629 local vendor="$(java-pkg_get-vm-vendor)" 1767 local vendor="$(java-pkg_get-vm-vendor)"
1630 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge 1 5; then 1768 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1631 addpredict "/dev/random" 1769 addpredict "/dev/random"
1632 elif [[ "${vendor}" == "ibm" ]]; then 1770 elif [[ "${vendor}" == "ibm" ]]; then
1633 addpredict "/proc/self/maps" 1771 addpredict "/proc/self/maps"
1634 addpredict "/proc/cpuinfo" 1772 addpredict "/proc/cpuinfo"
1635 export LANG="C" LC_ALL="C" 1773 export LANG="C" LC_ALL="C"
1684# @return - The version of the current VM 1822# @return - The version of the current VM
1685# ------------------------------------------------------------------------------ 1823# ------------------------------------------------------------------------------
1686java-pkg_get-vm-version() { 1824java-pkg_get-vm-version() {
1687 debug-print-function ${FUNCNAME} $* 1825 debug-print-function ${FUNCNAME} $*
1688 1826
1689 java-pkg_get-current-vm | sed -e "s/.*-\([0-9.]\+\).*/\1/" 1827 java-config -g PROVIDES_VERSION
1690} 1828}
1691 1829
1692# ------------------------------------------------------------------------------ 1830# ------------------------------------------------------------------------------
1693# @internal-function java-pkg_switch-vm 1831# @internal-function java-pkg_switch-vm
1694# 1832#
1695# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 1833# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1696# verify that the current VM is sufficient. 1834# verify that the current VM is sufficient.
1697# Setup the environment for the VM being used. 1835# Setup the environment for the VM being used.
1698# ------------------------------------------------------------------------------ 1836# ------------------------------------------------------------------------------
1699java-pkg_switch-vm() { 1837java-pkg_switch-vm() {
1700 if java-pkg_needs-vm; then 1838 if java-pkg_needs-vm; then
1704 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 1842 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1705 # if we're allowed to switch the vm... 1843 # if we're allowed to switch the vm...
1706 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 1844 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1707 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 1845 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1708 if [[ -n ${JAVA_PKG_VNEED} ]]; then 1846 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1709 export GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1847 GENTOO_VM="$(depend-java-query --need-virtual "${JAVA_PKG_VNEED}" --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1710 else 1848 else
1711 export GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")" 1849 GENTOO_VM="$(depend-java-query --get-vm "${JAVA_PKG_NV_DEPEND:-${DEPEND}}")"
1850 fi
1851 if [[ -z "${GENTOO_VM}" || "${GENTOO_VM}" == "None" ]]; then
1852 eerror "Unable to determine VM for building from dependencies:"
1853 echo "NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}}"
1854 echo "VNEED: ${JAVA_PKG_VNEED}"
1855 die "Failed to determine VM for building."
1856 else
1857 export GENTOO_VM
1712 fi 1858 fi
1713 # otherwise just make sure the current VM is sufficient 1859 # otherwise just make sure the current VM is sufficient
1714 else 1860 else
1715 java-pkg_ensure-vm-version-sufficient 1861 java-pkg_ensure-vm-version-sufficient
1716 fi 1862 fi
1717 debug-print "Using: $(java-config -f)" 1863 debug-print "Using: $(java-config -f)"
1718 1864
1719 java-pkg_setup-vm 1865 java-pkg_setup-vm
1720 1866
1721 export JAVA=$(java-config --java) 1867 export JAVA=$(java-config --java)
1722 export JAVAC=$(java-config --javac) 1868 export JAVAC=$(java-config --javac)
1723 export JAVACFLAGS="$(java-pkg_javac-args)" 1869 JAVACFLAGS="$(java-pkg_javac-args)"
1870 if [[ ${?} != 0 ]]; then
1871 eerror "There was a problem determining JAVACFLAGS: ${JAVACFLAGS}"
1872 die "java-pkg_javac-args failed"
1873 fi
1724 [[ -n ${JAVACFLAGS_EXTRA} ]] && export JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}" 1874 [[ -n ${JAVACFLAGS_EXTRA} ]] && JAVACFLAGS="${JAVACFLAGS_EXTRA} ${JAVACFLAGS}"
1875 export JAVACFLAGS
1725 1876
1726 export JAVA_HOME="$(java-config -g JAVA_HOME)" 1877 export JAVA_HOME="$(java-config -g JAVA_HOME)"
1727 export JDK_HOME=${JAVA_HOME} 1878 export JDK_HOME=${JAVA_HOME}
1728 1879
1729 #TODO If you know a better solution let us know. 1880 #TODO If you know a better solution let us know.
1730 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 1881 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1731 1882
1732 local tann="${T}/announced-vm" 1883 local tann="${T}/announced-vm"
1733 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 1884 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1734 # Add a check for setup/preinst phase... to avoid duplicate outputs 1885 # Add a check for setup/preinst phase... to avoid duplicate outputs
1735 # for when FEATURES=buildpkg 1886 # for when FEATURES=buildpkg
1736 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]]; 1887 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1780# TODO document 1931# TODO document
1781# Verify that the classes were compiled for the right source / target 1932# Verify that the classes were compiled for the right source / target
1782java-pkg_verify-classes() { 1933java-pkg_verify-classes() {
1783 ebegin "Verifying java class versions" 1934 ebegin "Verifying java class versions"
1784 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1785 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D}
1786 result=$? 1937 result=$?
1787 eend ${result} 1938 eend ${result}
1788 if [[ ${result} == 0 ]]; then 1939 if [[ ${result} == 0 ]]; then
1789 einfo "All good" 1940 einfo "All good"
1790 else 1941 else
1791 ewarn "Possible problem" 1942 ewarn "Possible problem"
1792 die "Bad class files found" 1943 die "Bad class files found"
1793 fi 1944 fi
1794} 1945}
1795 1946
1796
1797# ------------------------------------------------------------------------------ 1947# ------------------------------------------------------------------------------
1798# @section-end internal 1948# @section-end internal
1799# ------------------------------------------------------------------------------ 1949# ------------------------------------------------------------------------------
1800 1950
1801java-pkg_check-phase() { 1951java-pkg_check-phase() {
1832 let "JAVA_PKG_QA_VIOLATIONS+=1" 1982 let "JAVA_PKG_QA_VIOLATIONS+=1"
1833 export JAVA_PKG_QA_VIOLATIONS 1983 export JAVA_PKG_QA_VIOLATIONS
1834} 1984}
1835 1985
1836is-java-strict() { 1986is-java-strict() {
1837 hasq java-strict ${FEATURES}; 1987 [[ -n ${JAVA_PKG_STRICT} ]]
1838 return $? 1988 return $?
1839} 1989}
1840 1990
1841# ------------------------------------------------------------------------------ 1991# ------------------------------------------------------------------------------
1842# @eclass-end 1992# @eclass-end

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

  ViewVC Help
Powered by ViewVC 1.1.20