/[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.38 Revision 1.96
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.38 2006/12/31 19:30:54 betelgeuse Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.96 2007/11/25 07:51:41 caster 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
36# ----------------------------------------------------------------------------- 35# -----------------------------------------------------------------------------
37 36
38# Make sure we use java-config-2 37# Make sure we use java-config-2
39export WANT_JAVA_CONFIG="2" 38export WANT_JAVA_CONFIG="2"
40 39
41# TODO document 40# -----------------------------------------------------------------------------
41# @variable-external WANT_ANT_TASKS
42# @variable-default ""
43#
44# An $IFS separated list of ant tasks.
45# Ebuild can specify this variable before inheriting java-ant-2 eclass to
46# determine ANT_TASKS it needs. They will be automatically translated to
47# DEPEND variable and ANT_TASKS variable. JAVA_PKG_FORCE_ANT_TASKS can override
48# ANT_TASKS set by WANT_ANT_TASKS, but not the DEPEND due to caching.
49# Ebuilds that need to depend conditionally on certain tasks and specify them
50# differently for different eant calls can't use this simplified approach.
51# You also cannot specify version or anything else than ant-*.
52#
53# @example WANT_ANT_TASKS="ant-junit ant-trax"
54#
55# @seealso JAVA_PKG_FORCE_ANT_TASKS
56# -----------------------------------------------------------------------------
57#WANT_ANT_TASKS
58
59# -----------------------------------------------------------------------------
60# @variable-internal JAVA_PKG_PORTAGE_DEP
61#
62# The version of portage we need to function properly. Previously it was
63# portage with phase hooks support but now we use a version with proper env
64# saving.
65# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 66JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
43 67
44# ----------------------------------------------------------------------------- 68# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 69# @variable-internal JAVA_PKG_E_DEPEND
46# 70#
47# 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
48# 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
49# portage, that includes phase hooks. 73# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 74# -----------------------------------------------------------------------------
51JAVA_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 )"
52 77
53# ----------------------------------------------------------------------------- 78# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 79# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 80# @variable-default yes
56# 81#
130# @note This should only be used internally or for testing. 155# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 156# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 157# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 158# -----------------------------------------------------------------------------
134 159
160# -----------------------------------------------------------------------------
161# @variable-external JAVA_PKG_FORCE_ANT_TASKS
162#
163# An $IFS separated list of ant tasks. Can be set in environment before calling
164# emerge/ebuild to override variables set in ebuild, mainly for testing before
165# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
166# eant() call, not the dependencies specified in WANT_ANT_TASKS.
167#
168# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
169# ebuild foo.ebuild compile
170#
171# @seealso WANT_ANT_TASKS
172# -----------------------------------------------------------------------------
173
135# TODO document me 174# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 175JAVA_PKG_QA_VIOLATIONS=0
137 176
138# ----------------------------------------------------------------------------- 177# -----------------------------------------------------------------------------
139# @section-end variables 178# @section-end variables
146# 185#
147# 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
148# libraries, etc. 187# libraries, etc.
149# ----------------------------------------------------------------------------- 188# -----------------------------------------------------------------------------
150 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}
151 230
152# ----------------------------------------------------------------------------- 231# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 232# @ebuild-function java-pkg_dojar
154# 233#
155# Installs any number of jars. 234# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 253 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 254 dodir ${JAVA_PKG_JARDEST}
176 255
177 local jar 256 local jar
178 # for each jar 257 # for each jar
179 for jar in "$@"; do 258 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 259 local jar_basename=$(basename "${jar}")
181 260
182 java-pkg_check-versioned-jar ${jar_basename} 261 java-pkg_check-versioned-jar ${jar_basename}
183 262
184 # check if it exists 263 # check if it exists
185 if [[ -e "${jar}" ]] ; then 264 if [[ -e "${jar}" ]] ; then
265 # Don't overwrite if jar has already been installed with the same
266 # name
267 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
268 if [[ -e "${dest}" ]]; then
269 ewarn "Overwriting ${dest}"
270 fi
271
186 # install it into JARDEST if it's a non-symlink 272 # install it into JARDEST if it's a non-symlink
187 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
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 277 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 278 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 279 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 280 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 281 # make a symlink to the original jar if it's symlink
212# Using env variables keeps this eclass working with java-config versions that 301# Using env variables keeps this eclass working with java-config versions that
213# do not handle use flags. 302# do not handle use flags.
214# ------------------------------------------------------------------------------ 303# ------------------------------------------------------------------------------
215 304
216depend-java-query() { 305depend-java-query() {
306 # Used to have a which call here but it caused endless loops for some people
307 # that had some weird bashrc voodoo for which.
217 USE="${USE}" $(which depend-java-query) "${@}" 308 USE="${USE}" /usr/bin/depend-java-query "${@}"
218} 309}
219 310
220# ------------------------------------------------------------------------------ 311# ------------------------------------------------------------------------------
221# @ebuild-function java-pkg_regjar 312# @ebuild-function java-pkg_regjar
222# 313#
254 [[ ${#} -lt 1 ]] && die "at least one argument needed" 345 [[ ${#} -lt 1 ]] && die "at least one argument needed"
255 346
256 java-pkg_init_paths_ 347 java-pkg_init_paths_
257 348
258 local jar jar_dir jar_file 349 local jar jar_dir jar_file
259 for jar in "$@"; do 350 for jar in "${@}"; do
260 # TODO use java-pkg_check-versioned-jar 351 # TODO use java-pkg_check-versioned-jar
261 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then 352 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
262 [[ -d "${jar}" || -d "${D}${jar}" ]] \ 353 [[ -d "${jar}" || -d "${D}${jar}" ]] \
263 && die "Called ${FUNCNAME} on a directory $*" 354 && die "Called ${FUNCNAME} on a directory $*"
355
356 #check that class version correct when in strict mode
357 is-java-strict && java-pkg_verify-classes "${jar}"
358
264 # nelchael: we should strip ${D} in this case too, here's why: 359 # nelchael: we should strip ${D} in this case too, here's why:
265 # imagine such call: 360 # imagine such call:
266 # java-pkg_regjar ${D}/opt/java/*.jar 361 # java-pkg_regjar ${D}/opt/java/*.jar
267 # such call will fall into this case (-e ${jar}) and will 362 # such call will fall into this case (-e ${jar}) and will
268 # record paths with ${D} in package.env 363 # record paths with ${D} in package.env
269 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 364 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
270 else 365 else
366 if [[ ${jar} = *\** ]]; then
367 eerror "The argument ${jar} to ${FUNCNAME}"
368 eerror "has * in it. If you want it to glob in"
369 eerror '${D} add ${D} to the argument.'
370 fi
271 die "${jar} does not exist" 371 die "${jar} does not exist"
272 fi 372 fi
273 done 373 done
274 374
275 java-pkg_do_write_ 375 java-pkg_do_write_
292 local original_jar="${1}" 392 local original_jar="${1}"
293 local new_jar="${2:-${PN}.jar}" 393 local new_jar="${2:-${PN}.jar}"
294 local new_jar_dest="${T}/${new_jar}" 394 local new_jar_dest="${T}/${new_jar}"
295 395
296 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 396 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
297 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 397 [[ ! -f ${original_jar} ]] \
398 && die "${original_jar} does not exist or is not a file!"
298 399
299 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 400 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
300 cp "${original_jar}" "${new_jar_dest}" \ 401 cp "${original_jar}" "${new_jar_dest}" \
301 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 402 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
302 java-pkg_dojar "${new_jar_dest}" 403 java-pkg_dojar "${new_jar_dest}"
351 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 452 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
352 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 453 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
353 # otherwise make a symlink to the symlink's origin 454 # otherwise make a symlink to the symlink's origin
354 else 455 else
355 # TODO use dosym 456 # TODO use dosym
457 ln -s "$(readlink "${lib}")" \
356 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 458 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
357 debug-print "${lib} is a symlink, linking accordanly" 459 debug-print "${lib} is a symlink, linking accordanly"
358 fi 460 fi
359 # otherwise die 461 # otherwise die
360 else 462 else
361 die "${lib} does not exist" 463 die "${lib} does not exist"
462# @example: 564# @example:
463# java-pkg_dojavadoc docs/api 565# java-pkg_dojavadoc docs/api
464# 566#
465# ------------------------------------------------------------------------------ 567# ------------------------------------------------------------------------------
466java-pkg_dojavadoc() { 568java-pkg_dojavadoc() {
569 debug-print-function ${FUNCNAME} $*
467 local dir="$1" 570 local dir="$1"
571
572 # QA checks
468 573
469 java-pkg_check-phase install 574 java-pkg_check-phase install
470 575
471 [[ -z "${dir}" ]] && die "Must specify a directory!" 576 [[ -z "${dir}" ]] && die "Must specify a directory!"
472 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 577 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
578 if [[ ! -e "${dir}/index.html" ]]; then
579 local msg="No index.html in javadoc directory"
580 ewarn "${msg}"
581 is-java-strict && die "${msg}"
582 fi
583
584 # Renaming to match our directory layout
473 585
474 local dir_to_install="${dir}" 586 local dir_to_install="${dir}"
475 if [[ "$(basename "${dir}")" != "api" ]]; then 587 if [[ "$(basename "${dir}")" != "api" ]]; then
476 dir_to_install="${T}/api" 588 dir_to_install="${T}/api"
477 # TODO use doins 589 # TODO use doins
478 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 590 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
479 fi 591 fi
592
593 # Actual installation
480 594
481 java-pkg_dohtml -r ${dir_to_install} 595 java-pkg_dohtml -r ${dir_to_install}
482} 596}
483 597
484# ------------------------------------------------------------------------------ 598# ------------------------------------------------------------------------------
502# FIXME apparently this fails if you give it an empty directories 616# FIXME apparently this fails if you give it an empty directories
503java-pkg_dosrc() { 617java-pkg_dosrc() {
504 debug-print-function ${FUNCNAME} $* 618 debug-print-function ${FUNCNAME} $*
505 619
506 [ ${#} -lt 1 ] && die "At least one argument needed" 620 [ ${#} -lt 1 ] && die "At least one argument needed"
507 if ! hasq source ${IUSE}; then
508 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
509 fi
510 621
511 java-pkg_check-phase install 622 java-pkg_check-phase install
512 623
513 [[ ${#} -lt 1 ]] && die "At least one argument needed" 624 [[ ${#} -lt 1 ]] && die "At least one argument needed"
625
626 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
627 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
628 if is-java-strict; then
629 eerror "${msg}"
630 die "${msg}"
631 else
632 echo "${msg}"
633 echo "Please report this to http://bugs.gentoo.org."
634 fi
635 fi
514 636
515 java-pkg_init_paths_ 637 java-pkg_init_paths_
516 638
517 local zip_name="${PN}-src.zip" 639 local zip_name="${PN}-src.zip"
518 local zip_path="${T}/${zip_name}" 640 local zip_path="${T}/${zip_name}"
519 local dir 641 local dir
520 for dir in ${@}; do 642 for dir in "${@}"; do
521 local dir_parent=$(dirname "${dir}") 643 local dir_parent=$(dirname "${dir}")
522 local dir_name=$(basename "${dir}") 644 local dir_name=$(basename "${dir}")
523 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 645 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
524 zip -q -r ${zip_path} ${dir_name} -i '*.java' 646 zip -q -r ${zip_path} ${dir_name} -i '*.java'
525 local result=$? 647 local result=$?
550# @param $1 - filename of launcher to create 672# @param $1 - filename of launcher to create
551# @param $2 - options, as follows: 673# @param $2 - options, as follows:
552# --main the.main.class.too.start 674# --main the.main.class.too.start
553# --jar /the/jar/too/launch.jar or just <name>.jar 675# --jar /the/jar/too/launch.jar or just <name>.jar
554# --java_args 'Extra arguments to pass to java' 676# --java_args 'Extra arguments to pass to java'
555# --pkg_args 'Extra arguments too pass to the package' 677# --pkg_args 'Extra arguments to pass to the package'
556# --pwd 678# --pwd Directory the launcher changes to before executing java
557# -into 679# -into Directory to install the launcher to, instead of /usr/bin
558# -pre 680# -pre Prepend contents of this file to the launcher
559# ------------------------------------------------------------------------------ 681# ------------------------------------------------------------------------------
560java-pkg_dolauncher() { 682java-pkg_dolauncher() {
561 debug-print-function ${FUNCNAME} $* 683 debug-print-function ${FUNCNAME} $*
562 684
563 java-pkg_check-phase install 685 java-pkg_check-phase install
604 fi 726 fi
605 fi 727 fi
606 728
607 # Write the actual script 729 # Write the actual script
608 echo "#!/bin/bash" > "${target}" 730 echo "#!/bin/bash" > "${target}"
609 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 731 if [[ -n "${pre}" ]]; then
732 if [[ -f "${pre}" ]]; then
733 cat "${pre}" >> "${target}"
734 else
735 die "-pre specified file '${pre}' does not exist"
736 fi
737 fi
610 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 738 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
611 cat "${var_tmp}" >> "${target}" 739 cat "${var_tmp}" >> "${target}"
612 rm -f "${var_tmp}" 740 rm -f "${var_tmp}"
613 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 741 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
614 742
706# Example: get a specific jar from xerces slot 2, and name it diffrently 834# Example: get a specific jar from xerces slot 2, and name it diffrently
707# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 835# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
708# Example: get junit.jar which is needed only for building 836# Example: get junit.jar which is needed only for building
709# java-pkg_jar-from --build-only junit junit.jar 837# java-pkg_jar-from --build-only junit junit.jar
710# 838#
711# @param $1 - (optional) "--build-only" makes the jar(s) not added into 839# @param $opt
712# package.env DEPEND line. 840# --build-only - makes the jar(s) not added into package.env DEPEND line.
713# @param $1 - Package to get jars from. 841# (assumed automatically when called inside src_test)
842# --with-dependencies - get jars also from requested package's dependencies
843# transitively.
844# --virtual - Packages passed to this function are to be handled as virtuals
845# and will not have individual jar dependencies recorded.
846# --into $dir - symlink jar(s) into $dir (must exist) instead of .
847# @param $1 - Package to get jars from, or comma-separated list of packages in
848# case other parameters are not used.
714# @param $2 - jar from package. If not specified, all jars will be used. 849# @param $2 - jar from package. If not specified, all jars will be used.
715# @param $3 - When a single jar is specified, destination filename of the 850# @param $3 - When a single jar is specified, destination filename of the
716# symlink. Defaults to the name of the jar. 851# symlink. Defaults to the name of the jar.
717# ------------------------------------------------------------------------------ 852# ------------------------------------------------------------------------------
718# TODO could probably be cleaned up a little 853# TODO could probably be cleaned up a little
719java-pkg_jar-from() { 854java-pkg_jar-from() {
720 debug-print-function ${FUNCNAME} $* 855 debug-print-function ${FUNCNAME} $*
721 856
722 local build_only="" 857 local build_only=""
858 local destdir="."
859 local deep=""
860 local virtual=""
723 861
862 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
863
864 while [[ "${1}" == --* ]]; do
724 if [[ "${1}" = "--build-only" ]]; then 865 if [[ "${1}" = "--build-only" ]]; then
725 build_only="true" 866 build_only="build"
867 elif [[ "${1}" = "--with-dependencies" ]]; then
868 deep="--with-dependencies"
869 elif [[ "${1}" = "--virtual" ]]; then
870 virtual="true"
871 elif [[ "${1}" = "--into" ]]; then
872 destdir="${2}"
873 shift
874 else
875 die "java-pkg_jar-from called with unknown parameter: ${1}"
876 fi
726 shift 877 shift
727 fi 878 done
728 879
729 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 880 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
730 881
731 [[ -z ${target_pkg} ]] && die "Must specify a package" 882 [[ -z ${target_pkg} ]] && die "Must specify a package"
732 883
733 # default destjar to the target jar 884 # default destjar to the target jar
734 [[ -z "${destjar}" ]] && destjar="${target_jar}" 885 [[ -z "${destjar}" ]] && destjar="${target_jar}"
735 886
736 local error_msg="There was a problem getting the classpath for ${target_pkg}." 887 local error_msg="There was a problem getting the classpath for ${target_pkg}."
737 local classpath 888 local classpath
738 classpath="$(java-config --classpath=${target_pkg})" 889 classpath="$(java-config ${deep} --classpath=${target_pkg})"
739 [[ $? != 0 ]] && die ${error_msg} 890 [[ $? != 0 ]] && die ${error_msg}
891
892 # When we have commas this functions is called to bring jars from multiple
893 # packages. This affects recording of dependencencies performed later
894 # which expects one package only, so we do it here.
895 if [[ ${target_pkg} = *,* ]]; then
896 for pkg in ${target_pkg//,/ }; do
897 java-pkg_ensure-dep "${build_only}" "${pkg}"
898 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
899 done
900 # setting this disables further record-jar_ calls later
901 build_only="build"
902 else
903 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
904 fi
905
906 # Record the entire virtual as a dependency so that
907 # no jars are missed.
908 if [[ -z "${build_only}" && -n "${virtual}" ]]; then
909 java-pkg_record-jar_ "${target_pkg}"
910 # setting this disables further record-jars_ calls later
911 build_only="build"
912 fi
913
914 pushd ${destdir} > /dev/null \
915 || die "failed to change directory to ${destdir}"
740 916
741 local jar 917 local jar
742 for jar in ${classpath//:/ }; do 918 for jar in ${classpath//:/ }; do
743 local jar_name=$(basename "${jar}") 919 local jar_name=$(basename "${jar}")
744 if [[ ! -f "${jar}" ]] ; then 920 if [[ ! -f "${jar}" ]] ; then
755 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 931 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
756 [[ -f "${destjar}" ]] && rm "${destjar}" 932 [[ -f "${destjar}" ]] && rm "${destjar}"
757 ln -snf "${jar}" "${destjar}" \ 933 ln -snf "${jar}" "${destjar}" \
758 || die "Failed to make symlink from ${jar} to ${destjar}" 934 || die "Failed to make symlink from ${jar} to ${destjar}"
759 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 935 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
936 popd > /dev/null
760 return 0 937 return 0
761 fi 938 fi
762 done 939 done
940 popd > /dev/null
763 # if no target was specified, we're ok 941 # if no target was specified, we're ok
764 if [[ -z "${target_jar}" ]] ; then 942 if [[ -z "${target_jar}" ]] ; then
765 return 0 943 return 0
766 # otherwise, die bitterly 944 # otherwise, die bitterly
767 else 945 else
791# Example: Get the classpath for xerces-2 and xalan, 969# Example: Get the classpath for xerces-2 and xalan,
792# java-pkg_getjars xerces-2,xalan 970# java-pkg_getjars xerces-2,xalan
793# Example Return: 971# Example Return:
794# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 972# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
795# 973#
796# @param $1 - (optional) "--build-only" makes the jar(s) not added into 974# @param $opt
797# package.env DEPEND line. 975# --build-only - makes the jar(s) not added into package.env DEPEND line.
976# (assumed automatically when called inside src_test)
977# --with-dependencies - get jars also from requested package's dependencies
978# transitively.
798# @param $2 - list of packages to get jars from 979# @param $1 - list of packages to get jars from
799# (passed to java-config --classpath) 980# (passed to java-config --classpath)
800# ------------------------------------------------------------------------------ 981# ------------------------------------------------------------------------------
801java-pkg_getjars() { 982java-pkg_getjars() {
802 debug-print-function ${FUNCNAME} $* 983 debug-print-function ${FUNCNAME} $*
803 984
985 local build_only=""
986 local deep=""
987
988 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
989
990 while [[ "${1}" == --* ]]; do
804 if [[ "${1}" = "--build-only" ]]; then 991 if [[ "${1}" = "--build-only" ]]; then
805 local build_only="true" 992 build_only="build"
993 elif [[ "${1}" = "--with-dependencies" ]]; then
994 deep="--with-dependencies"
995 else
996 die "java-pkg_jar-from called with unknown parameter: ${1}"
997 fi
806 shift 998 shift
807 fi 999 done
808 1000
809 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --build-only" 1001 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
1002
810 1003
811 local classpath pkgs="${1}" 1004 local classpath pkgs="${1}"
812 jars="$(java-config --classpath=${pkgs})" 1005 jars="$(java-config ${deep} --classpath=${pkgs})"
813 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 1006 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
814 debug-print "${pkgs}:${jars}" 1007 debug-print "${pkgs}:${jars}"
1008
1009 for pkg in ${pkgs//,/ }; do
1010 java-pkg_ensure-dep "${build_only}" "${pkg}"
1011 done
815 1012
816 if [[ -z "${classpath}" ]]; then 1013 if [[ -z "${classpath}" ]]; then
817 classpath="${jars}" 1014 classpath="${jars}"
818 else 1015 else
819 classpath="${classpath}:${jars}" 1016 classpath="${classpath}:${jars}"
820 fi 1017 fi
821 1018
822 # Only record jars that aren't build-only 1019 # Only record jars that aren't build-only
823 if [[ -z "${build_only}" ]]; then 1020 if [[ -z "${build_only}" ]]; then
824 oldifs="${IFS}"
825 IFS=","
826 for pkg in ${pkgs}; do 1021 for pkg in ${pkgs//,/ }; do
827 java-pkg_record-jar_ "${pkg}" 1022 java-pkg_record-jar_ "${pkg}"
828 done 1023 done
829 IFS="${oldifs}"
830 fi 1024 fi
831 1025
832 echo "${classpath}" 1026 echo "${classpath}"
833} 1027}
834 1028
844# @example 1038# @example
845# java-pkg_getjar xerces-2 xml-apis.jar 1039# java-pkg_getjar xerces-2 xml-apis.jar
846# @example-return 1040# @example-return
847# /usr/share/xerces-2/lib/xml-apis.jar 1041# /usr/share/xerces-2/lib/xml-apis.jar
848# 1042#
849# @param $1 - (optional) "--build-only" makes the jar not added into 1043# @param $opt
850# package.env DEPEND line. 1044# --build-only - makes the jar not added into package.env DEPEND line.
1045# --virtual - Packages passed to this function are to be handled as virtuals
1046# and will not have individual jar dependencies recorded.
851# @param $1 - package to use 1047# @param $1 - package to use
852# @param $2 - jar to get 1048# @param $2 - jar to get
853# ------------------------------------------------------------------------------ 1049# ------------------------------------------------------------------------------
854java-pkg_getjar() { 1050java-pkg_getjar() {
855 debug-print-function ${FUNCNAME} $* 1051 debug-print-function ${FUNCNAME} $*
856 1052
857 local build_only="" 1053 local build_only=""
1054 local virtual=""
858 1055
1056 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1057
1058 while [[ "${1}" == --* ]]; do
859 if [[ "${1}" = "--build-only" ]]; then 1059 if [[ "${1}" = "--build-only" ]]; then
860 build_only="true" 1060 build_only="build"
1061 elif [[ "${1}" == --* ]]; then
1062 virtual="true"
1063 else
1064 die "java-pkg_jar-from called with unknown parameter: ${1}"
1065 fi
861 shift 1066 shift
862 fi 1067 done
1068
1069 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
863 1070
864 local pkg="${1}" target_jar="${2}" jar 1071 local pkg="${1}" target_jar="${2}" jar
865 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1072 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
866 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1073 [[ -z ${target_jar} ]] && die "Must specify jar to get"
867 1074
868 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1075 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
869 local classpath 1076 local classpath
870 classpath=$(java-config --classpath=${pkg}) 1077 classpath=$(java-config --classpath=${pkg})
871 [[ $? != 0 ]] && die ${error_msg} 1078 [[ $? != 0 ]] && die ${error_msg}
1079
1080 java-pkg_ensure-dep "${build_only}" "${pkg}"
1081
1082 # Record the package(Virtual) as a dependency and then set build_only
1083 # So that individual jars are not recorded.
1084 if [[ -n "${virtual}" ]]; then
1085 java-pkg_record-jar_ "${pkg}"
1086 build_only="true"
1087 fi
872 1088
873 for jar in ${classpath//:/ }; do 1089 for jar in ${classpath//:/ }; do
874 if [[ ! -f "${jar}" ]] ; then 1090 if [[ ! -f "${jar}" ]] ; then
875 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1091 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
876 fi 1092 fi
883 fi 1099 fi
884 done 1100 done
885 1101
886 die "Could not find ${target_jar} in ${pkg}" 1102 die "Could not find ${target_jar} in ${pkg}"
887 return 1 1103 return 1
1104}
1105
1106# ------------------------------------------------------------------------------
1107# @ebuild-function java-pkg_register-dependency
1108#
1109# Registers runtime dependency on a package, list of packages, or a single jar
1110# from a package, into package.env DEPEND line. Can only be called in
1111# src_install phase.
1112# Intended for binary packages where you don't need to symlink the jars or get
1113# their classpath during build. As such, the dependencies only need to be
1114# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1115#
1116# @param $1 - comma-separated list of packages, or a single package
1117# @param $2 - if param $1 is a single package, optionally specify the jar
1118# to depend on
1119#
1120# Example: Record the dependency on whole xerces-2 and xalan,
1121# java-pkg_register-dependency xerces-2,xalan
1122# Example: Record the dependency on ant.jar from ant-core
1123# java-pkg_register-dependency ant-core ant.jar
1124#
1125# Note: Passing both list of packages as the first parameter AND specifying the
1126# jar as the second is not allowed and will cause the function to die. We assume
1127# that there's more chance one passes such combination as a mistake, than that
1128# there are more packages providing identically named jar without class
1129# collisions.
1130# ------------------------------------------------------------------------------
1131java-pkg_register-dependency() {
1132 debug-print-function ${FUNCNAME} $*
1133
1134 java-pkg_check-phase install
1135
1136 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1137
1138 local pkgs="${1}"
1139 local jar="${2}"
1140
1141 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1142
1143 if [[ -z "${jar}" ]]; then
1144 for pkg in ${pkgs//,/ }; do
1145 java-pkg_ensure-dep runtime "${pkg}"
1146 java-pkg_record-jar_ "${pkg}"
1147 done
1148 else
1149 [[ ${pkgs} == *,* ]] && \
1150 die "${FUNCNAME} called with both package list and jar name"
1151 java-pkg_ensure-dep runtime "${pkgs}"
1152 java-pkg_record-jar_ "${pkgs}" "${jar}"
1153 fi
1154
1155 java-pkg_do_write_
1156}
1157
1158# ------------------------------------------------------------------------------
1159# @ebuild-function java-pkg_register-optional-dependency
1160#
1161# Registers optional runtime dependency on a package, list of packages, or a
1162# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1163# called in src_install phase.
1164# Intended for packages that can use other packages when those are in classpath.
1165# Will be put on classpath by launcher if they are installed. Typical case is
1166# JDBC implementations for various databases. It's better than having USE flag
1167# for each implementation triggering hard dependency.
1168#
1169# @param $1 - comma-separated list of packages, or a single package
1170# @param $2 - if param $1 is a single package, optionally specify the jar
1171# to depend on
1172#
1173# Example: Record the optional dependency on some jdbc providers
1174# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1175#
1176# Note: Passing both list of packages as the first parameter AND specifying the
1177# jar as the second is not allowed and will cause the function to die. We assume
1178# that there's more chance one passes such combination as a mistake, than that
1179# there are more packages providing identically named jar without class
1180# collisions.
1181# ------------------------------------------------------------------------------
1182java-pkg_register-optional-dependency() {
1183 debug-print-function ${FUNCNAME} $*
1184
1185 java-pkg_check-phase install
1186
1187 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1188
1189 local pkgs="${1}"
1190 local jar="${2}"
1191
1192 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1193
1194 if [[ -z "${jar}" ]]; then
1195 for pkg in ${pkgs//,/ }; do
1196 java-pkg_record-jar_ --optional "${pkg}"
1197 done
1198 else
1199 [[ ${pkgs} == *,* ]] && \
1200 die "${FUNCNAME} called with both package list and jar name"
1201 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1202 fi
1203
1204 java-pkg_do_write_
1205}
1206
1207# ------------------------------------------------------------------------------
1208# @ebuild-function java-pkg_register-environment-variable
1209#
1210# Register an arbitrary environment variable into package.env. The gjl launcher
1211# for this package or any package depending on this will export it into
1212# environement before executing java command.
1213# Must only be called in src_install phase.
1214#
1215# @param $1 - variable name
1216# @param $2 - variable value
1217# ------------------------------------------------------------------------------
1218JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1219JAVA_PKG_EXTRA_ENV_VARS=""
1220java-pkg_register-environment-variable() {
1221 debug-print-function ${FUNCNAME} $*
1222
1223 java-pkg_check-phase install
1224
1225 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1226
1227 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1228 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1229
1230 java-pkg_do_write_
888} 1231}
889 1232
890# This function reads stdin, and based on that input, figures out how to 1233# This function reads stdin, and based on that input, figures out how to
891# populate jars from the filesystem. 1234# populate jars from the filesystem.
892# Need to figure out a good way of making use of this, ie be able to use a 1235# Need to figure out a good way of making use of this, ie be able to use a
1009# 1352#
1010# export DEPEND="${DEPEND} ${depstr}" 1353# export DEPEND="${DEPEND} ${depstr}"
1011# export RDEPEND="${RDEPEND} ${depstr}" 1354# export RDEPEND="${RDEPEND} ${depstr}"
1012#} 1355#}
1013 1356
1357# ------------------------------------------------------------------------------
1358# @ebuild-function java-pkg_find-normal-jars
1359#
1360# Find the files with suffix .jar file in the given directory or $WORKDIR
1361#
1362# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1363# ------------------------------------------------------------------------------
1364java-pkg_find-normal-jars() {
1365 local dir=$1
1366 [[ "${dir}" ]] || dir="${WORKDIR}"
1367 local found
1368 for jar in $(find "${dir}" -name "*.jar" -type f); do
1369 echo "${jar}"
1370 found="true"
1371 done
1372 [[ "${found}" ]]
1373 return $?
1374}
1375
1376# ------------------------------------------------------------------------------
1377# @ebuild-function java-pkg_ensure-no-bundled-jars
1378#
1379# Try to locate bundled jar files in ${WORKDIR} and die if found.
1014# This should be used after S has been populated with symlinks to jars 1380# This function should be called after WORKDIR has been populated with symlink
1015# TODO document 1381# to system jar files or bundled jars removed.
1382# ------------------------------------------------------------------------------
1016java-pkg_ensure-no-bundled-jars() { 1383java-pkg_ensure-no-bundled-jars() {
1017 debug-print-function ${FUNCNAME} $* 1384 debug-print-function ${FUNCNAME} $*
1018 pushd ${WORKDIR} >/dev/null 2>/dev/null
1019 1385
1020 local bundled_jars=$(find . -name "*.jar" -type f) 1386 local bundled_jars=$(java-pkg_find-normal-jars)
1021 if [[ -n ${bundled_jars} ]]; then 1387 if [[ -n ${bundled_jars} ]]; then
1022 echo "Bundled jars found:" 1388 echo "Bundled jars found:"
1023 local jar 1389 local jar
1024 for jar in ${bundled_jars}; do 1390 for jar in ${bundled_jars}; do
1025 echo $(pwd)${jar/./} 1391 echo $(pwd)${jar/./}
1026 done 1392 done
1027 die "Bundled jars found!" 1393 die "Bundled jars found!"
1028
1029 fi 1394 fi
1030 popd >/dev/null 2>/dev/null
1031} 1395}
1032 1396
1033# ------------------------------------------------------------------------------ 1397# ------------------------------------------------------------------------------
1034# @internal-function java-pkg_ensure-vm-version-sufficient 1398# @internal-function java-pkg_ensure-vm-version-sufficient
1035# 1399#
1297 die "Need USE=test enabled" 1661 die "Need USE=test enabled"
1298 fi 1662 fi
1299} 1663}
1300 1664
1301# ------------------------------------------------------------------------------ 1665# ------------------------------------------------------------------------------
1666# @ebuild-function java-pkg_register-ant-task
1667#
1668# Register this package as ant task, so that ant will load it when no specific
1669# ANT_TASKS are specified. Note that even without this registering, all packages
1670# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1671# packages, but can be also used by other ebuilds that used to symlink their
1672# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1673# compatibility.
1674#
1675# @param --version x.y Register only for ant version x.y (otherwise for any ant
1676# version). Used by the ant-* packages to prevent loading of mismatched
1677# ant-core ant tasks after core was updated, before the tasks are updated,
1678# without a need for blockers.
1679# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1680# ------------------------------------------------------------------------------
1681java-pkg_register-ant-task() {
1682 local TASKS_DIR="tasks"
1683
1684 # check for --version x.y parameters
1685 while [[ -n "${1}" && -n "${2}" ]]; do
1686 local var="${1#--}"
1687 local val="${2}"
1688 if [[ "${var}" == "version" ]]; then
1689 TASKS_DIR="tasks-${val}"
1690 else
1691 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1692 fi
1693 shift 2
1694 done
1695
1696 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1697
1698 dodir /usr/share/ant/${TASKS_DIR}
1699 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1700}
1701
1702# ------------------------------------------------------------------------------
1703# @internal-function java-pkg_ant-tasks-from-deps
1704#
1705# Function to determine ANT_TASKS from DEPEND variable for backwards
1706# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1707# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1708# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1709# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1710# be a problem, the worst it can do is activace all tasks when not needed.
1711# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1712# insufficient dependencies, otherwise all available tasks are used for
1713# backwards compatilbility.
1714#
1715# @return "all" or "none"
1716# ------------------------------------------------------------------------------
1717java-pkg_ant-tasks-from-deps() {
1718 local found_ant found_ant_tasks
1719
1720 for dep in ${DEPEND}
1721 do
1722 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1723 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1724 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1725 done
1726
1727 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1728 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1729 echo "all"
1730 else
1731 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1732 # so we deactivate all tasks that may be installed
1733 echo "none"
1734 fi
1735}
1736
1737# ------------------------------------------------------------------------------
1738# @internal-function java-pkg_ant-tasks-depend
1739#
1740# Translates the WANT_ANT_TASKS variable into valid dependencies.
1741# ------------------------------------------------------------------------------
1742java-pkg_ant-tasks-depend() {
1743 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1744
1745 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1746 local DEP=""
1747 for i in ${WANT_ANT_TASKS}
1748 do
1749 if [[ ${i} != ant-* ]]; then
1750 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1751 return 1
1752 fi
1753 DEP="${DEP}dev-java/${i} "
1754 done
1755 echo ${DEP}
1756 return 0
1757 else
1758 return 0
1759 fi
1760}
1761
1762# ------------------------------------------------------------------------------
1763# @ebuild-function ejunit
1764#
1765# Junit wrapper function. Makes it easier to run the tests and checks for
1766# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1767#
1768# Examples:
1769# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1770# ejunit org.blinkenlights.jid3.test.AllTests
1771#
1772# @param $1 - -cp or -classpath
1773# @param $2 - classpath; junit and recorded dependencies get appended
1774# @param $@ - the rest of the parameters are passed to java
1775# ------------------------------------------------------------------------------
1776ejunit() {
1777 debug-print-function ${FUNCNAME} $*
1778
1779 local pkgs
1780 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1781 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1782 done
1783
1784 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1785 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1786 cp="${2}:${cp}"
1787 shift 2
1788 else
1789 cp=".:${cp}"
1790 fi
1791
1792 local runner=junit.textui.TestRunner
1793 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1794 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1795}
1796
1797# ------------------------------------------------------------------------------
1302# @section-end helper 1798# @section-end helper
1303# ------------------------------------------------------------------------------ 1799# ------------------------------------------------------------------------------
1304 1800
1305# ------------------------------------------------------------------------------ 1801# ------------------------------------------------------------------------------
1306# @section-begin build 1802# @section-begin build
1312 1808
1313# ------------------------------------------------------------------------------ 1809# ------------------------------------------------------------------------------
1314# @ebuild-function eant 1810# @ebuild-function eant
1315# 1811#
1316# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1812# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1317# compiler. 1813# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1318# 1814# variables:
1815# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1816# gentoo.classpath property. Be sure to call
1817# java-ant_rewrite-classpath in src_unpack.
1818# JAVA_PKG_NO_BUNDLED_SEARCH - Don't search for bundled jars or class files
1819# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1319# ------------------------------------------------------------------------------ 1820# ------------------------------------------------------------------------------
1320eant() { 1821eant() {
1321 debug-print-function ${FUNCNAME} $* 1822 debug-print-function ${FUNCNAME} $*
1322 1823
1323 # FIXME get this working 1824 if [[ ${EBUILD_PHASE} = compile ]]; then
1324# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1825 # Used to be done in hooks in java-ant-2.eclass but moved here so that we can
1826 # finally get rid of the hooks without breaking stuff
1827
1828 [[ "${JAVA_ANT_IGNORE_SYSTEM_CLASSES}" && "${JAVA_PKG_BSFIX}" ]] \
1829 && java-ant_ignore-system-classes "${S}/build.xml"
1830
1831 if hasq java-ant-2 ${INHERITED}; then
1832 java-ant_bsfix
1833 fi
1834
1835 # eant can be called multiple times
1836 JAVA_PKG_BSFIX="off"
1837
1838 if [[ -z ${JAVA_PKG_NO_BUNDLED_SEARCH} ]] && is-java-strict; then
1839 echo "Searching for bundled jars:"
1840 java-pkg_find-normal-jars || echo "None found."
1841 echo "Searching for bundled classes (no output if none found):"
1842 find "${WORKDIR}" -name "*.class"
1843 echo "Search done."
1844 JAVA_PKG_NO_BUNDLED_SEARCH=true # eant can be called many times
1845 fi
1846 fi
1847
1848 if ! hasq java-ant-2 ${INHERITED}; then
1849 local msg="You should inherit java-ant-2 when using eant"
1325# java-pkg_announce-qa-violation \ 1850 java-pkg_announce-qa-violation "${msg}"
1326# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1327# fi 1851 fi
1328 1852
1329 local antflags="-Dnoget=true" 1853 local antflags="-Dnoget=true -Dmaven.mode.offline=true -Dbuild.sysclasspath=ignore"
1854
1330 java-pkg_init-compiler_ 1855 java-pkg_init-compiler_
1331 local compiler="${GENTOO_COMPILER}" 1856 local compiler="${GENTOO_COMPILER}"
1332 1857
1333 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1858 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1334
1335 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})" 1859 local build_compiler="$(source ${compiler_env} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER})"
1336 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1860 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1337 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1861 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1338 fi 1862 fi
1339 1863
1347 if [[ -n ${build_compiler_deps} ]]; then 1871 if [[ -n ${build_compiler_deps} ]]; then
1348 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})" 1872 antflags="${antflags} -lib $(java-config -p ${build_compiler_deps})"
1349 fi 1873 fi
1350 fi 1874 fi
1351 1875
1876 for arg in "${@}"; do
1877 if [[ ${arg} = -lib ]]; then
1878 if is-java-strict; then
1879 eerror "You should not use the -lib argument to eant because it will fail"
1880 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1881 eerror "or ant properties to make dependencies available."
1882 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1883 eerror "split ant (>=dev-java/ant-core-1.7)."
1884 die "eant -lib is deprecated/forbidden"
1885 else
1886 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1887 echo "more info."
1888 fi
1889 fi
1890 done
1891
1892 # we use this in src_* so we run ant from /
1893 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1894 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1895 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1896
1897 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1898 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1899
1352 if is-java-strict; then 1900 if is-java-strict; then
1353 einfo "Disabling system classpath for ant" 1901 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1354 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1902 if [[ -z "${ANT_TASKS}" ]]; then
1903 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1904 fi
1905 else
1906 # if ant-tasks is not set by ebuild or forced, activate all of them
1907 ANT_TASKS="${ANT_TASKS:-all}"
1355 fi 1908 fi
1356 1909
1357 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1910 # at this point, ANT_TASKS should be "all", "none" or explicit list
1358 antflags="${antflags} -debug" 1911 if [[ "${ANT_TASKS}" == "all" ]]; then
1912 einfo "Using all available ANT_TASKS"
1913 elif [[ "${ANT_TASKS}" == "none" ]]; then
1914 einfo "Disabling all optional ANT_TASKS"
1915 else
1916 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1917 fi
1918
1919 export ANT_TASKS
1920 fi
1921
1922 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1923 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1924
1925 local gcp="${EANT_GENTOO_CLASSPATH}"
1926 local getjarsarg=""
1927
1928 if [[ ${EBUILD_PHASE} = "test" ]]; then
1929 antflags="${antflags} -DJunit.present=true"
1930 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1931 getjarsarg="--with-dependencies"
1932 fi
1933
1934 local cp
1935
1936 for atom in ${gcp}; do
1937 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1938 done
1939
1940 if [[ ${cp} ]]; then
1941 # It seems ant does not like single quotes around ${cp}
1942 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1359 fi 1943 fi
1360 1944
1361 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1945 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1946 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1362 ant ${antflags} "${@}" || die "eant failed" 1947 ant ${antflags} "${@}" || die "eant failed"
1363
1364} 1948}
1365 1949
1366# ------------------------------------------------------------------------------ 1950# ------------------------------------------------------------------------------
1367# @ebuild-function ejavac 1951# @ebuild-function ejavac
1368# 1952#
1465# 2049#
1466# ----------------------------------------------------------------------------- 2050# -----------------------------------------------------------------------------
1467java-pkg_init() { 2051java-pkg_init() {
1468 unset JAVAC 2052 unset JAVAC
1469 unset JAVA_HOME 2053 unset JAVA_HOME
2054
2055 # People do all kinds of weird things.
2056 # http://forums.gentoo.org/viewtopic-p-3943166.html
2057 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2058 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2059 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2060 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2061 ewarn "sun-jdk vms and and as such break configure scripts that"
2062 ewarn "use it (for example app-office/openoffice) so we filter it out."
2063 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2064 ewarn "make.conf for example) to silence this warning or"
2065 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2066 fi
2067
2068 if [[ -z ${accept} ]]; then
2069 unset _JAVA_OPTIONS
2070 # phase hooks make this run many times without this
2071 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2072 fi
2073
2074 if java-pkg_func-exists ant_src_unpack; then
2075 java-pkg_announce-qa-violation "Using old ant_src_unpack. Should be src_unpack"
2076 fi
2077
1470 java-pkg_init_paths_ 2078 java-pkg_init_paths_
1471 java-pkg_switch-vm 2079 java-pkg_switch-vm
1472 PATH=${JAVA_HOME}/bin:${PATH} 2080 PATH=${JAVA_HOME}/bin:${PATH}
1473 2081
1474 # TODO we will probably want to set JAVAC and JAVACFLAGS 2082 # TODO we will probably want to set JAVAC and JAVACFLAGS
1479 # When users have crazy classpaths some packages can fail to compile. 2087 # When users have crazy classpaths some packages can fail to compile.
1480 # and everything should work with empty CLASSPATH. 2088 # and everything should work with empty CLASSPATH.
1481 # This also helps prevent unexpected dependencies on random things 2089 # This also helps prevent unexpected dependencies on random things
1482 # from the CLASSPATH. 2090 # from the CLASSPATH.
1483 unset CLASSPATH 2091 unset CLASSPATH
2092
2093 # Unset external ANT_ stuff
2094 unset ANT_TASKS
2095 unset ANT_OPTS
1484} 2096}
1485 2097
1486# ------------------------------------------------------------------------------ 2098# ------------------------------------------------------------------------------
1487# @function-internal java-pkg-init-compiler_ 2099# @function-internal java-pkg-init-compiler_
1488# 2100#
1610 fi 2222 fi
1611 2223
1612 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}" 2224 JAVA_PKG_SHAREPATH="${DESTTREE}/share/${JAVA_PKG_NAME}"
1613 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/" 2225 JAVA_PKG_SOURCESPATH="${JAVA_PKG_SHAREPATH}/sources/"
1614 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env" 2226 JAVA_PKG_ENV="${D}${JAVA_PKG_SHAREPATH}/package.env"
2227 JAVA_PKG_VIRTUALS_PATH="${DESTTREE}/share/java-config-2/virtuals"
2228 JAVA_PKG_VIRTUAL_PROVIDER="${D}/${JAVA_PKG_VIRTUALS_PATH}/${JAVA_PKG_NAME}"
1615 2229
1616 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib" 2230 [[ -z "${JAVA_PKG_JARDEST}" ]] && JAVA_PKG_JARDEST="${JAVA_PKG_SHAREPATH}/lib"
1617 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}" 2231 [[ -z "${JAVA_PKG_LIBDEST}" ]] && JAVA_PKG_LIBDEST="${DESTTREE}/$(get_libdir)/${JAVA_PKG_NAME}"
1618 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps" 2232 [[ -z "${JAVA_PKG_WARDEST}" ]] && JAVA_PKG_WARDEST="${JAVA_PKG_SHAREPATH}/webapps"
1619 2233
1632# Writes the package.env out to disk. 2246# Writes the package.env out to disk.
1633# 2247#
1634# ------------------------------------------------------------------------------ 2248# ------------------------------------------------------------------------------
1635# TODO change to do-write, to match everything else 2249# TODO change to do-write, to match everything else
1636java-pkg_do_write_() { 2250java-pkg_do_write_() {
2251 debug-print-function ${FUNCNAME} $*
1637 java-pkg_init_paths_ 2252 java-pkg_init_paths_
1638 # Create directory for package.env 2253 # Create directory for package.env
1639 dodir "${JAVA_PKG_SHAREPATH}" 2254 dodir "${JAVA_PKG_SHAREPATH}"
1640 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2255 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2256 "${JAVA_PKG_DEPEND_FILE}" || -f \
2257 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1641 # Create package.env 2258 # Create package.env
1642 ( 2259 (
1643 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2260 echo "DESCRIPTION=\"${DESCRIPTION}\""
1644 echo "GENERATION=\"2\"" 2261 echo "GENERATION=\"2\""
1645 2262
1646 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2263 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1647 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2264 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1648 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2265 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1649 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2266 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2267 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2268 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2269 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1650 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2270 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1651 ) > "${JAVA_PKG_ENV}" 2271 ) > "${JAVA_PKG_ENV}"
1652 2272
1653 # register target/source 2273 # register target/source
1654 local target="$(java-pkg_get-target)" 2274 local target="$(java-pkg_get-target)"
1665 2285
1666 2286
1667 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2287 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1668 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2288 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1669 2289
2290 # extra env variables
2291 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2292 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2293 # nested echo to remove leading/trailing spaces
2294 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2295 >> "${JAVA_PKG_ENV}" || die
2296 fi
2297
1670 # Strip unnecessary leading and trailing colons 2298 # Strip unnecessary leading and trailing colons
1671 # TODO try to cleanup if possible 2299 # TODO try to cleanup if possible
1672 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2300 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2301 else
2302 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2303 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2304 debug-print "write package.env."
1673 fi 2305 fi
1674} 2306}
1675 2307
1676# ------------------------------------------------------------------------------ 2308# ------------------------------------------------------------------------------
1677# @internal-function java-pkg_record-jar_ 2309# @internal-function java-pkg_record-jar_
1678# 2310#
1679# Record a dependency to the package.env 2311# Record an (optional) dependency to the package.env
1680# 2312# @param --optional - record dependency as optional
2313# @param $1 - package to record
2314# @param $2 - (optional) jar of package to record
1681# ------------------------------------------------------------------------------ 2315# ------------------------------------------------------------------------------
1682JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2316JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2317JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1683 2318
1684java-pkg_record-jar_() { 2319java-pkg_record-jar_() {
1685 debug-print-function ${FUNCNAME} $* 2320 debug-print-function ${FUNCNAME} $*
2321
2322 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2323 if [[ "${1}" == "--optional" ]]; then
2324 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2325 shift
2326 fi
1686 2327
1687 local pkg=${1} jar=${2} append 2328 local pkg=${1} jar=${2} append
1688 if [[ -z "${jar}" ]]; then 2329 if [[ -z "${jar}" ]]; then
1689 append="${pkg}" 2330 append="${pkg}"
1690 else 2331 else
1691 append="$(basename ${jar})@${pkg}" 2332 append="$(basename ${jar})@${pkg}"
1692 fi 2333 fi
1693 2334
1694 echo ${append} >> ${JAVA_PKG_DEPEND} 2335 echo "${append}" >> "${depend_file}"
1695} 2336}
1696 2337
1697# ------------------------------------------------------------------------------ 2338# ------------------------------------------------------------------------------
1698# @internal-function java-pkg_append_ 2339# @internal-function java-pkg_append_
1699# 2340#
1759# 2400#
1760# ------------------------------------------------------------------------------ 2401# ------------------------------------------------------------------------------
1761java-pkg_setup-vm() { 2402java-pkg_setup-vm() {
1762 debug-print-function ${FUNCNAME} $* 2403 debug-print-function ${FUNCNAME} $*
1763 2404
2405 export LANG="C" LC_ALL="C"
2406
1764 local vendor="$(java-pkg_get-vm-vendor)" 2407 local vendor="$(java-pkg_get-vm-vendor)"
1765 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2408 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1766 addpredict "/dev/random" 2409 addpredict "/dev/random"
1767 elif [[ "${vendor}" == "ibm" ]]; then 2410 elif [[ "${vendor}" == "ibm" ]]; then
1768 addpredict "/proc/self/maps" 2411 addpredict "/proc/self/maps"
1769 addpredict "/proc/cpuinfo" 2412 addpredict "/proc/cpuinfo"
1770 export LANG="C" LC_ALL="C"
1771 elif [[ "${vendor}" == "jrockit" ]]; then 2413 elif [[ "${vendor}" == "jrockit" ]]; then
1772 addpredict "/proc/cpuinfo" 2414 addpredict "/proc/cpuinfo"
1773 fi 2415 fi
1774} 2416}
1775 2417
1879 2521
1880 #TODO If you know a better solution let us know. 2522 #TODO If you know a better solution let us know.
1881 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)" 2523 java-pkg_append_ LD_LIBRARY_PATH "$(java-config -g LDPATH)"
1882 2524
1883 local tann="${T}/announced-vm" 2525 local tann="${T}/announced-vm"
2526 # With the hooks we should only get here once from pkg_setup but better safe than sorry
2527 # if people have for example modified eclasses some where
1884 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then 2528 if [[ -n "${JAVA_PKG_DEBUG}" ]] || [[ ! -f "${tann}" ]] ; then
1885 # Add a check for setup/preinst phase... to avoid duplicate outputs
1886 # for when FEATURES=buildpkg
1887 if [[ ${EBUILD_PHASE} != "setup" && ${EBUILD_PHASE} != "preinst" && ${EBUILD_PHASE} != "postinst" ]];
1888 then
1889 einfo "Using: $(java-config -f)" 2529 einfo "Using: $(java-config -f)"
1890 [[ ! -f "${tann}" ]] && touch "${tann}" 2530 [[ ! -f "${tann}" ]] && touch "${tann}"
1891 fi
1892 fi 2531 fi
1893 2532
1894 else 2533 else
1895 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!" 2534 [[ -n "${JAVA_PKG_DEBUG}" ]] && ewarn "!!! This package inherits java-pkg but doesn't depend on a JDK. -bin or broken dependency!!!"
1896 fi 2535 fi
1926 einfo "Classes" 2565 einfo "Classes"
1927 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2566 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1928 fi 2567 fi
1929} 2568}
1930 2569
1931# TODO document 2570# ------------------------------------------------------------------------------
2571# @internal-function java-pkg_verify-classes
2572#
1932# Verify that the classes were compiled for the right source / target 2573# Verify that the classes were compiled for the right source / target. Dies if
2574# not.
2575# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2576# ------------------------------------------------------------------------------
1933java-pkg_verify-classes() { 2577java-pkg_verify-classes() {
1934 ebegin "Verifying java class versions"
1935 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2578 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1936 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2579 local target=$(java-pkg_get-target)
2580 local result
2581 local log="${T}/class-version-verify.log"
2582 if [[ -n "${1}" ]]; then
2583 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1937 result=$? 2584 result=$?
1938 eend ${result}
1939 if [[ ${result} == 0 ]]; then
1940 einfo "All good"
1941 else 2585 else
1942 ewarn "Possible problem" 2586 ebegin "Verifying java class versions (target: ${target})"
1943 die "Bad class files found" 2587 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2588 result=$?
2589 eend ${result}
2590 fi
2591 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2592 if [[ ${result} != 0 ]]; then
2593 eerror "Incorrect bytecode version found"
2594 [[ -n "${1}" ]] && eerror "in file: ${1}"
2595 eerror "See ${log} for more details."
2596 die "Incorrect bytecode found"
2597 fi
2598}
2599
2600# ----------------------------------------------------------------------------
2601# @internal-function java-pkg_ensure-dep
2602# Check that a package being used in jarfrom, getjars and getjar is contained
2603# within DEPEND or RDEPEND.
2604# @param $1 - empty - check both vars; "runtime" or "build" - check only
2605# RDEPEND, resp. DEPEND
2606# @param $2 - Package name and slot.
2607
2608java-pkg_ensure-dep() {
2609 debug-print-function ${FUNCNAME} $*
2610
2611 local limit_to="${1}"
2612 local target_pkg="${2}"
2613 local dev_error=""
2614
2615 local stripped_pkg=$(echo "${target_pkg}" | sed \
2616 's/-[0-9]*\(\.[0-9]\)*$//')
2617
2618 debug-print "Matching against: ${stripped_pkg}"
2619
2620 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2621 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2622 dev_error="${dev_error} declared in DEPEND."
2623 if is-java-strict; then
2624 eerror "${dev_error}"
2625 die "${dev_error}"
2626 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2627 eerror "${dev_error}"
2628 elog "Because you have this package installed the package will"
2629 elog "build without problems, but please report this to"
2630 elog "http://bugs.gentoo.org"
2631 fi
2632 fi
2633
2634 if [[ ${limit_to} != build ]]; then
2635 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2636 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2637 dev_error="The ebuild is attempting to use ${target_pkg},"
2638 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2639 dev_error="${dev_error} or PDEPEND."
2640 if is-java-strict; then
2641 eerror "${dev_error}"
2642 die "${dev_error}"
2643 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2644 eerror "${dev_error}"
2645 elog "The package will build without problems, but may fail to run"
2646 elog "if you don't have ${target_pkg} installed, so please report"
2647 elog "this to http://bugs.gentoo.org"
2648 fi
2649 fi
2650 fi
1944 fi 2651 fi
1945} 2652}
1946 2653
1947# ------------------------------------------------------------------------------ 2654# ------------------------------------------------------------------------------
1948# @section-end internal 2655# @section-end internal
1949# ------------------------------------------------------------------------------ 2656# ------------------------------------------------------------------------------
1950 2657
1951java-pkg_check-phase() { 2658java-pkg_check-phase() {
1952 local phase=${1} 2659 local phase=${1}
1953 local funcname=${2} 2660 local funcname=${FUNCNAME[1]}
1954 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2661 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1955 java-pkg_announce-qa-violation \
1956 "${funcname} used outside of src_${phase}" 2662 local msg="${funcname} used outside of src_${phase}"
2663 java-pkg_announce-qa-violation "${msg}"
1957 fi 2664 fi
1958} 2665}
1959 2666
1960java-pkg_check-versioned-jar() { 2667java-pkg_check-versioned-jar() {
1961 local jar=${1} 2668 local jar=${1}
1970 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2677 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1971 fi 2678 fi
1972} 2679}
1973 2680
1974java-pkg_announce-qa-violation() { 2681java-pkg_announce-qa-violation() {
1975 if is-java-strict; then 2682 local nodie
2683 if [[ ${1} == "--nodie" ]]; then
2684 nodie="true"
2685 shift
2686 fi
1976 echo "Java QA Notice: $@" >&2 2687 echo "Java QA Notice: $@" >&2
1977 increment-qa-violations 2688 increment-qa-violations
1978 fi 2689 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1979} 2690}
1980 2691
1981increment-qa-violations() { 2692increment-qa-violations() {
1982 let "JAVA_PKG_QA_VIOLATIONS+=1" 2693 let "JAVA_PKG_QA_VIOLATIONS+=1"
1983 export JAVA_PKG_QA_VIOLATIONS 2694 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.96

  ViewVC Help
Powered by ViewVC 1.1.20