/[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.55 Revision 1.107
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.55 2007/01/30 12:50:25 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.107 2008/05/03 21:28:45 betelgeuse Exp $
10
11 10
12# ----------------------------------------------------------------------------- 11# -----------------------------------------------------------------------------
13# @eclass-begin 12# @eclass-begin
14# @eclass-shortdesc Java Utility eclass 13# @eclass-shortdesc Java Utility eclass
15# @eclass-maintainer java@gentoo.org 14# @eclass-maintainer java@gentoo.org
55# 54#
56# @seealso JAVA_PKG_FORCE_ANT_TASKS 55# @seealso JAVA_PKG_FORCE_ANT_TASKS
57# ----------------------------------------------------------------------------- 56# -----------------------------------------------------------------------------
58#WANT_ANT_TASKS 57#WANT_ANT_TASKS
59 58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP 60# @variable-internal JAVA_PKG_PORTAGE_DEP
61# 61#
62# The version of portage we need to function properly. At this moment it's 62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support. 63# portage with phase hooks support but now we use a version with proper env
64# saving.
64# ----------------------------------------------------------------------------- 65# -----------------------------------------------------------------------------
65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
66 67
67# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
68# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
69# 70#
70# This is a convience variable to be used from the other java eclasses. This is 71# This is a convience variable to be used from the other java eclasses. This is
71# the version of java-config we want to use. We also need a recent version 72# the version of java-config we want to use. Usually the latest stable version
72# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
73# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 75JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
76hasq source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
75 77
76# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
78# @variable-default yes 80# @variable-default yes
79# 81#
183# 185#
184# These are used to install Java-related things, such as jars, Javadocs, JNI 186# These are used to install Java-related things, such as jars, Javadocs, JNI
185# libraries, etc. 187# libraries, etc.
186# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
187 189
190# -----------------------------------------------------------------------------
191# @ebuild-function java-pkg_doexamples
192#
193# Installs given arguments to /usr/share/doc/${PF}/examples
194# If you give it only one parameter and it is a directory it will install
195# everything in that directory to the examples directory.
196#
197# @example
198# java-pkg_doexamples demo
199# java-pkg_doexamples demo/* examples/*
200#
201# @param --subdir - If the examples need a certain directory structure
202# @param $* - list of files to install
203# ------------------------------------------------------------------------------
204java-pkg_doexamples() {
205 debug-print-function ${FUNCNAME} $*
206
207 [[ ${#} -lt 1 ]] && die "At least one argument needed"
208
209 java-pkg_check-phase install
210
211 local dest=/usr/share/doc/${PF}/examples
212 if [[ ${1} == --subdir ]]; then
213 local dest=${dest}/${2}
214 dodir ${dest}
215 shift 2
216 fi
217
218 if [[ ${#} = 1 && -d ${1} ]]; then
219 ( # dont want to pollute calling env
220 insinto "${dest}"
221 doins -r ${1}/*
222 ) || die "Installing examples failed"
223 else
224 ( # dont want to pollute calling env
225 insinto "${dest}"
226 doins -r "$@"
227 ) || die "Installing examples failed"
228 fi
229}
188 230
189# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
190# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
191# 233#
192# Installs any number of jars. 234# Installs any number of jars.
249 done 291 done
250 292
251 java-pkg_do_write_ 293 java-pkg_do_write_
252} 294}
253 295
254
255# ------------------------------------------------------------------------------ 296# ------------------------------------------------------------------------------
256# @internal-function depend-java-query 297# @internal-function depend-java-query
257# 298#
258# Wrapper for the depend-java-query binary to enable passing USE in env. 299# Wrapper for the depend-java-query binary to enable passing USE in env.
259# Using env variables keeps this eclass working with java-config versions that 300# Using env variables keeps this eclass working with java-config versions that
260# do not handle use flags. 301# do not handle use flags.
261# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
262 303
263depend-java-query() { 304depend-java-query() {
305 # Used to have a which call here but it caused endless loops for some people
306 # that had some weird bashrc voodoo for which.
264 USE="${USE}" $(which depend-java-query) "${@}" 307 USE="${USE}" /usr/bin/depend-java-query "${@}"
265} 308}
266 309
267# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
268# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
269# 312#
317 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
318 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
319 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
320 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
321 else 364 else
365 if [[ ${jar} = *\** ]]; then
366 eerror "The argument ${jar} to ${FUNCNAME}"
367 eerror "has * in it. If you want it to glob in"
368 eerror '${D} add ${D} to the argument.'
369 fi
322 die "${jar} does not exist" 370 die "${jar} does not exist"
323 fi 371 fi
324 done 372 done
325 373
326 java-pkg_do_write_ 374 java-pkg_do_write_
403 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
404 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
405 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
406 else 454 else
407 # TODO use dosym 455 # TODO use dosym
456 ln -s "$(readlink "${lib}")" \
408 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 457 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
409 debug-print "${lib} is a symlink, linking accordanly" 458 debug-print "${lib} is a symlink, linking accordanly"
410 fi 459 fi
411 # otherwise die 460 # otherwise die
412 else 461 else
413 die "${lib} does not exist" 462 die "${lib} does not exist"
507# ------------------------------------------------------------------------------ 556# ------------------------------------------------------------------------------
508# @ebuild-function java-pkg_dojavadoc 557# @ebuild-function java-pkg_dojavadoc
509# 558#
510# Installs javadoc documentation. This should be controlled by the doc use flag. 559# Installs javadoc documentation. This should be controlled by the doc use flag.
511# 560#
561# @param $1: optional --symlink creates to symlink like this for html
562# documentation bundles.
512# @param $1: - The javadoc root directory. 563# @param $2: - The javadoc root directory.
513# 564#
514# @example: 565# @example:
515# java-pkg_dojavadoc docs/api 566# java-pkg_dojavadoc docs/api
567# java-pkg_dojavadoc --symlink apidocs docs/api
516# 568#
517# ------------------------------------------------------------------------------ 569# ------------------------------------------------------------------------------
518java-pkg_dojavadoc() { 570java-pkg_dojavadoc() {
571 debug-print-function ${FUNCNAME} $*
572
573 # For html documentation bundles that link to Javadoc
574 local symlink
575 if [[ ${1} = --symlink ]]; then
576 symlink=${2}
577 shift 2
578 fi
579
519 local dir="$1" 580 local dir="$1"
581 local dest=/usr/share/doc/${PF}/html
582
583 # QA checks
520 584
521 java-pkg_check-phase install 585 java-pkg_check-phase install
522 586
523 [[ -z "${dir}" ]] && die "Must specify a directory!" 587 [[ -z "${dir}" ]] && die "Must specify a directory!"
524 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 588 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
589 if [[ ! -e "${dir}/index.html" ]]; then
590 local msg="No index.html in javadoc directory"
591 ewarn "${msg}"
592 is-java-strict && die "${msg}"
593 fi
594
595 if [[ -e ${D}/${dest}/api ]]; then
596 eerror "${dest} already exists. Will not overwrite."
597 die "${dest}"
598 fi
599
600 # Renaming to match our directory layout
525 601
526 local dir_to_install="${dir}" 602 local dir_to_install="${dir}"
527 if [[ "$(basename "${dir}")" != "api" ]]; then 603 if [[ "$(basename "${dir}")" != "api" ]]; then
528 dir_to_install="${T}/api" 604 dir_to_install="${T}/api"
529 # TODO use doins 605 # TODO use doins
530 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 606 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
531 fi 607 fi
532 608
609 # Actual installation
610
533 java-pkg_dohtml -r ${dir_to_install} 611 java-pkg_dohtml -r "${dir_to_install}"
612
613 # Let's make a symlink to the directory we have everything else under
614 dosym ${dest}/api "${JAVA_PKG_SHAREPATH}/api" || die
615
616 if [[ ${symlink} ]]; then
617 debug-print "symlinking ${dest}/{api,${symlink}}"
618 dosym ${dest}/{api,${symlink}} || die
619 fi
534} 620}
535 621
536# ------------------------------------------------------------------------------ 622# ------------------------------------------------------------------------------
537# @ebuild-function java-pkg_dosrc 623# @ebuild-function java-pkg_dosrc
538# 624#
554# FIXME apparently this fails if you give it an empty directories 640# FIXME apparently this fails if you give it an empty directories
555java-pkg_dosrc() { 641java-pkg_dosrc() {
556 debug-print-function ${FUNCNAME} $* 642 debug-print-function ${FUNCNAME} $*
557 643
558 [ ${#} -lt 1 ] && die "At least one argument needed" 644 [ ${#} -lt 1 ] && die "At least one argument needed"
559 if ! hasq source ${IUSE}; then
560 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
561 fi
562 645
563 java-pkg_check-phase install 646 java-pkg_check-phase install
564 647
565 [[ ${#} -lt 1 ]] && die "At least one argument needed" 648 [[ ${#} -lt 1 ]] && die "At least one argument needed"
649
650 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
651 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
652 java-pkg_announce-qa-violation ${msg}
653 fi
566 654
567 java-pkg_init_paths_ 655 java-pkg_init_paths_
568 656
569 local zip_name="${PN}-src.zip" 657 local zip_name="${PN}-src.zip"
570 local zip_path="${T}/${zip_name}" 658 local zip_path="${T}/${zip_name}"
764# Example: get a specific jar from xerces slot 2, and name it diffrently 852# Example: get a specific jar from xerces slot 2, and name it diffrently
765# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 853# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
766# Example: get junit.jar which is needed only for building 854# Example: get junit.jar which is needed only for building
767# java-pkg_jar-from --build-only junit junit.jar 855# java-pkg_jar-from --build-only junit junit.jar
768# 856#
769# @param $opt 857# @param $opt
770# --build-only - makes the jar(s) not added into package.env DEPEND line. 858# --build-only - makes the jar(s) not added into package.env DEPEND line.
771# (assumed automatically when called inside src_test) 859# (assumed automatically when called inside src_test)
772# --with-dependencies - get jars also from requested package's dependencies 860# --with-dependencies - get jars also from requested package's dependencies
773# transitively. 861# transitively.
862# --virtual - Packages passed to this function are to be handled as virtuals
863# and will not have individual jar dependencies recorded.
774# --into $dir - symlink jar(s) into $dir (must exist) instead of . 864# --into $dir - symlink jar(s) into $dir (must exist) instead of .
775# @param $1 - Package to get jars from. 865# @param $1 - Package to get jars from, or comma-separated list of packages in
866# case other parameters are not used.
776# @param $2 - jar from package. If not specified, all jars will be used. 867# @param $2 - jar from package. If not specified, all jars will be used.
777# @param $3 - When a single jar is specified, destination filename of the 868# @param $3 - When a single jar is specified, destination filename of the
778# symlink. Defaults to the name of the jar. 869# symlink. Defaults to the name of the jar.
779# ------------------------------------------------------------------------------ 870# ------------------------------------------------------------------------------
780# TODO could probably be cleaned up a little 871# TODO could probably be cleaned up a little
782 debug-print-function ${FUNCNAME} $* 873 debug-print-function ${FUNCNAME} $*
783 874
784 local build_only="" 875 local build_only=""
785 local destdir="." 876 local destdir="."
786 local deep="" 877 local deep=""
787 878 local virtual=""
879
788 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 880 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
789 881
790 while [[ "${1}" == --* ]]; do 882 while [[ "${1}" == --* ]]; do
791 if [[ "${1}" = "--build-only" ]]; then 883 if [[ "${1}" = "--build-only" ]]; then
792 build_only="true" 884 build_only="build"
793 elif [[ "${1}" = "--with-dependencies" ]]; then 885 elif [[ "${1}" = "--with-dependencies" ]]; then
794 deep="--with-dependencies" 886 deep="--with-dependencies"
887 elif [[ "${1}" = "--virtual" ]]; then
888 virtual="true"
795 elif [[ "${1}" = "--into" ]]; then 889 elif [[ "${1}" = "--into" ]]; then
796 destdir="${2}" 890 destdir="${2}"
797 shift 891 shift
798 else 892 else
799 die "java-pkg_jar-from called with unknown parameter: ${1}" 893 die "java-pkg_jar-from called with unknown parameter: ${1}"
803 897
804 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 898 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
805 899
806 [[ -z ${target_pkg} ]] && die "Must specify a package" 900 [[ -z ${target_pkg} ]] && die "Must specify a package"
807 901
902 if [[ "${EAPI}" == "1" ]]; then
903 target_pkg="${target_pkg//:/-}"
904 fi
905
808 # default destjar to the target jar 906 # default destjar to the target jar
809 [[ -z "${destjar}" ]] && destjar="${target_jar}" 907 [[ -z "${destjar}" ]] && destjar="${target_jar}"
810 908
811 local error_msg="There was a problem getting the classpath for ${target_pkg}." 909 local error_msg="There was a problem getting the classpath for ${target_pkg}."
812 local classpath 910 local classpath
813 classpath="$(java-config ${deep} --classpath=${target_pkg})" 911 classpath="$(java-config ${deep} --classpath=${target_pkg})"
814 [[ $? != 0 ]] && die ${error_msg} 912 [[ $? != 0 ]] && die ${error_msg}
815 913
914 # When we have commas this functions is called to bring jars from multiple
915 # packages. This affects recording of dependencencies performed later
916 # which expects one package only, so we do it here.
917 if [[ ${target_pkg} = *,* ]]; then
918 for pkg in ${target_pkg//,/ }; do
919 java-pkg_ensure-dep "${build_only}" "${pkg}"
920 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
921 done
922 # setting this disables further record-jar_ calls later
923 build_only="build"
924 else
925 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
926 fi
927
928 # Record the entire virtual as a dependency so that
929 # no jars are missed.
930 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
931 java-pkg_record-jar_ "${target_pkg}"
932 # setting this disables further record-jars_ calls later
933 build_only="build"
934 fi
935
816 pushd ${destdir} > /dev/null \ 936 pushd ${destdir} > /dev/null \
817 || die "failed to change directory to ${destdir}" 937 || die "failed to change directory to ${destdir}"
938
818 local jar 939 local jar
819 for jar in ${classpath//:/ }; do 940 for jar in ${classpath//:/ }; do
820 local jar_name=$(basename "${jar}") 941 local jar_name=$(basename "${jar}")
821 if [[ ! -f "${jar}" ]] ; then 942 if [[ ! -f "${jar}" ]] ; then
822 debug-print "${jar} from ${target_pkg} does not exist" 943 debug-print "${jar} from ${target_pkg} does not exist"
870# Example: Get the classpath for xerces-2 and xalan, 991# Example: Get the classpath for xerces-2 and xalan,
871# java-pkg_getjars xerces-2,xalan 992# java-pkg_getjars xerces-2,xalan
872# Example Return: 993# Example Return:
873# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 994# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
874# 995#
875# @param $opt 996# @param $opt
876# --build-only - makes the jar(s) not added into package.env DEPEND line. 997# --build-only - makes the jar(s) not added into package.env DEPEND line.
877# (assumed automatically when called inside src_test) 998# (assumed automatically when called inside src_test)
878# --with-dependencies - get jars also from requested package's dependencies 999# --with-dependencies - get jars also from requested package's dependencies
879# transitively. 1000# transitively.
880# @param $1 - list of packages to get jars from 1001# @param $1 - list of packages to get jars from
883java-pkg_getjars() { 1004java-pkg_getjars() {
884 debug-print-function ${FUNCNAME} $* 1005 debug-print-function ${FUNCNAME} $*
885 1006
886 local build_only="" 1007 local build_only=""
887 local deep="" 1008 local deep=""
888 1009
889 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 1010 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
890 1011
891 while [[ "${1}" == --* ]]; do 1012 while [[ "${1}" == --* ]]; do
892 if [[ "${1}" = "--build-only" ]]; then 1013 if [[ "${1}" = "--build-only" ]]; then
893 build_only="true" 1014 build_only="build"
894 elif [[ "${1}" = "--with-dependencies" ]]; then 1015 elif [[ "${1}" = "--with-dependencies" ]]; then
895 deep="--with-dependencies" 1016 deep="--with-dependencies"
896 else 1017 else
897 die "java-pkg_jar-from called with unknown parameter: ${1}" 1018 die "java-pkg_jar-from called with unknown parameter: ${1}"
898 fi 1019 fi
899 shift 1020 shift
900 done 1021 done
901 1022
902 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*" 1023 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
903 1024
1025
904 local classpath pkgs="${1}" 1026 local pkgs="${1}"
1027
1028 if [[ "${EAPI}" == "1" ]]; then
1029 pkgs="${pkgs//:/-}"
1030 fi
1031
905 jars="$(java-config ${deep} --classpath=${pkgs})" 1032 jars="$(java-config ${deep} --classpath=${pkgs})"
906 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1033 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
907 debug-print "${pkgs}:${jars}" 1034 debug-print "${pkgs}:${jars}"
908 1035
909 if [[ -z "${classpath}" ]]; then 1036 for pkg in ${pkgs//,/ }; do
910 classpath="${jars}" 1037 java-pkg_ensure-dep "${build_only}" "${pkg}"
911 else 1038 done
912 classpath="${classpath}:${jars}"
913 fi
914 1039
915 # Only record jars that aren't build-only 1040 # Only record jars that aren't build-only
916 if [[ -z "${build_only}" ]]; then 1041 if [[ -z "${build_only}" ]]; then
917 oldifs="${IFS}"
918 IFS=","
919 for pkg in ${pkgs}; do 1042 for pkg in ${pkgs//,/ }; do
920 java-pkg_record-jar_ "${pkg}" 1043 java-pkg_record-jar_ "${pkg}"
921 done 1044 done
922 IFS="${oldifs}"
923 fi 1045 fi
924 1046
925 echo "${classpath}" 1047 echo "${jars}"
926} 1048}
927 1049
928# ------------------------------------------------------------------------------ 1050# ------------------------------------------------------------------------------
929# @ebuild-function java-pkg_getjar 1051# @ebuild-function java-pkg_getjar
930# 1052#
939# @example-return 1061# @example-return
940# /usr/share/xerces-2/lib/xml-apis.jar 1062# /usr/share/xerces-2/lib/xml-apis.jar
941# 1063#
942# @param $opt 1064# @param $opt
943# --build-only - makes the jar not added into package.env DEPEND line. 1065# --build-only - makes the jar not added into package.env DEPEND line.
1066# --virtual - Packages passed to this function are to be handled as virtuals
1067# and will not have individual jar dependencies recorded.
944# @param $1 - package to use 1068# @param $1 - package to use
945# @param $2 - jar to get 1069# @param $2 - jar to get
946# ------------------------------------------------------------------------------ 1070# ------------------------------------------------------------------------------
947java-pkg_getjar() { 1071java-pkg_getjar() {
948 debug-print-function ${FUNCNAME} $* 1072 debug-print-function ${FUNCNAME} $*
949 1073
950 local build_only="" 1074 local build_only=""
951 1075 local virtual=""
1076
952 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="true" 1077 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
953 1078
954 while [[ "${1}" == --* ]]; do 1079 while [[ "${1}" == --* ]]; do
955 if [[ "${1}" = "--build-only" ]]; then 1080 if [[ "${1}" = "--build-only" ]]; then
956 build_only="true" 1081 build_only="build"
1082 elif [[ "${1}" == "--virtual" ]]; then
1083 virtual="true"
957 else 1084 else
958 die "java-pkg_jar-from called with unknown parameter: ${1}" 1085 die "java-pkg_getjar called with unknown parameter: ${1}"
959 fi 1086 fi
960 shift 1087 shift
961 done 1088 done
962 1089
963 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*" 1090 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
964 1091
965 local pkg="${1}" target_jar="${2}" jar 1092 local pkg="${1}" target_jar="${2}" jar
1093
1094 if [[ "${EAPI}" == "1" ]]; then
1095 pkg="${pkg//:/-}"
1096 fi
1097
966 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1098 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
967 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1099 [[ -z ${target_jar} ]] && die "Must specify jar to get"
968 1100
969 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1101 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
970 local classpath 1102 local classpath
971 classpath=$(java-config --classpath=${pkg}) 1103 classpath=$(java-config --classpath=${pkg})
972 [[ $? != 0 ]] && die ${error_msg} 1104 [[ $? != 0 ]] && die ${error_msg}
1105
1106 java-pkg_ensure-dep "${build_only}" "${pkg}"
1107
1108 # Record the package(Virtual) as a dependency and then set build_only
1109 # So that individual jars are not recorded.
1110 if [[ -n "${virtual}" ]]; then
1111 java-pkg_record-jar_ "${pkg}"
1112 build_only="true"
1113 fi
973 1114
974 for jar in ${classpath//:/ }; do 1115 for jar in ${classpath//:/ }; do
975 if [[ ! -f "${jar}" ]] ; then 1116 if [[ ! -f "${jar}" ]] ; then
976 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1117 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
977 fi 1118 fi
984 fi 1125 fi
985 done 1126 done
986 1127
987 die "Could not find ${target_jar} in ${pkg}" 1128 die "Could not find ${target_jar} in ${pkg}"
988 return 1 1129 return 1
1130}
1131
1132# ------------------------------------------------------------------------------
1133# @ebuild-function java-pkg_register-dependency
1134#
1135# Registers runtime dependency on a package, list of packages, or a single jar
1136# from a package, into package.env DEPEND line. Can only be called in
1137# src_install phase.
1138# Intended for binary packages where you don't need to symlink the jars or get
1139# their classpath during build. As such, the dependencies only need to be
1140# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1141#
1142# @param $1 - comma-separated list of packages, or a single package
1143# @param $2 - if param $1 is a single package, optionally specify the jar
1144# to depend on
1145#
1146# Example: Record the dependency on whole xerces-2 and xalan,
1147# java-pkg_register-dependency xerces-2,xalan
1148# Example: Record the dependency on ant.jar from ant-core
1149# java-pkg_register-dependency ant-core ant.jar
1150#
1151# Note: Passing both list of packages as the first parameter AND specifying the
1152# jar as the second is not allowed and will cause the function to die. We assume
1153# that there's more chance one passes such combination as a mistake, than that
1154# there are more packages providing identically named jar without class
1155# collisions.
1156# ------------------------------------------------------------------------------
1157java-pkg_register-dependency() {
1158 debug-print-function ${FUNCNAME} $*
1159
1160 java-pkg_check-phase install
1161
1162 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1163
1164 local pkgs="${1}"
1165 local jar="${2}"
1166
1167 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1168
1169 if [[ "${EAPI}" == "1" ]]; then
1170 pkgs="${pkgs//:/-}"
1171 fi
1172
1173 if [[ -z "${jar}" ]]; then
1174 for pkg in ${pkgs//,/ }; do
1175 java-pkg_ensure-dep runtime "${pkg}"
1176 java-pkg_record-jar_ "${pkg}"
1177 done
1178 else
1179 [[ ${pkgs} == *,* ]] && \
1180 die "${FUNCNAME} called with both package list and jar name"
1181 java-pkg_ensure-dep runtime "${pkgs}"
1182 java-pkg_record-jar_ "${pkgs}" "${jar}"
1183 fi
1184
1185 java-pkg_do_write_
1186}
1187
1188# ------------------------------------------------------------------------------
1189# @ebuild-function java-pkg_register-optional-dependency
1190#
1191# Registers optional runtime dependency on a package, list of packages, or a
1192# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1193# called in src_install phase.
1194# Intended for packages that can use other packages when those are in classpath.
1195# Will be put on classpath by launcher if they are installed. Typical case is
1196# JDBC implementations for various databases. It's better than having USE flag
1197# for each implementation triggering hard dependency.
1198#
1199# @param $1 - comma-separated list of packages, or a single package
1200# @param $2 - if param $1 is a single package, optionally specify the jar
1201# to depend on
1202#
1203# Example: Record the optional dependency on some jdbc providers
1204# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1205#
1206# Note: Passing both list of packages as the first parameter AND specifying the
1207# jar as the second is not allowed and will cause the function to die. We assume
1208# that there's more chance one passes such combination as a mistake, than that
1209# there are more packages providing identically named jar without class
1210# collisions.
1211# ------------------------------------------------------------------------------
1212java-pkg_register-optional-dependency() {
1213 debug-print-function ${FUNCNAME} $*
1214
1215 java-pkg_check-phase install
1216
1217 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1218
1219 local pkgs="${1}"
1220 local jar="${2}"
1221
1222 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1223
1224 if [[ "${EAPI}" == "1" ]]; then
1225 pkgs="${pkgs//:/-}"
1226 fi
1227
1228 if [[ -z "${jar}" ]]; then
1229 for pkg in ${pkgs//,/ }; do
1230 java-pkg_record-jar_ --optional "${pkg}"
1231 done
1232 else
1233 [[ ${pkgs} == *,* ]] && \
1234 die "${FUNCNAME} called with both package list and jar name"
1235 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1236 fi
1237
1238 java-pkg_do_write_
1239}
1240
1241# ------------------------------------------------------------------------------
1242# @ebuild-function java-pkg_register-environment-variable
1243#
1244# Register an arbitrary environment variable into package.env. The gjl launcher
1245# for this package or any package depending on this will export it into
1246# environement before executing java command.
1247# Must only be called in src_install phase.
1248#
1249# @param $1 - variable name
1250# @param $2 - variable value
1251# ------------------------------------------------------------------------------
1252JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1253JAVA_PKG_EXTRA_ENV_VARS=""
1254java-pkg_register-environment-variable() {
1255 debug-print-function ${FUNCNAME} $*
1256
1257 java-pkg_check-phase install
1258
1259 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1260
1261 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1262 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1263
1264 java-pkg_do_write_
989} 1265}
990 1266
991# This function reads stdin, and based on that input, figures out how to 1267# This function reads stdin, and based on that input, figures out how to
992# populate jars from the filesystem. 1268# populate jars from the filesystem.
993# Need to figure out a good way of making use of this, ie be able to use a 1269# Need to figure out a good way of making use of this, ie be able to use a
1456 dodir /usr/share/ant/${TASKS_DIR} 1732 dodir /usr/share/ant/${TASKS_DIR}
1457 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}" 1733 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1458} 1734}
1459 1735
1460# ------------------------------------------------------------------------------ 1736# ------------------------------------------------------------------------------
1461# @internal-function java-pkg_ant-tasks-from-deps
1462#
1463# Function to determine ANT_TASKS from DEPEND variable for backwards
1464# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1465# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1466# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1467# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1468# be a problem, the worst it can do is activace all tasks when not needed.
1469# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1470# insufficient dependencies, otherwise all available tasks are used for
1471# backwards compatilbility.
1472#
1473# @return "all" or "none"
1474# ------------------------------------------------------------------------------
1475java-pkg_ant-tasks-from-deps() {
1476 local found_ant found_ant_tasks
1477
1478 for dep in ${DEPEND}
1479 do
1480 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1481 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1482 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1483 done
1484
1485 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1486 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1487 echo "all"
1488 else
1489 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1490 # so we deactivate all tasks that may be installed
1491 echo "none"
1492 fi
1493}
1494
1495# ------------------------------------------------------------------------------
1496# @internal-function java-pkg_ant-tasks-depend 1737# @internal-function java-pkg_ant-tasks-depend
1497# 1738#
1498# Translates the WANT_ANT_TASKS variable into valid dependencies. 1739# Translates the WANT_ANT_TASKS variable into valid dependencies.
1499# ------------------------------------------------------------------------------ 1740# ------------------------------------------------------------------------------
1500java-pkg_ant-tasks-depend() { 1741java-pkg_ant-tasks-depend() {
1516 return 0 1757 return 0
1517 fi 1758 fi
1518} 1759}
1519 1760
1520# ------------------------------------------------------------------------------ 1761# ------------------------------------------------------------------------------
1762# @ebuild-function ejunit
1763#
1764# Junit wrapper function. Makes it easier to run the tests and checks for
1765# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1766#
1767# Examples:
1768# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1769# ejunit org.blinkenlights.jid3.test.AllTests
1770#
1771# @param $1 - -cp or -classpath
1772# @param $2 - classpath; junit and recorded dependencies get appended
1773# @param $@ - the rest of the parameters are passed to java
1774# ------------------------------------------------------------------------------
1775ejunit() {
1776 debug-print-function ${FUNCNAME} $*
1777
1778 local pkgs
1779 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1780 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1781 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1782 done
1783 fi
1784
1785 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1786 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1787 cp="${2}:${cp}"
1788 shift 2
1789 else
1790 cp=".:${cp}"
1791 fi
1792
1793 local runner=junit.textui.TestRunner
1794 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1795 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1796}
1797
1798# ------------------------------------------------------------------------------
1521# @section-end helper 1799# @section-end helper
1522# ------------------------------------------------------------------------------ 1800# ------------------------------------------------------------------------------
1523 1801
1524# ------------------------------------------------------------------------------ 1802# ------------------------------------------------------------------------------
1525# @section-begin build 1803# @section-begin build
1536# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS, 1814# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1537# variables: 1815# variables:
1538# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the 1816# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1539# gentoo.classpath property. Be sure to call 1817# gentoo.classpath property. Be sure to call
1540# java-ant_rewrite-classpath in src_unpack. 1818# java-ant_rewrite-classpath in src_unpack.
1819# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1541# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. 1820# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1542# ------------------------------------------------------------------------------ 1821# ------------------------------------------------------------------------------
1543eant() { 1822eant() {
1544 debug-print-function ${FUNCNAME} $* 1823 debug-print-function ${FUNCNAME} $*
1545 1824
1546 # FIXME get this working 1825 if [[ ${EBUILD_PHASE} = compile ]]; then
1547# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1826 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1548# java-pkg_announce-qa-violation \ 1827 # finally get rid of the hooks without breaking stuff
1549# "Using eant, but not depending on dev-java/ant or dev-java/ant-core" 1828
1829 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1830 && java-ant_ignore-system-classes "${S}/build.xml"
1831
1832 if hasq java-ant-2 ${INHERITED}; then
1833 java-ant_bsfix
1834 fi
1835
1836 # eant can be called multiple times
1837 JAVA_PKG_BSFIX="off"
1838
1839 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1840 echo "Searching for bundled jars:"
1841 java-pkg_find-normal-jars || echo "None found."
1842 echo "Searching for bundled classes (no output if none found):"
1843 find "${WORKDIR}" -name "*.class"
1844 echo "Search done."
1845 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1846 fi
1550# fi 1847 fi
1551 1848
1552 if ! hasq java-ant-2 ${INHERITED} && is-java-strict; then 1849 if ! hasq java-ant-2 ${INHERITED}; then
1553 local msg="You should inherit java-ant-2 when using eant" 1850 local msg="You should inherit java-ant-2 when using eant"
1554 java-pkg_announce-qa-violation ${msg} 1851 java-pkg_announce-qa-violation "${msg}"
1555 die ${msg}
1556 fi 1852 fi
1557 1853
1558 local antflags="-Dnoget=true -Dmaven.mode.offline=true" 1854 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1855
1559 java-pkg_init-compiler_ 1856 java-pkg_init-compiler_
1560 local compiler="${GENTOO_COMPILER}" 1857 local compiler="${GENTOO_COMPILER}"
1561 1858
1562 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1859 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1563
1564 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1860 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1565 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1861 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1566 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1862 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1567 fi 1863 fi
1568 1864
1574 # java-config -p 1870 # java-config -p
1575 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1871 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1576 if [[ -n ${build_compiler_deps} ]]; then 1872 if [[ -n ${build_compiler_deps} ]]; then
1577 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1873 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1578 fi 1874 fi
1579 fi
1580
1581 if is-java-strict; then
1582 einfo "Disabling system classpath for ant"
1583 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1584 fi 1875 fi
1585 1876
1586 for arg in "${@}"; do 1877 for arg in "${@}"; do
1587 if [[ ${arg} = -lib ]]; then 1878 if [[ ${arg} = -lib ]]; then
1588 if is-java-strict; then 1879 if is-java-strict; then
1597 echo "more info." 1888 echo "more info."
1598 fi 1889 fi
1599 fi 1890 fi
1600 done 1891 done
1601 1892
1602 if has_version ">=dev-java/ant-core-1.7.0"; then
1603 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly 1893 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1604 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}" 1894 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1605 1895
1606 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set 1896 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1607 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}" 1897 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1608 1898
1609 if is-java-strict; then
1610 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1611 if [[ -z "${ANT_TASKS}" ]]; then
1612 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1613 fi
1614 else
1615 # if ant-tasks is not set by ebuild or forced, activate all of them 1899 # if ant-tasks is not set by ebuild or forced, use none
1616 ANT_TASKS="${ANT_TASKS:-all}" 1900 ANT_TASKS="${ANT_TASKS:-none}"
1617 fi
1618 1901
1619 # at this point, ANT_TASKS should be "all", "none" or explicit list 1902 # at this point, ANT_TASKS should be "all", "none" or explicit list
1620 if [[ "${ANT_TASKS}" == "all" ]]; then 1903 if [[ "${ANT_TASKS}" == "all" ]]; then
1621 einfo "Using all available ANT_TASKS" 1904 einfo "Using all available ANT_TASKS"
1622 elif [[ "${ANT_TASKS}" == "none" ]]; then 1905 elif [[ "${ANT_TASKS}" == "none" ]]; then
1623 einfo "Disabling all optional ANT_TASKS" 1906 einfo "Disabling all optional ANT_TASKS"
1624 else 1907 else
1625 einfo "Using following ANT_TASKS: ${ANT_TASKS}" 1908 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1626 fi 1909 fi
1627 1910
1628 export ANT_TASKS 1911 export ANT_TASKS
1629 fi
1630 1912
1631 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug" 1913 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1632 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q" 1914 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1633 1915
1634 local gcp="${EANT_GENTOO_CLASSPATH}" 1916 local gcp="${EANT_GENTOO_CLASSPATH}"
1917 local getjarsarg=""
1635 1918
1919 if [[ ${EBUILD_PHASE} = "test" ]]; then
1920 antflags="${antflags} -DJunit.present=true"
1921 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1922 getjarsarg="--with-dependencies"
1923 fi
1924
1925 local cp
1926
1927 for atom in ${gcp}; do
1928 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1929 done
1930
1636 if [[ "${gcp}" ]]; then 1931 if [[ ${cp} ]]; then
1637 local cp="$(java-pkg_getjars ${gcp})"
1638 # It seems ant does not like single quotes around ${cp} 1932 # It seems ant does not like single quotes around ${cp}
1639 antflags="${antflags} -Dgentoo.classpath=\"${cp}\"" 1933 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1640 fi 1934 fi
1641 1935
1642 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1936 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1643 debug-print "Calling ant: ${antflags} ${@}" 1937 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1644 ant ${antflags} "${@}" || die "eant failed" 1938 ant ${antflags} "${@}" || die "eant failed"
1645
1646} 1939}
1647 1940
1648# ------------------------------------------------------------------------------ 1941# ------------------------------------------------------------------------------
1649# @ebuild-function ejavac 1942# @ebuild-function ejavac
1650# 1943#
1745# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2038# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1746# call it during each of the phases of the merge process. 2039# call it during each of the phases of the merge process.
1747# 2040#
1748# ----------------------------------------------------------------------------- 2041# -----------------------------------------------------------------------------
1749java-pkg_init() { 2042java-pkg_init() {
2043 debug-print-function ${FUNCNAME} $*
1750 unset JAVAC 2044 unset JAVAC
1751 unset JAVA_HOME 2045 unset JAVA_HOME
2046
2047 # People do all kinds of weird things.
2048 # http://forums.gentoo.org/viewtopic-p-3943166.html
2049 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2050 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2051 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2052 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2053 ewarn "sun-jdk vms and and as such break configure scripts that"
2054 ewarn "use it (for example app-office/openoffice) so we filter it out."
2055 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2056 ewarn "make.conf for example) to silence this warning or"
2057 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2058 fi
2059
2060 if [[ -z ${accept} ]]; then
2061 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2062 # -version output
2063 unset _JAVA_OPTIONS
2064 # phase hooks make this run many times without this
2065 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2066 fi
2067
2068 if java-pkg_func-exists ant_src_unpack; then
2069 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2070 fi
2071
1752 java-pkg_init_paths_ 2072 java-pkg_init_paths_
1753 java-pkg_switch-vm 2073 java-pkg_switch-vm
1754 PATH=${JAVA_HOME}/bin:${PATH} 2074 PATH=${JAVA_HOME}/bin:${PATH}
1755 2075
1756 # TODO we will probably want to set JAVAC and JAVACFLAGS 2076 # TODO we will probably want to set JAVAC and JAVACFLAGS
1757 2077
1758 # Do some QA checks 2078 # Do some QA checks
1759 java-pkg_check-jikes 2079 java-pkg_check-jikes
2080
2081 # Can't use unset here because Portage does not save the unset
2082 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1760 2083
1761 # When users have crazy classpaths some packages can fail to compile. 2084 # When users have crazy classpaths some packages can fail to compile.
1762 # and everything should work with empty CLASSPATH. 2085 # and everything should work with empty CLASSPATH.
1763 # This also helps prevent unexpected dependencies on random things 2086 # This also helps prevent unexpected dependencies on random things
1764 # from the CLASSPATH. 2087 # from the CLASSPATH.
1765 unset CLASSPATH 2088 export CLASSPATH=
1766 2089
1767 # Unset external ANT_ stuff 2090 # Unset external ANT_ stuff
1768 unset ANT_TASKS 2091 export ANT_TASKS=
1769 unset ANT_OPTS 2092 export ANT_OPTS=
1770} 2093}
1771 2094
1772# ------------------------------------------------------------------------------ 2095# ------------------------------------------------------------------------------
1773# @function-internal java-pkg-init-compiler_ 2096# @function-internal java-pkg-init-compiler_
1774# 2097#
1865 done 2188 done
1866 2189
1867 # If it hasn't been defined already, default to javac 2190 # If it hasn't been defined already, default to javac
1868 if [[ -z ${GENTOO_COMPILER} ]]; then 2191 if [[ -z ${GENTOO_COMPILER} ]]; then
1869 if [[ -n ${compilers} ]]; then 2192 if [[ -n ${compilers} ]]; then
1870 einfo "No suitable compiler found: defaulting javac for compilation" 2193 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1871 else 2194 else
1872 # probably don't need to notify users about the default. 2195 # probably don't need to notify users about the default.
1873 :;#einfo "Defaulting to javac for compilation" 2196 :;#einfo "Defaulting to javac for compilation"
1874 fi 2197 fi
2198 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2199 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2200 else
1875 export GENTOO_COMPILER=javac 2201 export GENTOO_COMPILER=javac
2202 fi
1876 else 2203 else
1877 einfo "Using ${GENTOO_COMPILER} for compilation" 2204 einfo "Using ${GENTOO_COMPILER} for compilation"
1878 fi 2205 fi
1879 2206
1880} 2207}
1896 fi 2223 fi
1897 2224
1898 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2225 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1899 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2226 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1900 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2227 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2228 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2229 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1901 2230
1902 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2231 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1903 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2232 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1904 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2233 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1905 2234
1918# Writes the package.env out to disk. 2247# Writes the package.env out to disk.
1919# 2248#
1920# ------------------------------------------------------------------------------ 2249# ------------------------------------------------------------------------------
1921# TODO change to do-write, to match everything else 2250# TODO change to do-write, to match everything else
1922java-pkg_do_write_() { 2251java-pkg_do_write_() {
2252 debug-print-function ${FUNCNAME} $*
1923 java-pkg_init_paths_ 2253 java-pkg_init_paths_
1924 # Create directory for package.env 2254 # Create directory for package.env
1925 dodir "${JAVA_PKG_SHAREPATH}" 2255 dodir "${JAVA_PKG_SHAREPATH}"
1926 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2256 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2257 "${JAVA_PKG_DEPEND_FILE}" || -f \
2258 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1927 # Create package.env 2259 # Create package.env
1928 ( 2260 (
1929 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2261 echo "DESCRIPTION=\"${DESCRIPTION}\""
1930 echo "GENERATION=\"2\"" 2262 echo "GENERATION=\"2\""
2263 echo "SLOT=\"${SLOT}\""
1931 2264
1932 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2265 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1933 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2266 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1934 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2267 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1935 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2268 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2269 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2270 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2271 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1936 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2272 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1937 ) > "${JAVA_PKG_ENV}" 2273 ) > "${JAVA_PKG_ENV}"
1938 2274
1939 # register target/source 2275 # register target/source
1940 local target="$(java-pkg_get-target)" 2276 local target="$(java-pkg_get-target)"
1951 2287
1952 2288
1953 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2289 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1954 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2290 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1955 2291
2292 # extra env variables
2293 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2294 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2295 # nested echo to remove leading/trailing spaces
2296 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2297 >> "${JAVA_PKG_ENV}" || die
2298 fi
2299
1956 # Strip unnecessary leading and trailing colons 2300 # Strip unnecessary leading and trailing colons
1957 # TODO try to cleanup if possible 2301 # TODO try to cleanup if possible
1958 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2302 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2303 else
2304 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2305 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2306 debug-print "write package.env."
1959 fi 2307 fi
1960} 2308}
1961 2309
1962# ------------------------------------------------------------------------------ 2310# ------------------------------------------------------------------------------
1963# @internal-function java-pkg_record-jar_ 2311# @internal-function java-pkg_record-jar_
1964# 2312#
1965# Record a dependency to the package.env 2313# Record an (optional) dependency to the package.env
1966# 2314# @param --optional - record dependency as optional
2315# @param $1 - package to record
2316# @param $2 - (optional) jar of package to record
1967# ------------------------------------------------------------------------------ 2317# ------------------------------------------------------------------------------
1968JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2318JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2319JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1969 2320
1970java-pkg_record-jar_() { 2321java-pkg_record-jar_() {
1971 debug-print-function ${FUNCNAME} $* 2322 debug-print-function ${FUNCNAME} $*
2323
2324 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2325 if [[ "${1}" == "--optional" ]]; then
2326 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2327 shift
2328 fi
1972 2329
1973 local pkg=${1} jar=${2} append 2330 local pkg=${1} jar=${2} append
1974 if [[ -z "${jar}" ]]; then 2331 if [[ -z "${jar}" ]]; then
1975 append="${pkg}" 2332 append="${pkg}"
1976 else 2333 else
1977 append="$(basename ${jar})@${pkg}" 2334 append="$(basename ${jar})@${pkg}"
1978 fi 2335 fi
1979 2336
1980 echo ${append} >> ${JAVA_PKG_DEPEND} 2337 echo "${append}" >> "${depend_file}"
1981} 2338}
1982 2339
1983# ------------------------------------------------------------------------------ 2340# ------------------------------------------------------------------------------
1984# @internal-function java-pkg_append_ 2341# @internal-function java-pkg_append_
1985# 2342#
2045# 2402#
2046# ------------------------------------------------------------------------------ 2403# ------------------------------------------------------------------------------
2047java-pkg_setup-vm() { 2404java-pkg_setup-vm() {
2048 debug-print-function ${FUNCNAME} $* 2405 debug-print-function ${FUNCNAME} $*
2049 2406
2407 export LANG="C" LC_ALL="C"
2408
2050 local vendor="$(java-pkg_get-vm-vendor)" 2409 local vendor="$(java-pkg_get-vm-vendor)"
2051 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2410 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
2052 addpredict "/dev/random" 2411 addpredict "/dev/random"
2053 elif [[ "${vendor}" == "ibm" ]]; then 2412 elif [[ "${vendor}" == "ibm" ]]; then
2054 addpredict "/proc/self/maps" 2413 addpredict "/proc/self/maps"
2055 addpredict "/proc/cpuinfo" 2414 addpredict "/proc/cpuinfo"
2056 export LANG="C" LC_ALL="C"
2057 elif [[ "${vendor}" == "jrockit" ]]; then 2415 elif [[ "${vendor}" == "jrockit" ]]; then
2058 addpredict "/proc/cpuinfo" 2416 addpredict "/proc/cpuinfo"
2059 fi 2417 fi
2060} 2418}
2061 2419
2165 2523
2166 #TODO If you know a better solution let us know. 2524 #TODO If you know a better solution let us know.
2167 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2525 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2168 2526
2169 local tann="${T}/announced-vm" 2527 local tann="${T}/announced-vm"
2528 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2529 # if people have for example modified eclasses some where
2170 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2530 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2171 # Add a check for setup/preinst phase... to avoid duplicate outputs
2172 # for when FEATURES=buildpkg
2173 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
2174 then
2175 einfo "Using: $(java-config -f)" 2531 einfo "Using: $(java-config -f)"
2176 [[ ! -f "${tann}" ]] && touch "${tann}" 2532 [[ ! -f "${tann}" ]] && touch "${tann}"
2177 fi
2178 fi 2533 fi
2179 2534
2180 else 2535 else
2181 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2536 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2182 fi 2537 fi
2212 einfo "Classes" 2567 einfo "Classes"
2213 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2568 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2214 fi 2569 fi
2215} 2570}
2216 2571
2217# TODO document 2572# ------------------------------------------------------------------------------
2573# @internal-function java-pkg_verify-classes
2574#
2218# Verify that the classes were compiled for the right source / target 2575# Verify that the classes were compiled for the right source / target. Dies if
2219# If $1 is present will check that file otherwise the ${D} directory 2576# not.
2220# recursively. 2577# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2578# ------------------------------------------------------------------------------
2221java-pkg_verify-classes() { 2579java-pkg_verify-classes() {
2222 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2580 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2223 local target=$(java-pkg_get-target) 2581 local target=$(java-pkg_get-target)
2224 ebegin "Verifying java class versions (target: ${target})" 2582 local result
2583 local log="${T}/class-version-verify.log"
2225 if [[ -n "${1}" ]]; then 2584 if [[ -n "${1}" ]]; then
2226 class-version-verify.py -t ${target} "${1}" 2585 class-version-verify.py -v -t ${target} "${1}" > "${log}"
2586 result=$?
2227 else 2587 else
2588 ebegin "Verifying java class versions (target: ${target})"
2228 class-version-verify.py -t ${target} -r "${D}" 2589 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2229 fi
2230 result=$? 2590 result=$?
2231 eend ${result} 2591 eend ${result}
2592 fi
2593 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2232 if [[ ${result} != 0 ]]; then 2594 if [[ ${result} != 0 ]]; then
2233 ewarn "Possible problem" 2595 eerror "Incorrect bytecode version found"
2234 die "Bad class files found" 2596 [[ -n "${1}" ]] && eerror "in file: ${1}"
2597 eerror "See ${log} for more details."
2598 die "Incorrect bytecode found"
2599 fi
2600}
2601
2602# ----------------------------------------------------------------------------
2603# @internal-function java-pkg_ensure-dep
2604# Check that a package being used in jarfrom, getjars and getjar is contained
2605# within DEPEND or RDEPEND.
2606# @param $1 - empty - check both vars; "runtime" or "build" - check only
2607# RDEPEND, resp. DEPEND
2608# @param $2 - Package name and slot.
2609
2610java-pkg_ensure-dep() {
2611 debug-print-function ${FUNCNAME} $*
2612
2613 local limit_to="${1}"
2614 local target_pkg="${2}"
2615 local dev_error=""
2616
2617 local stripped_pkg=$(echo "${target_pkg}" | sed \
2618 's/-[0-9]*\(\.[0-9]\)*$//')
2619
2620 debug-print "Matching against: ${stripped_pkg}"
2621
2622 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2623 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2624 dev_error="${dev_error} declared in DEPEND."
2625 if is-java-strict; then
2626 eerror "${dev_error}"
2627 die "${dev_error}"
2628 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2629 eerror "${dev_error}"
2630 elog "Because you have this package installed the package will"
2631 elog "build without problems, but please report this to"
2632 elog "http://bugs.gentoo.org"
2633 fi
2634 fi
2635
2636 if [[ ${limit_to} != build ]]; then
2637 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2638 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2639 dev_error="The ebuild is attempting to use ${target_pkg},"
2640 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2641 dev_error="${dev_error} or PDEPEND."
2642 if is-java-strict; then
2643 eerror "${dev_error}"
2644 die "${dev_error}"
2645 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2646 eerror "${dev_error}"
2647 elog "The package will build without problems, but may fail to run"
2648 elog "if you don't have ${target_pkg} installed, so please report"
2649 elog "this to http://bugs.gentoo.org"
2650 fi
2651 fi
2652 fi
2235 fi 2653 fi
2236} 2654}
2237 2655
2238# ------------------------------------------------------------------------------ 2656# ------------------------------------------------------------------------------
2239# @section-end internal 2657# @section-end internal
2240# ------------------------------------------------------------------------------ 2658# ------------------------------------------------------------------------------
2241 2659
2242java-pkg_check-phase() { 2660java-pkg_check-phase() {
2243 local phase=${1} 2661 local phase=${1}
2244 local funcname=${2} 2662 local funcname=${FUNCNAME[1]}
2245 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2663 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2246 java-pkg_announce-qa-violation \
2247 "${funcname} used outside of src_${phase}" 2664 local msg="${funcname} used outside of src_${phase}"
2665 java-pkg_announce-qa-violation "${msg}"
2248 fi 2666 fi
2249} 2667}
2250 2668
2251java-pkg_check-versioned-jar() { 2669java-pkg_check-versioned-jar() {
2252 local jar=${1} 2670 local jar=${1}
2261 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2679 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2262 fi 2680 fi
2263} 2681}
2264 2682
2265java-pkg_announce-qa-violation() { 2683java-pkg_announce-qa-violation() {
2266 if is-java-strict; then 2684 local nodie
2685 if [[ ${1} == "--nodie" ]]; then
2686 nodie="true"
2687 shift
2688 fi
2267 echo "Java QA Notice: $@" >&2 2689 echo "Java QA Notice: $@" >&2
2268 increment-qa-violations 2690 increment-qa-violations
2269 fi 2691 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2270} 2692}
2271 2693
2272increment-qa-violations() { 2694increment-qa-violations() {
2273 let "JAVA_PKG_QA_VIOLATIONS+=1" 2695 let "JAVA_PKG_QA_VIOLATIONS+=1"
2274 export JAVA_PKG_QA_VIOLATIONS 2696 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.107

  ViewVC Help
Powered by ViewVC 1.1.20