/[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.33 Revision 1.91
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.33 2006/12/07 02:27:22 flameeyes Exp $ 9# $Header: /var/cvsroot/gentoo-x86/eclass/java-utils-2.eclass,v 1.91 2007/07/20 18:36:02 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
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. At this moment it's
63# portage with phase hooks support.
64# -----------------------------------------------------------------------------
42JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1" 65JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1_pre1"
43 66
44# ----------------------------------------------------------------------------- 67# -----------------------------------------------------------------------------
45# @variable-internal JAVA_PKG_E_DEPEND 68# @variable-internal JAVA_PKG_E_DEPEND
46# 69#
47# This is a convience variable to be used from the other java eclasses. This is 70# 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 71# the version of java-config we want to use. Usually the latest stable version
49# portage, that includes phase hooks. 72# so that ebuilds can use new features without depending on specific versions.
50# ----------------------------------------------------------------------------- 73# -----------------------------------------------------------------------------
51JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.19-r1 ${JAVA_PKG_PORTAGE_DEP}" 74JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.0.33-r1 ${JAVA_PKG_PORTAGE_DEP}"
52 75
53# ----------------------------------------------------------------------------- 76# -----------------------------------------------------------------------------
54# @variable-external JAVA_PKG_ALLOW_VM_CHANGE 77# @variable-external JAVA_PKG_ALLOW_VM_CHANGE
55# @variable-default yes 78# @variable-default yes
56# 79#
130# @note This should only be used internally or for testing. 153# @note This should only be used internally or for testing.
131# @example Use jikes and javac, in that order 154# @example Use jikes and javac, in that order
132# JAVA_PKG_FORCE_COMPILER="jikes javac" 155# JAVA_PKG_FORCE_COMPILER="jikes javac"
133# ----------------------------------------------------------------------------- 156# -----------------------------------------------------------------------------
134 157
158# -----------------------------------------------------------------------------
159# @variable-external JAVA_PKG_FORCE_ANT_TASKS
160#
161# An $IFS separated list of ant tasks. Can be set in environment before calling
162# emerge/ebuild to override variables set in ebuild, mainly for testing before
163# putting the resulting (WANT_)ANT_TASKS into ebuild. Affects only ANT_TASKS in
164# eant() call, not the dependencies specified in WANT_ANT_TASKS.
165#
166# @example JAVA_PKG_FORCE_ANT_TASKS="ant-junit ant-trax" \
167# ebuild foo.ebuild compile
168#
169# @seealso WANT_ANT_TASKS
170# -----------------------------------------------------------------------------
171
135# TODO document me 172# TODO document me
136JAVA_PKG_QA_VIOLATIONS=0 173JAVA_PKG_QA_VIOLATIONS=0
137 174
138# ----------------------------------------------------------------------------- 175# -----------------------------------------------------------------------------
139# @section-end variables 176# @section-end variables
146# 183#
147# These are used to install Java-related things, such as jars, Javadocs, JNI 184# These are used to install Java-related things, such as jars, Javadocs, JNI
148# libraries, etc. 185# libraries, etc.
149# ----------------------------------------------------------------------------- 186# -----------------------------------------------------------------------------
150 187
188# -----------------------------------------------------------------------------
189# @ebuild-function java-pkg_doexamples
190#
191# Installs given arguments to /usr/share/doc/${PF}/examples
192# If you give it only one parameter and it is a directory it will install
193# everything in that directory to the examples directory.
194#
195# @example
196# java-pkg_doexamples demo
197# java-pkg_doexamples demo/* examples/*
198#
199# @param $* - list of files to install
200# ------------------------------------------------------------------------------
201java-pkg_doexamples() {
202 debug-print-function ${FUNCNAME} $*
203
204 [[ ${#} -lt 1 ]] && die "At least one argument needed"
205
206 java-pkg_check-phase install
207
208 local dest=/usr/share/doc/${PF}/examples
209 if [[ ${#} = 1 && -d ${1} ]]; then
210 ( # dont want to pollute calling env
211 insinto "${dest}"
212 doins -r ${1}/*
213 ) || die "Installing examples failed"
214 else
215 ( # dont want to pollute calling env
216 insinto "${dest}"
217 doins -r "$@"
218 ) || die "Installing examples failed"
219 fi
220}
151 221
152# ----------------------------------------------------------------------------- 222# -----------------------------------------------------------------------------
153# @ebuild-function java-pkg_dojar 223# @ebuild-function java-pkg_dojar
154# 224#
155# Installs any number of jars. 225# Installs any number of jars.
174 # Create JARDEST if it doesn't exist 244 # Create JARDEST if it doesn't exist
175 dodir ${JAVA_PKG_JARDEST} 245 dodir ${JAVA_PKG_JARDEST}
176 246
177 local jar 247 local jar
178 # for each jar 248 # for each jar
179 for jar in "$@"; do 249 for jar in "${@}"; do
180 local jar_basename=$(basename "${jar}") 250 local jar_basename=$(basename "${jar}")
181 251
182 java-pkg_check-versioned-jar ${jar_basename} 252 java-pkg_check-versioned-jar ${jar_basename}
183 253
184 # check if it exists 254 # check if it exists
185 if [[ -e "${jar}" ]] ; then 255 if [[ -e "${jar}" ]] ; then
256 # Don't overwrite if jar has already been installed with the same
257 # name
258 local dest="${D}${JAVA_PKG_JARDEST}/${jar_basename}"
259 if [[ -e "${dest}" ]]; then
260 ewarn "Overwriting ${dest}"
261 fi
262
186 # install it into JARDEST if it's a non-symlink 263 # install it into JARDEST if it's a non-symlink
187 if [[ ! -L "${jar}" ]] ; then 264 if [[ ! -L "${jar}" ]] ; then
265 #but first check class version when in strict mode.
266 is-java-strict && java-pkg_verify-classes "${jar}"
267
188 INSDESTTREE="${JAVA_PKG_JARDEST}" \ 268 INSDESTTREE="${JAVA_PKG_JARDEST}" \
189 doins "${jar}" || die "failed to install ${jar}" 269 doins "${jar}" || die "failed to install ${jar}"
190 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}" 270 java-pkg_append_ JAVA_PKG_CLASSPATH "${JAVA_PKG_JARDEST}/${jar_basename}"
191 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}" 271 debug-print "installed ${jar} to ${D}${JAVA_PKG_JARDEST}"
192 # make a symlink to the original jar if it's symlink 272 # make a symlink to the original jar if it's symlink
203 283
204 java-pkg_do_write_ 284 java-pkg_do_write_
205} 285}
206 286
207 287
288# ------------------------------------------------------------------------------
289# @internal-function depend-java-query
290#
291# Wrapper for the depend-java-query binary to enable passing USE in env.
292# Using env variables keeps this eclass working with java-config versions that
293# do not handle use flags.
294# ------------------------------------------------------------------------------
295
296depend-java-query() {
297 # Used to have a which call here but it caused endless loops for some people
298 # that had some weird bashrc voodoo for which.
299 USE="${USE}" /usr/bin/depend-java-query "${@}"
300}
208 301
209# ------------------------------------------------------------------------------ 302# ------------------------------------------------------------------------------
210# @ebuild-function java-pkg_regjar 303# @ebuild-function java-pkg_regjar
211# 304#
212# Records an already installed jar in the package.env 305# Records an already installed jar in the package.env
243 [[ ${#} -lt 1 ]] && die "at least one argument needed" 336 [[ ${#} -lt 1 ]] && die "at least one argument needed"
244 337
245 java-pkg_init_paths_ 338 java-pkg_init_paths_
246 339
247 local jar jar_dir jar_file 340 local jar jar_dir jar_file
248 for jar in "$@"; do 341 for jar in "${@}"; do
249 # TODO use java-pkg_check-versioned-jar 342 # TODO use java-pkg_check-versioned-jar
250 if [[ -e "${jar}" ]]; then 343 if [[ -e "${jar}" || -e "${D}${jar}" ]]; then
344 [[ -d "${jar}" || -d "${D}${jar}" ]] \
345 && die "Called ${FUNCNAME} on a directory $*"
346
347 #check that class version correct when in strict mode
348 is-java-strict && java-pkg_verify-classes "${jar}"
349
251 # nelchael: we should strip ${D} in this case too, here's why: 350 # nelchael: we should strip ${D} in this case too, here's why:
252 # imagine such call: 351 # imagine such call:
253 # java-pkg_regjar ${D}/opt/java/*.jar 352 # java-pkg_regjar ${D}/opt/java/*.jar
254 # such call will fall into this case (-e ${jar}) and will 353 # such call will fall into this case (-e ${jar}) and will
255 # record paths with ${D} in package.env 354 # record paths with ${D} in package.env
256 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}" 355 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
257 elif [[ -e "${D}${jar}" ]]; then
258 java-pkg_append_ JAVA_PKG_CLASSPATH "${jar#${D}}"
259 else 356 else
357 if [[ ${jar} = *\** ]]; then
358 eerror "The argument ${jar} to ${FUNCNAME}"
359 eerror "has * in it. If you want it to glob in"
360 eerror '${D} add ${D} to the argument.'
361 fi
260 die "${jar} does not exist" 362 die "${jar} does not exist"
261 fi 363 fi
262 done 364 done
263 365
264 java-pkg_do_write_ 366 java-pkg_do_write_
265} 367}
266
267 368
268# ------------------------------------------------------------------------------ 369# ------------------------------------------------------------------------------
269# @ebuild-function java-pkg_newjar 370# @ebuild-function java-pkg_newjar
270# 371#
271# Installs a jar with a new name 372# Installs a jar with a new name
282 local original_jar="${1}" 383 local original_jar="${1}"
283 local new_jar="${2:-${PN}.jar}" 384 local new_jar="${2:-${PN}.jar}"
284 local new_jar_dest="${T}/${new_jar}" 385 local new_jar_dest="${T}/${new_jar}"
285 386
286 [[ -z ${original_jar} ]] && die "Must specify a jar to install" 387 [[ -z ${original_jar} ]] && die "Must specify a jar to install"
287 [[ ! -f ${original_jar} ]] && die "${original_jar} does not exist!" 388 [[ ! -f ${original_jar} ]] \
389 && die "${original_jar} does not exist or is not a file!"
288 390
289 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}" 391 rm -f "${new_jar_dest}" || die "Failed to remove ${new_jar_dest}"
290 cp "${original_jar}" "${new_jar_dest}" \ 392 cp "${original_jar}" "${new_jar_dest}" \
291 || die "Failed to copy ${original_jar} to ${new_jar_dest}" 393 || die "Failed to copy ${original_jar} to ${new_jar_dest}"
292 java-pkg_dojar "${new_jar_dest}" 394 java-pkg_dojar "${new_jar_dest}"
341 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}" 443 java-pkg_append_ JAVA_PKG_LIBRARY "${JAVA_PKG_LIBDEST}"
342 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}" 444 debug-print "Installing ${lib} to ${JAVA_PKG_LIBDEST}"
343 # otherwise make a symlink to the symlink's origin 445 # otherwise make a symlink to the symlink's origin
344 else 446 else
345 # TODO use dosym 447 # TODO use dosym
448 ln -s "$(readlink "${lib}")" \
346 ln -s "$(readlink "${lib}")" "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")" 449 "${D}${JAVA_PKG_LIBDEST}/$(basename "${lib}")"
347 debug-print "${lib} is a symlink, linking accordanly" 450 debug-print "${lib} is a symlink, linking accordanly"
348 fi 451 fi
349 # otherwise die 452 # otherwise die
350 else 453 else
351 die "${lib} does not exist" 454 die "${lib} does not exist"
452# @example: 555# @example:
453# java-pkg_dojavadoc docs/api 556# java-pkg_dojavadoc docs/api
454# 557#
455# ------------------------------------------------------------------------------ 558# ------------------------------------------------------------------------------
456java-pkg_dojavadoc() { 559java-pkg_dojavadoc() {
560 debug-print-function ${FUNCNAME} $*
457 local dir="$1" 561 local dir="$1"
562
563 # QA checks
458 564
459 java-pkg_check-phase install 565 java-pkg_check-phase install
460 566
461 [[ -z "${dir}" ]] && die "Must specify a directory!" 567 [[ -z "${dir}" ]] && die "Must specify a directory!"
462 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!" 568 [[ ! -d "${dir}" ]] && die "${dir} does not exist, or isn't a directory!"
569 if [[ ! -e "${dir}/index.html" ]]; then
570 local msg="No index.html in javadoc directory"
571 ewarn "${msg}"
572 is-java-strict && die "${msg}"
573 fi
574
575 # Renaming to match our directory layout
463 576
464 local dir_to_install="${dir}" 577 local dir_to_install="${dir}"
465 if [[ "$(basename "${dir}")" != "api" ]]; then 578 if [[ "$(basename "${dir}")" != "api" ]]; then
466 dir_to_install="${T}/api" 579 dir_to_install="${T}/api"
467 # TODO use doins 580 # TODO use doins
468 cp -r "${dir}" "${dir_to_install}" || die "cp failed" 581 cp -r "${dir}" "${dir_to_install}" || die "cp failed"
469 fi 582 fi
583
584 # Actual installation
470 585
471 java-pkg_dohtml -r ${dir_to_install} 586 java-pkg_dohtml -r ${dir_to_install}
472} 587}
473 588
474# ------------------------------------------------------------------------------ 589# ------------------------------------------------------------------------------
492# FIXME apparently this fails if you give it an empty directories 607# FIXME apparently this fails if you give it an empty directories
493java-pkg_dosrc() { 608java-pkg_dosrc() {
494 debug-print-function ${FUNCNAME} $* 609 debug-print-function ${FUNCNAME} $*
495 610
496 [ ${#} -lt 1 ] && die "At least one argument needed" 611 [ ${#} -lt 1 ] && die "At least one argument needed"
497 if ! hasq source ${IUSE}; then
498 echo "Java QA Notice: ${FUNCNAME} called without source in IUSE"
499 fi
500 612
501 java-pkg_check-phase install 613 java-pkg_check-phase install
502 614
503 [[ ${#} -lt 1 ]] && die "At least one argument needed" 615 [[ ${#} -lt 1 ]] && die "At least one argument needed"
616
617 if ! [[ ${DEPEND} = *app-arch/zip* ]]; then
618 local msg="${FUNCNAME} called without app-arch/zip in DEPEND"
619 if is-java-strict; then
620 eerror "${msg}"
621 die "${msg}"
622 else
623 echo "${msg}"
624 echo "Please report this to http://bugs.gentoo.org."
625 fi
626 fi
504 627
505 java-pkg_init_paths_ 628 java-pkg_init_paths_
506 629
507 local zip_name="${PN}-src.zip" 630 local zip_name="${PN}-src.zip"
508 local zip_path="${T}/${zip_name}" 631 local zip_path="${T}/${zip_name}"
509 local dir 632 local dir
510 for dir in ${@}; do 633 for dir in "${@}"; do
511 local dir_parent=$(dirname "${dir}") 634 local dir_parent=$(dirname "${dir}")
512 local dir_name=$(basename "${dir}") 635 local dir_name=$(basename "${dir}")
513 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}" 636 pushd ${dir_parent} > /dev/null || die "problem entering ${dir_parent}"
514 zip -q -r ${zip_path} ${dir_name} -i '*.java' 637 zip -q -r ${zip_path} ${dir_name} -i '*.java'
515 local result=$? 638 local result=$?
540# @param $1 - filename of launcher to create 663# @param $1 - filename of launcher to create
541# @param $2 - options, as follows: 664# @param $2 - options, as follows:
542# --main the.main.class.too.start 665# --main the.main.class.too.start
543# --jar /the/jar/too/launch.jar or just <name>.jar 666# --jar /the/jar/too/launch.jar or just <name>.jar
544# --java_args 'Extra arguments to pass to java' 667# --java_args 'Extra arguments to pass to java'
545# --pkg_args 'Extra arguments too pass to the package' 668# --pkg_args 'Extra arguments to pass to the package'
546# --pwd 669# --pwd Directory the launcher changes to before executing java
547# -into 670# -into Directory to install the launcher to, instead of /usr/bin
548# -pre 671# -pre Prepend contents of this file to the launcher
549# ------------------------------------------------------------------------------ 672# ------------------------------------------------------------------------------
550java-pkg_dolauncher() { 673java-pkg_dolauncher() {
551 debug-print-function ${FUNCNAME} $* 674 debug-print-function ${FUNCNAME} $*
552 675
553 java-pkg_check-phase install 676 java-pkg_check-phase install
565 local var_tmp="${T}/launcher_variables_tmp" 688 local var_tmp="${T}/launcher_variables_tmp"
566 local target_dir pre 689 local target_dir pre
567 690
568 # Process the other the rest of the arguments 691 # Process the other the rest of the arguments
569 while [[ -n "${1}" && -n "${2}" ]]; do 692 while [[ -n "${1}" && -n "${2}" ]]; do
570 local var=${1} value=${2} 693 local var="${1}" value="${2}"
571 if [[ "${var:0:2}" == "--" ]]; then 694 if [[ "${var:0:2}" == "--" ]]; then
572 local var=${var:2} 695 local var=${var:2}
573 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}" 696 echo "gjl_${var}=\"${value}\"" >> "${var_tmp}"
574 local gjl_${var}="${value}" 697 local gjl_${var}="${value}"
575 elif [[ "${var}" == "-into" ]]; then 698 elif [[ "${var}" == "-into" ]]; then
594 fi 717 fi
595 fi 718 fi
596 719
597 # Write the actual script 720 # Write the actual script
598 echo "#!/bin/bash" > "${target}" 721 echo "#!/bin/bash" > "${target}"
599 [[ -n "${pre}" ]] && [[ -f "${pre}" ]] && cat "${pre}" >> "${target}" 722 if [[ -n "${pre}" ]]; then
723 if [[ -f "${pre}" ]]; then
724 cat "${pre}" >> "${target}"
725 else
726 die "-pre specified file '${pre}' does not exist"
727 fi
728 fi
600 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}" 729 echo "gjl_package=${JAVA_PKG_NAME}" >> "${target}"
601 cat "${var_tmp}" >> "${target}" 730 cat "${var_tmp}" >> "${target}"
602 rm -f "${var_tmp}" 731 rm -f "${var_tmp}"
603 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}" 732 echo "source /usr/share/java-config-2/launcher/launcher.bash" >> "${target}"
604 733
696# Example: get a specific jar from xerces slot 2, and name it diffrently 825# Example: get a specific jar from xerces slot 2, and name it diffrently
697# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar 826# java-pkg_jar-from xerces-2 xml-apis.jar xml.jar
698# Example: get junit.jar which is needed only for building 827# Example: get junit.jar which is needed only for building
699# java-pkg_jar-from --build-only junit junit.jar 828# java-pkg_jar-from --build-only junit junit.jar
700# 829#
701# @param $1 - (optional) "--build-only" makes the jar(s) not added into 830# @param $opt
702# package.env DEPEND line. 831# --build-only - makes the jar(s) not added into package.env DEPEND line.
703# @param $1 - Package to get jars from. 832# (assumed automatically when called inside src_test)
833# --with-dependencies - get jars also from requested package's dependencies
834# transitively.
835# --into $dir - symlink jar(s) into $dir (must exist) instead of .
836# @param $1 - Package to get jars from, or comma-separated list of packages in
837# case other parameters are not used.
704# @param $2 - jar from package. If not specified, all jars will be used. 838# @param $2 - jar from package. If not specified, all jars will be used.
705# @param $3 - When a single jar is specified, destination filename of the 839# @param $3 - When a single jar is specified, destination filename of the
706# symlink. Defaults to the name of the jar. 840# symlink. Defaults to the name of the jar.
707# ------------------------------------------------------------------------------ 841# ------------------------------------------------------------------------------
708# TODO could probably be cleaned up a little 842# TODO could probably be cleaned up a little
709java-pkg_jar-from() { 843java-pkg_jar-from() {
710 debug-print-function ${FUNCNAME} $* 844 debug-print-function ${FUNCNAME} $*
711 845
712 local build_only="" 846 local build_only=""
847 local destdir="."
848 local deep=""
713 849
850 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
851
852 while [[ "${1}" == --* ]]; do
714 if [[ "${1}" = "--build-only" ]]; then 853 if [[ "${1}" = "--build-only" ]]; then
715 build_only="true" 854 build_only="build"
855 elif [[ "${1}" = "--with-dependencies" ]]; then
856 deep="--with-dependencies"
857 elif [[ "${1}" = "--into" ]]; then
858 destdir="${2}"
859 shift
860 else
861 die "java-pkg_jar-from called with unknown parameter: ${1}"
862 fi
716 shift 863 shift
717 fi 864 done
718 865
719 local target_pkg="${1}" target_jar="${2}" destjar="${3}" 866 local target_pkg="${1}" target_jar="${2}" destjar="${3}"
720 867
721 [[ -z ${target_pkg} ]] && die "Must specify a package" 868 [[ -z ${target_pkg} ]] && die "Must specify a package"
722 869
723 # default destjar to the target jar 870 # default destjar to the target jar
724 [[ -z "${destjar}" ]] && destjar="${target_jar}" 871 [[ -z "${destjar}" ]] && destjar="${target_jar}"
725 872
726 local error_msg="There was a problem getting the classpath for ${target_pkg}." 873 local error_msg="There was a problem getting the classpath for ${target_pkg}."
727 local classpath 874 local classpath
728 classpath="$(java-config --classpath=${target_pkg})" 875 classpath="$(java-config ${deep} --classpath=${target_pkg})"
729 [[ $? != 0 ]] && die ${error_msg} 876 [[ $? != 0 ]] && die ${error_msg}
877
878 # When we have commas this functions is called to bring jars from multiple
879 # packages. This affects recording of dependencencies performed later
880 # which expects one package only, so we do it here.
881 if [[ ${target_pkg} = *,* ]]; then
882 for pkg in ${target_pkg//,/ }; do
883 java-pkg_ensure-dep "${build_only}" "${pkg}"
884 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${pkg}"
885 done
886 # setting this disables further record-jar_ calls later
887 build_only="build"
888 else
889 java-pkg_ensure-dep "${build_only}" "${target_pkg}"
890 fi
891
892 pushd ${destdir} > /dev/null \
893 || die "failed to change directory to ${destdir}"
730 894
731 local jar 895 local jar
732 for jar in ${classpath//:/ }; do 896 for jar in ${classpath//:/ }; do
733 local jar_name=$(basename "${jar}") 897 local jar_name=$(basename "${jar}")
734 if [[ ! -f "${jar}" ]] ; then 898 if [[ ! -f "${jar}" ]] ; then
745 elif [[ "${jar_name}" == "${target_jar}" ]] ; then 909 elif [[ "${jar_name}" == "${target_jar}" ]] ; then
746 [[ -f "${destjar}" ]] && rm "${destjar}" 910 [[ -f "${destjar}" ]] && rm "${destjar}"
747 ln -snf "${jar}" "${destjar}" \ 911 ln -snf "${jar}" "${destjar}" \
748 || die "Failed to make symlink from ${jar} to ${destjar}" 912 || die "Failed to make symlink from ${jar} to ${destjar}"
749 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}" 913 [[ -z "${build_only}" ]] && java-pkg_record-jar_ "${target_pkg}" "${jar}"
914 popd > /dev/null
750 return 0 915 return 0
751 fi 916 fi
752 done 917 done
918 popd > /dev/null
753 # if no target was specified, we're ok 919 # if no target was specified, we're ok
754 if [[ -z "${target_jar}" ]] ; then 920 if [[ -z "${target_jar}" ]] ; then
755 return 0 921 return 0
756 # otherwise, die bitterly 922 # otherwise, die bitterly
757 else 923 else
781# Example: Get the classpath for xerces-2 and xalan, 947# Example: Get the classpath for xerces-2 and xalan,
782# java-pkg_getjars xerces-2,xalan 948# java-pkg_getjars xerces-2,xalan
783# Example Return: 949# Example Return:
784# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar 950# /usr/share/xerces-2/lib/xml-apis.jar:/usr/share/xerces-2/lib/xmlParserAPIs.jar:/usr/share/xalan/lib/xalan.jar
785# 951#
786# @param $1 - (optional) "--build-only" makes the jar(s) not added into 952# @param $opt
787# package.env DEPEND line. 953# --build-only - makes the jar(s) not added into package.env DEPEND line.
954# (assumed automatically when called inside src_test)
955# --with-dependencies - get jars also from requested package's dependencies
956# transitively.
788# @param $2 - list of packages to get jars from 957# @param $1 - list of packages to get jars from
789# (passed to java-config --classpath) 958# (passed to java-config --classpath)
790# ------------------------------------------------------------------------------ 959# ------------------------------------------------------------------------------
791java-pkg_getjars() { 960java-pkg_getjars() {
792 debug-print-function ${FUNCNAME} $* 961 debug-print-function ${FUNCNAME} $*
793 962
794 [[ ${#} -lt 1 || ${#} -gt 2 ]] && die "${FUNCNAME} takes only one or two arguments" 963 local build_only=""
964 local deep=""
795 965
966 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
967
968 while [[ "${1}" == --* ]]; do
796 if [[ "${1}" = "--build-only" ]]; then 969 if [[ "${1}" = "--build-only" ]]; then
797 local build_only="true" 970 build_only="build"
971 elif [[ "${1}" = "--with-dependencies" ]]; then
972 deep="--with-dependencies"
973 else
974 die "java-pkg_jar-from called with unknown parameter: ${1}"
975 fi
798 shift 976 shift
799 fi 977 done
978
979 [[ ${#} -ne 1 ]] && die "${FUNCNAME} takes only one argument besides --*"
980
800 981
801 local classpath pkgs="${1}" 982 local classpath pkgs="${1}"
802 jars="$(java-config --classpath=${pkgs})" 983 jars="$(java-config ${deep} --classpath=${pkgs})"
803 [[ -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed" 984 [[ $? != 0 || -z "${jars}" ]] && die "java-config --classpath=${pkgs} failed"
804 debug-print "${pkgs}:${jars}" 985 debug-print "${pkgs}:${jars}"
986
987 for pkg in ${pkgs//,/ }; do
988 java-pkg_ensure-dep "${build_only}" "${pkg}"
989 done
805 990
806 if [[ -z "${classpath}" ]]; then 991 if [[ -z "${classpath}" ]]; then
807 classpath="${jars}" 992 classpath="${jars}"
808 else 993 else
809 classpath="${classpath}:${jars}" 994 classpath="${classpath}:${jars}"
810 fi 995 fi
811 996
812 # Only record jars that aren't build-only 997 # Only record jars that aren't build-only
813 if [[ -z "${build_only}" ]]; then 998 if [[ -z "${build_only}" ]]; then
814 oldifs="${IFS}"
815 IFS=","
816 for pkg in ${pkgs}; do 999 for pkg in ${pkgs//,/ }; do
817 java-pkg_record-jar_ "${pkg}" 1000 java-pkg_record-jar_ "${pkg}"
818 done 1001 done
819 IFS="${oldifs}"
820 fi 1002 fi
821 1003
822 echo "${classpath}" 1004 echo "${classpath}"
823} 1005}
824 1006
834# @example 1016# @example
835# java-pkg_getjar xerces-2 xml-apis.jar 1017# java-pkg_getjar xerces-2 xml-apis.jar
836# @example-return 1018# @example-return
837# /usr/share/xerces-2/lib/xml-apis.jar 1019# /usr/share/xerces-2/lib/xml-apis.jar
838# 1020#
839# @param $1 - (optional) "--build-only" makes the jar not added into 1021# @param $opt
840# package.env DEPEND line. 1022# --build-only - makes the jar not added into package.env DEPEND line.
841# @param $1 - package to use 1023# @param $1 - package to use
842# @param $2 - jar to get 1024# @param $2 - jar to get
843# ------------------------------------------------------------------------------ 1025# ------------------------------------------------------------------------------
844java-pkg_getjar() { 1026java-pkg_getjar() {
845 debug-print-function ${FUNCNAME} $* 1027 debug-print-function ${FUNCNAME} $*
846 1028
847 local build_only="" 1029 local build_only=""
848 1030
1031 [[ "${EBUILD_PHASE}" == "test" ]] && build_only="build"
1032
1033 while [[ "${1}" == --* ]]; do
849 if [[ "${1}" = "--build-only" ]]; then 1034 if [[ "${1}" = "--build-only" ]]; then
850 build_only="true" 1035 build_only="build"
1036 else
1037 die "java-pkg_jar-from called with unknown parameter: ${1}"
1038 fi
851 shift 1039 shift
852 fi 1040 done
1041
1042 [[ ${#} -ne 2 ]] && die "${FUNCNAME} takes only two arguments besides --*"
853 1043
854 local pkg="${1}" target_jar="${2}" jar 1044 local pkg="${1}" target_jar="${2}" jar
855 [[ -z ${pkg} ]] && die "Must specify package to get a jar from" 1045 [[ -z ${pkg} ]] && die "Must specify package to get a jar from"
856 [[ -z ${target_jar} ]] && die "Must specify jar to get" 1046 [[ -z ${target_jar} ]] && die "Must specify jar to get"
857 1047
858 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?" 1048 local error_msg="Could not find classpath for ${pkg}. Are you sure its installed?"
859 local classpath 1049 local classpath
860 classpath=$(java-config --classpath=${pkg}) 1050 classpath=$(java-config --classpath=${pkg})
861 [[ $? != 0 ]] && die ${error_msg} 1051 [[ $? != 0 ]] && die ${error_msg}
1052
1053 java-pkg_ensure-dep "${build_only}" "${pkg}"
862 1054
863 for jar in ${classpath//:/ }; do 1055 for jar in ${classpath//:/ }; do
864 if [[ ! -f "${jar}" ]] ; then 1056 if [[ ! -f "${jar}" ]] ; then
865 die "Installation problem with jar ${jar} in ${pkg} - is it installed?" 1057 die "Installation problem with jar ${jar} in ${pkg} - is it installed?"
866 fi 1058 fi
873 fi 1065 fi
874 done 1066 done
875 1067
876 die "Could not find ${target_jar} in ${pkg}" 1068 die "Could not find ${target_jar} in ${pkg}"
877 return 1 1069 return 1
1070}
1071
1072# ------------------------------------------------------------------------------
1073# @ebuild-function java-pkg_register-dependency
1074#
1075# Registers runtime dependency on a package, list of packages, or a single jar
1076# from a package, into package.env DEPEND line. Can only be called in
1077# src_install phase.
1078# Intended for binary packages where you don't need to symlink the jars or get
1079# their classpath during build. As such, the dependencies only need to be
1080# specified in ebuild's RDEPEND, and should be omitted in DEPEND.
1081#
1082# @param $1 - comma-separated list of packages, or a single package
1083# @param $2 - if param $1 is a single package, optionally specify the jar
1084# to depend on
1085#
1086# Example: Record the dependency on whole xerces-2 and xalan,
1087# java-pkg_register-dependency xerces-2,xalan
1088# Example: Record the dependency on ant.jar from ant-core
1089# java-pkg_register-dependency ant-core ant.jar
1090#
1091# Note: Passing both list of packages as the first parameter AND specifying the
1092# jar as the second is not allowed and will cause the function to die. We assume
1093# that there's more chance one passes such combination as a mistake, than that
1094# there are more packages providing identically named jar without class
1095# collisions.
1096# ------------------------------------------------------------------------------
1097java-pkg_register-dependency() {
1098 debug-print-function ${FUNCNAME} $*
1099
1100 java-pkg_check-phase install
1101
1102 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1103
1104 local pkgs="${1}"
1105 local jar="${2}"
1106
1107 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1108
1109 if [[ -z "${jar}" ]]; then
1110 for pkg in ${pkgs//,/ }; do
1111 java-pkg_ensure-dep runtime "${pkg}"
1112 java-pkg_record-jar_ "${pkg}"
1113 done
1114 else
1115 [[ ${pkgs} == *,* ]] && \
1116 die "${FUNCNAME} called with both package list and jar name"
1117 java-pkg_ensure-dep runtime "${pkgs}"
1118 java-pkg_record-jar_ "${pkgs}" "${jar}"
1119 fi
1120
1121 java-pkg_do_write_
1122}
1123
1124# ------------------------------------------------------------------------------
1125# @ebuild-function java-pkg_register-optional-dependency
1126#
1127# Registers optional runtime dependency on a package, list of packages, or a
1128# single jar from a package, into package.env OPTIONAL_DEPEND line. Can only be
1129# called in src_install phase.
1130# Intended for packages that can use other packages when those are in classpath.
1131# Will be put on classpath by launcher if they are installed. Typical case is
1132# JDBC implementations for various databases. It's better than having USE flag
1133# for each implementation triggering hard dependency.
1134#
1135# @param $1 - comma-separated list of packages, or a single package
1136# @param $2 - if param $1 is a single package, optionally specify the jar
1137# to depend on
1138#
1139# Example: Record the optional dependency on some jdbc providers
1140# java-pkg_register-optional-dependency jdbc-jaybird,jtds-1.2,jdbc-mysql
1141#
1142# Note: Passing both list of packages as the first parameter AND specifying the
1143# jar as the second is not allowed and will cause the function to die. We assume
1144# that there's more chance one passes such combination as a mistake, than that
1145# there are more packages providing identically named jar without class
1146# collisions.
1147# ------------------------------------------------------------------------------
1148java-pkg_register-optional-dependency() {
1149 debug-print-function ${FUNCNAME} $*
1150
1151 java-pkg_check-phase install
1152
1153 [[ ${#} -gt 2 ]] && die "${FUNCNAME} takes at most two arguments"
1154
1155 local pkgs="${1}"
1156 local jar="${2}"
1157
1158 [[ -z "${pkgs}" ]] && die "${FUNCNAME} called with no package(s) specified"
1159
1160 if [[ -z "${jar}" ]]; then
1161 for pkg in ${pkgs//,/ }; do
1162 java-pkg_record-jar_ --optional "${pkg}"
1163 done
1164 else
1165 [[ ${pkgs} == *,* ]] && \
1166 die "${FUNCNAME} called with both package list and jar name"
1167 java-pkg_record-jar_ --optional "${pkgs}" "${jar}"
1168 fi
1169
1170 java-pkg_do_write_
1171}
1172
1173# ------------------------------------------------------------------------------
1174# @ebuild-function java-pkg_register-environment-variable
1175#
1176# Register an arbitrary environment variable into package.env. The gjl launcher
1177# for this package or any package depending on this will export it into
1178# environement before executing java command.
1179# Must only be called in src_install phase.
1180#
1181# @param $1 - variable name
1182# @param $2 - variable value
1183# ------------------------------------------------------------------------------
1184JAVA_PKG_EXTRA_ENV="${T}/java-pkg-extra-env"
1185JAVA_PKG_EXTRA_ENV_VARS=""
1186java-pkg_register-environment-variable() {
1187 debug-print-function ${FUNCNAME} $*
1188
1189 java-pkg_check-phase install
1190
1191 [[ ${#} != 2 ]] && die "${FUNCNAME} takes two arguments"
1192
1193 echo "${1}=\"${2}\"" >> ${JAVA_PKG_EXTRA_ENV}
1194 JAVA_PKG_EXTRA_ENV_VARS="${JAVA_PKG_EXTRA_ENV_VARS} ${1}"
1195
1196 java-pkg_do_write_
878} 1197}
879 1198
880# This function reads stdin, and based on that input, figures out how to 1199# This function reads stdin, and based on that input, figures out how to
881# populate jars from the filesystem. 1200# populate jars from the filesystem.
882# Need to figure out a good way of making use of this, ie be able to use a 1201# Need to figure out a good way of making use of this, ie be able to use a
999# 1318#
1000# export DEPEND="${DEPEND} ${depstr}" 1319# export DEPEND="${DEPEND} ${depstr}"
1001# export RDEPEND="${RDEPEND} ${depstr}" 1320# export RDEPEND="${RDEPEND} ${depstr}"
1002#} 1321#}
1003 1322
1323# ------------------------------------------------------------------------------
1324# @ebuild-function java-pkg_find-normal-jars
1325#
1326# Find the files with suffix .jar file in the given directory or $WORKDIR
1327#
1328# @param $1 - The directory to search for jar files (default: ${WORKDIR})
1329# ------------------------------------------------------------------------------
1330java-pkg_find-normal-jars() {
1331 local dir=$1
1332 [[ "${dir}" ]] || dir="${WORKDIR}"
1333 local found
1334 for jar in $(find "${dir}" -name "*.jar" -type f); do
1335 echo "${jar}"
1336 found="true"
1337 done
1338 [[ "${found}" ]]
1339 return $?
1340}
1341
1342# ------------------------------------------------------------------------------
1343# @ebuild-function java-pkg_ensure-no-bundled-jars
1344#
1345# Try to locate bundled jar files in ${WORKDIR} and die if found.
1004# This should be used after S has been populated with symlinks to jars 1346# This function should be called after WORKDIR has been populated with symlink
1005# TODO document 1347# to system jar files or bundled jars removed.
1348# ------------------------------------------------------------------------------
1006java-pkg_ensure-no-bundled-jars() { 1349java-pkg_ensure-no-bundled-jars() {
1007 debug-print-function ${FUNCNAME} $* 1350 debug-print-function ${FUNCNAME} $*
1008 pushd ${WORKDIR} >/dev/null 2>/dev/null
1009 1351
1010 local bundled_jars=$(find . -name "*.jar" -type f) 1352 local bundled_jars=$(java-pkg_find-normal-jars)
1011 if [[ -n ${bundled_jars} ]]; then 1353 if [[ -n ${bundled_jars} ]]; then
1012 echo "Bundled jars found:" 1354 echo "Bundled jars found:"
1013 local jar 1355 local jar
1014 for jar in ${bundled_jars}; do 1356 for jar in ${bundled_jars}; do
1015 echo $(pwd)${jar/./} 1357 echo $(pwd)${jar/./}
1016 done 1358 done
1017 die "Bundled jars found!" 1359 die "Bundled jars found!"
1018
1019 fi 1360 fi
1020 popd >/dev/null 2>/dev/null
1021} 1361}
1022 1362
1023# ------------------------------------------------------------------------------ 1363# ------------------------------------------------------------------------------
1024# @internal-function java-pkg_ensure-vm-version-sufficient 1364# @internal-function java-pkg_ensure-vm-version-sufficient
1025# 1365#
1174# @ebuild-function java-pkg_get-target 1514# @ebuild-function java-pkg_get-target
1175# 1515#
1176# Determines what target version should be used, for passing to -target. 1516# Determines what target version should be used, for passing to -target.
1177# If you don't care about lower versions, you can set _WANT_TARGET to the 1517# If you don't care about lower versions, you can set _WANT_TARGET to the
1178# version of your JDK. 1518# version of your JDK.
1179# Remember doing this will mostly like cause things to break.
1180# Doesn't allow it to be lower then the one in depend.
1181# Doesn't allow it to be higher then the active vm.
1182# 1519#
1183# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET 1520# @return string - Either the lowest possible target, or JAVA_PKG_WANT_TARGET
1184# ------------------------------------------------------------------------------ 1521# ------------------------------------------------------------------------------
1185java-pkg_get-target() { 1522java-pkg_get-target() {
1186 local min=$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")
1187 if [[ -n "${JAVA_PKG_WANT_TARGET}" ]]; then
1188 local max="$(java-config --select-vm "${GENTOO_VM}" -g PROVIDES_VERSION)"
1189 if version_is_at_least "${min}" "${JAVA_PKG_WANT_TARGET}" && version_is_at_least "${JAVA_PKG_WANT_TARGET}" "${max}"; then
1190 echo ${JAVA_PKG_WANT_TARGET}
1191 else
1192 echo ${min}
1193 fi
1194 else
1195 echo ${min}
1196 fi
1197
1198 #echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND}")} 1523 echo ${JAVA_PKG_WANT_TARGET:-$(depend-java-query --get-lowest "${DEPEND} ${RDEPEND}")}
1199} 1524}
1200 1525
1201java-pkg_get-javac() { 1526java-pkg_get-javac() {
1202 debug-print-function ${FUNCNAME} $* 1527 debug-print-function ${FUNCNAME} $*
1203 1528
1292 die "No GCJ support found!" 1617 die "No GCJ support found!"
1293 fi 1618 fi
1294} 1619}
1295 1620
1296java-pkg_ensure-test() { 1621java-pkg_ensure-test() {
1297 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} && ! use test; then 1622 if hasq test ${FEATURES} && ! hasq -test ${FEATURES} \
1623 && hasq test ${IUSE} && ! use test;
1624 then
1298 eerror "You specified FEATURES=test, but USE=test is needed" 1625 eerror "You specified FEATURES=test, but USE=test is needed"
1299 eerror "to pull in the additional dependencies for testing" 1626 eerror "to pull in the additional dependencies for testing"
1300 die "Need USE=test enabled" 1627 die "Need USE=test enabled"
1301 fi 1628 fi
1302} 1629}
1303 1630
1304# ------------------------------------------------------------------------------ 1631# ------------------------------------------------------------------------------
1632# @ebuild-function java-pkg_register-ant-task
1633#
1634# Register this package as ant task, so that ant will load it when no specific
1635# ANT_TASKS are specified. Note that even without this registering, all packages
1636# specified in ANT_TASKS will be loaded. Mostly used by the actual ant tasks
1637# packages, but can be also used by other ebuilds that used to symlink their
1638# .jar into /usr/share/ant-core/lib to get autoloaded, for backwards
1639# compatibility.
1640#
1641# @param --version x.y Register only for ant version x.y (otherwise for any ant
1642# version). Used by the ant-* packages to prevent loading of mismatched
1643# ant-core ant tasks after core was updated, before the tasks are updated,
1644# without a need for blockers.
1645# @param $1 Name to register as. Defaults to JAVA_PKG_NAME ($PN[-$SLOT])
1646# ------------------------------------------------------------------------------
1647java-pkg_register-ant-task() {
1648 local TASKS_DIR="tasks"
1649
1650 # check for --version x.y parameters
1651 while [[ -n "${1}" && -n "${2}" ]]; do
1652 local var="${1#--}"
1653 local val="${2}"
1654 if [[ "${var}" == "version" ]]; then
1655 TASKS_DIR="tasks-${val}"
1656 else
1657 die "Unknown parameter passed to java-pkg_register-ant-tasks: ${1} ${2}"
1658 fi
1659 shift 2
1660 done
1661
1662 local TASK_NAME="${1:-${JAVA_PKG_NAME}}"
1663
1664 dodir /usr/share/ant/${TASKS_DIR}
1665 touch "${D}/usr/share/ant/${TASKS_DIR}/${TASK_NAME}"
1666}
1667
1668# ------------------------------------------------------------------------------
1669# @internal-function java-pkg_ant-tasks-from-deps
1670#
1671# Function to determine ANT_TASKS from DEPEND variable for backwards
1672# compatibility with ebuilds that don't set ANT_TASKS before calling eant() or
1673# WANT_ANT_TASKS before inheriting java-pkg-2. If the DEPEND string contains
1674# "dev-java/ant" or "dev-java/ant-tasks", then it returns "all", otherwise
1675# "none". It's not smart enough to cope with USE flag depends but that shouldn't
1676# be a problem, the worst it can do is activace all tasks when not needed.
1677# Note that this is called only with JAVA_PKG_STRICT=1, to find ebuilds with
1678# insufficient dependencies, otherwise all available tasks are used for
1679# backwards compatilbility.
1680#
1681# @return "all" or "none"
1682# ------------------------------------------------------------------------------
1683java-pkg_ant-tasks-from-deps() {
1684 local found_ant found_ant_tasks
1685
1686 for dep in ${DEPEND}
1687 do
1688 local ant="$(awk '/(dev-java\/ant)/ { if (match($1, "(dev-java/ant)((-[0-9])+|$)", m)) print m[1] }' <<< ${dep})"
1689 [[ "${ant}" == "dev-java/ant" ]] && found_ant=true
1690 [[ "${dep}" == *"ant-tasks"* ]] && found_ant_tasks=true
1691 done
1692
1693 if [[ -n "${found_ant}" || -n "${found_ant_tasks}" ]]; then
1694 java-pkg_announce-qa-violation --nodie "The ebuild DEPENDS on deprecated ant or ant-tasks"
1695 echo "all"
1696 else
1697 # ebuild doesn't set ANT_TASKS and doesn't depend on ant-tasks or ant
1698 # so we deactivate all tasks that may be installed
1699 echo "none"
1700 fi
1701}
1702
1703# ------------------------------------------------------------------------------
1704# @internal-function java-pkg_ant-tasks-depend
1705#
1706# Translates the WANT_ANT_TASKS variable into valid dependencies.
1707# ------------------------------------------------------------------------------
1708java-pkg_ant-tasks-depend() {
1709 debug-print-function ${FUNCNAME} ${WANT_ANT_TASKS}
1710
1711 if [[ -n "${WANT_ANT_TASKS}" ]]; then
1712 local DEP=""
1713 for i in ${WANT_ANT_TASKS}
1714 do
1715 if [[ ${i} != ant-* ]]; then
1716 echo "Invalid atom in WANT_ANT_TASKS: ${i}"
1717 return 1
1718 fi
1719 DEP="${DEP}dev-java/${i} "
1720 done
1721 echo ${DEP}
1722 return 0
1723 else
1724 return 0
1725 fi
1726}
1727
1728# ------------------------------------------------------------------------------
1729# @ebuild-function ejunit
1730#
1731# Junit wrapper function. Makes it easier to run the tests and checks for
1732# dev-java/junit in DEPEND. Launches the tests using junit.textui.TestRunner.
1733#
1734# Examples:
1735# ejunit -cp build/classes org.blinkenlights.jid3.test.AllTests
1736# ejunit org.blinkenlights.jid3.test.AllTests
1737#
1738# @param $1 - -cp or -classpath
1739# @param $2 - classpath; junit and recorded dependencies get appended
1740# @param $@ - the rest of the parameters are passed to java
1741# ------------------------------------------------------------------------------
1742ejunit() {
1743 debug-print-function ${FUNCNAME} $*
1744
1745 local pkgs
1746 for atom in $(cat ${JAVA_PKG_DEPEND_FILE} | tr : ' '); do
1747 pkgs=${pkgs},$(echo ${atom} | sed -re "s/^.*@//")
1748 done
1749
1750 local cp=$(java-pkg_getjars --with-dependencies junit${pkgs})
1751 if [[ ${1} = -cp || ${1} = -classpath ]]; then
1752 cp="${2}:${cp}"
1753 shift 2
1754 else
1755 cp=".:${cp}"
1756 fi
1757
1758 local runner=junit.textui.TestRunner
1759 debug-print "Calling: java -cp \"${cp}\" -Djava.awt.headless=true ${runner} ${@}"
1760 java -cp "${cp}" -Djava.awt.headless=true ${runner} "${@}" || die "Running junit failed"
1761}
1762
1763# ------------------------------------------------------------------------------
1305# @section-end helper 1764# @section-end helper
1306# ------------------------------------------------------------------------------ 1765# ------------------------------------------------------------------------------
1307 1766
1308# ------------------------------------------------------------------------------ 1767# ------------------------------------------------------------------------------
1309# @section-begin build 1768# @section-begin build
1315 1774
1316# ------------------------------------------------------------------------------ 1775# ------------------------------------------------------------------------------
1317# @ebuild-function eant 1776# @ebuild-function eant
1318# 1777#
1319# Ant wrapper function. Will use the appropriate compiler, based on user-defined 1778# Ant wrapper function. Will use the appropriate compiler, based on user-defined
1320# compiler. 1779# compiler. Will also set proper ANT_TASKS from the variable ANT_TASKS,
1321# 1780# variables:
1781# EANT_GENTOO_CLASSPATH - calls java-pkg_getjars for the value and adds to the
1782# gentoo.classpath property. Be sure to call
1783# java-ant_rewrite-classpath in src_unpack.
1784# *ANT_TASKS - used to determine ANT_TASKS before calling Ant.
1322# ------------------------------------------------------------------------------ 1785# ------------------------------------------------------------------------------
1323eant() { 1786eant() {
1324 debug-print-function ${FUNCNAME} $* 1787 debug-print-function ${FUNCNAME} $*
1325 1788
1326 # FIXME get this working 1789 if ! hasq java-ant-2 ${INHERITED}; then
1327# if is-java-strict && [[ ! ${DEPEND} =~ "dev-java/ant" ]]; then 1790 local msg="You should inherit java-ant-2 when using eant"
1328# java-pkg_announce-qa-violation \ 1791 java-pkg_announce-qa-violation "${msg}"
1329# "Using eant, but not depending on dev-java/ant or dev-java/ant-core"
1330# fi 1792 fi
1331 1793
1332 local antflags 1794 local antflags="-Dnoget=true -Dmaven.mode.offline=true"
1795
1333 java-pkg_init-compiler_ 1796 java-pkg_init-compiler_
1334 local compiler="${GENTOO_COMPILER}" 1797 local compiler="${GENTOO_COMPILER}"
1335 1798
1336 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}" 1799 local compiler_env="${JAVA_PKG_COMPILER_DIR}/${compiler}"
1337 1800
1339 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then 1802 if [[ "${compiler}" != "javac" && -z "${build_compiler}" ]]; then
1340 die "ANT_BUILD_COMPILER undefined in ${compiler_env}" 1803 die "ANT_BUILD_COMPILER undefined in ${compiler_env}"
1341 fi 1804 fi
1342 1805
1343 if [[ ${compiler} != "javac" ]]; then 1806 if [[ ${compiler} != "javac" ]]; then
1344 antflags="-Dbuild.compiler=${build_compiler}" 1807 antflags="${antflags} -Dbuild.compiler=${build_compiler}"
1345 # Figure out any extra stuff to put on the classpath for compilers aside 1808 # Figure out any extra stuff to put on the classpath for compilers aside
1346 # from javac 1809 # from javac
1347 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to 1810 # ANT_BUILD_COMPILER_DEPS should be something that could be passed to
1348 # java-config -p 1811 # java-config -p
1349 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})" 1812 local build_compiler_deps="$(source ${JAVA_PKG_COMPILER_DIR}/${compiler} 1>/dev/null 2>&1; echo ${ANT_BUILD_COMPILER_DEPS})"
1355 if is-java-strict; then 1818 if is-java-strict; then
1356 einfo "Disabling system classpath for ant" 1819 einfo "Disabling system classpath for ant"
1357 antflags="${antflags} -Dbuild.sysclasspath=ignore" 1820 antflags="${antflags} -Dbuild.sysclasspath=ignore"
1358 fi 1821 fi
1359 1822
1360 if [[ -n ${JAVA_PKG_DEBUG} ]]; then 1823 for arg in "${@}"; do
1361 antflags="${antflags} -debug" 1824 if [[ ${arg} = -lib ]]; then
1825 if is-java-strict; then
1826 eerror "You should not use the -lib argument to eant because it will fail"
1827 eerror "with JAVA_PKG_STRICT. Please use for example java-pkg_jar-from"
1828 eerror "or ant properties to make dependencies available."
1829 eerror "For ant tasks use WANT_ANT_TASKS or ANT_TASKS from."
1830 eerror "split ant (>=dev-java/ant-core-1.7)."
1831 die "eant -lib is deprecated/forbidden"
1832 else
1833 echo "eant -lib is deprecated. Turn JAVA_PKG_STRICT on for"
1834 echo "more info."
1835 fi
1836 fi
1837 done
1838
1839 # we use this in src_* so we run ant from /
1840 if ROOT=/ has_version ">=dev-java/ant-core-1.7.0"; then
1841 # default ANT_TASKS to WANT_ANT_TASKS, if ANT_TASKS is not set explicitly
1842 ANT_TASKS="${ANT_TASKS:-${WANT_ANT_TASKS}}"
1843
1844 # override ANT_TASKS with JAVA_PKG_FORCE_ANT_TASKS if it's set
1845 ANT_TASKS="${JAVA_PKG_FORCE_ANT_TASKS:-${ANT_TASKS}}"
1846
1847 if is-java-strict; then
1848 # if ant-tasks were not set by ebuild or forced, try to determine them from depends
1849 if [[ -z "${ANT_TASKS}" ]]; then
1850 ANT_TASKS="$(java-pkg_ant-tasks-from-deps)"
1851 fi
1852 else
1853 # if ant-tasks is not set by ebuild or forced, activate all of them
1854 ANT_TASKS="${ANT_TASKS:-all}"
1855 fi
1856
1857 # at this point, ANT_TASKS should be "all", "none" or explicit list
1858 if [[ "${ANT_TASKS}" == "all" ]]; then
1859 einfo "Using all available ANT_TASKS"
1860 elif [[ "${ANT_TASKS}" == "none" ]]; then
1861 einfo "Disabling all optional ANT_TASKS"
1862 else
1863 einfo "Using following ANT_TASKS: ${ANT_TASKS}"
1864 fi
1865
1866 export ANT_TASKS
1867 fi
1868
1869 [[ -n ${JAVA_PKG_DEBUG} ]] && antflags="${antflags} --execdebug -debug"
1870 [[ -n ${PORTAGE_QUIET} ]] && antflags="${antflags} -q"
1871
1872 local gcp="${EANT_GENTOO_CLASSPATH}"
1873 local getjarsarg=""
1874
1875 if [[ ${EBUILD_PHASE} = "test" ]]; then
1876 antflags="${antflags} -DJunit.present=true"
1877 [[ ${gcp} && ${ANT_TASKS} = *ant-junit* ]] && gcp="${gcp} junit"
1878 getjarsarg="--with-dependencies"
1879 fi
1880
1881 local cp
1882
1883 for atom in ${gcp}; do
1884 cp="${cp}:$(java-pkg_getjars ${getjarsarg} ${atom})"
1885 done
1886
1887 if [[ ${cp} ]]; then
1888 # It seems ant does not like single quotes around ${cp}
1889 antflags="${antflags} -Dgentoo.classpath=\"${cp#:}\""
1362 fi 1890 fi
1363 1891
1364 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}" 1892 [[ -n ${JAVA_PKG_DEBUG} ]] && echo ant ${antflags} "${@}"
1893 debug-print "Calling ant (GENTOO_VM: ${GENTOO_VM}): ${antflags} ${@}"
1365 ant ${antflags} "${@}" || die "eant failed" 1894 ant ${antflags} "${@}" || die "eant failed"
1366
1367} 1895}
1368 1896
1369# ------------------------------------------------------------------------------ 1897# ------------------------------------------------------------------------------
1370# @ebuild-function ejavac 1898# @ebuild-function ejavac
1371# 1899#
1440# ------------------------------------------------------------------------------ 1968# ------------------------------------------------------------------------------
1441use_doc() { 1969use_doc() {
1442 use doc && echo ${@:-javadoc} 1970 use doc && echo ${@:-javadoc}
1443} 1971}
1444 1972
1973
1445# ------------------------------------------------------------------------------ 1974# ------------------------------------------------------------------------------
1446# @section-end build 1975# @section-end build
1447# ------------------------------------------------------------------------------ 1976# ------------------------------------------------------------------------------
1448 1977
1449# ------------------------------------------------------------------------------ 1978# ------------------------------------------------------------------------------
1467# 1996#
1468# ----------------------------------------------------------------------------- 1997# -----------------------------------------------------------------------------
1469java-pkg_init() { 1998java-pkg_init() {
1470 unset JAVAC 1999 unset JAVAC
1471 unset JAVA_HOME 2000 unset JAVA_HOME
2001
2002 # People do all kinds of weird things.
2003 # http://forums.gentoo.org/viewtopic-p-3943166.html
2004 local silence="${SILENCE_JAVA_OPTIONS_WARNING}"
2005 local accept="${I_WANT_GLOBAL_JAVA_OPTIONS}"
2006 if [[ -n ${_JAVA_OPTIONS} && -z ${accept} && -z ${silence} ]]; then
2007 ewarn "_JAVA_OPTIONS changes what java -version outputs at least for"
2008 ewarn "sun-jdk vms and and as such break configure scripts that"
2009 ewarn "use it (for example app-office/openoffice) so we filter it out."
2010 ewarn "Use SILENCE_JAVA_OPTIONS_WARNING=true in the environment (use"
2011 ewarn "make.conf for example) to silence this warning or"
2012 ewarn "I_WANT_GLOBAL_JAVA_OPTIONS to not filter it."
2013 fi
2014
2015 if [[ -z ${accept} ]]; then
2016 unset _JAVA_OPTIONS
2017 # phase hooks make this run many times without this
2018 I_WANT_GLOBAL_JAVA_OPTIONS="true"
2019 fi
2020
1472 java-pkg_init_paths_ 2021 java-pkg_init_paths_
1473 java-pkg_switch-vm 2022 java-pkg_switch-vm
1474 PATH=${JAVA_HOME}/bin:${PATH} 2023 PATH=${JAVA_HOME}/bin:${PATH}
1475 2024
1476 # TODO we will probably want to set JAVAC and JAVACFLAGS 2025 # TODO we will probably want to set JAVAC and JAVACFLAGS
1481 # When users have crazy classpaths some packages can fail to compile. 2030 # When users have crazy classpaths some packages can fail to compile.
1482 # and everything should work with empty CLASSPATH. 2031 # and everything should work with empty CLASSPATH.
1483 # This also helps prevent unexpected dependencies on random things 2032 # This also helps prevent unexpected dependencies on random things
1484 # from the CLASSPATH. 2033 # from the CLASSPATH.
1485 unset CLASSPATH 2034 unset CLASSPATH
2035
2036 # Unset external ANT_ stuff
2037 unset ANT_TASKS
2038 unset ANT_OPTS
1486} 2039}
1487 2040
1488# ------------------------------------------------------------------------------ 2041# ------------------------------------------------------------------------------
1489# @function-internal java-pkg-init-compiler_ 2042# @function-internal java-pkg-init-compiler_
1490# 2043#
1634# Writes the package.env out to disk. 2187# Writes the package.env out to disk.
1635# 2188#
1636# ------------------------------------------------------------------------------ 2189# ------------------------------------------------------------------------------
1637# TODO change to do-write, to match everything else 2190# TODO change to do-write, to match everything else
1638java-pkg_do_write_() { 2191java-pkg_do_write_() {
2192 debug-print-function ${FUNCNAME} $*
1639 java-pkg_init_paths_ 2193 java-pkg_init_paths_
1640 # Create directory for package.env 2194 # Create directory for package.env
1641 dodir "${JAVA_PKG_SHAREPATH}" 2195 dodir "${JAVA_PKG_SHAREPATH}"
1642 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f "${JAVA_PKG_DEPEND}" ]]; then 2196 if [[ -n "${JAVA_PKG_CLASSPATH}" || -n "${JAVA_PKG_LIBRARY}" || -f \
2197 "${JAVA_PKG_DEPEND_FILE}" || -f \
2198 "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]]; then
1643 # Create package.env 2199 # Create package.env
1644 ( 2200 (
1645 echo "DESCRIPTION=\"${DESCRIPTION}\"" 2201 echo "DESCRIPTION=\"${DESCRIPTION}\""
1646 echo "GENERATION=\"2\"" 2202 echo "GENERATION=\"2\""
1647 2203
1648 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\"" 2204 [[ -n "${JAVA_PKG_CLASSPATH}" ]] && echo "CLASSPATH=\"${JAVA_PKG_CLASSPATH}\""
1649 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\"" 2205 [[ -n "${JAVA_PKG_LIBRARY}" ]] && echo "LIBRARY_PATH=\"${JAVA_PKG_LIBRARY}\""
1650 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\"" 2206 [[ -n "${JAVA_PROVIDE}" ]] && echo "PROVIDES=\"${JAVA_PROVIDE}\""
1651 [[ -f "${JAVA_PKG_DEPEND}" ]] && echo "DEPEND=\"$(cat ${JAVA_PKG_DEPEND} | uniq | tr '\n' ':')\"" 2207 [[ -f "${JAVA_PKG_DEPEND_FILE}" ]] \
2208 && echo "DEPEND=\"$(cat "${JAVA_PKG_DEPEND_FILE}" | uniq | tr '\n' ':')\""
2209 [[ -f "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" ]] \
2210 && echo "OPTIONAL_DEPEND=\"$(cat "${JAVA_PKG_OPTIONAL_DEPEND_FILE}" | uniq | tr '\n' ':')\""
1652 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup ! 2211 echo "VM=\"$(echo ${RDEPEND} ${DEPEND} | sed -e 's/ /\n/g' | sed -n -e '/virtual\/\(jre\|jdk\)/ { p;q }')\"" # TODO cleanup !
1653 ) > "${JAVA_PKG_ENV}" 2212 ) > "${JAVA_PKG_ENV}"
1654 2213
1655 # register target/source 2214 # register target/source
1656 local target="$(java-pkg_get-target)" 2215 local target="$(java-pkg_get-target)"
1667 2226
1668 2227
1669 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}" 2228 echo "MERGE_VM=\"${GENTOO_VM}\"" >> "${JAVA_PKG_ENV}"
1670 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}" 2229 [[ -n ${GENTOO_COMPILER} ]] && echo "MERGE_COMPILER=\"${GENTOO_COMPILER}\"" >> "${JAVA_PKG_ENV}"
1671 2230
2231 # extra env variables
2232 if [[ -n "${JAVA_PKG_EXTRA_ENV_VARS}" ]]; then
2233 cat "${JAVA_PKG_EXTRA_ENV}" >> "${JAVA_PKG_ENV}" || die
2234 # nested echo to remove leading/trailing spaces
2235 echo "ENV_VARS=\"$(echo ${JAVA_PKG_EXTRA_ENV_VARS})\"" \
2236 >> "${JAVA_PKG_ENV}" || die
2237 fi
2238
1672 # Strip unnecessary leading and trailing colons 2239 # Strip unnecessary leading and trailing colons
1673 # TODO try to cleanup if possible 2240 # TODO try to cleanup if possible
1674 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?" 2241 sed -e "s/=\":/=\"/" -e "s/:\"$/\"/" -i "${JAVA_PKG_ENV}" || die "Did you forget to call java_init ?"
2242 else
2243 debug-print "JAVA_PKG_CLASSPATH, JAVA_PKG_LIBRARY, JAVA_PKG_DEPEND_FILE"
2244 debug-print "or JAVA_PKG_OPTIONAL_DEPEND_FILE not defined so can't"
2245 debug-print "write package.env."
1675 fi 2246 fi
1676} 2247}
1677 2248
1678# ------------------------------------------------------------------------------ 2249# ------------------------------------------------------------------------------
1679# @internal-function java-pkg_record-jar_ 2250# @internal-function java-pkg_record-jar_
1680# 2251#
1681# Record a dependency to the package.env 2252# Record an (optional) dependency to the package.env
1682# 2253# @param --optional - record dependency as optional
2254# @param $1 - package to record
2255# @param $2 - (optional) jar of package to record
1683# ------------------------------------------------------------------------------ 2256# ------------------------------------------------------------------------------
1684JAVA_PKG_DEPEND="${T}/java-pkg-depend" 2257JAVA_PKG_DEPEND_FILE="${T}/java-pkg-depend"
2258JAVA_PKG_OPTIONAL_DEPEND_FILE="${T}/java-pkg-optional-depend"
1685 2259
1686java-pkg_record-jar_() { 2260java-pkg_record-jar_() {
1687 debug-print-function ${FUNCNAME} $* 2261 debug-print-function ${FUNCNAME} $*
2262
2263 local depend_file="${JAVA_PKG_DEPEND_FILE}"
2264 if [[ "${1}" == "--optional" ]]; then
2265 depend_file="${JAVA_PKG_OPTIONAL_DEPEND_FILE}"
2266 shift
2267 fi
1688 2268
1689 local pkg=${1} jar=${2} append 2269 local pkg=${1} jar=${2} append
1690 if [[ -z "${jar}" ]]; then 2270 if [[ -z "${jar}" ]]; then
1691 append="${pkg}" 2271 append="${pkg}"
1692 else 2272 else
1693 append="$(basename ${jar})@${pkg}" 2273 append="$(basename ${jar})@${pkg}"
1694 fi 2274 fi
1695 2275
1696 echo ${append} >> ${JAVA_PKG_DEPEND} 2276 echo "${append}" >> "${depend_file}"
1697} 2277}
1698 2278
1699# ------------------------------------------------------------------------------ 2279# ------------------------------------------------------------------------------
1700# @internal-function java-pkg_append_ 2280# @internal-function java-pkg_append_
1701# 2281#
1761# 2341#
1762# ------------------------------------------------------------------------------ 2342# ------------------------------------------------------------------------------
1763java-pkg_setup-vm() { 2343java-pkg_setup-vm() {
1764 debug-print-function ${FUNCNAME} $* 2344 debug-print-function ${FUNCNAME} $*
1765 2345
2346 export LANG="C" LC_ALL="C"
2347
1766 local vendor="$(java-pkg_get-vm-vendor)" 2348 local vendor="$(java-pkg_get-vm-vendor)"
1767 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then 2349 if [[ "${vendor}" == "sun" ]] && java-pkg_is-vm-version-ge "1.5" ; then
1768 addpredict "/dev/random" 2350 addpredict "/dev/random"
1769 elif [[ "${vendor}" == "ibm" ]]; then 2351 elif [[ "${vendor}" == "ibm" ]]; then
1770 addpredict "/proc/self/maps" 2352 addpredict "/proc/self/maps"
1771 addpredict "/proc/cpuinfo" 2353 addpredict "/proc/cpuinfo"
1772 export LANG="C" LC_ALL="C"
1773 elif [[ "${vendor}" == "jrockit" ]]; then 2354 elif [[ "${vendor}" == "jrockit" ]]; then
1774 addpredict "/proc/cpuinfo" 2355 addpredict "/proc/cpuinfo"
1775 fi 2356 fi
1776} 2357}
1777 2358
1832# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and 2413# Switch VM if we're allowed to (controlled by JAVA_PKG_ALLOW_VM_CHANGE), and
1833# verify that the current VM is sufficient. 2414# verify that the current VM is sufficient.
1834# Setup the environment for the VM being used. 2415# Setup the environment for the VM being used.
1835# ------------------------------------------------------------------------------ 2416# ------------------------------------------------------------------------------
1836java-pkg_switch-vm() { 2417java-pkg_switch-vm() {
2418 debug-print-function ${FUNCNAME} $*
2419
1837 if java-pkg_needs-vm; then 2420 if java-pkg_needs-vm; then
1838 # Use the VM specified by JAVA_PKG_FORCE_VM 2421 # Use the VM specified by JAVA_PKG_FORCE_VM
1839 if [[ -n ${JAVA_PKG_FORCE_VM} ]]; then 2422 if [[ -n "${JAVA_PKG_FORCE_VM}" ]]; then
1840 # If you're forcing the VM, I hope you know what your doing... 2423 # If you're forcing the VM, I hope you know what your doing...
2424 debug-print "JAVA_PKG_FORCE_VM used: ${JAVA_PKG_FORCE_VM}"
1841 export GENTOO_VM="${JAVA_PKG_FORCE_VM}" 2425 export GENTOO_VM="${JAVA_PKG_FORCE_VM}"
1842 # if we're allowed to switch the vm... 2426 # if we're allowed to switch the vm...
1843 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then 2427 elif [[ "${JAVA_PKG_ALLOW_VM_CHANGE}" == "yes" ]]; then
1844 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}" 2428 debug-print "depend-java-query: NV_DEPEND: ${JAVA_PKG_NV_DEPEND:-${DEPEND}} VNEED: ${JAVA_PKG_VNEED}"
1845 if [[ -n ${JAVA_PKG_VNEED} ]]; then 2429 if [[ -n ${JAVA_PKG_VNEED} ]]; then
1925 einfo "Classes" 2509 einfo "Classes"
1926 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR}," 2510 find "${S}" -type f -name '*.class' -print0 | xargs -0 -r -n 500 ls -ald | sed -e "s,${WORKDIR},\${WORKDIR},"
1927 fi 2511 fi
1928} 2512}
1929 2513
1930# TODO document 2514# ------------------------------------------------------------------------------
2515# @internal-function java-pkg_verify-classes
2516#
1931# Verify that the classes were compiled for the right source / target 2517# Verify that the classes were compiled for the right source / target. Dies if
2518# not.
2519# @param $1 (optional) - the file to check, otherwise checks whole ${D}
2520# ------------------------------------------------------------------------------
1932java-pkg_verify-classes() { 2521java-pkg_verify-classes() {
1933 ebegin "Verifying java class versions"
1934 #$(find ${D} -type f -name '*.jar' -o -name '*.class') 2522 #$(find ${D} -type f -name '*.jar' -o -name '*.class')
1935 class-version-verify.py -t $(java-pkg_get-target) -r ${D} 2523 local target=$(java-pkg_get-target)
2524 local result
2525 local log="${T}/class-version-verify.log"
2526 if [[ -n "${1}" ]]; then
2527 class-version-verify.py -v -t ${target} "${1}" > "${log}"
1936 result=$? 2528 result=$?
1937 eend ${result}
1938 if [[ ${result} == 0 ]]; then
1939 einfo "All good"
1940 else 2529 else
1941 ewarn "Possible problem" 2530 ebegin "Verifying java class versions (target: ${target})"
1942 die "Bad class files found" 2531 class-version-verify.py -v -t ${target} -r "${D}" > "${log}"
2532 result=$?
2533 eend ${result}
2534 fi
2535 [[ -n ${JAVA_PKG_DEBUG} ]] && cat "${log}"
2536 if [[ ${result} != 0 ]]; then
2537 eerror "Incorrect bytecode version found"
2538 [[ -n "${1}" ]] && eerror "in file: ${1}"
2539 eerror "See ${log} for more details."
2540 die "Incorrect bytecode found"
2541 fi
2542}
2543
2544# ----------------------------------------------------------------------------
2545# @internal-function java-pkg_ensure-dep
2546# Check that a package being used in jarfrom, getjars and getjar is contained
2547# within DEPEND or RDEPEND.
2548# @param $1 - empty - check both vars; "runtime" or "build" - check only
2549# RDEPEND, resp. DEPEND
2550# @param $2 - Package name and slot.
2551
2552java-pkg_ensure-dep() {
2553 debug-print-function ${FUNCNAME} $*
2554
2555 local limit_to="${1}"
2556 local target_pkg="${2}"
2557 local dev_error=""
2558
2559 local stripped_pkg=$(echo "${target_pkg}" | sed \
2560 's/-[0-9]*\(\.[0-9]\)*$//')
2561
2562 debug-print "Matching against: ${stripped_pkg}"
2563
2564 if [[ ${limit_to} != runtime && ! ( "${DEPEND}" =~ "$stripped_pkg" ) ]]; then
2565 dev_error="The ebuild is attempting to use ${target_pkg} that is not"
2566 dev_error="${dev_error} declared in DEPEND."
2567 if is-java-strict; then
2568 eerror "${dev_error}"
2569 die "${dev_error}"
2570 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2571 eerror "${dev_error}"
2572 elog "Because you have this package installed the package will"
2573 elog "build without problems, but please report this to"
2574 elog "http://bugs.gentoo.org"
2575 fi
2576 fi
2577
2578 if [[ ${limit_to} != build ]]; then
2579 if [[ ! ( ${RDEPEND} =~ "${stripped_pkg}" ) ]]; then
2580 if [[ ! ( ${PDEPEND} =~ "${stripped_pkg}" ) ]]; then
2581 dev_error="The ebuild is attempting to use ${target_pkg},"
2582 dev_error="${dev_error} without specifying --build-only, that is not declared in RDEPEND"
2583 dev_error="${dev_error} or PDEPEND."
2584 if is-java-strict; then
2585 eerror "${dev_error}"
2586 die "${dev_error}"
2587 elif [[ ${BASH_SUBSHELL} = 0 ]]; then
2588 eerror "${dev_error}"
2589 elog "The package will build without problems, but may fail to run"
2590 elog "if you don't have ${target_pkg} installed, so please report"
2591 elog "this to http://bugs.gentoo.org"
2592 fi
2593 fi
2594 fi
1943 fi 2595 fi
1944} 2596}
1945 2597
1946# ------------------------------------------------------------------------------ 2598# ------------------------------------------------------------------------------
1947# @section-end internal 2599# @section-end internal
1948# ------------------------------------------------------------------------------ 2600# ------------------------------------------------------------------------------
1949 2601
1950java-pkg_check-phase() { 2602java-pkg_check-phase() {
1951 local phase=${1} 2603 local phase=${1}
1952 local funcname=${2} 2604 local funcname=${FUNCNAME[1]}
1953 if is-java-strict && [[ ${EBUILD_PHASE} != ${phase} ]]; then 2605 if [[ ${EBUILD_PHASE} != ${phase} ]]; then
1954 java-pkg_announce-qa-violation \
1955 "${funcname} used outside of src_${phase}" 2606 local msg="${funcname} used outside of src_${phase}"
2607 java-pkg_announce-qa-violation "${msg}"
1956 fi 2608 fi
1957} 2609}
1958 2610
1959java-pkg_check-versioned-jar() { 2611java-pkg_check-versioned-jar() {
1960 local jar=${1} 2612 local jar=${1}
1969 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE" 2621 java-pkg_announce-qa-violation "deprecated USE flag 'jikes' in IUSE"
1970 fi 2622 fi
1971} 2623}
1972 2624
1973java-pkg_announce-qa-violation() { 2625java-pkg_announce-qa-violation() {
1974 if is-java-strict; then 2626 local nodie
2627 if [[ ${1} == "--nodie" ]]; then
2628 nodie="true"
2629 shift
2630 fi
1975 echo "Java QA Notice: $@" >&2 2631 echo "Java QA Notice: $@" >&2
1976 increment-qa-violations 2632 increment-qa-violations
1977 fi 2633 [[ -z "${nodie}" ]] && is-java-strict && die "${@}"
1978} 2634}
1979 2635
1980increment-qa-violations() { 2636increment-qa-violations() {
1981 let "JAVA_PKG_QA_VIOLATIONS+=1" 2637 let "JAVA_PKG_QA_VIOLATIONS+=1"
1982 export JAVA_PKG_QA_VIOLATIONS 2638 export JAVA_PKG_QA_VIOLATIONS

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.91

  ViewVC Help
Powered by ViewVC 1.1.20