/[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.47 Revision 1.113
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.47 2007/01/21 20:31:55 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.113 2008/10/01 15:23:17 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.
211 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
212 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
213 255
214 local jar 256 local jar
215 # for each jar 257 # for each jar
216 for jar in ${@}; do 258 for jar in "${@}"; do
217 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
218 260
219 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
220 262
221 # check if it exists 263 # check if it exists
227 ewarn "Overwriting ${dest}" 269 ewarn "Overwriting ${dest}"
228 fi 270 fi
229 271
230 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
231 if [[ ! -L "${jar}" ]] ; then 273 if [[ ! -L "${jar}" ]] ; then
274 #but first check class version when in strict mode.
275 is-java-strict && java-pkg_verify-classes "${jar}"
276
232 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
233 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
234 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
235 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
236 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
246 done 291 done
247 292
248 java-pkg_do_write_ 293 java-pkg_do_write_
249} 294}
250 295
251
252# ------------------------------------------------------------------------------ 296# ------------------------------------------------------------------------------
253# @internal-function depend-java-query 297# @internal-function depend-java-query
254# 298#
255# 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.
256# 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
257# do not handle use flags. 301# do not handle use flags.
258# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
259 303
260depend-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.
261 USE="${USE}" $(which depend-java-query) "${@}" 307 USE="${USE}" /usr/bin/depend-java-query "${@}"
262} 308}
263 309
264# ------------------------------------------------------------------------------ 310# ------------------------------------------------------------------------------
265# @ebuild-function java-pkg_regjar 311# @ebuild-function java-pkg_regjar
266# 312#
298 [[ ${#} -lt 1 ]] && die "at least one argument needed" 344 [[ ${#} -lt 1 ]] && die "at least one argument needed"
299 345
300 java-pkg_init_paths_ 346 java-pkg_init_paths_
301 347
302 local jar jar_dir jar_file 348 local jar jar_dir jar_file
303 for jar in ${@}; do 349 for jar in "${@}"; do
304 # TODO use java-pkg_check-versioned-jar 350 # TODO use java-pkg_check-versioned-jar
305 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 351 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
306 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 352 [[ -d "${jar}" || -d "${D}${jar}" ]] \
307 && die "Called ${FUNCNAME} on a directory $*" 353 && die "Called ${FUNCNAME} on a directory $*"
354
355 #check that class version correct when in strict mode
356 is-java-strict && java-pkg_verify-classes "${jar}"
357
308 # nelchael: we should strip ${D} in this case too, here's why: 358 # nelchael: we should strip ${D} in this case too, here's why:
309 # imagine such call: 359 # imagine such call:
310 # java-pkg_regjar ${D}/opt/java/*.jar 360 # java-pkg_regjar ${D}/opt/java/*.jar
311 # such call will fall into this case (-e ${jar}) and will 361 # such call will fall into this case (-e ${jar}) and will
312 # record paths with ${D} in package.env 362 # record paths with ${D} in package.env
313 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 363 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
314 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
315 die "${jar} does not exist" 370 die "${jar} does not exist"
316 fi 371 fi
317 done 372 done
318 373
319 java-pkg_do_write_ 374 java-pkg_do_write_
390 if [[ -e "${lib}" ]] ; then 445 if [[ -e "${lib}" ]] ; then
391 # install if it isn't a symlink 446 # install if it isn't a symlink
392 if [[ ! -L "${lib}" ]] ; then 447 if [[ ! -L "${lib}" ]] ; then
393 INSDESTTREE="${JAVA_PKG_LIBDEST}" \ 448 INSDESTTREE="${JAVA_PKG_LIBDEST}" \
394 INSOPTIONS="${LIBOPTIONS}" \ 449 INSOPTIONS="${LIBOPTIONS}" \
395 doins "${lib}" || "failed to install ${lib}" 450 doins "${lib}" || die "failed to install ${lib}"
396 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 451 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
397 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 452 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
398 # otherwise make a symlink to the symlink's origin 453 # otherwise make a symlink to the symlink's origin
399 else 454 else
400 # TODO use dosym 455 # TODO use dosym
456 ln -s "$(readlink "${lib}")" \
401 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 457 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
402 debug-print "${lib} is a symlink, linking accordanly" 458 debug-print "${lib} is a symlink, linking accordanly"
403 fi 459 fi
404 # otherwise die 460 # otherwise die
405 else 461 else
406 die "${lib} does not exist" 462 die "${lib} does not exist"
500# ------------------------------------------------------------------------------ 556# ------------------------------------------------------------------------------
501# @ebuild-function java-pkg_dojavadoc 557# @ebuild-function java-pkg_dojavadoc
502# 558#
503# 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.
504# 560#
561# @param $1: optional --symlink creates to symlink like this for html
562# documentation bundles.
505# @param $1: - The javadoc root directory. 563# @param $2: - The javadoc root directory.
506# 564#
507# @example: 565# @example:
508# java-pkg_dojavadoc docs/api 566# java-pkg_dojavadoc docs/api
567# java-pkg_dojavadoc --symlink apidocs docs/api
509# 568#
510# ------------------------------------------------------------------------------ 569# ------------------------------------------------------------------------------
511java-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
512 local dir="$1" 580 local dir="$1"
581 local dest=/usr/share/doc/${PF}/html
582
583 # QA checks
513 584
514 java-pkg_check-phase install 585 java-pkg_check-phase install
515 586
516 [[ -z "${dir}" ]] && die "Must specify a directory!" 587 [[ -z "${dir}" ]] && die "Must specify a directory!"
517 [[ ! -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
518 601
519 local dir_to_install="${dir}" 602 local dir_to_install="${dir}"
520 if [[ "$(basename "${dir}")" != "api" ]]; then 603 if [[ "$(basename "${dir}")" != "api" ]]; then
521 dir_to_install="${T}/api" 604 dir_to_install="${T}/api"
522 # TODO use doins 605 # TODO use doins
523 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 606 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
524 fi 607 fi
525 608
609 # Actual installation
610
526 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
527} 620}
528 621
529# ------------------------------------------------------------------------------ 622# ------------------------------------------------------------------------------
530# @ebuild-function java-pkg_dosrc 623# @ebuild-function java-pkg_dosrc
531# 624#
547# FIXME apparently this fails if you give it an empty directories 640# FIXME apparently this fails if you give it an empty directories
548java-pkg_dosrc() { 641java-pkg_dosrc() {
549 debug-print-function ${FUNCNAME} $* 642 debug-print-function ${FUNCNAME} $*
550 643
551 [ ${#} -lt 1 ] && die "At least one argument needed" 644 [ ${#} -lt 1 ] && die "At least one argument needed"
552 if ! hasq source ${IUSE}; then
553 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
554 fi
555 645
556 java-pkg_check-phase install 646 java-pkg_check-phase install
557 647
558 [[ ${#} -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
559 654
560 java-pkg_init_paths_ 655 java-pkg_init_paths_
561 656
562 local zip_name="${PN}-src.zip" 657 local zip_name="${PN}-src.zip"
563 local zip_path="${T}/${zip_name}" 658 local zip_path="${T}/${zip_name}"
564 local dir 659 local dir
565 for dir in ${@}; do 660 for dir in "${@}"; do
566 local dir_parent=$(dirname "${dir}") 661 local dir_parent=$(dirname "${dir}")
567 local dir_name=$(basename "${dir}") 662 local dir_name=$(basename "${dir}")
568 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 663 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
569 zip -q -r ${zip_path} ${dir_name} -i '*.java' 664 zip -q -r ${zip_path} ${dir_name} -i '*.java'
570 local result=$? 665 local result=$?
757# 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
758# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 853# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
759# Example: get junit.jar which is needed only for building 854# Example: get junit.jar which is needed only for building
760# java-pkg_jar-from --build-only junit junit.jar 855# java-pkg_jar-from --build-only junit junit.jar
761# 856#
762# @param $1 - (optional) "--build-only" makes the jar(s) not added into 857# @param $opt
763# package.env DEPEND line. 858# --build-only - makes the jar(s) not added into package.env DEPEND line.
764# @param $1 - Package to get jars from. 859# (assumed automatically when called inside src_test)
860# --with-dependencies - get jars also from requested package's dependencies
861# transitively.
862# --virtual - Packages passed to this function are to be handled as virtuals
863# and will not have individual jar dependencies recorded.
864# --into $dir - symlink jar(s) into $dir (must exist) instead of .
865# @param $1 - Package to get jars from, or comma-separated list of packages in
866# case other parameters are not used.
765# @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.
766# @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
767# symlink. Defaults to the name of the jar. 869# symlink. Defaults to the name of the jar.
768# ------------------------------------------------------------------------------ 870# ------------------------------------------------------------------------------
769# TODO could probably be cleaned up a little 871# TODO could probably be cleaned up a little
770java-pkg_jar-from() { 872java-pkg_jar-from() {
771 debug-print-function ${FUNCNAME} $* 873 debug-print-function ${FUNCNAME} $*
772 874
773 local build_only="" 875 local build_only=""
876 local destdir="."
877 local deep=""
878 local virtual=""
774 879
880 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
881
882 while [[ "${1}" == --* ]]; do
775 if [[ "${1}" = "--build-only" ]]; then 883 if [[ "${1}" = "--build-only" ]]; then
776 build_only="true" 884 build_only="build"
885 elif [[ "${1}" = "--with-dependencies" ]]; then
886 deep="--with-dependencies"
887 elif [[ "${1}" = "--virtual" ]]; then
888 virtual="true"
889 elif [[ "${1}" = "--into" ]]; then
890 destdir="${2}"
891 shift
892 else
893 die "java-pkg_jar-from called with unknown parameter: ${1}"
894 fi
777 shift 895 shift
778 fi 896 done
779
780 if [[ "${1}" = "--with-dependencies" ]]; then
781 local deep="--with-dependencies"
782 shift
783 fi
784 897
785 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 898 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
786 899
787 [[ -z ${target_pkg} ]] && die "Must specify a package" 900 [[ -z ${target_pkg} ]] && die "Must specify a package"
901
902 if [[ "${EAPI}" == "1" ]]; then
903 target_pkg="${target_pkg//:/-}"
904 fi
788 905
789 # default destjar to the target jar 906 # default destjar to the target jar
790 [[ -z "${destjar}" ]] && destjar="${target_jar}" 907 [[ -z "${destjar}" ]] && destjar="${target_jar}"
791 908
792 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}."
793 local classpath 910 local classpath
794 classpath="$(java-config ${deep} --classpath=${target_pkg})" 911 classpath="$(java-config ${deep} --classpath=${target_pkg})"
795 [[ $? != 0 ]] && die ${error_msg} 912 [[ $? != 0 ]] && die ${error_msg}
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
936 pushd ${destdir} > /dev/null \
937 || die "failed to change directory to ${destdir}"
796 938
797 local jar 939 local jar
798 for jar in ${classpath//:/ }; do 940 for jar in ${classpath//:/ }; do
799 local jar_name=$(basename "${jar}") 941 local jar_name=$(basename "${jar}")
800 if [[ ! -f "${jar}" ]] ; then 942 if [[ ! -f "${jar}" ]] ; then
811 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 953 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
812 [[ -f "${destjar}" ]] && rm "${destjar}" 954 [[ -f "${destjar}" ]] && rm "${destjar}"
813 ln -snf "${jar}" "${destjar}" \ 955 ln -snf "${jar}" "${destjar}" \
814 || die "Failed to make symlink from ${jar} to ${destjar}" 956 || die "Failed to make symlink from ${jar} to ${destjar}"
815 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 957 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
958 popd > /dev/null
816 return 0 959 return 0
817 fi 960 fi
818 done 961 done
962 popd > /dev/null
819 # if no target was specified, we're ok 963 # if no target was specified, we're ok
820 if [[ -z "${target_jar}" ]] ; then 964 if [[ -z "${target_jar}" ]] ; then
821 return 0 965 return 0
822 # otherwise, die bitterly 966 # otherwise, die bitterly
823 else 967 else
847# Example: Get the classpath for xerces-2 and xalan, 991# Example: Get the classpath for xerces-2 and xalan,
848# java-pkg_getjars xerces-2,xalan 992# java-pkg_getjars xerces-2,xalan
849# Example Return: 993# Example Return:
850# /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
851# 995#
852# @param $1 - (optional) "--build-only" makes the jar(s) not added into 996# @param $opt
853# package.env DEPEND line. 997# --build-only - makes the jar(s) not added into package.env DEPEND line.
998# (assumed automatically when called inside src_test)
999# --with-dependencies - get jars also from requested package's dependencies
1000# transitively.
854# @param $2 - list of packages to get jars from 1001# @param $1 - list of packages to get jars from
855# (passed to java-config --classpath) 1002# (passed to java-config --classpath)
856# ------------------------------------------------------------------------------ 1003# ------------------------------------------------------------------------------
857java-pkg_getjars() { 1004java-pkg_getjars() {
858 debug-print-function ${FUNCNAME} $* 1005 debug-print-function ${FUNCNAME} $*
859 1006
1007 local build_only=""
1008 local deep=""
1009
1010 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1011
1012 while [[ "${1}" == --* ]]; do
860 if [[ "${1}" = "--build-only" ]]; then 1013 if [[ "${1}" = "--build-only" ]]; then
861 local build_only="true" 1014 build_only="build"
1015 elif [[ "${1}" = "--with-dependencies" ]]; then
1016 deep="--with-dependencies"
1017 else
1018 die "java-pkg_jar-from called with unknown parameter: ${1}"
1019 fi
862 shift 1020 shift
863 fi 1021 done
864 1022
865 if [[ "${1}" = "--with-dependencies" ]]; then
866 local deep="--with-dependencies"
867 shift
868 fi
869
870 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 1023 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
871 1024
1025
872 local classpath pkgs="${1}" 1026 local pkgs="${1}"
1027
1028 if [[ "${EAPI}" == "1" ]]; then
1029 pkgs="${pkgs//:/-}"
1030 fi
1031
873 jars="$(java-config ${deep} --classpath=${pkgs})" 1032 jars="$(java-config ${deep} --classpath=${pkgs})"
874 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1033 [[ $? != 0 ]] && die "java-config --classpath=${pkgs} failed"
875 debug-print "${pkgs}:${jars}" 1034 debug-print "${pkgs}:${jars}"
876 1035
877 if [[ -z "${classpath}" ]]; then 1036 for pkg in ${pkgs//,/ }; do
878 classpath="${jars}" 1037 java-pkg_ensure-dep "${build_only}" "${pkg}"
879 else 1038 done
880 classpath="${classpath}:${jars}"
881 fi
882 1039
883 # Only record jars that aren't build-only 1040 # Only record jars that aren't build-only
884 if [[ -z "${build_only}" ]]; then 1041 if [[ -z "${build_only}" ]]; then
885 oldifs="${IFS}"
886 IFS=","
887 for pkg in ${pkgs}; do 1042 for pkg in ${pkgs//,/ }; do
888 java-pkg_record-jar_ "${pkg}" 1043 java-pkg_record-jar_ "${pkg}"
889 done 1044 done
890 IFS="${oldifs}"
891 fi 1045 fi
892 1046
893 echo "${classpath}" 1047 echo "${jars}"
894} 1048}
895 1049
896# ------------------------------------------------------------------------------ 1050# ------------------------------------------------------------------------------
897# @ebuild-function java-pkg_getjar 1051# @ebuild-function java-pkg_getjar
898# 1052#
905# @example 1059# @example
906# java-pkg_getjar xerces-2 xml-apis.jar 1060# java-pkg_getjar xerces-2 xml-apis.jar
907# @example-return 1061# @example-return
908# /usr/share/xerces-2/lib/xml-apis.jar 1062# /usr/share/xerces-2/lib/xml-apis.jar
909# 1063#
910# @param $1 - (optional) "--build-only" makes the jar not added into 1064# @param $opt
911# 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.
912# @param $1 - package to use 1068# @param $1 - package to use
913# @param $2 - jar to get 1069# @param $2 - jar to get
914# ------------------------------------------------------------------------------ 1070# ------------------------------------------------------------------------------
915java-pkg_getjar() { 1071java-pkg_getjar() {
916 debug-print-function ${FUNCNAME} $* 1072 debug-print-function ${FUNCNAME} $*
917 1073
918 local build_only="" 1074 local build_only=""
1075 local virtual=""
919 1076
1077 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1078
1079 while [[ "${1}" == --* ]]; do
920 if [[ "${1}" = "--build-only" ]]; then 1080 if [[ "${1}" = "--build-only" ]]; then
921 build_only="true" 1081 build_only="build"
1082 elif [[ "${1}" == "--virtual" ]]; then
1083 virtual="true"
1084 else
1085 die "java-pkg_getjar called with unknown parameter: ${1}"
1086 fi
922 shift 1087 shift
923 fi 1088 done
1089
1090 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
924 1091
925 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
926 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1098 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
927 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1099 [[ -z ${target_jar} ]] && die "Must specify jar to get"
928 1100
929 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?"
930 local classpath 1102 local classpath
931 classpath=$(java-config --classpath=${pkg}) 1103 classpath=$(java-config --classpath=${pkg})
932 [[ $? != 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
933 1114
934 for jar in ${classpath//:/ }; do 1115 for jar in ${classpath//:/ }; do
935 if [[ ! -f "${jar}" ]] ; then 1116 if [[ ! -f "${jar}" ]] ; then
936 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1117 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
937 fi 1118 fi
944 fi 1125 fi
945 done 1126 done
946 1127
947 die "Could not find ${target_jar} in ${pkg}" 1128 die "Could not find ${target_jar} in ${pkg}"
948 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_
949} 1265}
950 1266
951# 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
952# populate jars from the filesystem. 1268# populate jars from the filesystem.
953# 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
1416 dodir /usr/share/ant/${TASKS_DIR} 1732 dodir /usr/share/ant/${TASKS_DIR}
1417 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}" 1733 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1418} 1734}
1419 1735
1420# ------------------------------------------------------------------------------ 1736# ------------------------------------------------------------------------------
1421# @internal-function java-pkg_ant-tasks-from-deps
1422#
1423# Function to determine ANT_TASKS from DEPEND variable for backwards
1424# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1425# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1426# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1427# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1428# be a problem, the worst it can do is activace all tasks when not needed.
1429# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1430# insufficient dependencies, otherwise all available tasks are used for
1431# backwards compatilbility.
1432#
1433# @return "all" or "none"
1434# ------------------------------------------------------------------------------
1435java-pkg_ant-tasks-from-deps() {
1436 local found_ant found_ant_tasks
1437
1438 for dep in ${DEPEND}
1439 do
1440 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1441 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1442 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1443 done
1444
1445 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1446 java-pkg_announce-qa-violation "The ebuild DEPENDS on deprecated ant or ant-tasks"
1447 echo "all"
1448 else
1449 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1450 # so we deactivate all tasks that may be installed
1451 echo "none"
1452 fi
1453}
1454
1455# ------------------------------------------------------------------------------
1456# @internal-function java-pkg_ant-tasks-depend 1737# @internal-function java-pkg_ant-tasks-depend
1457# 1738#
1458# Translates the WANT_ANT_TASKS variable into valid dependencies. 1739# Translates the WANT_ANT_TASKS variable into valid dependencies.
1459# ------------------------------------------------------------------------------ 1740# ------------------------------------------------------------------------------
1460java-pkg_ant-tasks-depend() { 1741java-pkg_ant-tasks-depend() {
1462 1743
1463 if [[ -n "${WANT_ANT_TASKS}" ]]; then 1744 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1464 local DEP="" 1745 local DEP=""
1465 for i in ${WANT_ANT_TASKS} 1746 for i in ${WANT_ANT_TASKS}
1466 do 1747 do
1467 if [[ ${i} != ant-* ]]; then 1748 if [[ ${i} = ant-* ]]; then
1749 DEP="${DEP}dev-java/${i} "
1750 elif [[ ${i} = */*:* ]]; then
1751 DEP="${DEP}${i} "
1752 else
1468 echo "Invalid atom in WANT_ANT_TASKS: ${i}" 1753 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1469 return 1 1754 return 1
1470 fi 1755 fi
1471 DEP="${DEP}dev-java/${i} "
1472 done 1756 done
1473 echo ${DEP} 1757 echo ${DEP}
1474 return 0 1758 return 0
1475 else 1759 else
1476 return 0 1760 return 0
1477 fi 1761 fi
1478} 1762}
1479 1763
1480# ------------------------------------------------------------------------------ 1764# ------------------------------------------------------------------------------
1765# @ebuild-function ejunit
1766#
1767# Junit wrapper function. Makes it easier to run the tests and checks for
1768# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1769#
1770# Examples:
1771# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1772# ejunit org.blinkenlights.jid3.test.AllTests
1773#
1774# @param $1 - -cp or -classpath
1775# @param $2 - classpath; junit and recorded dependencies get appended
1776# @param $@ - the rest of the parameters are passed to java
1777# ------------------------------------------------------------------------------
1778ejunit() {
1779 debug-print-function ${FUNCNAME} $*
1780
1781 local pkgs
1782 if [[ -f ${JAVA_PKG_DEPEND_FILE} ]]; then
1783 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1784 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1785 done
1786 fi
1787
1788 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1789 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1790 cp="${2}:${cp}"
1791 shift 2
1792 else
1793 cp=".:${cp}"
1794 fi
1795
1796 local runner=junit.textui.TestRunner
1797 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1798 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1799}
1800
1801# ------------------------------------------------------------------------------
1481# @section-end helper 1802# @section-end helper
1482# ------------------------------------------------------------------------------ 1803# ------------------------------------------------------------------------------
1804
1805# ------------------------------------------------------------------------------
1806# @eclass-src_prepare
1807#
1808# src_prepare Searches for bundled jars
1809# ------------------------------------------------------------------------------
1810
1811java-utils-2_src_prepare() {
1812 # Remember that eant will call this unless called via Portage
1813 if [[ ! -e "${T}/java-utils-2_src_prepare-run" ]] && is-java-strict; then
1814 echo "Searching for bundled jars:"
1815 java-pkg_find-normal-jars || echo "None found."
1816 echo "Searching for bundled classes (no output if none found):"
1817 find "${WORKDIR}" -name "*.class"
1818 echo "Search done."
1819 fi
1820 touch "${T}/java-utils-2_src_prepare-run"
1821}
1483 1822
1484# ------------------------------------------------------------------------------ 1823# ------------------------------------------------------------------------------
1485# @section-begin build 1824# @section-begin build
1486# @section-summary Build functions 1825# @section-summary Build functions
1487# 1826#
1496# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS, 1835# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1497# variables: 1836# variables:
1498# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the 1837# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1499# gentoo.classpath property. Be sure to call 1838# gentoo.classpath property. Be sure to call
1500# java-ant_rewrite-classpath in src_unpack. 1839# java-ant_rewrite-classpath in src_unpack.
1840# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1501# *ANT_TASKS - used to determine ANT_TASKS before calling Ant. 1841# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1502# ------------------------------------------------------------------------------ 1842# ------------------------------------------------------------------------------
1503eant() { 1843eant() {
1504 debug-print-function ${FUNCNAME} $* 1844 debug-print-function ${FUNCNAME} $*
1505 1845
1506 # FIXME get this working 1846 if [[ ${EBUILD_PHASE} = compile ]]; then
1507# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1847 java-ant-2_src_configure
1848 java-utils-2_src_prepare
1849 fi
1850
1851 if ! hasq java-ant-2 ${INHERITED}; then
1852 local msg="You should inherit java-ant-2 when using eant"
1508# java-pkg_announce-qa-violation \ 1853 java-pkg_announce-qa-violation "${msg}"
1509# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1510# fi 1854 fi
1511 1855
1512 local antflags="-Dnoget=true -Dmaven.mode.offline=true" 1856 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1857
1513 java-pkg_init-compiler_ 1858 java-pkg_init-compiler_
1514 local compiler="${GENTOO_COMPILER}" 1859 local compiler="${GENTOO_COMPILER}"
1515 1860
1516 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1861 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1517
1518 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1862 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1519 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1863 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1520 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1864 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1521 fi 1865 fi
1522 1866
1530 if [[ -n ${build_compiler_deps} ]]; then 1874 if [[ -n ${build_compiler_deps} ]]; then
1531 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1875 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1532 fi 1876 fi
1533 fi 1877 fi
1534 1878
1535 if is-java-strict; then 1879 for arg in "${@}"; do
1536 einfo "Disabling system classpath for ant" 1880 if [[ ${arg} = -lib ]]; then
1537 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1538 fi
1539
1540 if has_version ">=dev-java/ant-core-1.7.0"; then
1541 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1542 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1543
1544 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1545 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1546
1547 if is-java-strict; then 1881 if is-java-strict; then
1548 # if ant-tasks were not set by ebuild or forced, try to determine them from depends 1882 eerror "You should not use the -lib argument to eant because it will fail"
1549 if [[ -z "${ANT_TASKS}" ]]; then 1883 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1550 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)" 1884 eerror "or ant properties to make dependencies available."
1885 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1886 eerror "split ant (>=dev-java/ant-core-1.7)."
1887 die "eant -lib is deprecated/forbidden"
1888 else
1889 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1890 echo "more info."
1551 fi 1891 fi
1892 fi
1893 done
1894
1895 # parse WANT_ANT_TASKS for atoms
1896 local want_ant_tasks
1897 for i in ${WANT_ANT_TASKS}; do
1898 if [[ ${i} = */*:* ]]; then
1899 i=${i#*/}
1900 i=${i%:0}
1901 want_ant_tasks+="${i/:/-} "
1552 else 1902 else
1903 want_ant_tasks+="${i} "
1904 fi
1905 done
1906 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1907 ANT_TASKS="${ANT_TASKS:-${want_ant_tasks% }}"
1908
1909 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1910 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1911
1553 # if ant-tasks is not set by ebuild or forced, activate all of them 1912 # if ant-tasks is not set by ebuild or forced, use none
1554 ANT_TASKS="${ANT_TASKS:-all}" 1913 ANT_TASKS="${ANT_TASKS:-none}"
1555 fi
1556 1914
1557 # at this point, ANT_TASKS should be "all", "none" or explicit list 1915 # at this point, ANT_TASKS should be "all", "none" or explicit list
1558 if [[ "${ANT_TASKS}" == "all" ]]; then 1916 if [[ "${ANT_TASKS}" == "all" ]]; then
1559 einfo "Using all available ANT_TASKS" 1917 einfo "Using all available ANT_TASKS"
1560 elif [[ "${ANT_TASKS}" == "none" ]]; then 1918 elif [[ "${ANT_TASKS}" == "none" ]]; then
1561 einfo "Disabling all optional ANT_TASKS" 1919 einfo "Disabling all optional ANT_TASKS"
1562 else 1920 else
1563 einfo "Using following ANT_TASKS: ${ANT_TASKS}" 1921 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1564 fi 1922 fi
1565 1923
1566 export ANT_TASKS 1924 export ANT_TASKS
1567 fi
1568 1925
1569 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug" 1926 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1570 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q" 1927 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1571 1928
1572 local gcp="${EANT_GENTOO_CLASSPATH}" 1929 local gcp="${EANT_GENTOO_CLASSPATH}"
1930 local getjarsarg=""
1573 1931
1932 if [[ ${EBUILD_PHASE} = "test" ]]; then
1933 antflags="${antflags} -DJunit.present=true"
1934 [[ ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1935 getjarsarg="--with-dependencies"
1936 fi
1937
1938 local cp
1939
1940 for atom in ${gcp}; do
1941 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1942 done
1943
1574 if [[ "${gcp}" ]]; then 1944 if [[ ${cp} ]]; then
1575 local cp="$(java-pkg_getjars ${gcp})"
1576 # It seems ant does not like single quotes around ${cp} 1945 # It seems ant does not like single quotes around ${cp}
1946 cp=${cp#:}
1947 [[ ${EANT_GENTOO_CLASSPATH_EXTRA} ]] && \
1948 cp="${cp}:${EANT_GENTOO_CLASSPATH_EXTRA}"
1577 antflags="${antflags} -Dgentoo.classpath=\"${cp}\"" 1949 antflags="${antflags} -Dgentoo.classpath=\"${cp}\""
1578 fi 1950 fi
1579 1951
1580 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1952 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1581 debug-print "Calling ant: ${antflags} ${@}" 1953 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1582 ant ${antflags} "${@}" || die "eant failed" 1954 ant ${antflags} "${@}" || die "eant failed"
1583
1584} 1955}
1585 1956
1586# ------------------------------------------------------------------------------ 1957# ------------------------------------------------------------------------------
1587# @ebuild-function ejavac 1958# @ebuild-function ejavac
1588# 1959#
1683# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will 2054# This shouldn't be used directly. Instead, java-pkg and java-pkg-opt will
1684# call it during each of the phases of the merge process. 2055# call it during each of the phases of the merge process.
1685# 2056#
1686# ----------------------------------------------------------------------------- 2057# -----------------------------------------------------------------------------
1687java-pkg_init() { 2058java-pkg_init() {
2059 debug-print-function ${FUNCNAME} $*
1688 unset JAVAC 2060 unset JAVAC
1689 unset JAVA_HOME 2061 unset JAVA_HOME
2062
2063 # People do all kinds of weird things.
2064 # http://forums.gentoo.org/viewtopic-p-3943166.html
2065 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2066 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2067 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2068 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2069 ewarn "sun-jdk vms and and as such break configure scripts that"
2070 ewarn "use it (for example app-office/openoffice) so we filter it out."
2071 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2072 ewarn "make.conf for example) to silence this warning or"
2073 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2074 fi
2075
2076 if [[ -z ${accept} ]]; then
2077 # export _JAVA_OPTIONS= doesn't work because it will show up in java
2078 # -version output
2079 unset _JAVA_OPTIONS
2080 # phase hooks make this run many times without this
2081 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2082 fi
2083
2084 if java-pkg_func-exists ant_src_unpack; then
2085 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2086 fi
2087
1690 java-pkg_init_paths_ 2088 java-pkg_init_paths_
1691 java-pkg_switch-vm 2089 java-pkg_switch-vm
1692 PATH=${JAVA_HOME}/bin:${PATH} 2090 PATH=${JAVA_HOME}/bin:${PATH}
1693 2091
1694 # TODO we will probably want to set JAVAC and JAVACFLAGS 2092 # TODO we will probably want to set JAVAC and JAVACFLAGS
1695 2093
1696 # Do some QA checks 2094 # Do some QA checks
1697 java-pkg_check-jikes 2095 java-pkg_check-jikes
2096
2097 # Can't use unset here because Portage does not save the unset
2098 # see https://bugs.gentoo.org/show_bug.cgi?id=189417#c11
1698 2099
1699 # When users have crazy classpaths some packages can fail to compile. 2100 # When users have crazy classpaths some packages can fail to compile.
1700 # and everything should work with empty CLASSPATH. 2101 # and everything should work with empty CLASSPATH.
1701 # This also helps prevent unexpected dependencies on random things 2102 # This also helps prevent unexpected dependencies on random things
1702 # from the CLASSPATH. 2103 # from the CLASSPATH.
1703 unset CLASSPATH 2104 export CLASSPATH=
1704 2105
1705 # Unset external ANT_ stuff 2106 # Unset external ANT_ stuff
1706 unset ANT_TASKS 2107 export ANT_TASKS=
1707 unset ANT_OPTS 2108 export ANT_OPTS=
1708} 2109}
1709 2110
1710# ------------------------------------------------------------------------------ 2111# ------------------------------------------------------------------------------
1711# @function-internal java-pkg-init-compiler_ 2112# @function-internal java-pkg-init-compiler_
1712# 2113#
1803 done 2204 done
1804 2205
1805 # If it hasn't been defined already, default to javac 2206 # If it hasn't been defined already, default to javac
1806 if [[ -z ${GENTOO_COMPILER} ]]; then 2207 if [[ -z ${GENTOO_COMPILER} ]]; then
1807 if [[ -n ${compilers} ]]; then 2208 if [[ -n ${compilers} ]]; then
1808 einfo "No suitable compiler found: defaulting javac for compilation" 2209 einfo "No suitable compiler found: defaulting to JDK default for compilation"
1809 else 2210 else
1810 # probably don't need to notify users about the default. 2211 # probably don't need to notify users about the default.
1811 :;#einfo "Defaulting to javac for compilation" 2212 :;#einfo "Defaulting to javac for compilation"
1812 fi 2213 fi
2214 if java-config -g GENTOO_COMPILER 2> /dev/null; then
2215 export GENTOO_COMPILER=$(java-config -g GENTOO_COMPILER)
2216 else
1813 export GENTOO_COMPILER=javac 2217 export GENTOO_COMPILER=javac
2218 fi
1814 else 2219 else
1815 einfo "Using ${GENTOO_COMPILER} for compilation" 2220 einfo "Using ${GENTOO_COMPILER} for compilation"
1816 fi 2221 fi
1817 2222
1818} 2223}
1834 fi 2239 fi
1835 2240
1836 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2241 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1837 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2242 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1838 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2243 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2244 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2245 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1839 2246
1840 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2247 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1841 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2248 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1842 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2249 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1843 2250
1856# Writes the package.env out to disk. 2263# Writes the package.env out to disk.
1857# 2264#
1858# ------------------------------------------------------------------------------ 2265# ------------------------------------------------------------------------------
1859# TODO change to do-write, to match everything else 2266# TODO change to do-write, to match everything else
1860java-pkg_do_write_() { 2267java-pkg_do_write_() {
2268 debug-print-function ${FUNCNAME} $*
1861 java-pkg_init_paths_ 2269 java-pkg_init_paths_
1862 # Create directory for package.env 2270 # Create directory for package.env
1863 dodir "${JAVA_PKG_SHAREPATH}" 2271 dodir "${JAVA_PKG_SHAREPATH}"
1864 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2272 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2273 "${JAVA_PKG_DEPEND_FILE}" || -f \
2274 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1865 # Create package.env 2275 # Create package.env
1866 ( 2276 (
1867 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2277 echo "DESCRIPTION=\"${DESCRIPTION}\""
1868 echo "GENERATION=\"2\"" 2278 echo "GENERATION=\"2\""
2279 echo "SLOT=\"${SLOT}\""
1869 2280
1870 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2281 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1871 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2282 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1872 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2283 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1873 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2284 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2285 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2286 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2287 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1874 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2288 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1875 ) > "${JAVA_PKG_ENV}" 2289 ) > "${JAVA_PKG_ENV}"
1876 2290
1877 # register target/source 2291 # register target/source
1878 local target="$(java-pkg_get-target)" 2292 local target="$(java-pkg_get-target)"
1889 2303
1890 2304
1891 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2305 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1892 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2306 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1893 2307
2308 # extra env variables
2309 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2310 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2311 # nested echo to remove leading/trailing spaces
2312 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2313 >> "${JAVA_PKG_ENV}" || die
2314 fi
2315
1894 # Strip unnecessary leading and trailing colons 2316 # Strip unnecessary leading and trailing colons
1895 # TODO try to cleanup if possible 2317 # TODO try to cleanup if possible
1896 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2318 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2319 else
2320 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2321 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2322 debug-print "write package.env."
1897 fi 2323 fi
1898} 2324}
1899 2325
1900# ------------------------------------------------------------------------------ 2326# ------------------------------------------------------------------------------
1901# @internal-function java-pkg_record-jar_ 2327# @internal-function java-pkg_record-jar_
1902# 2328#
1903# Record a dependency to the package.env 2329# Record an (optional) dependency to the package.env
1904# 2330# @param --optional - record dependency as optional
2331# @param $1 - package to record
2332# @param $2 - (optional) jar of package to record
1905# ------------------------------------------------------------------------------ 2333# ------------------------------------------------------------------------------
1906JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2334JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2335JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1907 2336
1908java-pkg_record-jar_() { 2337java-pkg_record-jar_() {
1909 debug-print-function ${FUNCNAME} $* 2338 debug-print-function ${FUNCNAME} $*
2339
2340 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2341 if [[ "${1}" == "--optional" ]]; then
2342 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2343 shift
2344 fi
1910 2345
1911 local pkg=${1} jar=${2} append 2346 local pkg=${1} jar=${2} append
1912 if [[ -z "${jar}" ]]; then 2347 if [[ -z "${jar}" ]]; then
1913 append="${pkg}" 2348 append="${pkg}"
1914 else 2349 else
1915 append="$(basename ${jar})@${pkg}" 2350 append="$(basename ${jar})@${pkg}"
1916 fi 2351 fi
1917 2352
1918 echo ${append} >> ${JAVA_PKG_DEPEND} 2353 echo "${append}" >> "${depend_file}"
1919} 2354}
1920 2355
1921# ------------------------------------------------------------------------------ 2356# ------------------------------------------------------------------------------
1922# @internal-function java-pkg_append_ 2357# @internal-function java-pkg_append_
1923# 2358#
1983# 2418#
1984# ------------------------------------------------------------------------------ 2419# ------------------------------------------------------------------------------
1985java-pkg_setup-vm() { 2420java-pkg_setup-vm() {
1986 debug-print-function ${FUNCNAME} $* 2421 debug-print-function ${FUNCNAME} $*
1987 2422
2423 export LANG="C" LC_ALL="C"
2424
1988 local vendor="$(java-pkg_get-vm-vendor)" 2425 local vendor="$(java-pkg_get-vm-vendor)"
1989 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2426 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1990 addpredict "/dev/random" 2427 addpredict "/dev/random"
1991 elif [[ "${vendor}" == "ibm" ]]; then 2428 elif [[ "${vendor}" == "ibm" ]]; then
1992 addpredict "/proc/self/maps" 2429 addpredict "/proc/self/maps"
1993 addpredict "/proc/cpuinfo" 2430 addpredict "/proc/cpuinfo"
1994 export LANG="C" LC_ALL="C"
1995 elif [[ "${vendor}" == "jrockit" ]]; then 2431 elif [[ "${vendor}" == "jrockit" ]]; then
1996 addpredict "/proc/cpuinfo" 2432 addpredict "/proc/cpuinfo"
1997 fi 2433 fi
1998} 2434}
1999 2435
2103 2539
2104 #TODO If you know a better solution let us know. 2540 #TODO If you know a better solution let us know.
2105 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2541 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
2106 2542
2107 local tann="${T}/announced-vm" 2543 local tann="${T}/announced-vm"
2544 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2545 # if people have for example modified eclasses some where
2108 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2546 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
2109 # Add a check for setup/preinst phase... to avoid duplicate outputs
2110 # for when FEATURES=buildpkg
2111 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
2112 then
2113 einfo "Using: $(java-config -f)" 2547 einfo "Using: $(java-config -f)"
2114 [[ ! -f "${tann}" ]] && touch "${tann}" 2548 [[ ! -f "${tann}" ]] && touch "${tann}"
2115 fi
2116 fi 2549 fi
2117 2550
2118 else 2551 else
2119 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2552 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
2120 fi 2553 fi
2150 einfo "Classes" 2583 einfo "Classes"
2151 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2584 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
2152 fi 2585 fi
2153} 2586}
2154 2587
2155# TODO document 2588# ------------------------------------------------------------------------------
2589# @internal-function java-pkg_verify-classes
2590#
2156# Verify that the classes were compiled for the right source / target 2591# Verify that the classes were compiled for the right source / target. Dies if
2592# not.
2593# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2594# ------------------------------------------------------------------------------
2157java-pkg_verify-classes() { 2595java-pkg_verify-classes() {
2158 ebegin "Verifying java class versions"
2159 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2596 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
2160 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2597
2598 local version_verify="/usr/bin/class-version-verify.py"
2599
2600 if [[ ! -x "${version_verify}" ]]; then
2601 version_verify="/usr/$(get_libdir)/javatoolkit/bin/class-version-verify.py"
2602 fi
2603
2604 if [[ ! -x "${version_verify}" ]]; then
2605 ewarn "Unable to perform class version checks as"
2606 ewarn "class-version-verify.py is unavailable"
2607 ewarn "Please install dev-java/javatoolkit."
2608 return
2609 fi
2610
2611 local target=$(java-pkg_get-target)
2612 local result
2613 local log="${T}/class-version-verify.log"
2614 if [[ -n "${1}" ]]; then
2615 ${version_verify} -v -t ${target} "${1}" > "${log}"
2161 result=$? 2616 result=$?
2162 eend ${result}
2163 if [[ ${result} == 0 ]]; then
2164 einfo "All good"
2165 else 2617 else
2166 ewarn "Possible problem" 2618 ebegin "Verifying java class versions (target: ${target})"
2167 die "Bad class files found" 2619 ${version_verify} -v -t ${target} -r "${D}" > "${log}"
2620 result=$?
2621 eend ${result}
2622 fi
2623 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2624 if [[ ${result} != 0 ]]; then
2625 eerror "Incorrect bytecode version found"
2626 [[ -n "${1}" ]] && eerror "in file: ${1}"
2627 eerror "See ${log} for more details."
2628 die "Incorrect bytecode found"
2629 fi
2630}
2631
2632# ----------------------------------------------------------------------------
2633# @internal-function java-pkg_ensure-dep
2634# Check that a package being used in jarfrom, getjars and getjar is contained
2635# within DEPEND or RDEPEND.
2636# @param $1 - empty - check both vars; "runtime" or "build" - check only
2637# RDEPEND, resp. DEPEND
2638# @param $2 - Package name and slot.
2639
2640java-pkg_ensure-dep() {
2641 debug-print-function ${FUNCNAME} $*
2642
2643 local limit_to="${1}"
2644 local target_pkg="${2}"
2645 local dev_error=""
2646
2647 local stripped_pkg=$(echo "${target_pkg}" | sed \
2648 's/-[0-9]*\(\.[0-9]\)*$//')
2649
2650 debug-print "Matching against: ${stripped_pkg}"
2651
2652 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2653 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2654 dev_error="${dev_error} declared in DEPEND."
2655 if is-java-strict; then
2656 eerror "${dev_error}"
2657 die "${dev_error}"
2658 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2659 eerror "${dev_error}"
2660 elog "Because you have this package installed the package will"
2661 elog "build without problems, but please report this to"
2662 elog "http://bugs.gentoo.org"
2663 fi
2664 fi
2665
2666 if [[ ${limit_to} != build ]]; then
2667 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2668 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2669 dev_error="The ebuild is attempting to use ${target_pkg},"
2670 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2671 dev_error="${dev_error} or PDEPEND."
2672 if is-java-strict; then
2673 eerror "${dev_error}"
2674 die "${dev_error}"
2675 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2676 eerror "${dev_error}"
2677 elog "The package will build without problems, but may fail to run"
2678 elog "if you don't have ${target_pkg} installed, so please report"
2679 elog "this to http://bugs.gentoo.org"
2680 fi
2681 fi
2682 fi
2168 fi 2683 fi
2169} 2684}
2170 2685
2171# ------------------------------------------------------------------------------ 2686# ------------------------------------------------------------------------------
2172# @section-end internal 2687# @section-end internal
2173# ------------------------------------------------------------------------------ 2688# ------------------------------------------------------------------------------
2174 2689
2175java-pkg_check-phase() { 2690java-pkg_check-phase() {
2176 local phase=${1} 2691 local phase=${1}
2177 local funcname=${2} 2692 local funcname=${FUNCNAME[1]}
2178 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2693 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
2179 java-pkg_announce-qa-violation \
2180 "${funcname} used outside of src_${phase}" 2694 local msg="${funcname} used outside of src_${phase}"
2695 java-pkg_announce-qa-violation "${msg}"
2181 fi 2696 fi
2182} 2697}
2183 2698
2184java-pkg_check-versioned-jar() { 2699java-pkg_check-versioned-jar() {
2185 local jar=${1} 2700 local jar=${1}
2194 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2709 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
2195 fi 2710 fi
2196} 2711}
2197 2712
2198java-pkg_announce-qa-violation() { 2713java-pkg_announce-qa-violation() {
2199 if is-java-strict; then 2714 local nodie
2715 if [[ ${1} == "--nodie" ]]; then
2716 nodie="true"
2717 shift
2718 fi
2200 echo "Java QA Notice: $@" >&2 2719 echo "Java QA Notice: $@" >&2
2201 increment-qa-violations 2720 increment-qa-violations
2202 fi 2721 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
2203} 2722}
2204 2723
2205increment-qa-violations() { 2724increment-qa-violations() {
2206 let "JAVA_PKG_QA_VIOLATIONS+=1" 2725 let "JAVA_PKG_QA_VIOLATIONS+=1"
2207 export JAVA_PKG_QA_VIOLATIONS 2726 export JAVA_PKG_QA_VIOLATIONS
2210is-java-strict() { 2729is-java-strict() {
2211 [[ -n ${JAVA_PKG_STRICT} ]] 2730 [[ -n ${JAVA_PKG_STRICT} ]]
2212 return $? 2731 return $?
2213} 2732}
2214 2733
2734[[ "${EAPI}" = "2" ]] && EXPORT_FUNCTIONS src_prepare
2735
2215# ------------------------------------------------------------------------------ 2736# ------------------------------------------------------------------------------
2216# @eclass-end 2737# @eclass-end
2217# ------------------------------------------------------------------------------ 2738# ------------------------------------------------------------------------------

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.113

  ViewVC Help
Powered by ViewVC 1.1.20